Skip to content

Commit

Permalink
Merge pull request #1011 from auhlig/designate
Browse files Browse the repository at this point in the history
designate v2 service
  • Loading branch information
auhlig authored May 7, 2017
2 parents d1d13cd + c6db075 commit d4fb1d9
Show file tree
Hide file tree
Showing 38 changed files with 3,148 additions and 622 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
package org.openstack4j.api.dns.v2
import co.freeside.betamax.TapeMode
import groovy.util.logging.Slf4j
import org.junit.Rule
import org.junit.rules.TestName
import org.openstack4j.api.AbstractSpec
import org.openstack4j.api.Builders
import org.openstack4j.api.OSClient.OSClientV3
import org.openstack4j.model.common.ActionResponse
import org.openstack4j.model.common.Identifier
import org.openstack4j.model.dns.v2.Recordset
import org.openstack4j.openstack.OSFactory
import software.betamax.Configuration
import software.betamax.MatchRules
import software.betamax.TapeMode
import software.betamax.junit.Betamax
import software.betamax.junit.RecorderRule
import spock.lang.IgnoreIf
@Slf4j
class DesignateRecordsetServiceSpec extends AbstractSpec {
@Rule TestName DesignateRecordsetServiceTest
@Rule public RecorderRule recorderRule = new RecorderRule(
Configuration.builder()
.tapeRoot(new File(TAPEROOT + "identity.v3"))
//.defaultMatchRules(MatchRules.method, MatchRules.path, MatchRules.queryParams)
.defaultMode(TapeMode.WRITE_SEQUENTIAL)
.build());
// used for domain crud tests
def static final String RECORDSET_NAME = "Atest."
def static final String RECORDSET_TYPE = "A"
def static final List<String> RECORDSET_RECORDS= ["10.1.0.2"]
def static final String RECORDSET_DESCRIPTION = "This is my recordset."
def String ZONE_ID, ZONE_NAME, RECORDSET_ID
static final boolean skipTest
static {
if(
USER_ID == null ||
AUTH_URL == null ||
PASSWORD == null ||
DOMAIN_ID == null ) {
skipTest = true
}
else{
skipTest = false
}
}
// run before the first feature method; similar to JUnit's @BeforeClass
def setupSpec() {
if( skipTest != true ) {
log.info("USER_NAME: " + USER_NAME)
log.info("USER_DOMAIN_ID: " + USER_DOMAIN_ID)
log.info("AUTH_URL: " + AUTH_URL)
log.info("PROJECT_ID: " + PROJECT_ID)
}
else {
log.warn("Skipping integration-test cases because not all mandatory attributes are set.");
}
}
def setup() {
log.info("-> Test: '$DesignateRecordsetServiceTest.methodName'")
}
// ------------ DomainService Tests ------------
@IgnoreIf({ skipTest })
@Betamax(tape="recordsetService_crud")
def "dns/v2/recordset test cases"() {
given: "an authenticated OSClient"
OSClientV3 os = OSFactory.builderV3()
.endpoint(AUTH_URL)
.credentials(USER_NAME, PASSWORD, Identifier.byId(USER_DOMAIN_ID))
.scopeToProject(Identifier.byId(PROJECT_ID))
.withConfig(CONFIG_PROXY_BETAMAX)
.authenticate()
and: "get the id of a dns zone"
ZONE_ID = os.dns().zones().list().first().getId()
and: "the id of the zone shouldn't be null"
ZONE_ID != null
and: "get name of the zone"
ZONE_NAME = os.dns().zones().list().first().getName()
and: "the name of the zone shouldn't be null"
ZONE_NAME != null
when: "we try to create a recordset with argument 'null' "
os.dns().recordsets().create(null, null)
then: "a NPE is thrown"
thrown NullPointerException
when: "creating a recordset"
Recordset recordset = os.dns().recordsets().create(ZONE_ID, RECORDSET_NAME+ZONE_NAME, RECORDSET_TYPE, RECORDSET_RECORDS)
then: "the attributes of the recordset should be equal"
recordset.getName() == RECORDSET_NAME+ZONE_NAME
recordset.getZoneId() == ZONE_ID
recordset.getType() == RECORDSET_TYPE
recordset.getRecords() == RECORDSET_RECORDS
when: "getting the id of the recordset"
RECORDSET_ID = recordset.getId()
then: "this shouldn't be null"
RECORDSET_ID != null
when: "list recordsets owned by project"
List<? extends Recordset> recordsetList = os.dns().recordsets().list()
then: "the list shouldn't be empty and the recordset belongs to the project"
recordsetList.isEmpty() == false
recordsetList.first().getProjectId() == PROJECT_ID
when: "list recordsets in a zone"
List<? extends Recordset> recordsetListZone = os.dns().recordsets().list(ZONE_ID)
then: "the list shouldn't be empty and the recordset is within the zone"
recordsetListZone.isEmpty() == false
recordsetListZone.first().getZoneId() == ZONE_ID
when: "get a recordset by id"
Recordset recordsetById = os.dns().recordsets().get(ZONE_ID,RECORDSET_ID)
then: "the attributes of the recordset should be equal"
recordsetById.getZoneId() == ZONE_ID
recordsetById.getId() == RECORDSET_ID
when: "updating a recordset"
Recordset recordsetUpdated = os.dns().recordsets().update(ZONE_ID, Builders.recordset().id(RECORDSET_ID).description(RECORDSET_DESCRIPTION).build())
then: "the attribute of the recordset should be updated"
recordsetUpdated.getDescription() == RECORDSET_DESCRIPTION
when: "deleting a recordset"
ActionResponse deleteRecordset = os.dns().recordsets().delete(ZONE_ID,RECORDSET_ID)
then: "this should be successful"
deleteRecordset.isSuccess() == true
cleanup: "delete created recordset in case of errors"
os.dns().recordsets().delete(ZONE_ID,RECORDSET_ID)
}
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
package org.openstack4j.api.dns.v2
import co.freeside.betamax.TapeMode
import groovy.util.logging.Slf4j
import org.junit.Rule
import org.junit.rules.TestName
import org.openstack4j.api.AbstractSpec
import org.openstack4j.api.Builders
import org.openstack4j.api.OSClient.OSClientV3
import org.openstack4j.model.common.ActionResponse
import org.openstack4j.model.common.Identifier
import org.openstack4j.model.dns.v2.Nameserver
import org.openstack4j.model.dns.v2.Zone
import org.openstack4j.model.dns.v2.ZoneType
import org.openstack4j.openstack.OSFactory
import software.betamax.Configuration
import software.betamax.MatchRules
import software.betamax.TapeMode
import software.betamax.junit.Betamax
import software.betamax.junit.RecorderRule
import spock.lang.IgnoreIf
@Slf4j
class DesignateZoneServiceSpec extends AbstractSpec {
@Rule TestName DesignateZoneServiceTest
@Rule public RecorderRule recorderRule = new RecorderRule(
Configuration.builder()
.tapeRoot(new File(TAPEROOT + "dns.v2"))
//.defaultMatchRules(MatchRules.method, MatchRules.path, MatchRules.queryParams)
.defaultMode(TapeMode.WRITE_ONLY)
.build());
// used for domain crud tests
def static final String ZONE_NAME = "b.org."
def static final String ZONE_EMAIL = "[email protected]"
def static final Integer ZONE_TTL = 3602
def static final ZoneType ZONE_TYPE = ZoneType.PRIMARY
def static final String ZONE_DESCRIPTION = "This is my zone."
def static final String NAMESERVER_HOSTNAME = "hostname"
def String ZONE_ID
static final boolean skipTest
static {
if(
USER_ID == null ||
AUTH_URL == null ||
PASSWORD == null ||
DOMAIN_ID == null ) {
skipTest = true
}
else{
skipTest = false
}
}
// run before the first feature method; similar to JUnit's @BeforeClass
def setupSpec() {
if( skipTest != true ) {
log.info("USER_NAME: " + USER_NAME)
log.info("USER_DOMAIN_ID: " + USER_DOMAIN_ID)
log.info("AUTH_URL: " + AUTH_URL)
log.info("PROJECT_ID: " + PROJECT_ID)
}
else {
log.warn("Skipping integration-test cases because not all mandatory attributes are set.");
}
}
def setup() {
log.info("-> Test: '$DesignateZoneServiceTest.methodName'")
}
// ------------ DomainService Tests ------------
@IgnoreIf({ skipTest })
@Betamax(tape="zoneService_crud")
def "dns/v2/zone service test cases"() {
given: "an authenticated OSClient"
OSClientV3 os = OSFactory.builderV3()
.endpoint(AUTH_URL)
.credentials(USER_NAME, PASSWORD, Identifier.byId(USER_DOMAIN_ID))
.scopeToProject(Identifier.byId(PROJECT_ID))
.withConfig(CONFIG_PROXY_BETAMAX)
.authenticate()
when: "we try to create a zone with argument 'null' "
os.dns().zones().create(null)
then: "a NPE is thrown"
thrown NullPointerException
// commented out due to permission foo
// when: "a new domain is created using DomainBuilder with valid arguments"
// Zone zone = Builders.zone()
// .name(ZONE_NAME)
// .email(ZONE_EMAIL)
// .ttl(ZONE_TTL)
// .description(ZONE_DESCRIPTION)
// .type(ZONE_TYPE)
// .build()
//
// and:
// Zone newZone = os.dns().zones().create(zone)
//
// then: "verify that the new domain is correct"
// newZone.getId != null
// newZone.getName() == ZONE_NAME
// newZone.getEmail() == ZONE_EMAIL
// newZone.getTTL() == ZONE_TTL
// newZone.getDescription() == ZONE_DESCRIPTION
// newZone.getType() == ZONE_TYPE
when: "listing all zones"
List<? extends Zone> zoneList = os.dns().zones().list()
then: "the list shouldn't be empty"
zoneList.isEmpty() == false
when: "get the id of the first zone"
ZONE_ID = zoneList.first().getId()
then: "the id of the first item shouldn't be null"
ZONE_ID != null
and: "the attributes of the zone should be equal"
zoneList.first().getProjectId() == PROJECT_ID
zoneList.first().getType() == ZONE_TYPE
zoneList.first().getTTL() == ZONE_TTL
when: "get a zone by id"
Zone zoneById = os.dns().zones().get(ZONE_ID)
then: "the attributes of the zone should be as expected "
zoneById.getId() == ZONE_ID
zoneById.getProjectId() == PROJECT_ID
when: "get nameserver for a zone specified by id"
List<? extends Nameserver> nameserverList = os.dns().zones().listNameservers(ZONE_ID)
then: "this list shouldn't be empty"
nameserverList.isEmpty() == false
nameserverList.first().getHostname() == NAMESERVER_HOSTNAME
nameserverList.first().getPriority() == 1
// commented out due to permission foo
// when: "updating a zone description"
// Zone zoneUpdated = os.dns().zones().update(Builders.zone().id(ZONE_ID).description(ZONE_DESCRIPTION).build())
//
// then: "the description should be updated"
// zoneUpdated.getDescription() == ZONE_DESCRIPTION
// commented out due to permission foo
// when: "deleting a zone"
// ActionResponse deleteZoneResponse = os.dns().zones().delete(ZONE_ID)
//
// then: "this should be successfull"
// deleteZoneResponse.isSuccess() == true
}
}
*/
Loading

0 comments on commit d4fb1d9

Please sign in to comment.