use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class TestHelperConfigurationTest method testMessageWithErrors.
@Test
public void testMessageWithErrors() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.failure("Failure"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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));
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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());
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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));
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelTest method convertDefinedFieldModelEmptyTest.
@Test
public void convertDefinedFieldModelEmptyTest() throws Exception {
List<DefinedFieldModel> configFields = createConfigFields();
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
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, true), VALUE_FIELD_1, true);
assertTrue(optionalModel.isEmpty());
}
Aggregations