Search in sources :

Example 1 with CreateOrUpdateRecordAndReverseCommand

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();
}
Also used : Answer(com.cloud.agent.api.Answer) InOrder(org.mockito.InOrder) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 2 with CreateOrUpdateRecordAndReverseCommand

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());
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 3 with CreateOrUpdateRecordAndReverseCommand

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();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 4 with CreateOrUpdateRecordAndReverseCommand

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();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 5 with CreateOrUpdateRecordAndReverseCommand

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();
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Aggregations

CreateOrUpdateRecordAndReverseCommand (com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand)7 Answer (com.cloud.agent.api.Answer)6 Domain (com.globo.globodns.client.model.Domain)6 Record (com.globo.globodns.client.model.Record)6 Test (org.junit.Test)6 DataCenter (com.cloud.dc.DataCenter)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 DB (com.cloud.utils.db.DB)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 InOrder (org.mockito.InOrder)1