Search in sources :

Example 1 with RemoveDomainCommand

use of com.globo.globodns.cloudstack.commands.RemoveDomainCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testRemoveDomainWithSuccessWhenDomainExistsAndThereAreOnlyNSRecordsAndOverrideIsFalse.

@Test
public void testRemoveDomainWithSuccessWhenDomainExistsAndThereAreOnlyNSRecordsAndOverrideIsFalse() throws Exception {
    String domainName = "domain.name.com";
    Domain domain = generateFakeDomain(domainName, false);
    List<Record> recordList = new ArrayList<Record>();
    for (int i = 0; i < 10; i++) {
        Record record = new Record();
        record.getTypeNSRecordAttributes().setDomainId(domain.getId());
        record.getTypeNSRecordAttributes().setId(sequenceId++);
        record.getTypeNSRecordAttributes().setType("NS");
        recordList.add(record);
    }
    when(_recordApi.listAll(domain.getId())).thenReturn(recordList);
    Answer answer = _globoDnsResource.execute(new RemoveDomainCommand(domainName, false));
    assertEquals(true, answer.getResult());
    verify(_domainApi, times(1)).removeDomain(eq(domain.getId()));
    verify(_exportApi, times(1)).scheduleExport();
}
Also used : Answer(com.cloud.agent.api.Answer) RemoveDomainCommand(com.globo.globodns.cloudstack.commands.RemoveDomainCommand) ArrayList(java.util.ArrayList) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) Test(org.junit.Test)

Example 2 with RemoveDomainCommand

use of com.globo.globodns.cloudstack.commands.RemoveDomainCommand in project cloudstack by apache.

the class GloboDnsElement method destroy.

@Override
@DB
public boolean destroy(final Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    Long zoneId = network.getDataCenterId();
    final DataCenter zone = _dcDao.findById(zoneId);
    if (zone == null) {
        throw new CloudRuntimeException("Could not find zone associated to this network");
    }
    RemoveDomainCommand cmd = new RemoveDomainCommand(network.getNetworkDomain(), GloboDNSOverride.value());
    callCommand(cmd, zoneId);
    return true;
}
Also used : RemoveDomainCommand(com.globo.globodns.cloudstack.commands.RemoveDomainCommand) DataCenter(com.cloud.dc.DataCenter) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 3 with RemoveDomainCommand

use of com.globo.globodns.cloudstack.commands.RemoveDomainCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testRemoveDomainWithSuccessWhenDomainExistsAndThereAreRecordsAndOverrideIsTrue.

@Test
public void testRemoveDomainWithSuccessWhenDomainExistsAndThereAreRecordsAndOverrideIsTrue() throws Exception {
    String domainName = "domain.name.com";
    Domain domain = generateFakeDomain(domainName, false);
    List<Record> recordList = new ArrayList<Record>();
    for (int i = 0; i < 10; i++) {
        Record record = new Record();
        record.getTypeNSRecordAttributes().setDomainId(domain.getId());
        record.getTypeNSRecordAttributes().setId(sequenceId++);
        record.getTypeNSRecordAttributes().setType(new String[] { "A", "NS", "PTR" }[i % 3]);
        recordList.add(record);
    }
    when(_recordApi.listAll(domain.getId())).thenReturn(recordList);
    Answer answer = _globoDnsResource.execute(new RemoveDomainCommand(domainName, true));
    assertEquals(true, answer.getResult());
    verify(_domainApi, times(1)).removeDomain(eq(domain.getId()));
    verify(_exportApi, times(1)).scheduleExport();
}
Also used : Answer(com.cloud.agent.api.Answer) RemoveDomainCommand(com.globo.globodns.cloudstack.commands.RemoveDomainCommand) ArrayList(java.util.ArrayList) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) Test(org.junit.Test)

Aggregations

RemoveDomainCommand (com.globo.globodns.cloudstack.commands.RemoveDomainCommand)3 Answer (com.cloud.agent.api.Answer)2 Domain (com.globo.globodns.client.model.Domain)2 Record (com.globo.globodns.client.model.Record)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DataCenter (com.cloud.dc.DataCenter)1 DB (com.cloud.utils.db.DB)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1