@Test public void getConfigurationsByDescriptorKeyAndContextTest() throws Exception { 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(); DefaultConfigurationAccessor configurationAccessor = new DefaultConfigurationAccessor(registeredDescriptorRepository, null, definedFieldRepository, descriptorConfigRepository, null, configContextRepository, fieldValueRepository, encryptionUtility); List<ConfigurationModel> configurationModelList = configurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, configContextEnum); assertEquals(1, configurationModelList.size()); ConfigurationModel configurationModel = configurationModelList.get(0); testConfigurationModel(configurationId, descriptorId, configurationModel); }
@Override public List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format(EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID, descriptorKey)); } return getConfigurationsByDescriptorNameAndContext(descriptorKey.getUniversalKey(), context); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format(EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID, descriptorKey)); } return getConfigurationsByDescriptorNameAndContext(descriptorKey.getUniversalKey(), context); } }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format(EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID, descriptorKey)); } return getConfigurationsByDescriptorNameAndContext(descriptorKey.getUniversalKey(), context); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format(EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID, descriptorKey)); } return getConfigurationsByDescriptorNameAndContext(descriptorKey.getUniversalKey(), context); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); @Override List<ConfigurationJobModel> getAllJobs(); @Override Optional<ConfigurationJobModel> getJobById(UUID jobId); @Override List<ConfigurationJobModel> getJobsByFrequency(FrequencyType frequency); @Override ConfigurationJobModel createJob(Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override ConfigurationJobModel updateJob(UUID jobId, Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteJob(UUID jobId); @Override Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName); @Override Optional<ConfigurationModel> getConfigurationById(Long id); @Override List<ConfigurationModel> getConfigurationsByDescriptorKey(DescriptorKey descriptorKey); @Override List<ConfigurationModel> getConfigurationsByDescriptorType(DescriptorType descriptorType); @Override List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType); @Override List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context); @Override ConfigurationModel createConfiguration(DescriptorKey descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields); @Override List<ConfigurationModel> getConfigurationsByDescriptorNameAndContext(String descriptorName, ConfigContextEnum context); @Override ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteConfiguration(ConfigurationModel configModel); @Override void deleteConfiguration(Long descriptorConfigId); }
DefaultConfigurationAccessor implements ConfigurationAccessor { @Override public List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format(EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID, descriptorKey)); } return getConfigurationsByDescriptorNameAndContext(descriptorKey.getUniversalKey(), context); } @Autowired  DefaultConfigurationAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DescriptorTypeRepository descriptorTypeRepository, DefinedFieldRepository definedFieldRepository,
        DescriptorConfigRepository descriptorConfigsRepository, ConfigGroupRepository configGroupRepository, ConfigContextRepository configContextRepository, FieldValueRepository fieldValueRepository,
        EncryptionUtility encryptionUtility); @Override List<ConfigurationJobModel> getAllJobs(); @Override Optional<ConfigurationJobModel> getJobById(UUID jobId); @Override List<ConfigurationJobModel> getJobsByFrequency(FrequencyType frequency); @Override ConfigurationJobModel createJob(Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override ConfigurationJobModel updateJob(UUID jobId, Collection<String> descriptorNames, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteJob(UUID jobId); @Override Optional<ConfigurationModel> getProviderConfigurationByName(String providerConfigName); @Override Optional<ConfigurationModel> getConfigurationById(Long id); @Override List<ConfigurationModel> getConfigurationsByDescriptorKey(DescriptorKey descriptorKey); @Override List<ConfigurationModel> getConfigurationsByDescriptorType(DescriptorType descriptorType); @Override List<ConfigurationModel> getChannelConfigurationsByFrequency(FrequencyType frequencyType); @Override List<ConfigurationModel> getConfigurationsByDescriptorKeyAndContext(DescriptorKey descriptorKey, ConfigContextEnum context); @Override ConfigurationModel createConfiguration(DescriptorKey descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields); @Override List<ConfigurationModel> getConfigurationsByDescriptorNameAndContext(String descriptorName, ConfigContextEnum context); @Override ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields); @Override void deleteConfiguration(ConfigurationModel configModel); @Override void deleteConfiguration(Long descriptorConfigId); static final String EXCEPTION_FORMAT_DESCRIPTOR_KEY_IS_NOT_VALID; }