Here are the examples of the java api org.springframework.mock.web.MockHttpServletResponse.getStatus() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
293 Examples
19
Source : PrintingResultHandler.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Print the response.
*/
protected void printResponse(MockHttpServletResponse response) throws Exception {
String body = (response.getCharacterEncoding() != null ? response.getContentreplacedtring() : MISSING_CHARACTER_ENCODING);
this.printer.printValue("Status", response.getStatus());
this.printer.printValue("Error message", response.getErrorMessage());
this.printer.printValue("Headers", getResponseHeaders(response));
this.printer.printValue("Content type", response.getContentType());
this.printer.printValue("Body", body);
this.printer.printValue("Forwarded URL", response.getForwardedUrl());
this.printer.printValue("Redirected URL", response.getRedirectedUrl());
printCookies(response.getCookies());
}
19
Source : AbstractTusExtensionIntegrationTest.java
with MIT License
from tomdesair
with MIT License
from tomdesair
protected void replacedertResponseStatus(int httpStatus) {
replacedertThat(servletResponse.getStatus(), is(httpStatus));
}
19
Source : PrintingResultHandler.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Print the response.
*/
protected void printResponse(MockHttpServletResponse response) throws Exception {
this.printer.printValue("Status", response.getStatus());
this.printer.printValue("Error message", response.getErrorMessage());
this.printer.printValue("Headers", getResponseHeaders(response));
this.printer.printValue("Content type", response.getContentType());
this.printer.printValue("Body", response.getContentreplacedtring());
this.printer.printValue("Forwarded URL", response.getForwardedUrl());
this.printer.printValue("Redirected URL", response.getRedirectedUrl());
printCookies(response.getCookies());
}
19
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenValidSessionWithIdNull_whenUpdateSession_thenRejectAnd400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/session/valid-session-with-id-null-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.put(BASE_SESSION_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(sessionService);
}
19
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenInvalidSession_whenCreateSession_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/session/invalid-session-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(BASE_SESSION_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(sessionService);
}
19
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenInvalidSession_whenUpdateSession_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/session/invalid-session-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.put(BASE_SESSION_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(sessionService);
}
19
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenBadFormattedRequest_whenCreateSession_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/session/invalid-session-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(BASE_SESSION_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(sessionService);
}
19
Source : BatchControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenValidBatchWithIdNull_whenUpdateBatch_thenRejectAnd400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/batch/valid-batchDTO-with-id-null-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.put(BASE_BATCH_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(batchService);
}
19
Source : BatchControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenInvalidBatch_whenUpdateBatch_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/batch/invalid-batch-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.put(BASE_BATCH_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(batchService);
}
19
Source : BatchControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenInvalidBatch_whenCreateBatch_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/batch/invalid-batch-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(BASE_BATCH_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(batchService);
}
19
Source : CommonServiceTest.java
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche
public void deleteUser(String userName) throws LoginException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.addHeader(CMISService.AUTHENTICATION_HEADER, cmisAuthenticatorFactory.getTicket(adminUserName, adminPreplacedword));
request.addParameter("url", "service/cnr/person/person/".concat(userName));
proxy.delete(request, response);
replacedertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
19
Source : DeleteMethodTest.java
with GNU Lesser General Public License v3.0
from Alfresco
with GNU Lesser General Public License v3.0
from Alfresco
/**
* Checks that file with the versionable aspect applied can be deleted
*
* @throws Exception
*/
@Test
public void testDeleteFileWithVersionableAspect() throws Exception {
// create file
createFileWithVersionableAscpect();
// delete file
method = new DeleteMethod();
request = new MockHttpServletRequest(WebDAV.METHOD_DELETE, "/alfresco/webdav/" + versionableDocName);
response = new MockHttpServletResponse();
request.setServerPort(8080);
request.setServletPath("/webdav");
method.setDetails(request, response, webDAVHelper, companyHomeNodeRef);
method.execute();
// check the response
replacedertEquals(HttpServletResponse.SC_OK, response.getStatus());
}
18
Source : BaseTypeConversionIT.java
with Apache License 2.0
from vaadin
with Apache License 2.0
from vaadin
protected void replacedert400ResponseWhenCallingMethod(String methodName, String requestValue) {
try {
MockHttpServletResponse response = callMethod(methodName, requestValue);
replacedert.replacedertEquals(400, response.getStatus());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
18
Source : OAuth2TokenEndpointFilterTests.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
private void doFilterWhenTokenRequestInvalidParameterThenError(String parameterName, String errorCode, MockHttpServletRequest request) throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = mock(FilterChain.clreplaced);
this.filter.doFilter(request, response, filterChain);
verifyNoInteractions(filterChain);
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
OAuth2Error error = readError(response);
replacedertThat(error.getErrorCode()).isEqualTo(errorCode);
replacedertThat(error.getDescription()).isEqualTo("OAuth 2.0 Parameter: " + parameterName);
}
18
Source : OAuth2AuthorizationEndpointFilterTests.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
private void doFilterWhenRequestInvalidParameterThenError(MockHttpServletRequest request, String parameterName, String errorCode, Consumer<MockHttpServletRequest> requestConsumer) throws Exception {
requestConsumer.accept(request);
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = mock(FilterChain.clreplaced);
this.filter.doFilter(request, response, filterChain);
verifyNoInteractions(filterChain);
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
replacedertThat(response.getErrorMessage()).isEqualTo("[" + errorCode + "] OAuth 2.0 Parameter: " + parameterName);
}
18
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenANonExistentSessionId_whenQueryBatchById_then404Status() throws Exception {
// given
UUID sessionId = UUID.randomUUID();
when(sessionService.findById(sessionId)).thenReturn(Optional.empty());
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_SESSION_URL + "/" + sessionId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
verify(sessionService).findById(sessionId);
verifyNoMoreInteractions(sessionService);
}
18
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void whenListSessions_thenReturnListAnd200Status() throws Exception {
// given
Type sessionDTOListType = new TypeToken<ArrayList<SessionDTO>>() {
}.getType();
String retrievedSessionsDTOs = MessageLoader.loadExampleRequest("requests/session/list-existent-sessionsDTOs.json");
List<SessionDTO> expectedListDTO = gson.fromJson(retrievedSessionsDTOs, sessionDTOListType);
Type sessionListType = new TypeToken<ArrayList<Session>>() {
}.getType();
String retrievedSessions = MessageLoader.loadExampleRequest("requests/session/list-existent-sessions.json");
List<Session> expectedListSession = gson.fromJson(retrievedSessions, sessionListType);
for (int i = 0; i < expectedListDTO.size(); i++) {
replacedertThat(expectedListSession.get(i).getId()).isEqualTo(expectedListDTO.get(i).getId());
}
when(sessionService.list()).thenReturn(expectedListSession);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_SESSION_URL)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(sessionService).list();
verifyNoMoreInteractions(sessionService);
String responseBody = response.getContentreplacedtring();
List<SessionDTO> receivedSessions = gson.fromJson(responseBody, sessionDTOListType);
replacedertThat(receivedSessions.size()).isEqualTo(expectedListDTO.size());
}
18
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenAnExistentBatchIdWithreplacedociatedSessions_whenListSessions_thenReturnListAnd200Status() throws Exception {
// given
Type sessionDTOListType = new TypeToken<ArrayList<SessionDTO>>() {
}.getType();
String retrievedSessionsDTOs = MessageLoader.loadExampleRequest("requests/session/list-existent-sessionsDTOs.json");
List<SessionDTO> expectedListDTO = gson.fromJson(retrievedSessionsDTOs, sessionDTOListType);
Type sessionListType = new TypeToken<ArrayList<Session>>() {
}.getType();
String retrievedSessions = MessageLoader.loadExampleRequest("requests/session/list-existent-sessions.json");
List<Session> expectedListSession = gson.fromJson(retrievedSessions, sessionListType);
UUID batchId = expectedListSession.get(0).getId();
for (int i = 0; i < expectedListDTO.size(); i++) {
replacedertThat(expectedListSession.get(i).getId()).isEqualTo(expectedListDTO.get(i).getId());
}
when(sessionService.findByBatch(batchId)).thenReturn(expectedListSession);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_SESSION_URL + "/batch/" + batchId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(sessionService).findByBatch(batchId);
String responseBody = response.getContentreplacedtring();
List<SessionDTO> receivedSessionsDTO = gson.fromJson(responseBody, sessionDTOListType);
replacedert.replacedertEquals(receivedSessionsDTO, expectedListDTO);
}
18
Source : DeliverableControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenAnExistentDeliverableId_whenDelete_then200Status() throws Exception {
// given
UUID deliverableId = UUID.randomUUID();
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.delete(BASE_DELIVERABLE_URL + "/" + deliverableId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(deliverableService).delete(deliverableId);
verifyNoMoreInteractions(deliverableService);
}
18
Source : BatchControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void whenListBatches_thenReturnListAnd200Status() throws Exception {
// given
Type batchDTOListType = new TypeToken<ArrayList<BatchDTO>>() {
}.getType();
String retrievedBatchesDTO = MessageLoader.loadExampleRequest("requests/batch/list-existent-batchesDTOs.json");
List<BatchDTO> expectedListDTO = gson.fromJson(retrievedBatchesDTO, batchDTOListType);
Type batchListType = new TypeToken<ArrayList<Batch>>() {
}.getType();
String retrievedBatches = MessageLoader.loadExampleRequest("requests/batch/list-existent-batches.json");
List<Batch> expectedList = gson.fromJson(retrievedBatches, batchListType);
for (int i = 0; i < expectedListDTO.size(); i++) {
replacedertThat(expectedList.get(i).getId()).isEqualTo(expectedListDTO.get(i).getId());
}
when(batchService.list()).thenReturn(expectedList);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_BATCH_URL)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(batchService).list();
verifyNoMoreInteractions(batchService);
String responseBody = response.getContentreplacedtring();
List<BatchDTO> receivedBatchesDTO = gson.fromJson(responseBody, batchDTOListType);
replacedertThat(receivedBatchesDTO).isEqualTo(expectedListDTO);
}
18
Source : BatchControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenAnNonExistentBatchId_whenQueryBatchById_then404Status() throws Exception {
// given
UUID batchId = UUID.randomUUID();
when(batchService.findById(batchId)).thenReturn(Optional.empty());
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_BATCH_URL + "/" + batchId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
verify(batchService).findById(batchId);
verifyNoMoreInteractions(batchService);
}
18
Source : HttpRangeProcessorTest.java
with GNU Lesser General Public License v3.0
from Alfresco
with GNU Lesser General Public License v3.0
from Alfresco
protected void testRange(String range, int expectedStatus) throws IOException {
MockHttpServletResponse response = new MockHttpServletResponse();
boolean result = httpRangeProcessor.processRange(response, reader, range, null, null, null, null);
replacedertTrue(result);
replacedertEquals(expectedStatus, response.getStatus());
reader.getContentInputStream().close();
}
17
Source : TopicControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
@Test
public void testTopicClose() throws Exception {
String url = "/topic/close?brokerId=" + brokerIdMap.get("brokerId") + "&topic=com.weevent.rest&groupId=1";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
String contentreplacedtring = response.getContentreplacedtring();
replacedert.replacedertEquals(Boolean.valueOf(contentreplacedtring), true);
}
17
Source : TopicControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
public void testTopicOpen() throws Exception {
String content = "{\"brokerId\":\"" + this.brokerIdMap.get("brokerId") + "\",\"topic\":\"com.weevent.rest\",\"userId\":\"1\",\"creater\":\"1\",\"groupId\":\"1\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/topic/openTopic").contentType(MediaType.APPLICATION_JSON_UTF8).content(content).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
}
17
Source : RuleEngineControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
// add broker
public void addBroker() throws Exception {
String content = "{\"name\":\"broker2\",\"brokerUrl\":\"" + this.brokerUrl + "\",\"userId\":\"1\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/broker/add").contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token).content(content)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
GovernanceResult<?> governanceResponse = JsonHelper.json2Object(response.getContentreplacedtring(), GovernanceResult.clreplaced);
ruleMap.put("brokerId", (Integer) governanceResponse.getData());
}
17
Source : FileControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
private void closeTopic() throws Exception {
String url = "/topic/close?brokerId=" + brokerIdMap.get("brokerId") + "&topic=" + this.senderTransport + "&groupId=1";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
String contentreplacedtring = response.getContentreplacedtring();
replacedert.replacedertEquals(Boolean.valueOf(contentreplacedtring), true);
url = "/topic/close?brokerId=" + brokerIdMap.get("brokerId") + "&topic=" + this.receiverTransport + "&groupId=1";
response = mockMvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
contentreplacedtring = response.getContentreplacedtring();
replacedert.replacedertEquals(Boolean.valueOf(contentreplacedtring), true);
}
17
Source : FileControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
private void openTopic() throws Exception {
String content = "{\"brokerId\":\"" + this.brokerIdMap.get("brokerId") + "\",\"topic\":\"" + this.senderTransport + "\",\"userId\":\"1\",\"creater\":\"1\",\"groupId\":\"1\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/topic/openTopic").contentType(MediaType.APPLICATION_JSON_UTF8).content(content).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
content = "{\"brokerId\":\"" + this.brokerIdMap.get("brokerId") + "\",\"topic\":\"" + this.receiverTransport + "\",\"userId\":\"1\",\"creater\":\"1\",\"groupId\":\"1\"}";
response = mockMvc.perform(MockMvcRequestBuilders.post("/topic/openTopic").contentType(MediaType.APPLICATION_JSON_UTF8).content(content).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
}
17
Source : AccountControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
public void testRegister() throws Exception {
String content = "{\"username\":\"zjy05\",\"preplacedword\":\"123456\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/user/register").contentType(MediaType.APPLICATION_JSON_UTF8).content(content)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
replacedert.replacedertTrue(response.getContentreplacedtring().contains("200"));
}
17
Source : BaseTypeConversionIT.java
with Apache License 2.0
from vaadin
with Apache License 2.0
from vaadin
protected void replacedertEqualExpectedValueWhenCallingMethod(String methodName, String requestValue, String expectedValue) {
try {
MockHttpServletResponse response = callMethod(methodName, requestValue);
replacedert.replacedertEquals(expectedValue, response.getContentreplacedtring());
replacedert.replacedertEquals(200, response.getStatus());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
17
Source : DownloadGetRequestHandlerTest.java
with MIT License
from tomdesair
with MIT License
from tomdesair
@Test(expected = UploadInProgressException.clreplaced)
public void testWithUnknownUpload() throws Exception {
when(uploadStorageService.getUploadInfo(nullable(String.clreplaced), nullable(String.clreplaced))).thenReturn(null);
handler.process(HttpMethod.GET, new TusServletRequest(servletRequest), new TusServletResponse(servletResponse), uploadStorageService, null);
verify(uploadStorageService, never()).copyUploadTo(any(UploadInfo.clreplaced), any(OutputStream.clreplaced));
replacedertThat(servletResponse.getStatus(), is(HttpServletResponse.SC_NO_CONTENT));
}
17
Source : OAuth2TokenRevocationEndpointFilterTests.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
private void doFilterWhenTokenRevocationRequestInvalidParameterThenError(String parameterName, String errorCode, Consumer<MockHttpServletRequest> requestConsumer) throws Exception {
MockHttpServletRequest request = createTokenRevocationRequest();
requestConsumer.accept(request);
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = mock(FilterChain.clreplaced);
this.filter.doFilter(request, response, filterChain);
verifyNoInteractions(filterChain);
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
OAuth2Error error = readError(response);
replacedertThat(error.getErrorCode()).isEqualTo(errorCode);
replacedertThat(error.getDescription()).isEqualTo("OAuth 2.0 Token Revocation Parameter: " + parameterName);
}
17
Source : OAuth2AuthorizationEndpointFilterTests.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
private void doFilterWhenRequestInvalidParameterThenRedirect(MockHttpServletRequest request, String parameterName, String errorCode, String errorUri, Consumer<MockHttpServletRequest> requestConsumer) throws Exception {
requestConsumer.accept(request);
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = mock(FilterChain.clreplaced);
this.filter.doFilter(request, response, filterChain);
verifyNoInteractions(filterChain);
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.FOUND.value());
replacedertThat(response.getRedirectedUrl()).matches("https://example.com\\?" + "error=" + errorCode + "&" + "error_description=OAuth%202.0%20Parameter:%20" + parameterName + "&" + "error_uri=" + errorUri + "&" + "state=state");
}
17
Source : UserControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void whenListInactiveUsers_thenReturnListAnd200Status() throws Exception {
// given
Type listInactiveDTOListType = new TypeToken<ArrayList<UserDTO>>() {
}.getType();
String retrievedUsersDTO = MessageLoader.loadExampleRequest("requests/user/list-existent-usersDTO.json");
List<UserDTO> expectedListInactiveDTO = gson.fromJson(retrievedUsersDTO, listInactiveDTOListType);
Type listInactiveUsersType = new TypeToken<ArrayList<User>>() {
}.getType();
String retrievedUsers = MessageLoader.loadExampleRequest("requests/user/list-existent-users.json");
List<User> expectedListInactive = gson.fromJson(retrievedUsers, listInactiveUsersType);
when(userService.findByValidated(false)).thenReturn(expectedListInactive);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_USER_URL + "/inactive")).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(userService).findByValidated(false);
verifyNoMoreInteractions(userService);
String responseBody = response.getContentreplacedtring();
List<UserDTO> receivedUsersInactiveDTO = gson.fromJson(responseBody, listInactiveDTOListType);
replacedertThat(receivedUsersInactiveDTO).isEqualTo(expectedListInactiveDTO);
}
17
Source : UserControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void whenListActiveUsers_thenReturnListAnd200Status() throws Exception {
// given
Type listActiveDTOListType = new TypeToken<ArrayList<UserDTO>>() {
}.getType();
String retrievedUsersDTO = MessageLoader.loadExampleRequest("requests/user/list-existent-usersDTO.json");
List<UserDTO> expectedListActiveDTO = gson.fromJson(retrievedUsersDTO, listActiveDTOListType);
Type listActiveUsersType = new TypeToken<ArrayList<User>>() {
}.getType();
String retrievedUsers = MessageLoader.loadExampleRequest("requests/user/list-existent-users.json");
List<User> expectedListActive = gson.fromJson(retrievedUsers, listActiveUsersType);
when(userService.findByValidated(true)).thenReturn(expectedListActive);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_USER_URL + "/active")).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(userService).findByValidated(true);
verifyNoMoreInteractions(userService);
String responseBody = response.getContentreplacedtring();
List<UserDTO> receivedUsersActiveDTO = gson.fromJson(responseBody, listActiveDTOListType);
replacedertThat(receivedUsersActiveDTO).isEqualTo(expectedListActiveDTO);
}
17
Source : SessionControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenAnExistentBatchIdWitNoreplacedociatedSessions_whenListSessions_thenReturnEmptyListAnd200Status() throws Exception {
// given
Type sessionListType = new TypeToken<ArrayList<Session>>() {
}.getType();
List<Session> expectedList = Collections.emptyList();
UUID batchId = UUID.randomUUID();
when(sessionService.findByBatch(batchId)).thenReturn(expectedList);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_SESSION_URL + "/batch/" + batchId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(sessionService).findByBatch(batchId);
verifyNoMoreInteractions(sessionService);
String responseBody = response.getContentreplacedtring();
List<Session> receivedSessions = gson.fromJson(responseBody, sessionListType);
replacedertThat(receivedSessions).isEqualTo(expectedList);
}
17
Source : ProgramControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenInvalidProgram_whenUpdateProgram_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/program/invalid-program-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.put(BASE_PROGRAM_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(programService);
}
17
Source : ProgramControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenValidProgramWithIdNull_whenUpdateProgram_thenRejectAnd400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/program/valid-program-with-id-null-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.put(BASE_PROGRAM_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(programService);
}
17
Source : ProgramControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void whenListPrograms_thenReturnListAnd200Status() throws Exception {
// given
Type programListType = new TypeToken<ArrayList<Program>>() {
}.getType();
String retrievedPrograms = MessageLoader.loadExampleRequest("requests/program/list-existent-programs.json");
List<Program> expectedList = gson.fromJson(retrievedPrograms, programListType);
when(programService.list()).thenReturn(expectedList);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_PROGRAM_URL)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(programService).list();
verifyNoMoreInteractions(programService);
String responseBody = response.getContentreplacedtring();
List<Program> receivedPrograms = gson.fromJson(responseBody, programListType);
replacedertThat(receivedPrograms).isEqualTo(expectedList);
}
17
Source : ProgramControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenANonExistentProgramId_whenDelete_then404Status() throws Exception {
// given
UUID programId = UUID.randomUUID();
Optional<Program> program = Optional.empty();
when(programService.delete(programId)).thenReturn(program);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.delete(BASE_PROGRAM_URL + "/" + programId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
verify(programService).delete(programId);
verifyNoMoreInteractions(programService);
}
17
Source : ProgramControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenBadFormattedRequest_whenCreateProgram_thenRejectWith400Status() throws Exception {
// given
String request = MessageLoader.loadExampleRequest("requests/program/invalid-program-01.json");
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(BASE_PROGRAM_URL).contentType(MediaType.APPLICATION_JSON_UTF8).content(request)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
verifyNoMoreInteractions(programService);
}
17
Source : BatchControllerTest.java
with Apache License 2.0
from desarrolladorSLP
with Apache License 2.0
from desarrolladorSLP
@Test
public void givenAnExistentProgramIdWithreplacedociatedBatches_whenListBatches_thenReturnListAnd200Status() throws Exception {
// given
Type batchDTOListType = new TypeToken<ArrayList<BatchDTO>>() {
}.getType();
String retrievedBatchesDTOs = MessageLoader.loadExampleRequest("requests/batch/list-existent-batchesDTOs.json");
List<BatchDTO> expectedListDTO = gson.fromJson(retrievedBatchesDTOs, batchDTOListType);
Type batchListType = new TypeToken<ArrayList<Batch>>() {
}.getType();
String retrievedBatches = MessageLoader.loadExampleRequest("requests/batch/list-existent-batches.json");
List<Batch> expectedList = gson.fromJson(retrievedBatches, batchListType);
UUID programId = expectedList.get(0).getId();
for (int i = 0; i < expectedListDTO.size(); i++) {
replacedertThat(expectedList.get(i).getId()).isEqualTo(expectedListDTO.get(i).getId());
}
when(batchService.findByProgram(programId)).thenReturn(expectedList);
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.get(BASE_BATCH_URL + "/program/" + programId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(batchService).findByProgram(programId);
verifyNoMoreInteractions(batchService);
String responseBody = response.getContentreplacedtring();
List<BatchDTO> receivedBatchesDTO = gson.fromJson(responseBody, batchDTOListType);
replacedertThat(receivedBatchesDTO).isEqualTo(expectedListDTO);
}
17
Source : HistoryTransactionServiceTest.java
with GNU General Public License v3.0
from coti-io
with GNU General Public License v3.0
from coti-io
@Test
public void getTransactionsByDate_noDate_emptyResponse() throws UnsupportedEncodingException {
GetTransactionsByDateRequest request = new GetTransactionsByDateRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
transactionService.getTransactionsByDate(request, response);
replacedert.replacedertEquals(HttpStatus.OK.value(), response.getStatus());
replacedert.replacedertEquals(EMPTY_OUTPUT, response.getContentreplacedtring());
}
16
Source : HttpRestartServerTests.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Test
public void sendNoContent() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
verifyZeroInteractions(this.delegate);
replacedertThat(response.getStatus()).isEqualTo(500);
}
16
Source : ServerEndpointFilterUtilTest.java
with Apache License 2.0
from webauthn4j
with Apache License 2.0
from webauthn4j
@Test
public void writeErrorResponse_with_RuntimeException_test() throws IOException {
MockHttpServletResponse response = new MockHttpServletResponse();
RuntimeException exception = new RuntimeException();
target.writeErrorResponse(response, exception);
replacedertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
replacedertThat(response.getContentType()).isEqualTo("application/json");
replacedertThat(response.getContentreplacedtring()).isEqualTo("{\"status\":\"failed\",\"errorMessage\":\"The server encountered an internal error\"}");
}
16
Source : TopicControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
@Test
public void testTopicInfo() throws Exception {
String url = "/topic/topicInfo?brokerId=" + brokerIdMap.get("brokerId") + "&topic=com.weevent.rest&groupId=1";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post(url).contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
replacedert.replacedertNotNull(response.getContentreplacedtring());
TopicEnreplacedy topicEnreplacedy = JsonHelper.json2Object(response.getContentreplacedtring(), TopicEnreplacedy.clreplaced);
replacedert.replacedertEquals(topicEnreplacedy.getTopicName(), "com.weevent.rest");
}
16
Source : TopicControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
@Test
public void testTopicOpenException() throws Exception {
String content = "{\"brokerId\":\"" + this.brokerIdMap.get("brokerId") + "\",\"topic\":\"com.weevent.rest\",\"userId\":\"1\",\"creater\":\"1\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/topic/openTopic").contentType(MediaType.APPLICATION_JSON_UTF8).content(content).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
GovernanceResult<?> governanceResponse = JsonHelper.json2Object(response.getContentreplacedtring(), GovernanceResult.clreplaced);
replacedert.replacedertEquals(governanceResponse.getCode().toString(), "100109");
}
16
Source : TopicControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
// add broker
public void addBroker() throws Exception {
String content = "{\"name\":\"broker2\",\"brokerUrl\":\"" + this.brokerUrl + "\",\"userId\":\"1\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/broker/add").contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token).content(content)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
GovernanceResult<?> governanceResponse = JsonHelper.json2Object(response.getContentreplacedtring(), GovernanceResult.clreplaced);
brokerIdMap.put("brokerId", (Integer) governanceResponse.getData());
replacedert.replacedertEquals(governanceResponse.getCode().toString(), "200");
}
16
Source : RuleEngineControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
@Test
public void testStartEngine() throws Exception {
testUpdateRuleEngine();
String content = "{\"id\":\"" + ruleMap.get("ruleId") + "\",\"userId\":\"1\",\"brokerId\":\"" + this.ruleMap.get("brokerId") + "\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/ruleEngine/start").contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token).content(content)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
GovernanceResult<?> governanceResponse = JsonHelper.json2Object(response.getContentreplacedtring(), GovernanceResult.clreplaced);
replacedert.replacedertEquals(governanceResponse.getCode().intValue(), 200);
}
16
Source : RuleEngineControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
@Test
public void testUpdateRuleEngine() throws Exception {
String content = "{\"id\":\"" + ruleMap.get("ruleId") + "\",\"ruleName\":\"temperature-alarm6616\",\"payloadType\":\"1\"," + "\"payloadMap\":{\"temperate\":30,\"humidity\":0.5},\"brokerId\":\"" + this.ruleMap.get("brokerId") + "\"," + "\"fromDestination\":\"com.weevent.stomp\",\"toDestination\":\"com.weevent.test\",\"com.weevent.mqtt\":\"test\"," + "\"selectField\":\"temperate\",\"conditionField\":\"temperate>38\",\"conditionType\":\"1\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/ruleEngine/update").contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token).content(content)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
GovernanceResult<?> governanceResponse = JsonHelper.json2Object(response.getContentreplacedtring(), GovernanceResult.clreplaced);
replacedert.replacedertEquals(governanceResponse.getCode().intValue(), 200);
}
16
Source : RuleEngineControllerTest.java
with Apache License 2.0
from WeBankFinTech
with Apache License 2.0
from WeBankFinTech
public void testDeleteRuleEngine() throws Exception {
String content = "{\"id\":\"" + ruleMap.get("ruleId") + "\",\"userId\":\"1\",\"brokerId\":\"" + this.ruleMap.get("brokerId") + "\"}";
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.post("/ruleEngine/delete").contentType(MediaType.APPLICATION_JSON_UTF8).header(JwtUtils.AUTHORIZATION_HEADER_PREFIX, token).content(content)).andReturn().getResponse();
replacedert.replacedertEquals(response.getStatus(), HttpStatus.SC_OK);
GovernanceResult<?> governanceResponse = JsonHelper.json2Object(response.getContentreplacedtring(), GovernanceResult.clreplaced);
replacedert.replacedertEquals(governanceResponse.getCode().intValue(), 200);
}
See More Examples