|
| 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