@Override public EndpointConfigurationDto findEndpointConfigurationByHash(byte[] hash) { validateHash(hash, "Can't find endpoint configuration by hash. Invalid configuration hash " + hash); return getDto(endpointConfigurationDao.findByHash(hash)); }
@Override public EndpointConfigurationDto saveEndpointConfiguration(EndpointConfigurationDto endpointConfigurationDto) { return getDto(endpointConfigurationDao.save(endpointConfigurationDto)); }
@Test public void testRemoveByHash() throws Exception { List<CassandraEndpointConfiguration> configs = generateConfiguration(3); CassandraEndpointConfiguration expected = configs.get(0); endpointConfigurationDao.removeByHash(expected.getConfigurationHash().array()); CassandraEndpointConfiguration found = endpointConfigurationDao.findByHash(expected.getConfigurationHash().array()); Assert.assertNull(found); }
@Test public void testRemoveByIdNullKey() throws Exception { List<CassandraEndpointConfiguration> configs = generateConfiguration(3); CassandraEndpointConfiguration expected = configs.get(0); endpointConfigurationDao.removeById(null); CassandraEndpointConfiguration found = endpointConfigurationDao.findByHash(expected.getConfigurationHash().array()); Assert.assertEquals(expected, found); }
@Test public void saveEndpointConfigurationTest() { EndpointConfigurationDto configurationDto = generateEndpointConfiguration(); MongoEndpointConfiguration found = endpointConfigurationDao.findById(ByteBuffer.wrap(configurationDto.getConfigurationHash())); Assert.assertNotNull(found); MongoEndpointConfiguration savedDto = endpointConfigurationDao.save(found); Assert.assertNotNull(savedDto); Assert.assertEquals(savedDto, found); }
@Test public void removeEndpointConfigurationByIdTest() { EndpointConfigurationDto endpointConfiguration = generateEndpointConfiguration(); Assert.assertNotNull(endpointConfiguration); endpointConfigurationDao.removeById(ByteBuffer.wrap(endpointConfiguration.getConfigurationHash())); MongoEndpointConfiguration found = endpointConfigurationDao.findById(ByteBuffer.wrap(endpointConfiguration.getConfigurationHash())); Assert.assertNull(found); }
@Test public void testFindByIdNullKey() throws Exception { CassandraEndpointConfiguration found = endpointConfigurationDao.findById(null); Assert.assertNull(found); }
@Test public void removeEndpointConfigurationByHashTest() { EndpointConfigurationDto endpointConfiguration = generateEndpointConfiguration(); Assert.assertNotNull(endpointConfiguration); byte[] bytes = endpointConfiguration.getConfigurationHash(); endpointConfigurationDao.removeByHash(bytes); MongoEndpointConfiguration configurationDto = endpointConfigurationDao.findByHash(bytes); Assert.assertNull(configurationDto); }
@Test public void testRemoveById() throws Exception { List<CassandraEndpointConfiguration> configs = generateConfiguration(3); CassandraEndpointConfiguration expected = configs.get(0); endpointConfigurationDao.removeById(expected.getConfigurationHash()); CassandraEndpointConfiguration found = endpointConfigurationDao.findByHash(expected.getConfigurationHash().array()); Assert.assertNull(found); } }
@Test public void testFindById() throws Exception { List<CassandraEndpointConfiguration> configs = generateConfiguration(3); CassandraEndpointConfiguration expected = configs.get(0); CassandraEndpointConfiguration found = endpointConfigurationDao.findById(expected.getConfigurationHash()); Assert.assertEquals(expected, found); }
protected EndpointConfigurationDto generateEndpointConfiguration() { EndpointConfigurationDto configurationDto = new EndpointConfigurationDto(); configurationDto.setConfigurationHash(UUID.randomUUID().toString().getBytes()); configurationDto.setConfiguration(UUID.randomUUID().toString().getBytes()); return endpointConfigurationDao.save(new MongoEndpointConfiguration(configurationDto)).toDto(); }
@Test public void testFindByHash() throws Exception { List<CassandraEndpointConfiguration> configs = generateConfiguration(3); CassandraEndpointConfiguration expected = configs.get(0); CassandraEndpointConfiguration found = endpointConfigurationDao.findByHash(expected.getConfigurationHash().array()); Assert.assertEquals(expected, found); }
@Test public void findEndpointConfigurationByIdTest() { EndpointConfigurationDto configurationDto = generateEndpointConfiguration(); MongoEndpointConfiguration found = endpointConfigurationDao.findById(ByteBuffer.wrap(configurationDto.getConfigurationHash())); Assert.assertNotNull(found); }
protected List<CassandraEndpointConfiguration> generateConfiguration(int count) { List<CassandraEndpointConfiguration> configurations = new ArrayList<>(); for (int i = 0; i < count; i++) { CassandraEndpointConfiguration configuration = new CassandraEndpointConfiguration(); configuration.setConfiguration(ByteBuffer.wrap(generateBytes())); configuration.setConfigurationHash(ByteBuffer.wrap(generateBytes())); configurations.add(endpointConfigurationDao.save(configuration)); } return configurations; }