protected EndpointSpecificConfigurationDto generateEpsConfigurationDto(byte[] endpointKeyHash, Integer configurationVersion, String configuration, Long version) { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(endpointKeyHash, configurationVersion, configuration, version); return endpointSpecificConfigurationDao.save(dto).toDto(); } }
/** * Constructs an endpoint specific configuration with the information provided and * saves it to the database. * * @param endpointKeyHash The endpoint key hash * @param configurationVersion The endpoint configuration version * @param configuration The configuration body * @param version The endpoint specific configuration version * @return saved endpoint specific configuration */ protected EndpointSpecificConfigurationDto generateEndpointSpecificConfigurationDto(byte[] endpointKeyHash, Integer configurationVersion, String configuration, Long version) { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(endpointKeyHash, configurationVersion, configuration, version); return endpointSpecificConfigurationDao.save(dto).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 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 dataConversionTest() throws Exception { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto("hash".getBytes(), 1, "conf body", 2L); CassandraEndpointSpecificConfiguration configuration = new CassandraEndpointSpecificConfiguration(dto); Assert.assertEquals(dto, configuration.toDto()); } }
@Test public void dataConversionTest() throws Exception { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto("hash".getBytes(), 1, "conf body", 2L); MongoEndpointSpecificConfiguration configuration = new MongoEndpointSpecificConfiguration(dto); Assert.assertEquals(dto, configuration.toDto()); } }
@Test public void testShouldSaveWithActiveConfigSchemaVersion() { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); dto.setConfigurationSchemaVersion(null); dto.setEndpointKeyHash(KEY); dto.setConfiguration(CONFIG_BODY); when(endpointServiceMock.findEndpointProfileByKeyHash(KEY)).thenReturn(generateProfile()); when(configurationServiceMock.normalizeAccordingToOverrideConfigurationSchema(APP_ID, CONF_VERSION, CONFIG_BODY)).thenReturn("valid body"); when(daoMock.save(dto)).thenReturn(configuration); when(configuration.toDto()).thenReturn(new EndpointSpecificConfigurationDto()); Assert.assertTrue(SERVICE.save(dto) != null); verify(configurationServiceMock).normalizeAccordingToOverrideConfigurationSchema(APP_ID, CONF_VERSION, CONFIG_BODY); verify(endpointServiceMock).findEndpointProfileByKeyHash(KEY); verify(daoMock).save(dto); }
@Test public void testShouldSaveWithProvidedConfigSchemaVersion() { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); dto.setConfigurationSchemaVersion(7); dto.setEndpointKeyHash(KEY); dto.setConfiguration(CONFIG_BODY); when(endpointServiceMock.findEndpointProfileByKeyHash(KEY)).thenReturn(generateProfile()); when(configurationServiceMock.normalizeAccordingToOverrideConfigurationSchema(APP_ID, 7, CONFIG_BODY)).thenReturn("valid body"); when(daoMock.save(dto)).thenReturn(configuration); when(configuration.toDto()).thenReturn(new EndpointSpecificConfigurationDto()); Assert.assertTrue(SERVICE.save(dto) != null); verify(configurationServiceMock).normalizeAccordingToOverrideConfigurationSchema(APP_ID, 7, CONFIG_BODY); verify(endpointServiceMock).findEndpointProfileByKeyHash(KEY); verify(daoMock).save(dto); }
@Override public EndpointSpecificConfigurationDto toDto() { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); dto.setEndpointKeyHash(this.getEndpointKeyHash()); dto.setConfiguration(this.getConfiguration()); dto.setConfigurationSchemaVersion(this.getConfigurationVersion()); dto.setVersion(this.getVersion()); return dto; }
@Override public EndpointSpecificConfigurationDto toDto() { EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); dto.setEndpointKeyHash(getBytes(this.getEndpointKeyHash())); dto.setConfiguration(this.getConfiguration()); dto.setConfigurationSchemaVersion(this.getConfigurationVersion()); dto.setVersion(this.getVersion()); return dto; }