rewrote ultradns TrafficControllerPoolApiLiveTest to validate metadata such as dname and record ttl

This commit is contained in:
adriancole 2013-03-24 11:41:46 -07:00
parent 5549eddf92
commit 43b2065947
1 changed files with 67 additions and 52 deletions

View File

@ -20,14 +20,18 @@ package org.jclouds.ultradns.ws.features;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.logging.Logger.getAnonymousLogger; import static java.util.logging.Logger.getAnonymousLogger;
import static org.jclouds.ultradns.ws.predicates.TrafficControllerPoolPredicates.idEqualTo;
import static org.jclouds.ultradns.ws.predicates.TrafficControllerPoolPredicates.recordIdEqualTo;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException;
import org.jclouds.ultradns.ws.domain.Account; import org.jclouds.ultradns.ws.domain.Account;
import org.jclouds.ultradns.ws.domain.PoolRecordSpec;
import org.jclouds.ultradns.ws.domain.TrafficControllerPool; import org.jclouds.ultradns.ws.domain.TrafficControllerPool;
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord; import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord;
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord.Status; import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord.Status;
@ -39,7 +43,7 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -64,6 +68,7 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
checkNotNull(pool.getId(), "Id cannot be null for %s", pool); checkNotNull(pool.getId(), "Id cannot be null for %s", pool);
checkNotNull(pool.getName(), "Name cannot be null for %s", pool); checkNotNull(pool.getName(), "Name cannot be null for %s", pool);
checkNotNull(pool.getDName(), "DName cannot be null for %s", pool); checkNotNull(pool.getDName(), "DName cannot be null for %s", pool);
assertEquals(api(zoneName).getNameByDName(pool.getDName()), pool.getName());
} }
@Test @Test
@ -80,13 +85,24 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) { for (Zone zone : context.getApi().getZoneApi().listByAccount(account.getId())) {
for (TrafficControllerPool pool : api(zone.getName()).list()) { for (TrafficControllerPool pool : api(zone.getName()).list()) {
for (TrafficControllerPoolRecord record : api(zone.getName()).listRecords(pool.getId())) { for (TrafficControllerPoolRecord record : api(zone.getName()).listRecords(pool.getId())) {
checkTrafficControllerPoolRecord(record); checkPoolRecordConsistent(zone.getName(), record);
} }
} }
} }
} }
static void checkTrafficControllerPoolRecord(TrafficControllerPoolRecord record) { private TrafficControllerPoolRecord checkPoolRecordConsistent(String zoneName, TrafficControllerPoolRecord record) {
Optional<TrafficControllerPool> pool = getPoolByZoneAndId(zoneName, record.getPoolId());
assertTrue(pool.isPresent(), "could not get pool for " + record);
assertEquals(record.getDescription(), pool.get().getName());
PoolRecordSpec spec = checkPoolRecordSpec(api(zoneName).getRecordSpec(record.getId()));
assertEquals(record.getDescription(), spec.getDescription());
assertEquals(record.getWeight(), spec.getWeight());
assertEquals(record.isProbingEnabled(), spec.isProbingEnabled());
return checkTrafficControllerPoolRecord(record);
}
static TrafficControllerPoolRecord checkTrafficControllerPoolRecord(TrafficControllerPoolRecord record) {
checkNotNull(record.getId(), "Id cannot be null for %s", record); checkNotNull(record.getId(), "Id cannot be null for %s", record);
checkNotNull(record.getPoolId(), "PoolId cannot be null for %s", record); checkNotNull(record.getPoolId(), "PoolId cannot be null for %s", record);
checkNotNull(record.getPointsTo(), "PointsTo cannot be null for %s", record); checkNotNull(record.getPointsTo(), "PointsTo cannot be null for %s", record);
@ -121,6 +137,21 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
api(zoneName).delete("06063D9C54C5AE09"); api(zoneName).delete("06063D9C54C5AE09");
} }
@Test
public void testDeleteRecordWhenNotFound() {
api(zoneName).deleteRecord("06063D9C54C5AE09");
}
@Test
public void testGetNameByDNameWhenNotFound() {
assertNull(api(zoneName).getNameByDName("www.razzledazzle.cn."));
}
@Test
public void testGetRecordSpecWhenNotFound() {
assertNull(api(zoneName).getRecordSpec("06063D9C54C5AE09"));
}
String hostname = "www.tcpool." + zoneName; String hostname = "www.tcpool." + zoneName;
String poolId; String poolId;
@ -134,8 +165,16 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
} catch (ResourceAlreadyExistsException e) { } catch (ResourceAlreadyExistsException e) {
} }
Optional<TrafficControllerPool> pool = getPoolById(poolId); // ensure there's only one pool for a hostname
try {
api(zoneName).createPoolForHostname("pool1", hostname);
fail();
} catch (ResourceAlreadyExistsException e) {
}
Optional<TrafficControllerPool> pool = getPoolByZoneAndId(zoneName, poolId);
assertTrue(pool.isPresent()); assertTrue(pool.isPresent());
assertEquals(pool.get().getId(), poolId);
assertEquals(pool.get().getName(), "pool"); assertEquals(pool.get().getName(), "pool");
assertEquals(pool.get().getDName(), hostname); assertEquals(pool.get().getDName(), hostname);
checkTCPool(pool.get()); checkTCPool(pool.get());
@ -143,25 +182,27 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
@DataProvider(name = "records") @DataProvider(name = "records")
public Object[][] createRecords() { public Object[][] createRecords() {
Object[][] records = new Object[2][2]; Object[][] records = new Object[2][3];
records[0][0] = "1.2.3.4"; records[0][0] = "1.2.3.4";
records[0][1] = "A"; records[0][1] = "A";
records[0][2] = 60;
records[1][0] = "5.6.7.8"; records[1][0] = "5.6.7.8";
records[1][1] = "A"; records[1][1] = "A";
records[1][2] = 60;
return records; return records;
} }
@Test(dependsOnMethods = "testCreatePool", dataProvider = "records") @Test(dependsOnMethods = "testCreatePool", dataProvider = "records")
public void addRecordsToPool(final String pointsTo, final String type) { public TrafficControllerPoolRecord addRecordToPool(final String pointsTo, final String type, final int ttl) {
final String record = api(zoneName).addRecordToPoolWithTTL(pointsTo, poolId, 30); String recordId = api(zoneName).addRecordToPoolWithTTL(pointsTo, poolId, ttl);
getAnonymousLogger().info("created " + type + " record: " + recordId);
getAnonymousLogger().info("created " + type + " record: " + record); TrafficControllerPoolRecord record = checkPoolRecordConsistent(zoneName, getRecordById(recordId).get());
PoolRecordSpec recordSpec = checkPoolRecordSpec(api(zoneName).getRecordSpec(recordId));
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() { assertEquals(record.getPointsTo(), pointsTo);
public boolean apply(TrafficControllerPoolRecord in) { assertEquals(record.getType(), type);
return record.equals(in.getId()) && pointsTo.equals(in.getPointsTo()) && type.equals(in.getType()); assertEquals(record.getWeight(), 2);
} assertEquals(recordSpec.getTTL(), ttl);
})); return record;
} }
String cname1; String cname1;
@ -169,15 +210,7 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
@Test(dependsOnMethods = "testCreatePool") @Test(dependsOnMethods = "testCreatePool")
public void addCNAMERecordsToPool() { public void addCNAMERecordsToPool() {
cname1 = api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30); cname1 = addRecordToPool("www.foo.com.", "CNAME", 30).getId();
getAnonymousLogger().info("created CNAME record: " + cname1);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname1.equals(in.getId()) && "www.foo.com.".equals(in.getPointsTo()) && "CNAME".equals(in.getType());
}
}));
try { try {
api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30); api(zoneName).addRecordToPoolWithTTL("www.foo.com.", poolId, 30);
@ -186,46 +219,28 @@ public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest
} }
cname2 = api(zoneName).addRecordToPoolWithTTL("www.bar.com.", poolId, 30); cname2 = addRecordToPool("www.bar.com.", "CNAME", 30).getId();
getAnonymousLogger().info("created CNAME record: " + cname2);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname2.equals(in.getId()) && "www.bar.com.".equals(in.getPointsTo()) && "CNAME".equals(in.getType());
}
}));
} }
@Test(dependsOnMethods = "addCNAMERecordsToPool") @Test(dependsOnMethods = "addCNAMERecordsToPool")
public void testDeleteRecord() { public void testDeleteRecord() {
api(zoneName).deleteRecord(cname1); api(zoneName).deleteRecord(cname1);
assertTrue(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() { assertFalse(getRecordById(cname1).isPresent());
public boolean apply(TrafficControllerPoolRecord in) { assertTrue(getRecordById(cname2).isPresent());
return cname2.equals(in.getId());
}
}));
assertFalse(api(zoneName).listRecords(poolId).anyMatch(new Predicate<TrafficControllerPoolRecord>() {
public boolean apply(TrafficControllerPoolRecord in) {
return cname1.equals(in.getId());
}
}));
} }
@Test(dependsOnMethods = "testDeleteRecord") @Test(dependsOnMethods = "testDeleteRecord")
public void testDeletePool() { public void testDeletePool() {
api(zoneName).delete(poolId); api(zoneName).delete(poolId);
assertFalse(getPoolById(poolId).isPresent()); assertFalse(getPoolByZoneAndId(zoneName, poolId).isPresent());
} }
protected Optional<TrafficControllerPool> getPoolById(final String poolId) { private Optional<TrafficControllerPoolRecord> getRecordById(String recordId) {
return api(zoneName).list().firstMatch(new Predicate<TrafficControllerPool>() { return api(zoneName).listRecords(poolId).firstMatch(recordIdEqualTo(recordId));
public boolean apply(TrafficControllerPool in) {
return in.getId().equals(poolId);
} }
});
private Optional<TrafficControllerPool> getPoolByZoneAndId(String zoneName, final String poolId) {
return api(zoneName).list().firstMatch(idEqualTo(poolId));
} }
private TrafficControllerPoolApi api(String zoneName) { private TrafficControllerPoolApi api(String zoneName) {