Search in sources :

Example 1 with MockGlobalHubRestModel

use of com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testInvalidConfig.

@Override
public void testInvalidConfig() {
    final MockGlobalHubRestModel mockUtil = new MockGlobalHubRestModel();
    mockUtil.setHubTimeout("qqq");
    final GlobalHubConfigRestModel restModel = mockUtil.createGlobalRestModel();
    String result = null;
    try {
        result = configActions.validateConfig(restModel);
        fail();
    } catch (final AlertFieldException e) {
        assertTrue(true);
    }
    assertNull(result);
    mockUtil.setHubApiKey(StringUtils.repeat('a', 300));
    final GlobalHubConfigRestModel restModelBigApi = mockUtil.createGlobalRestModel();
    String resultBigApi = null;
    try {
        resultBigApi = configActions.validateConfig(restModelBigApi);
        fail();
    } catch (final AlertFieldException e) {
        assertTrue(true);
    }
    assertNull(resultBigApi);
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) MockGlobalHubRestModel(com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel)

Example 2 with MockGlobalHubRestModel

use of com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel in project hub-alert by blackducksoftware.

the class ObjectTransformerTest method testTransformGlobalModels.

@Test
public void testTransformGlobalModels() throws Exception {
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final MockGlobalHubRestModel globalHubMockUtils = new MockGlobalHubRestModel();
    final MockGlobalHubEntity mockGlobalHubEntity = new MockGlobalHubEntity();
    final GlobalHubConfigRestModel restModel = globalHubMockUtils.createGlobalRestModel();
    final GlobalHubConfigEntity configEntity = mockGlobalHubEntity.createGlobalEntity();
    final GlobalHubConfigEntity transformedConfigEntity = objectTransformer.configRestModelToDatabaseEntity(restModel, GlobalHubConfigEntity.class);
    final GlobalHubConfigRestModel transformedConfigRestModel = objectTransformer.databaseEntityToConfigRestModel(configEntity, GlobalHubConfigRestModel.class);
    assertNull(transformedConfigRestModel.getHubAlwaysTrustCertificate());
    assertEquals(restModel.getHubApiKey(), transformedConfigRestModel.getHubApiKey());
    assertNull(transformedConfigRestModel.getHubProxyHost());
    assertNull(transformedConfigRestModel.getHubProxyPassword());
    assertNull(transformedConfigRestModel.getHubProxyPort());
    assertNull(transformedConfigRestModel.getHubProxyUsername());
    assertEquals(restModel.getHubTimeout(), transformedConfigRestModel.getHubTimeout());
    assertNull(transformedConfigRestModel.getHubUrl());
    assertEquals(restModel.getId(), transformedConfigRestModel.getId());
    assertEquals(configEntity.getHubApiKey(), transformedConfigEntity.getHubApiKey());
    assertEquals(configEntity.getHubTimeout(), transformedConfigEntity.getHubTimeout());
    assertEquals(configEntity.getId(), transformedConfigEntity.getId());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) MockGlobalHubRestModel(com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel) MockGlobalHubEntity(com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubEntity) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test)

Example 3 with MockGlobalHubRestModel

use of com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testChannelTestConfig.

@Test
@Override
public void testChannelTestConfig() throws Exception {
    final MockGlobalHubRestModel mockUtils = new MockGlobalHubRestModel();
    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(mockUtils.createGlobalRestModel());
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel restModel = mockUtils.createGlobalRestModel();
    final String result = configActions.channelTestConfig(restModel);
    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) MockGlobalHubRestModel(com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Aggregations

GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)3 MockGlobalHubRestModel (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubRestModel)3 Test (org.junit.Test)2 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)1 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)1 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)1 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)1 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)1 MockGlobalHubEntity (com.blackducksoftware.integration.hub.alert.hub.mock.MockGlobalHubEntity)1 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)1 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)1 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1