Skip to content

Commit d4fb1d9

Browse files
authored
Merge pull request #1011 from auhlig/designate
designate v2 service
2 parents d1d13cd + c6db075 commit d4fb1d9

38 files changed

+3148
-622
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
package org.openstack4j.api.dns.v2
3+
4+
import co.freeside.betamax.TapeMode
5+
import groovy.util.logging.Slf4j
6+
import org.junit.Rule
7+
import org.junit.rules.TestName
8+
import org.openstack4j.api.AbstractSpec
9+
import org.openstack4j.api.Builders
10+
import org.openstack4j.api.OSClient.OSClientV3
11+
import org.openstack4j.model.common.ActionResponse
12+
import org.openstack4j.model.common.Identifier
13+
import org.openstack4j.model.dns.v2.Recordset
14+
import org.openstack4j.openstack.OSFactory
15+
import software.betamax.Configuration
16+
import software.betamax.MatchRules
17+
import software.betamax.TapeMode
18+
import software.betamax.junit.Betamax
19+
import software.betamax.junit.RecorderRule
20+
import spock.lang.IgnoreIf
21+
22+
@Slf4j
23+
class DesignateRecordsetServiceSpec extends AbstractSpec {
24+
25+
@Rule TestName DesignateRecordsetServiceTest
26+
@Rule public RecorderRule recorderRule = new RecorderRule(
27+
Configuration.builder()
28+
.tapeRoot(new File(TAPEROOT + "identity.v3"))
29+
//.defaultMatchRules(MatchRules.method, MatchRules.path, MatchRules.queryParams)
30+
.defaultMode(TapeMode.WRITE_SEQUENTIAL)
31+
.build());
32+
33+
// used for domain crud tests
34+
def static final String RECORDSET_NAME = "Atest."
35+
def static final String RECORDSET_TYPE = "A"
36+
def static final List<String> RECORDSET_RECORDS= ["10.1.0.2"]
37+
def static final String RECORDSET_DESCRIPTION = "This is my recordset."
38+
def String ZONE_ID, ZONE_NAME, RECORDSET_ID
39+
40+
static final boolean skipTest
41+
42+
static {
43+
if(
44+
USER_ID == null ||
45+
AUTH_URL == null ||
46+
PASSWORD == null ||
47+
DOMAIN_ID == null ) {
48+
49+
skipTest = true
50+
}
51+
else{
52+
skipTest = false
53+
}
54+
}
55+
56+
57+
// run before the first feature method; similar to JUnit's @BeforeClass
58+
def setupSpec() {
59+
60+
if( skipTest != true ) {
61+
log.info("USER_NAME: " + USER_NAME)
62+
log.info("USER_DOMAIN_ID: " + USER_DOMAIN_ID)
63+
log.info("AUTH_URL: " + AUTH_URL)
64+
log.info("PROJECT_ID: " + PROJECT_ID)
65+
}
66+
else {
67+
log.warn("Skipping integration-test cases because not all mandatory attributes are set.");
68+
}
69+
}
70+
71+
def setup() {
72+
log.info("-> Test: '$DesignateRecordsetServiceTest.methodName'")
73+
}
74+
75+
76+
// ------------ DomainService Tests ------------
77+
78+
@IgnoreIf({ skipTest })
79+
@Betamax(tape="recordsetService_crud")
80+
def "dns/v2/recordset test cases"() {
81+
82+
given: "an authenticated OSClient"
83+
OSClientV3 os = OSFactory.builderV3()
84+
.endpoint(AUTH_URL)
85+
.credentials(USER_NAME, PASSWORD, Identifier.byId(USER_DOMAIN_ID))
86+
.scopeToProject(Identifier.byId(PROJECT_ID))
87+
.withConfig(CONFIG_PROXY_BETAMAX)
88+
.authenticate()
89+
90+
and: "get the id of a dns zone"
91+
ZONE_ID = os.dns().zones().list().first().getId()
92+
93+
and: "the id of the zone shouldn't be null"
94+
ZONE_ID != null
95+
96+
and: "get name of the zone"
97+
ZONE_NAME = os.dns().zones().list().first().getName()
98+
99+
and: "the name of the zone shouldn't be null"
100+
ZONE_NAME != null
101+
102+
when: "we try to create a recordset with argument 'null' "
103+
os.dns().recordsets().create(null, null)
104+
105+
then: "a NPE is thrown"
106+
thrown NullPointerException
107+
108+
when: "creating a recordset"
109+
Recordset recordset = os.dns().recordsets().create(ZONE_ID, RECORDSET_NAME+ZONE_NAME, RECORDSET_TYPE, RECORDSET_RECORDS)
110+
111+
then: "the attributes of the recordset should be equal"
112+
recordset.getName() == RECORDSET_NAME+ZONE_NAME
113+
recordset.getZoneId() == ZONE_ID
114+
recordset.getType() == RECORDSET_TYPE
115+
recordset.getRecords() == RECORDSET_RECORDS
116+
117+
when: "getting the id of the recordset"
118+
RECORDSET_ID = recordset.getId()
119+
120+
then: "this shouldn't be null"
121+
RECORDSET_ID != null
122+
123+
when: "list recordsets owned by project"
124+
List<? extends Recordset> recordsetList = os.dns().recordsets().list()
125+
126+
then: "the list shouldn't be empty and the recordset belongs to the project"
127+
recordsetList.isEmpty() == false
128+
recordsetList.first().getProjectId() == PROJECT_ID
129+
130+
when: "list recordsets in a zone"
131+
List<? extends Recordset> recordsetListZone = os.dns().recordsets().list(ZONE_ID)
132+
133+
then: "the list shouldn't be empty and the recordset is within the zone"
134+
recordsetListZone.isEmpty() == false
135+
recordsetListZone.first().getZoneId() == ZONE_ID
136+
137+
when: "get a recordset by id"
138+
Recordset recordsetById = os.dns().recordsets().get(ZONE_ID,RECORDSET_ID)
139+
140+
then: "the attributes of the recordset should be equal"
141+
recordsetById.getZoneId() == ZONE_ID
142+
recordsetById.getId() == RECORDSET_ID
143+
144+
when: "updating a recordset"
145+
Recordset recordsetUpdated = os.dns().recordsets().update(ZONE_ID, Builders.recordset().id(RECORDSET_ID).description(RECORDSET_DESCRIPTION).build())
146+
147+
then: "the attribute of the recordset should be updated"
148+
recordsetUpdated.getDescription() == RECORDSET_DESCRIPTION
149+
150+
when: "deleting a recordset"
151+
ActionResponse deleteRecordset = os.dns().recordsets().delete(ZONE_ID,RECORDSET_ID)
152+
153+
then: "this should be successful"
154+
deleteRecordset.isSuccess() == true
155+
156+
cleanup: "delete created recordset in case of errors"
157+
os.dns().recordsets().delete(ZONE_ID,RECORDSET_ID)
158+
159+
}
160+
}
161+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
package org.openstack4j.api.dns.v2
3+
4+
import co.freeside.betamax.TapeMode
5+
import groovy.util.logging.Slf4j
6+
import org.junit.Rule
7+
import org.junit.rules.TestName
8+
import org.openstack4j.api.AbstractSpec
9+
import org.openstack4j.api.Builders
10+
import org.openstack4j.api.OSClient.OSClientV3
11+
import org.openstack4j.model.common.ActionResponse
12+
import org.openstack4j.model.common.Identifier
13+
import org.openstack4j.model.dns.v2.Nameserver
14+
import org.openstack4j.model.dns.v2.Zone
15+
import org.openstack4j.model.dns.v2.ZoneType
16+
import org.openstack4j.openstack.OSFactory
17+
import software.betamax.Configuration
18+
import software.betamax.MatchRules
19+
import software.betamax.TapeMode
20+
import software.betamax.junit.Betamax
21+
import software.betamax.junit.RecorderRule
22+
import spock.lang.IgnoreIf
23+
24+
@Slf4j
25+
class DesignateZoneServiceSpec extends AbstractSpec {
26+
27+
@Rule TestName DesignateZoneServiceTest
28+
@Rule public RecorderRule recorderRule = new RecorderRule(
29+
Configuration.builder()
30+
.tapeRoot(new File(TAPEROOT + "dns.v2"))
31+
//.defaultMatchRules(MatchRules.method, MatchRules.path, MatchRules.queryParams)
32+
.defaultMode(TapeMode.WRITE_ONLY)
33+
.build());
34+
35+
// used for domain crud tests
36+
def static final String ZONE_NAME = "b.org."
37+
def static final String ZONE_EMAIL = "[email protected]"
38+
def static final Integer ZONE_TTL = 3602
39+
def static final ZoneType ZONE_TYPE = ZoneType.PRIMARY
40+
def static final String ZONE_DESCRIPTION = "This is my zone."
41+
def static final String NAMESERVER_HOSTNAME = "hostname"
42+
def String ZONE_ID
43+
44+
static final boolean skipTest
45+
46+
static {
47+
if(
48+
USER_ID == null ||
49+
AUTH_URL == null ||
50+
PASSWORD == null ||
51+
DOMAIN_ID == null ) {
52+
53+
skipTest = true
54+
}
55+
else{
56+
skipTest = false
57+
}
58+
}
59+
60+
61+
// run before the first feature method; similar to JUnit's @BeforeClass
62+
def setupSpec() {
63+
64+
if( skipTest != true ) {
65+
log.info("USER_NAME: " + USER_NAME)
66+
log.info("USER_DOMAIN_ID: " + USER_DOMAIN_ID)
67+
log.info("AUTH_URL: " + AUTH_URL)
68+
log.info("PROJECT_ID: " + PROJECT_ID)
69+
}
70+
else {
71+
log.warn("Skipping integration-test cases because not all mandatory attributes are set.");
72+
}
73+
}
74+
75+
def setup() {
76+
log.info("-> Test: '$DesignateZoneServiceTest.methodName'")
77+
}
78+
79+
80+
// ------------ DomainService Tests ------------
81+
82+
@IgnoreIf({ skipTest })
83+
@Betamax(tape="zoneService_crud")
84+
def "dns/v2/zone service test cases"() {
85+
86+
given: "an authenticated OSClient"
87+
OSClientV3 os = OSFactory.builderV3()
88+
.endpoint(AUTH_URL)
89+
.credentials(USER_NAME, PASSWORD, Identifier.byId(USER_DOMAIN_ID))
90+
.scopeToProject(Identifier.byId(PROJECT_ID))
91+
.withConfig(CONFIG_PROXY_BETAMAX)
92+
.authenticate()
93+
94+
when: "we try to create a zone with argument 'null' "
95+
os.dns().zones().create(null)
96+
97+
then: "a NPE is thrown"
98+
thrown NullPointerException
99+
100+
// commented out due to permission foo
101+
// when: "a new domain is created using DomainBuilder with valid arguments"
102+
// Zone zone = Builders.zone()
103+
// .name(ZONE_NAME)
104+
// .email(ZONE_EMAIL)
105+
// .ttl(ZONE_TTL)
106+
// .description(ZONE_DESCRIPTION)
107+
// .type(ZONE_TYPE)
108+
// .build()
109+
//
110+
// and:
111+
// Zone newZone = os.dns().zones().create(zone)
112+
//
113+
// then: "verify that the new domain is correct"
114+
// newZone.getId != null
115+
// newZone.getName() == ZONE_NAME
116+
// newZone.getEmail() == ZONE_EMAIL
117+
// newZone.getTTL() == ZONE_TTL
118+
// newZone.getDescription() == ZONE_DESCRIPTION
119+
// newZone.getType() == ZONE_TYPE
120+
121+
when: "listing all zones"
122+
List<? extends Zone> zoneList = os.dns().zones().list()
123+
124+
then: "the list shouldn't be empty"
125+
zoneList.isEmpty() == false
126+
127+
when: "get the id of the first zone"
128+
ZONE_ID = zoneList.first().getId()
129+
130+
then: "the id of the first item shouldn't be null"
131+
ZONE_ID != null
132+
133+
and: "the attributes of the zone should be equal"
134+
zoneList.first().getProjectId() == PROJECT_ID
135+
zoneList.first().getType() == ZONE_TYPE
136+
zoneList.first().getTTL() == ZONE_TTL
137+
138+
when: "get a zone by id"
139+
Zone zoneById = os.dns().zones().get(ZONE_ID)
140+
141+
then: "the attributes of the zone should be as expected "
142+
zoneById.getId() == ZONE_ID
143+
zoneById.getProjectId() == PROJECT_ID
144+
145+
when: "get nameserver for a zone specified by id"
146+
List<? extends Nameserver> nameserverList = os.dns().zones().listNameservers(ZONE_ID)
147+
148+
then: "this list shouldn't be empty"
149+
nameserverList.isEmpty() == false
150+
nameserverList.first().getHostname() == NAMESERVER_HOSTNAME
151+
nameserverList.first().getPriority() == 1
152+
153+
// commented out due to permission foo
154+
// when: "updating a zone description"
155+
// Zone zoneUpdated = os.dns().zones().update(Builders.zone().id(ZONE_ID).description(ZONE_DESCRIPTION).build())
156+
//
157+
// then: "the description should be updated"
158+
// zoneUpdated.getDescription() == ZONE_DESCRIPTION
159+
160+
// commented out due to permission foo
161+
// when: "deleting a zone"
162+
// ActionResponse deleteZoneResponse = os.dns().zones().delete(ZONE_ID)
163+
//
164+
// then: "this should be successfull"
165+
// deleteZoneResponse.isSuccess() == true
166+
167+
}
168+
}
169+
*/

0 commit comments

Comments
 (0)