Search in sources :

Example 16 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.

the class GlobalHubConfigControllerTestIT method testTestConfig.

@Test
@Override
@WithMockUser(roles = "ADMIN")
public void testTestConfig() throws Exception {
    final String hubUrl = testProperties.getProperty(TestPropertyKey.TEST_HUB_SERVER_URL);
    final String timeout = testProperties.getProperty(TestPropertyKey.TEST_HUB_TIMEOUT);
    final String apiKey = testProperties.getProperty(TestPropertyKey.TEST_HUB_API_KEY);
    final String alwaysTrust = testProperties.getProperty(TestPropertyKey.TEST_TRUST_HTTPS_CERT);
    final String testRestUrl = restUrl + "/test";
    globalProperties.setHubUrl(hubUrl);
    globalProperties.setHubTrustCertificate(Boolean.valueOf(alwaysTrust));
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    final GlobalHubConfigRestModel hubRestModel = new GlobalHubConfigRestModel(null, hubUrl, String.valueOf(timeout), apiKey, false, null, null, null, null, false, "true");
    request.content(gson.toJson(hubRestModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
    assertTrue(true);
    globalProperties.setHubUrl(null);
    globalProperties.setHubTrustCertificate(Boolean.FALSE);
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) GlobalControllerTest(com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest) Test(org.junit.Test)

Example 17 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.

the class GlobalSchedulingConfigControllerTestIT method testTestConfig.

@Test
@Override
@WithMockUser(roles = "ADMIN")
public void testTestConfig() throws Exception {
    globalEntityRepository.deleteAll();
    final GlobalSchedulingConfigEntity savedEntity = globalEntityRepository.save(entity);
    final String testRestUrl = restUrl + "/test";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    restModel.setId(String.valueOf(savedEntity.getId()));
    request.content(gson.toJson(restModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isMethodNotAllowed());
}
Also used : GlobalSchedulingConfigEntity(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) GlobalControllerTest(com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest) Test(org.junit.Test)

Example 18 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.

the class ControllerTest method testValidConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testValidConfig() throws Exception {
    entityRepository.deleteAll();
    final String testRestUrl = restUrl + "/validate";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    request.content(gson.toJson(restModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 19 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.

the class GlobalControllerTest method testPutConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testPutConfig() throws Exception {
    globalEntityRepository.deleteAll();
    final GE savedEntity = globalEntityRepository.save(entity);
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(restUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    restModel.setId(String.valueOf(savedEntity.getId()));
    request.content(gson.toJson(restModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isAccepted());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 20 with WithMockUser

use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.

the class GlobalControllerTest method testGetConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testGetConfig() throws Exception {
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(restUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)3191 Test (org.junit.jupiter.api.Test)1911 Test (org.junit.Test)1198 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)762 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)427 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)379 MvcResult (org.springframework.test.web.servlet.MvcResult)290 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)275 ResultActions (org.springframework.test.web.servlet.ResultActions)224 Transactional (org.springframework.transaction.annotation.Transactional)200 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 ArrayList (java.util.ArrayList)118 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 User (de.tum.in.www1.artemis.domain.User)95