@Test public void testRemoveByRecords() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); // Add 5 record DNSRecord record1 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1"); DNSRecord record2 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.2"); DNSRecord record3 = DNSRecordUtils.createARecord("example2.domain.com", 86400L, "127.0.0.3"); DNSRecord record4 = DNSRecordUtils.createSRVRecord( "_ldap_cerner._tcp.cerner.com", "example.domain.com", 86400L, 3506, 1, 1); DNSRecord record5 = DNSRecordUtils.createSRVRecord( "_ldap_cerner._tcp.cerner.com", "example2.domain.com", 86400L, 3506, 1, 1); dnsDao.add(Arrays.asList(record1, record2, record3, record4, record5)); assertEquals(5, dnsDao.count()); // remove the first three records dnsDao.remove(Arrays.asList(record1, record2, record3)); Collection<DNSRecord> records = dnsDao.get(Type.ANY); assertEquals(2, records.size()); assertTrue(records.contains(record4)); assertTrue(records.contains(record5)); // remove the last two records dnsDao.remove(Arrays.asList(record4, record5)); records = dnsDao.get(Type.ANY); assertEquals(0, records.size()); }
@Test public void testRemoveByIds_noqualifying() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); dnsDao.remove(876343); // should result in a functional no-op assertEquals(0, dnsDao.count()); }
@Test public void testRemoveByRecords_noqualifying() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); DNSRecord record1 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1"); // should result in a functional no-op dnsDao.remove(Arrays.asList(record1)); assertEquals(0, dnsDao.count()); }
@Test public void testUpdateRecord_illegalAnyType() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); DNSRecord record1 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1"); dnsDao.add(Arrays.asList(record1)); Collection<DNSRecord> records = dnsDao.get(Type.ANY); assertEquals(1, records.size()); DNSRecord checkRecord = records.iterator().next(); assertEquals(record1, checkRecord); checkRecord.setType(Type.ANY); boolean exceptionOccured = false; try { dnsDao.update(checkRecord.getId(), checkRecord); } catch (ConfigurationStoreException e) { exceptionOccured = true; } assertTrue(exceptionOccured); }
@Test public void testRemoveByIds() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); // Add 5 record DNSRecord record1 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1"); DNSRecord record2 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.2"); DNSRecord record3 = DNSRecordUtils.createARecord("example2.domain.com", 86400L, "127.0.0.3"); DNSRecord record4 = DNSRecordUtils.createSRVRecord( "_ldap_cerner._tcp.cerner.com", "example.domain.com", 86400L, 3506, 1, 1); DNSRecord record5 = DNSRecordUtils.createSRVRecord( "_ldap_cerner._tcp.cerner.com", "example2.domain.com", 86400L, 3506, 1, 1); dnsDao.add(Arrays.asList(record1, record2, record3, record4, record5)); assertEquals(5, dnsDao.count()); // remove record 3 Collection<DNSRecord> records = dnsDao.get(record3.getName()); assertEquals(1, records.size()); dnsDao.remove(records.iterator().next().getId()); records = dnsDao.get(Type.ANY); assertEquals(4, dnsDao.count()); assertTrue(records.contains(record1)); assertTrue(records.contains(record2)); assertTrue(records.contains(record4)); assertTrue(records.contains(record5)); // remove the rest long[] ids = new long[records.size()]; int cnt = 0; for (DNSRecord record : records) ids[cnt++] = record.getId(); dnsDao.remove(ids); records = dnsDao.get(Type.ANY); assertEquals(0, records.size()); }
@Test public void testGetCount() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); // Add 5 record DNSRecord record1 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1"); DNSRecord record2 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.2"); DNSRecord record3 = DNSRecordUtils.createARecord("example2.domain.com", 86400L, "127.0.0.3"); DNSRecord record4 = DNSRecordUtils.createSRVRecord( "_ldap_cerner._tcp.cerner.com", "example.domain.com", 86400L, 3506, 1, 1); DNSRecord record5 = DNSRecordUtils.createSRVRecord( "_ldap_cerner._tcp.cerner.com", "example2.domain.com", 86400L, 3506, 1, 1); dnsDao.add(Arrays.asList(record1, record2, record3, record4, record5)); assertEquals(5, dnsDao.count()); }
@Test public void testUpdateRecord_recordDoesNotExist() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); DNSRecord record1 = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1"); boolean exceptionOccured = false; try { dnsDao.update(123432, record1); } catch (ConfigurationStoreException e) { exceptionOccured = true; } assertTrue(exceptionOccured); }
@Test public void testUpdateRecord() throws Exception { testCleanDatabase(); assertEquals(0, dnsDao.count()); DNSRecord record1 = DNSRecordUtils.createMXRecord("example.domain.com", "127.0.0.1", 86400L, 1); dnsDao.add(Arrays.asList(record1)); Collection<DNSRecord> records = dnsDao.get(Type.ANY); assertEquals(1, records.size()); DNSRecord checkRecord = records.iterator().next(); assertEquals(record1, checkRecord); checkRecord.setName("example2.domain.com."); dnsDao.update(checkRecord.getId(), checkRecord); records = dnsDao.get(Type.ANY); assertEquals(1, records.size()); DNSRecord modRecord = records.iterator().next(); assertEquals(checkRecord, modRecord); }
/** {@inheritDoc} */ @Override public int getDNSCount() throws ConfigurationServiceException { return dao.count(); }