forked from thingsboard/thingsboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,11 @@ public abstract class AbstractControllerTest { | |
protected static final String CUSTOMER_USER_EMAIL = "[email protected]"; | ||
private static final String CUSTOMER_USER_PASSWORD = "customer"; | ||
|
||
/** See {@link org.springframework.test.web.servlet.DefaultMvcResult#getAsyncResult(long)} | ||
* and {@link org.springframework.mock.web.MockAsyncContext#getTimeout()} | ||
*/ | ||
private static final long DEFAULT_TIMEOUT = -1L; | ||
|
||
protected MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), | ||
MediaType.APPLICATION_JSON.getSubtype(), | ||
Charset.forName("utf8")); | ||
|
@@ -336,15 +341,19 @@ protected <T> T doPost(String urlTemplate, Class<T> responseClass, String... par | |
} | ||
|
||
protected <T> T doPost(String urlTemplate, T content, Class<T> responseClass, ResultMatcher resultMatcher, String... params) throws Exception { | ||
return readResponse(doPost(urlTemplate, params).andExpect(resultMatcher), responseClass); | ||
return readResponse(doPost(urlTemplate, content, params).andExpect(resultMatcher), responseClass); | ||
} | ||
|
||
protected <T> T doPost(String urlTemplate, T content, Class<T> responseClass, String... params) throws Exception { | ||
return readResponse(doPost(urlTemplate, content, params).andExpect(status().isOk()), responseClass); | ||
} | ||
|
||
protected <T> T doPostAsync(String urlTemplate, T content, Class<T> responseClass, ResultMatcher resultMatcher, String... params) throws Exception { | ||
return readResponse(doPostAsync(urlTemplate, content, params).andExpect(resultMatcher), responseClass); | ||
return readResponse(doPostAsync(urlTemplate, content, DEFAULT_TIMEOUT, params).andExpect(resultMatcher), responseClass); | ||
} | ||
|
||
protected <T> T doPostAsync(String urlTemplate, T content, Class<T> responseClass, ResultMatcher resultMatcher, Long timeout, String... params) throws Exception { | ||
return readResponse(doPostAsync(urlTemplate, content, timeout, params).andExpect(resultMatcher), responseClass); | ||
} | ||
|
||
protected <T> T doDelete(String urlTemplate, Class<T> responseClass, String... params) throws Exception { | ||
|
@@ -366,12 +375,13 @@ protected <T> ResultActions doPost(String urlTemplate, T content, String... para | |
return mockMvc.perform(postRequest); | ||
} | ||
|
||
protected <T> ResultActions doPostAsync(String urlTemplate, T content, String... params) throws Exception { | ||
protected <T> ResultActions doPostAsync(String urlTemplate, T content, Long timeout, String... params) throws Exception { | ||
MockHttpServletRequestBuilder postRequest = post(urlTemplate); | ||
setJwtToken(postRequest); | ||
String json = json(content); | ||
postRequest.contentType(contentType).content(json); | ||
MvcResult result = mockMvc.perform(postRequest).andReturn(); | ||
result.getAsyncResult(timeout); | ||
return mockMvc.perform(asyncDispatch(result)); | ||
} | ||
|
||
|
@@ -384,8 +394,8 @@ protected ResultActions doDelete(String urlTemplate, String... params) throws Ex | |
|
||
protected void populateParams(MockHttpServletRequestBuilder request, String... params) { | ||
if (params != null && params.length > 0) { | ||
Assert.assertEquals(params.length % 2, 0); | ||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<String, String>(); | ||
Assert.assertEquals(0, params.length % 2); | ||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); | ||
for (int i = 0; i < params.length; i += 2) { | ||
paramsMap.add(params[i], params[i + 1]); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters