Search in sources :

Example 1 with GlobalHubConfigRestModel

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testTestConfig.

@Test
public void testTestConfig() throws Exception {
    final RestConnection mockedRestConnection = Mockito.mock(RestConnection.class);
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, new ObjectTransformer());
    configActions = Mockito.spy(configActions);
    Mockito.doAnswer(new Answer<RestConnection>() {

        @Override
        public RestConnection answer(final InvocationOnMock invocation) throws Throwable {
            return mockedRestConnection;
        }
    }).when(configActions).createRestConnection(Mockito.any(HubServerConfigBuilder.class));
    Mockito.doNothing().when(configActions).validateHubConfiguration(Mockito.any(HubServerConfigBuilder.class));
    configActions.testConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel fullRestModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    configActions.testConfig(fullRestModel);
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel restModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    final GlobalHubConfigRestModel partialRestModel = configActions.maskRestModel(restModel);
    Mockito.doAnswer(new Answer<GlobalHubConfigEntity>() {

        @Override
        public GlobalHubConfigEntity answer(final InvocationOnMock invocation) throws Throwable {
            return getGlobalEntityMockUtil().createGlobalEntity();
        }
    }).when(mockedGlobalRepository).findOne(Mockito.anyLong());
    final String result = configActions.testConfig(partialRestModel);
    assertEquals("Successfully connected to the Hub.", result);
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
}
Also used : GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 2 with GlobalHubConfigRestModel

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel in project hub-alert by blackducksoftware.

the class GlobalHubConfigRestModelTest method testSetHubProxyPassword.

@Test
public void testSetHubProxyPassword() {
    final GlobalHubConfigRestModel model = getMockUtil().createEmptyGlobalRestModel();
    final String expectedPassword = "expected";
    model.setHubProxyPassword(expectedPassword);
    assertEquals(expectedPassword, model.getHubProxyPassword());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) Test(org.junit.Test) GlobalRestModelTest(com.blackducksoftware.integration.hub.alert.web.model.GlobalRestModelTest)

Example 3 with GlobalHubConfigRestModel

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel 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 4 with GlobalHubConfigRestModel

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel in project hub-alert by blackducksoftware.

the class CommonGlobalConfigHandlerTest method postConfigWhenAlreadyExistsTest.

@Test
public void postConfigWhenAlreadyExistsTest() {
    final GlobalHubConfigActions configActions = Mockito.mock(GlobalHubConfigActions.class);
    final CommonGlobalConfigHandler<GlobalHubConfigEntity, GlobalHubConfigRestModel, GlobalHubRepositoryWrapper> handler = new CommonGlobalConfigHandler<>(GlobalHubConfigEntity.class, GlobalHubConfigRestModel.class, configActions, objectTransformer);
    final GlobalHubRepositoryWrapper repository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    Mockito.when(configActions.getRepository()).thenReturn(repository);
    Mockito.when(repository.findAll()).thenReturn(Arrays.asList(null, null));
    final ResponseEntity<String> response = handler.postConfig(null);
    assertEquals(HttpStatus.PRECONDITION_FAILED, response.getStatusCode());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test)

Example 5 with GlobalHubConfigRestModel

use of com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel in project hub-alert by blackducksoftware.

the class CommonGlobalConfigHandlerTest method postConfigWhenDoesNotExistsTest.

@Test
public void postConfigWhenDoesNotExistsTest() {
    final GlobalHubConfigActions configActions = Mockito.mock(GlobalHubConfigActions.class);
    final CommonGlobalConfigHandler<GlobalHubConfigEntity, GlobalHubConfigRestModel, GlobalHubRepositoryWrapper> handler = new CommonGlobalConfigHandler<>(GlobalHubConfigEntity.class, GlobalHubConfigRestModel.class, configActions, objectTransformer);
    final GlobalHubRepositoryWrapper repository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    Mockito.when(configActions.getRepository()).thenReturn(repository);
    Mockito.when(repository.findAll()).thenReturn(Collections.emptyList());
    final ResponseEntity<String> response = handler.postConfig(null);
    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test)

Aggregations

GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)9 Test (org.junit.Test)8 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)5 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)5 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)5 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 MockGlobalHubRestModel (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel)3 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)3 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)3 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)1 MockGlobalHubEntity (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubEntity)1 GlobalControllerTest (com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest)1 GlobalRestModelTest (com.blackducksoftware.integration.hub.alert.web.model.GlobalRestModelTest)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1