Search in sources :

Example 6 with WithMockUser

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);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 7 with WithMockUser

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);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) List(java.util.List) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 8 with WithMockUser

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]);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 9 with WithMockUser

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());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 10 with WithMockUser

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());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)3041 Test (org.junit.jupiter.api.Test)1903 Test (org.junit.Test)1056 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)691 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)427 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)379 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)275 ResultActions (org.springframework.test.web.servlet.ResultActions)214 Transactional (org.springframework.transaction.annotation.Transactional)200 MvcResult (org.springframework.test.web.servlet.MvcResult)177 User (io.github.jhipster.sample.domain.User)138 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)136 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)130 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)130 Course (de.tum.in.www1.artemis.domain.Course)124 Exam (de.tum.in.www1.artemis.domain.exam.Exam)114 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)103 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)102 ArrayList (java.util.ArrayList)101 User (de.tum.in.www1.artemis.domain.User)95