Search in sources :

Example 6 with MockHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder in project spring-boot by spring-projects.

the class HalBrowserMvcEndpointDisabledIntegrationTests method endpointsDoNotHaveLinks.

@Test
public void endpointsDoNotHaveLinks() throws Exception {
    for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) {
        String path = endpoint.getPath();
        if ("/actuator".equals(path) || endpoint instanceof HeapdumpMvcEndpoint) {
            continue;
        }
        path = path.length() > 0 ? path : "/";
        MockHttpServletRequestBuilder requestBuilder = get(path);
        if (endpoint instanceof AuditEventsMvcEndpoint) {
            requestBuilder.param("after", "2016-01-01T12:00:00+00:00");
        }
        this.mockMvc.perform(requestBuilder.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(jsonPath("$._links").doesNotExist());
    }
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with MockHttpServletRequestBuilder

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

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

Example 9 with MockHttpServletRequestBuilder

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

the class AuditEntryControllerTestIT method testGetConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testGetConfig() throws Exception {
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(auditUrl).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) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 10 with MockHttpServletRequestBuilder

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

the class GlobalHipChatConfigControllerTestIT method testTestConfig.

@Test
@Override
@WithMockUser(roles = "ADMIN")
public void testTestConfig() throws Exception {
    final String testRestUrl = restUrl + "/test";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    final GlobalHipChatConfigRestModel globalHipChatConfigRestModel = new GlobalHipChatConfigRestModel(null, testProperties.getProperty(TestPropertyKey.TEST_HIPCHAT_API_KEY), true);
    request.content(gson.toJson(globalHipChatConfigRestModel));
    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) GlobalControllerTest(com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest) 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