use of org.springframework.security.test.context.support.WithMockUser in project open-kilda by telstra.
the class FlowControllerTest method deleteFlow.
@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void deleteFlow() throws Exception {
MvcResult result = mockMvc.perform(delete("/flows/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
FlowPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPayload.class);
assertEquals(TestMessageMock.flow, response);
}
use of org.springframework.security.test.context.support.WithMockUser in project open-kilda by telstra.
the class FlowControllerTest method getFlows.
@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void getFlows() throws Exception {
MvcResult result = mockMvc.perform(get("/flows", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
List<FlowPayload> response = MAPPER.readValue(result.getResponse().getContentAsString(), new TypeReference<List<FlowPayload>>() {
});
assertEquals(Collections.singletonList(TestMessageMock.flow), response);
}
use of org.springframework.security.test.context.support.WithMockUser in project open-kilda by telstra.
the class SwitchControllerTest method shouldDeleteSwitchRules.
@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void shouldDeleteSwitchRules() throws Exception {
// given TestMessageMock as kafka topic mocks
// when
MvcResult result = mockMvc.perform(delete("/switches/{switch-id}/rules", TEST_SWITCH_ID).header(CORRELATION_ID, testCorrelationId()).header(EXTRA_AUTH, System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(119)).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
Long[] response = MAPPER.readValue(result.getResponse().getContentAsString(), Long[].class);
assertEquals(TEST_SWITCH_RULE_COOKIE, (long) response[0]);
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testPostConfig.
@Test
@WithMockUser(roles = "ADMIN")
public void testPostConfig() throws Exception {
CommonDistributionConfigEntity commonEntity = mockCommonDistributionEntity.createEntity();
final MockNotificationEntity mockNotifications = new MockNotificationEntity();
NotificationEntity notificationEntity = mockNotifications.createEntity();
notificationEntity = notificationRepository.save(notificationEntity);
commonEntity = commonDistributionRepository.save(commonEntity);
mockAuditEntity.setCommonConfigId(commonEntity.getId());
AuditEntryEntity auditEntity = mockAuditEntity.createEntity();
auditEntity = auditEntryRepository.save(auditEntity);
auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
final String resendUrl = auditUrl + "/" + String.valueOf(auditEntity.getId()) + "/" + "/resend";
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testGetConfigWithId.
@Test
@WithMockUser(roles = "ADMIN")
public void testGetConfigWithId() throws Exception {
AuditEntryEntity entity = mockAuditEntity.createEntity();
entity = auditEntryRepository.save(entity);
final String getUrl = auditUrl + "/" + String.valueOf(entity.getId());
final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(getUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Aggregations