Search in sources :

Example 1 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorKeyAndContextTest.

@Test
public void getConfigurationsByDescriptorKeyAndContextTest() {
    final Long descriptorId = 3L;
    final Long configurationId = 5L;
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    configContextEntity.setId(3L);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
    registeredDescriptorEntity.setId(2L);
    FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(8L);
    Mockito.when(descriptorConfigRepository.findByDescriptorIdAndContextId(Mockito.any(), Mockito.any())).thenReturn(List.of(descriptorConfigEntity));
    Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(configContextRepository.findById(Mockito.any())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(fieldValueRepository.findByConfigId(Mockito.any())).thenReturn(List.of(fieldValueEntity));
    Mockito.when(definedFieldRepository.findById(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    EncryptionUtility encryptionUtility = createEncryptionUtility();
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, configContextEnum);
    assertEquals(1, configurationModelList.size());
    ConfigurationModel configurationModel = configurationModelList.get(0);
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 2 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertFromFieldModelEmptyFieldsTest.

@Test
public void convertFromFieldModelEmptyFieldsTest() throws Exception {
    FieldModel fieldModel = createFieldModel();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(List.of());
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Map<String, ConfigurationFieldModel> actualModelMap = modelConverter.convertToConfigurationFieldModelMap(fieldModel);
    assertTrue(actualModelMap.isEmpty());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 3 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertFromFieldModelTest.

@Test
public void convertFromFieldModelTest() throws Exception {
    FieldModel fieldModel = createFieldModel();
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Map<String, ConfigurationFieldModel> actualModelMap = modelConverter.convertToConfigurationFieldModelMap(fieldModel);
    assertTrue(actualModelMap.containsKey(KEY_FIELD_1));
    assertTrue(actualModelMap.containsKey(KEY_FIELD_2));
    assertEquals(VALUE_FIELD_1, actualModelMap.get(KEY_FIELD_1).getFieldValue().orElse(null));
    assertEquals(VALUE_FIELD_2, actualModelMap.get(KEY_FIELD_2).getFieldValue().orElse(null));
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 4 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertDefinedFieldModelWithValuesTest.

@Test
public void convertDefinedFieldModelWithValuesTest() throws Exception {
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, false), List.of(VALUE_FIELD_1, VALUE_FIELD_2), true);
    assertTrue(optionalModel.isPresent());
    ConfigurationFieldModel actualModel = optionalModel.get();
    assertTrue(actualModel.getFieldValues().containsAll(List.of(VALUE_FIELD_1, VALUE_FIELD_2)));
    assertFalse(actualModel.isSensitive());
    assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
    optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), List.of(VALUE_FIELD_1, VALUE_FIELD_2), true);
    assertTrue(optionalModel.isPresent());
    actualModel = optionalModel.get();
    assertTrue(actualModel.getFieldValues().containsAll(List.of(VALUE_FIELD_1, VALUE_FIELD_2)));
    assertTrue(actualModel.isSensitive());
    assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 5 with EncryptionUtility

use of com.synopsys.integration.alert.common.security.EncryptionUtility in project hub-alert by blackducksoftware.

the class ConfigurationFieldModelTest method convertToFieldAccessorTest.

@Test
public void convertToFieldAccessorTest() throws Exception {
    FieldModel fieldModel = createFieldModel();
    List<DefinedFieldModel> configFields = createConfigFields();
    EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
    Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
    DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
    List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
    ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
    FieldUtility accessor = modelConverter.convertToFieldAccessor(fieldModel);
    assertEquals(VALUE_FIELD_1, accessor.getString(KEY_FIELD_1).orElse(null));
    assertEquals(VALUE_FIELD_2, accessor.getString(KEY_FIELD_2).orElse(null));
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) MockDescriptorAccessor(com.synopsys.integration.alert.mock.MockDescriptorAccessor) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Aggregations

EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)21 Test (org.junit.jupiter.api.Test)20 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)14 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)7 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)7 FieldModelProcessor (com.synopsys.integration.alert.common.rest.FieldModelProcessor)7 SettingsDescriptorKey (com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey)7 MockDescriptorAccessor (com.synopsys.integration.alert.mock.MockDescriptorAccessor)7 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)6 FilePersistenceUtil (com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil)5 SettingsEncryptionModel (com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 EmailGlobalConfigurationModelConverter (com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelConverter)3