use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.
the class GloboDnsResourceTest method testUpdateRecordAndReverseWhenDomainExistsAndOverrideIsTrue.
// ///////////////////////
// Update Record tests //
// ///////////////////////
@Test
public void testUpdateRecordAndReverseWhenDomainExistsAndOverrideIsTrue() throws Exception {
String recordName = "recordname";
String oldRecordIp = "40.30.20.10";
String newRecordIp = "50.40.30.20";
String domainName = "domain.name.com";
String reverseDomainName = "30.40.50.in-addr.arpa";
String reverseRecordName = "20";
String reverseRecordContent = recordName + "." + domainName;
Domain domain = generateFakeDomain(domainName, false);
Record record = generateFakeRecord(domain, recordName, oldRecordIp, false);
Domain reverseDomain = generateFakeDomain(reverseDomainName, true);
Record reverseRecord = generateFakeRecord(reverseDomain, reverseRecordName, "X", true);
Answer answer = _globoDnsResource.execute(new CreateOrUpdateRecordAndReverseCommand(recordName, newRecordIp, domainName, TEMPLATE_ID, true));
// ensure calls in sequence to ensure this call are the only ones.
InOrder inOrder = inOrder(_recordApi);
inOrder.verify(_recordApi, times(1)).updateRecord(eq(record.getId()), eq(domain.getId()), eq(recordName), eq(newRecordIp));
inOrder.verify(_recordApi, times(1)).updateRecord(eq(reverseRecord.getId()), eq(reverseDomain.getId()), eq(reverseRecordName), eq(reverseRecordContent));
assertNotNull(answer);
assertEquals(true, answer.getResult());
verify(_exportApi, times(1)).scheduleExport();
}
use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.
the class GloboDnsResourceTest method testCreateRecordAndReverseWillFailWhenReverseRecordAlreadyExistsAndOverrideIsFalse.
@Test
@SuppressWarnings("unused")
public void testCreateRecordAndReverseWillFailWhenReverseRecordAlreadyExistsAndOverrideIsFalse() throws Exception {
String recordName = "recordname";
String recordIp = "40.30.20.10";
String domainName = "domain.name.com";
String reverseDomainName = "20.30.40.in-addr.arpa";
String reverseRecordName = "10";
Domain domain = generateFakeDomain(domainName, false);
Record record = generateFakeRecord(domain, recordName, recordIp, false);
Domain reverseDomain = generateFakeDomain(reverseDomainName, true);
Record reverseRecord = generateFakeRecord(reverseDomain, reverseRecordName, "X", true);
Answer answer = _globoDnsResource.execute(new CreateOrUpdateRecordAndReverseCommand(recordName, recordIp, domainName, TEMPLATE_ID, false));
assertNotNull(answer);
assertEquals(false, answer.getResult());
}
use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.
the class GloboDnsResourceTest method testCreateRecordAndReverseWhenDomainDoesNotExist.
@Test
public void testCreateRecordAndReverseWhenDomainDoesNotExist() throws Exception {
String recordName = "recordname";
String recordIp = "40.30.20.10";
String domainName = "domain.name.com";
String reverseDomainName = "20.30.40.in-addr.arpa";
String reverseRecordName = "10";
String reverseRecordContent = recordName + "." + domainName;
Domain domain = new Domain();
domain.getDomainAttributes().setId(sequenceId++);
Domain reverseDomain = new Domain();
reverseDomain.getDomainAttributes().setId(sequenceId++);
Record record = new Record();
when(_domainApi.listByQuery(domainName)).thenReturn(new ArrayList<Domain>());
when(_domainApi.createDomain(eq(domainName), eq(TEMPLATE_ID), eq("M"))).thenReturn(domain);
when(_recordApi.createRecord(eq(domain.getId()), eq(recordName), eq(recordIp), eq("A"))).thenReturn(record);
when(_domainApi.createReverseDomain(eq(reverseDomainName), eq(TEMPLATE_ID), eq("M"))).thenReturn(reverseDomain);
when(_recordApi.createRecord(eq(reverseDomain.getId()), eq(reverseRecordName), eq(reverseRecordContent), eq("PTR"))).thenReturn(record);
Answer answer = _globoDnsResource.execute(new CreateOrUpdateRecordAndReverseCommand(recordName, recordIp, domainName, TEMPLATE_ID, true));
assertNotNull(answer);
assertEquals(true, answer.getResult());
verify(_exportApi, times(1)).scheduleExport();
}
use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.
the class GloboDnsResourceTest method testCreateRecordAndReverseWithSuccessWhenDomainExistsAndRecordDoesntExistAndOverrideIsTrue.
// ///////////////////////
// Create Record tests //
// ///////////////////////
@Test
@SuppressWarnings("unused")
public void testCreateRecordAndReverseWithSuccessWhenDomainExistsAndRecordDoesntExistAndOverrideIsTrue() throws Exception {
String recordName = "recordname";
String recordIp = "40.30.20.10";
String domainName = "domain.name.com";
String reverseDomainName = "20.30.40.in-addr.arpa";
String reverseRecordName = "10";
String reverseRecordContent = recordName + "." + domainName;
Domain domain = generateFakeDomain(domainName, false);
Record record = generateFakeRecord(domain, recordName, recordIp, false);
Domain reverseDomain = generateFakeDomain(reverseDomainName, true);
Record reverseRecord = generateFakeRecord(reverseDomain, reverseRecordName, reverseRecordContent, true);
when(_recordApi.createRecord(eq(domain.getId()), eq(recordName), eq(recordIp), eq("A"))).thenReturn(record);
when(_recordApi.createRecord(eq(reverseDomain.getId()), eq(reverseRecordName), eq(reverseRecordContent), eq("PTR"))).thenReturn(record);
Answer answer = _globoDnsResource.execute(new CreateOrUpdateRecordAndReverseCommand(recordName, recordIp, domainName, TEMPLATE_ID, true));
assertNotNull(answer);
assertEquals(true, answer.getResult());
verify(_exportApi, times(1)).scheduleExport();
}
use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.
the class GloboDnsResourceTest method testCreateRecordAndReverseWhenDomainDoesNotExistAndOverrideIsFalse.
@Test
public void testCreateRecordAndReverseWhenDomainDoesNotExistAndOverrideIsFalse() throws Exception {
String recordName = "recordname";
String recordIp = "40.30.20.10";
String domainName = "domain.name.com";
String reverseDomainName = "20.30.40.in-addr.arpa";
String reverseRecordName = "10";
String reverseRecordContent = recordName + "." + domainName;
Domain domain = new Domain();
domain.getDomainAttributes().setId(sequenceId++);
Domain reverseDomain = new Domain();
reverseDomain.getDomainAttributes().setId(sequenceId++);
Record record = new Record();
when(_domainApi.listByQuery(domainName)).thenReturn(new ArrayList<Domain>());
when(_domainApi.createDomain(eq(domainName), eq(TEMPLATE_ID), eq("M"))).thenReturn(domain);
when(_recordApi.createRecord(eq(domain.getId()), eq(recordName), eq(recordIp), eq("A"))).thenReturn(record);
when(_domainApi.createReverseDomain(eq(reverseDomainName), eq(TEMPLATE_ID), eq("M"))).thenReturn(reverseDomain);
when(_recordApi.createRecord(eq(reverseDomain.getId()), eq(reverseRecordName), eq(reverseRecordContent), eq("PTR"))).thenReturn(record);
Answer answer = _globoDnsResource.execute(new CreateOrUpdateRecordAndReverseCommand(recordName, recordIp, domainName, TEMPLATE_ID, false));
assertNotNull(answer);
assertEquals(true, answer.getResult());
verify(_exportApi, times(1)).scheduleExport();
}
Aggregations