我用Spock测试Java代码.我测试这段代码:
try {
Set<String> availableActions = getSthAction()
List<String> goodActions = getGoodAction()
if (!CollectionUtils.containsAny(availableActions ,goodActions )){
throw new CustomException();
}
} catch (AnotherCustomExceptio e) {
throw new CustomException(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
我写了测试:
def "some test"() {
given:
bean.methodName(_) >> {throw new AnotherCustomExceptio ("Sth wrong")}
def order = new Order();
when:
validator.validate(order )
then:
final CustomException exception = thrown()
}
Run Code Online (Sandbox Code Playgroud)
它失败了,因为AnotherCustomExceptio抛出了.但在try{}catch块中我捕获此异常并抛出一个CustomException所以我期望我的方法将抛出CustomException而不是AnotherCustomExceptio.我该如何测试?
我想在mongo集合上创建文本索引.我写
db.test1.ensureIndex({'text':'text'})
Run Code Online (Sandbox Code Playgroud)
然后我在mongod过程中看到了
Sun Jan 5 10:08:47.289 [conn1] build index library.test1 { _fts: "text", _ftsx: 1 }
Sun Jan 5 10:09:00.220 [conn1] Index: (1/3) External Sort Progress: 200/980 20%
Sun Jan 5 10:09:13.603 [conn1] Index: (1/3) External Sort Progress: 400/980 40%
Sun Jan 5 10:09:26.745 [conn1] Index: (1/3) External Sort Progress: 600/980 61%
Sun Jan 5 10:09:37.809 [conn1] Index: (1/3) External Sort Progress: 800/980 81%
Sun Jan 5 10:09:49.344 [conn1] external sort used : 5547 files in 62 secs
Sun …Run Code Online (Sandbox Code Playgroud) 我创建如下的映射.如何将平面对象属性(如街道,城市等)映射到域对象中的嵌套地址.当我尝试我有一个错误:
[ERROR]诊断:返回类型中的未知属性"address.postalCode".@Mapping(source ="city",target ="address.city"),
@Mapper(componentModel = "spring", uses = {})
public interface CompanyMapper {
@Mappings({
@Mapping(source = "id", target = "id"),
@Mapping(source = "street", target = "address.street"),
@Mapping(source = "city", target = "address.city"),
@Mapping(source = "postalCode", target = "address.postalCode"),
@Mapping(source = "province", target = "address.province"),
})
DomainObject map(DtoObject dto);
Run Code Online (Sandbox Code Playgroud)
和班级......
public class Address {
private String street;
private Integer streetNumber;
private String city;
private String postalCode;
private String province;
//getters and setters
}
public class DomainObject {
private String id; …Run Code Online (Sandbox Code Playgroud) 我的网络服务有一个奇怪的问题.我有对象OrderPosition有一个价格(xsd:decimal,fractionDigits = 9).Apache CXF为我生成代理类,这个字段是BigDecimal.当我想发送大于10000000.00000的值时,soap消息中的这个字段有科学记数法(例如1.1423E + 7).
如何强制该值未以科学记数法发送.
我向spring mvc控制器发送请求时遇到了一些问题.我有实体:
public class Person {
private String name;
private int age;
private String city;
//..getters setters
}
Run Code Online (Sandbox Code Playgroud)
和SpringMvc控制器:
@Controller
@RequestMapping("/companies")
public class FirmaController {
@RequestMapping(value = "/addPerson", method = RequestMethod.POST, headers = {"Content-type=application/json"})
public String addPerson(@RequestBody Person person) {
return "person";
}
}
Run Code Online (Sandbox Code Playgroud)
当我想用curl向服务器发送请求时:
curl -i -X POST -HContent-Type:application/json -HAccept:application/json http://localhost:8080/api/companies/addPerson -d "{ 'name': 'Gerry', 'age': 20, 'city': 'Sydney' }"
Run Code Online (Sandbox Code Playgroud)
我有一个HTTP/1.1 400错误请求:
HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1392
Server: Jetty(8.1.10.v20130312)
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
java ×3
spring ×2
apache-kafka ×1
database ×1
groovy ×1
http ×1
json ×1
macos ×1
mapstruct ×1
mongodb ×1
nosql ×1
soap ×1
spock ×1
spring-mvc ×1
unit-testing ×1
web-services ×1
xsd ×1