Search in sources :

Example 76 with WithMockUser

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

the class SettingsEncryptionControllerTestIT method testCreate.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testCreate() throws Exception {
    String url = AlertRestConstants.SETTINGS_ENCRYPTION_PATH;
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isMethodNotAllowed());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 77 with WithMockUser

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

the class SettingsProxyControllerTestIT method testGetOne.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetOne() throws Exception {
    createDefaultSettingsProxyModel(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(AssertionFailedError::new);
    String url = AlertRestConstants.SETTINGS_PROXY_PATH;
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AssertionFailedError(org.opentest4j.AssertionFailedError) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 78 with WithMockUser

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

the class SettingsProxyControllerTestIT method testValidate.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidate() throws Exception {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    String url = AlertRestConstants.SETTINGS_PROXY_PATH + "/validate";
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(settingsProxyModel)).contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 79 with WithMockUser

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

the class RoleControllerTestIT method testCreate.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testCreate() throws Exception {
    PermissionModel permissionModel = new PermissionModel(blackDuckProviderKey.getUniversalKey(), context, true, true, true, true, true, true, true, true);
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel));
    String url = RoleController.ROLE_BASE_PATH;
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(rolePermissionModel)).contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 80 with WithMockUser

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

the class RoleControllerTestIT method testGetOne.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetOne() throws Exception {
    RolePermissionModel rolePermissionModel = createRolePermissionModel().orElseThrow(AssertionFailedError::new);
    String url = RoleController.ROLE_BASE_PATH + String.format("/%s", rolePermissionModel.getId());
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AssertionFailedError(junit.framework.AssertionFailedError) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)3415 Test (org.junit.jupiter.api.Test)2107 Test (org.junit.Test)1226 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)865 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)427 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)409 MvcResult (org.springframework.test.web.servlet.MvcResult)304 ResultActions (org.springframework.test.web.servlet.ResultActions)278 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)275 Transactional (org.springframework.transaction.annotation.Transactional)220 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)179 User (io.github.jhipster.sample.domain.User)149 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)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