创建mockMvc.perform(post("/press/group").param("filterId", filterId).content(mapper.writeValueAsString(someObject)).contentType(MediaType.APPLICATION_JSON)).andDo(print());
课程并应用于MockHttpServletRequest:
HTTP Method = POST
Request URI = /press/group
Parameters = {filterId=[filterId_val]}
Headers = {}
Handler:
Type = com.yourCompany.yourController
Method = public ReturnType com.yourCompany.yourController.yourHandlerMethod(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.String)
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body = {"val1" : "val_one"}
Forwarded URL = null
Redirected URL = null
Cookies = []
字段
teststring = "Check the direction . [%~ MACRO wdwDate(date) BLOCK;
SET tmpdate = date.clone();
END ~%] Determine if both directions."
cleanM = re.compile('\[\%\~ .*? \~\%\]')
scleantext = re.sub(cleanM,'', teststring)
DateFormatterAdapter
有一个使用date
对象作为输入的方法
@XmlAccessorType(XmlAccessType.FIELD)
public class Event {
@XmlJavaTypeAdapter(DateFormatterAdapter.class)
private Date date;
private String description;
public Date getDate() {
return date;
}
public void setDate(final Date date) {
this.date = date;
}
}
private static class DateFormatterAdapter extends XmlAdapter<String, Date> {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyyy");
@Override
public Date unmarshal(final String v) throws Exception {
return dateFormat.parse(v);
}
@Override
public String marshal(final Date v) throws Exception {
return dateFormat.format(v);
}
}
我们还在pom.xml中添加了2.10.1配置以及Java XML Client Module https://github.com/stoicflame/enunciate/wiki/Module-Java-XML-Client
我们有一个集成测试类,它在EventService
中测试Event
方法。但是在添加了enunciate配置后失败并出现编译错误。在它工作正常之前
public class EventService {
public void findEvent(Event event) {
}
}
但是在运行findEvent
之后,我们在EventService
类Event中的方法setDate不能应用于给定类型;
需要[ERROR]:java.lang.String
[ERROR]发现:java.util.Date