@Override public Optional<EndpointSpecificConfigurationDto> findActiveConfigurationByEndpointKeyHash(byte[] endpointKeyHash) { LOG.debug("Looking for active endpoint specific configuration by EP key hash {}", endpointKeyHash); EndpointProfileDto profileDto = getEndpointProfileDto(endpointKeyHash); if (profileDto == null) { return Optional.empty(); } EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(endpointKeyHash, profileDto.getConfigurationVersion()); return Optional.ofNullable(configuration).map(ToDto::toDto); }
@Override public Optional<EndpointSpecificConfigurationDto> findActiveConfigurationByEndpointProfile(EndpointProfileDto endpointProfileDto) { byte[] endpointKeyHash = endpointProfileDto.getEndpointKeyHash(); int configurationVersion = endpointProfileDto.getConfigurationVersion(); EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(endpointKeyHash, configurationVersion); return Optional.ofNullable(configuration).map(ToDto::toDto); }
@Override public Optional<EndpointSpecificConfigurationDto> findByEndpointKeyHashAndConfSchemaVersion(byte[] endpointKeyHash, Integer confSchemaVersion) { LOG.debug("Looking for endpoint specific configuration by EP key hash {} and confSchemaVersion", endpointKeyHash, confSchemaVersion); validateNotNull(confSchemaVersion, "Configuration schema version is required"); EndpointProfileDto profileDto = getEndpointProfileDto(endpointKeyHash); if (profileDto == null) { return Optional.empty(); } validateConfSchemaVersion(profileDto.getApplicationId(), confSchemaVersion); EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(endpointKeyHash, confSchemaVersion); return Optional.ofNullable(configuration).map(ToDto::toDto); }
@Test public void testShouldActiveConfigurationByEndpointProfile() { when(daoMock.findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION)).thenReturn(configuration); when(configuration.toDto()).thenReturn(new EndpointSpecificConfigurationDto()); Assert.assertTrue(SERVICE.findActiveConfigurationByEndpointProfile(generateProfile()).isPresent()); verify(daoMock).findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION); }
@Test public void testShouldDeleteActiveConfigurationByEndpointKeyHash() { when(endpointServiceMock.findEndpointProfileByKeyHash(KEY)).thenReturn(generateProfile()); when(daoMock.findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION)).thenReturn(configuration); when(configuration.toDto()).thenReturn(configurationDto); when(configurationDto.getConfigurationSchemaVersion()).thenReturn(CONF_VERSION); Assert.assertTrue(SERVICE.deleteActiveConfigurationByEndpointKeyHash(KEY).isPresent()); verify(endpointServiceMock).findEndpointProfileByKeyHash(KEY); verify(daoMock).findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION); verify(daoMock).removeByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION); }
@Test public void testShouldFindActiveConfigurationByEndpointKeyHash() { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); dto.setConfigurationSchemaVersion(CONF_VERSION); when(endpointServiceMock.findEndpointProfileByKeyHash(KEY)).thenReturn(generateProfile()); when(daoMock.findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION)).thenReturn(configuration); when(configuration.toDto()).thenReturn(dto); Assert.assertTrue(SERVICE.findActiveConfigurationByEndpointKeyHash(KEY).isPresent()); verify(endpointServiceMock).findEndpointProfileByKeyHash(KEY); verify(daoMock).findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION); }
@Test public void testFindByEndpointKeyHashAndConfigurationVersion() throws Exception { Assert.assertTrue(endpointSpecificConfigurationDao.find().size() == 3); EndpointSpecificConfigurationDto found1 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 0).toDto(); EndpointSpecificConfigurationDto found2 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 1).toDto(); EndpointSpecificConfigurationDto found3 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 0).toDto(); EndpointSpecificConfiguration found4 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 4); Assert.assertEquals(saved1, found1); Assert.assertEquals(saved2, found2); Assert.assertEquals(saved3, found3); Assert.assertNull(found4); }
@Test public void testFindByEndpointKeyHashAndConfigurationVersion() throws Exception { Assert.assertTrue(endpointSpecificConfigurationDao.find().size() == 3); EndpointSpecificConfigurationDto found1 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 0).toDto(); EndpointSpecificConfigurationDto found2 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 1).toDto(); EndpointSpecificConfigurationDto found3 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 0).toDto(); EndpointSpecificConfiguration found4 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 4); Assert.assertEquals(saved1, found1); Assert.assertEquals(saved2, found2); Assert.assertEquals(saved3, found3); Assert.assertNull(found4); }
@Test public void testShouldDeleteByEndpointKeyHashAndConfSchemaVersion() { EndpointProfileDto profile = generateProfile(); profile.setConfigurationVersion(0); when(endpointServiceMock.findEndpointProfileByKeyHash(KEY)).thenReturn(profile); when(daoMock.findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION)).thenReturn(configuration); when(configuration.toDto()).thenReturn(configurationDto); when(configurationServiceMock.findConfSchemaByAppIdAndVersion(APP_ID, CONF_VERSION)).thenReturn(new ConfigurationSchemaDto()); when(configurationDto.getConfigurationSchemaVersion()).thenReturn(CONF_VERSION); Assert.assertTrue(SERVICE.deleteByEndpointKeyHashAndConfSchemaVersion(KEY, CONF_VERSION).isPresent()); verify(endpointServiceMock).findEndpointProfileByKeyHash(KEY); verify(daoMock).findByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION); verify(daoMock).removeByEndpointKeyHashAndConfigurationVersion(KEY, CONF_VERSION); verify(configurationServiceMock).findConfSchemaByAppIdAndVersion(APP_ID, CONF_VERSION); }
@Test public void testRemoveByEndpointKeyHashAndConfigurationVersion() throws Exception { Assert.assertTrue(endpointSpecificConfigurationDao.find().size() == 3); endpointSpecificConfigurationDao.removeByEndpointKeyHashAndConfigurationVersion(KEY, 0); Assert.assertTrue(endpointSpecificConfigurationDao.find().size() == 2); Assert.assertTrue(endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 0) == null); }
@Test public void testRemoveByEndpointKeyHashAndConfigurationVersion() throws Exception { Assert.assertTrue(endpointSpecificConfigurationDao.find().size() == 3); endpointSpecificConfigurationDao.removeByEndpointKeyHashAndConfigurationVersion(KEY, 0); Assert.assertTrue(endpointSpecificConfigurationDao.find().size() == 2); Assert.assertTrue(endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 0) == null); }