Search in sources :

Example 16 with MockHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder in project hub-alert by blackducksoftware.

the class HomeControllerTestIT method testIndex.

@Test
public void testIndex() throws Exception {
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(homeUrl);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test)

Example 17 with MockHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder 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 18 with MockHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder 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 19 with MockHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder 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 20 with MockHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder 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)

Aggregations

MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)37 Test (org.junit.Test)35 WithMockUser (org.springframework.security.test.context.support.WithMockUser)23 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)18 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 GlobalControllerTest (com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest)4 HttpHeaders (org.springframework.http.HttpHeaders)4 CsrfToken (org.springframework.security.web.csrf.CsrfToken)3 MockAuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity)2 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 MockHttpSession (org.springframework.mock.web.MockHttpSession)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 TestProperties (com.blackducksoftware.integration.hub.alert.TestProperties)1 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)1 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)1 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)1 MockNotificationEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity)1