Search in sources :

Example 1 with SettingsProxyCrudActions

use of com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelSaveActionsTest method createInvalidConversionTest.

@Test
void createInvalidConversionTest() {
    AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
        for (NonProxyHostConfigurationEntity entity : iterable) {
            savedNonProxyHostEntity.set(entity);
        }
        return List.of(savedNonProxyHostEntity.get());
    });
    SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
    ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, "badport");
    saveActions.createConcreteModel(configurationModel);
    SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
    NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
    assertNull(actualEntity);
    assertNull(actualNonProxyHosts);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 2 with SettingsProxyCrudActions

use of com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelSaveActionsTest method deleteTest.

@Test
void deleteTest() {
    AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.doAnswer(invocation -> {
        savedEntity.set(null);
        savedNonProxyHostEntity.set(null);
        return null;
    }).when(settingsProxyConfigurationRepository).deleteByName(Mockito.anyString());
    Mockito.when(settingsProxyConfigurationRepository.existsByName(Mockito.anyString())).thenAnswer(invocation -> savedEntity.get() != null);
    Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
        for (NonProxyHostConfigurationEntity entity : iterable) {
            savedNonProxyHostEntity.set(entity);
        }
        return List.of(savedNonProxyHostEntity.get());
    });
    SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
    ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
    NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
    assertNotNull(actualEntity);
    assertNotNull(actualNonProxyHosts);
    saveActions.deleteConcreteModel(configurationModel);
    actualEntity = savedEntity.get();
    actualNonProxyHosts = savedNonProxyHostEntity.get();
    assertNull(actualEntity);
    assertNull(actualNonProxyHosts);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 3 with SettingsProxyCrudActions

use of com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelSaveActionsTest method updateInvalidConversionTest.

@Test
void updateInvalidConversionTest() {
    AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
        for (NonProxyHostConfigurationEntity entity : iterable) {
            savedNonProxyHostEntity.set(entity);
        }
        return List.of(savedNonProxyHostEntity.get());
    });
    SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
    ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
    String newHost = "updatedHost";
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_HOST, newHost);
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, "badPort");
    saveActions.updateConcreteModel(configurationModel);
    // Assert that the update failed and the original created values are used.
    SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_PROXY_HOST, actualEntity.getHost());
    assertEquals(Integer.valueOf(TEST_PROXY_PORT), actualEntity.getPort());
    assertEquals(TEST_PROXY_USERNAME, actualEntity.getUsername());
    assertEquals(TEST_PROXY_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with SettingsProxyCrudActions

use of com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions in project hub-alert by blackducksoftware.

the class SettingsProxyCrudActionsTest method deleteTest.

@Test
public void deleteTest() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(true);
    SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
    ActionResponse<SettingsProxyModel> actionResponse = configActions.delete();
    Mockito.verify(settingsProxyConfigurationRepository).deleteByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    assertTrue(actionResponse.isSuccessful());
    assertFalse(actionResponse.hasContent());
    assertEquals(HttpStatus.NO_CONTENT, actionResponse.getHttpStatus());
}
Also used : NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) UUID(java.util.UUID) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) Test(org.junit.jupiter.api.Test)

Example 5 with SettingsProxyCrudActions

use of com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions in project hub-alert by blackducksoftware.

the class SettingsProxyCrudActionsTest method createTest.

@Test
public void createTest() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    SettingsProxyConfigurationEntity entity = createSettingsProxyConfigurationEntity(uuid);
    Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(false);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any())).thenReturn(entity);
    Mockito.when(settingsProxyConfigurationRepository.getOne(uuid)).thenReturn(entity);
    SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
    ActionResponse<SettingsProxyModel> actionResponse = configActions.create(createSettingsProxyModel());
    Mockito.verify(nonProxyHostsConfigurationRepository).saveAll(Mockito.any());
    assertTrue(actionResponse.isSuccessful());
    assertTrue(actionResponse.hasContent());
    assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
    assertModelObfuscated(actionResponse);
}
Also used : NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) UUID(java.util.UUID) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) Test(org.junit.jupiter.api.Test)

Aggregations

SettingsProxyCrudActions (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions)10 SettingsProxyConfigAccessor (com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor)10 NonProxyHostsConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository)10 SettingsProxyConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository)10 Test (org.junit.jupiter.api.Test)10 SettingsProxyConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity)7 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)5 NonProxyHostConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity)5 List (java.util.List)5 UUID (java.util.UUID)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)4