Skip to content
Snippets Groups Projects
Commit 8ffe159d authored by Zachary Sabourin's avatar Zachary Sabourin
Browse files

feat: Update tests to use new testing package

Resolves #21
parent df36e5af
No related branches found
No related tags found
1 merge request!30feat: Update tests to use new testing package
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id> <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.6.3.Final</quarkus.platform.version> <quarkus.platform.version>2.6.3.Final</quarkus.platform.version>
<eclipse-api-version>0.6-SNAPSHOT</eclipse-api-version> <eclipse-api-version>0.6.6</eclipse-api-version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version> <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
...@@ -102,8 +102,15 @@ ...@@ -102,8 +102,15 @@
<artifactId>json-schema-validator</artifactId> <artifactId>json-schema-validator</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.eclipsefoundation</groupId>
<artifactId>quarkus-test-common</artifactId>
<version>${eclipse-api-version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
......
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
**********************************************************************/ **********************************************************************/
package org.eclipsefoundation.geoip.client.resources; package org.eclipsefoundation.geoip.client.resources;
import static io.restassured.RestAssured.given;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import org.eclipsefoundation.geoip.client.test.namespaces.SchemaNamespaceHelper; import org.eclipsefoundation.geoip.client.test.namespaces.SchemaNamespaceHelper;
import org.eclipsefoundation.testing.helpers.TestCaseHelper;
import org.eclipsefoundation.testing.templates.RestAssuredTemplates;
import org.eclipsefoundation.testing.templates.RestAssuredTemplates.EndpointTestCase;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
...@@ -34,45 +34,69 @@ class CityResourceTest { ...@@ -34,45 +34,69 @@ class CityResourceTest {
// Google IE server address // Google IE server address
private static final String VALID_IPV6_ADDRESS = "2a00:1450:400a:804::2004"; private static final String VALID_IPV6_ADDRESS = "2a00:1450:400a:804::2004";
public static final EndpointTestCase IPV4_SUCCESS = TestCaseHelper.buildSuccessCase(CITIES_ENDPOINT_URL,
new String[] { VALID_IPV4_ADDRESS }, SchemaNamespaceHelper.CITY_SCHEMA_PATH);
public static final EndpointTestCase IPV6_SUCCESS = TestCaseHelper.buildSuccessCase(CITIES_ENDPOINT_URL,
new String[] { VALID_IPV6_ADDRESS }, SchemaNamespaceHelper.CITY_SCHEMA_PATH);
@Test @Test
void testCities_success() { void testCities_success() {
given().when().get(CITIES_ENDPOINT_URL, VALID_IPV4_ADDRESS).then().statusCode(200); RestAssuredTemplates.testGet(IPV4_SUCCESS);
given().when().get(CITIES_ENDPOINT_URL, VALID_IPV6_ADDRESS).then().statusCode(200); RestAssuredTemplates.testGet(IPV6_SUCCESS);
}
@Test
void testCities_success_validSchema() {
RestAssuredTemplates.testGet_validateSchema(IPV4_SUCCESS);
RestAssuredTemplates.testGet_validateSchema(IPV6_SUCCESS);
} }
@Test @Test
void testCities_format() { void testCities_success_validateResponseFormat() {
given().when().get(CITIES_ENDPOINT_URL, VALID_IPV4_ADDRESS).then().assertThat() RestAssuredTemplates.testGet_validateResponseFormat(IPV4_SUCCESS);
.body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.CITY_SCHEMA_PATH)); RestAssuredTemplates.testGet_validateResponseFormat(IPV6_SUCCESS);
given().when().get(CITIES_ENDPOINT_URL, VALID_IPV6_ADDRESS).then().assertThat()
.body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.CITY_SCHEMA_PATH));
} }
@Test @Test
void testCity_badIPEndpoint() { void testCity_failure_badIPs() {
EndpointTestCase testCase;
String[] badIPV4s = new String[] { "bad.ip.add.res", "300.0.0.0", "1.300.0.0", "1.0.300.0", "1.0.0.300",
"sample", VALID_IPV4_ADDRESS + ":8080" };
// IPv4 tests // IPv4 tests
given().when().get(CITIES_ENDPOINT_URL, "bad.ip.add.res").then().statusCode(400); for (String ip : badIPV4s) {
given().when().get(CITIES_ENDPOINT_URL, "300.0.0.0").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(CITIES_ENDPOINT_URL, new String[] { ip }, "");
given().when().get(CITIES_ENDPOINT_URL, "1.300.0.0").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
given().when().get(CITIES_ENDPOINT_URL, "1.0.300.0").then().statusCode(400); }
given().when().get(CITIES_ENDPOINT_URL, "1.0.0.300").then().statusCode(400);
given().when().get(CITIES_ENDPOINT_URL, "sample").then().statusCode(400);
given().when().get(CITIES_ENDPOINT_URL, VALID_IPV4_ADDRESS + ":8080").then().statusCode(400);
// seems to be an issue with Google Guava code, only gets detected by MaxMind // seems to be an issue with Google Guava code, only gets detected by MaxMind
given().when().get(CITIES_ENDPOINT_URL, "0.1.1.1").then().statusCode(500); testCase = TestCaseHelper.prepareSuccessCase(CITIES_ENDPOINT_URL, new String[] { "0.1.1.1" }, "")
.setStatusCode(500).build();
RestAssuredTemplates.testGet(testCase);
// IPv6 tests // IPv6 test
given().when().get(CITIES_ENDPOINT_URL, "bad:ip:add::res").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(CITIES_ENDPOINT_URL, new String[] { "bad:ip:add::res" }, "");
RestAssuredTemplates.testGet(testCase);
} }
@Test @Test
void testCities_loopback() { void testCities_failure_loopback() {
EndpointTestCase testCase;
// loopback + unspecified address // loopback + unspecified address
given().when().get(CITIES_ENDPOINT_URL, "127.0.0.1").then().statusCode(400); String[] badIPV4s = new String[] { "127.0.0.1", "0.0.0.0" };
given().when().get(CITIES_ENDPOINT_URL, "0.0.0.0").then().statusCode(400); String[] badIPV6s = new String[] { "::", "::1" };
// loopback + unspecified address for (String ip : badIPV4s) {
given().when().get(CITIES_ENDPOINT_URL, "::").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(CITIES_ENDPOINT_URL, new String[] { ip }, "");
given().when().get(CITIES_ENDPOINT_URL, "::1").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
}
for (String ip : badIPV6s) {
testCase = TestCaseHelper.buildBadRequestCase(CITIES_ENDPOINT_URL, new String[] { ip }, "");
RestAssuredTemplates.testGet(testCase);
}
} }
} }
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
**********************************************************************/ **********************************************************************/
package org.eclipsefoundation.geoip.client.resources; package org.eclipsefoundation.geoip.client.resources;
import static io.restassured.RestAssured.given;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import org.eclipsefoundation.geoip.client.test.namespaces.SchemaNamespaceHelper; import org.eclipsefoundation.geoip.client.test.namespaces.SchemaNamespaceHelper;
import org.eclipsefoundation.testing.helpers.TestCaseHelper;
import org.eclipsefoundation.testing.templates.RestAssuredTemplates;
import org.eclipsefoundation.testing.templates.RestAssuredTemplates.EndpointTestCase;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
...@@ -35,51 +35,69 @@ public class CountryResourceTest { ...@@ -35,51 +35,69 @@ public class CountryResourceTest {
// Google IE server address // Google IE server address
private static final String VALID_IPV6_ADDRESS = "2a00:1450:400a:804::2004"; private static final String VALID_IPV6_ADDRESS = "2a00:1450:400a:804::2004";
public static final EndpointTestCase IPV4_SUCCESS = TestCaseHelper.buildSuccessCase(COUNTRY_ENDPOINT_URL,
new String[] { VALID_IPV4_ADDRESS }, SchemaNamespaceHelper.COUNTRY_SCHEMA_PATH);
public static final EndpointTestCase IPV6_SUCCESS = TestCaseHelper.buildSuccessCase(COUNTRY_ENDPOINT_URL,
new String[] { VALID_IPV6_ADDRESS }, SchemaNamespaceHelper.COUNTRY_SCHEMA_PATH);
@Test @Test
public void testCountries_success() { public void testCountries_success() {
given().when().get(COUNTRY_ENDPOINT_URL, VALID_IPV4_ADDRESS).then().statusCode(200); RestAssuredTemplates.testGet(IPV4_SUCCESS);
given().when().get(COUNTRY_ENDPOINT_URL, VALID_IPV6_ADDRESS).then().statusCode(200); RestAssuredTemplates.testGet(IPV6_SUCCESS);
} }
@Test @Test
void testCountries_format() { void testCities_success_validSchema() {
given().when().get(COUNTRY_ENDPOINT_URL, VALID_IPV4_ADDRESS).then().assertThat() RestAssuredTemplates.testGet_validateSchema(IPV4_SUCCESS);
.body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.COUNTRY_SCHEMA_PATH)); RestAssuredTemplates.testGet_validateSchema(IPV6_SUCCESS);
given().when().get(COUNTRY_ENDPOINT_URL, VALID_IPV6_ADDRESS).then().assertThat()
.body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.COUNTRY_SCHEMA_PATH));
} }
@Test @Test
public void testCountries_badIPEndpoint() { void testCities_success_validateResponseFormat() {
RestAssuredTemplates.testGet_validateResponseFormat(IPV4_SUCCESS);
RestAssuredTemplates.testGet_validateResponseFormat(IPV6_SUCCESS);
}
@Test
public void testCountries_badIPs() {
EndpointTestCase testCase;
String[] badIPV4s = new String[] { "bad.ip.add.res", "300.0.0.0", "1.300.0.0", "1.0.300.0", "1.0.0.300",
"sample", VALID_IPV4_ADDRESS + ":8080" };
// IPv4 tests // IPv4 tests
given().when().get(COUNTRY_ENDPOINT_URL, "bad.ip.add.res").then().statusCode(400); for (String ip : badIPV4s) {
given().when().get(COUNTRY_ENDPOINT_URL, "300.0.0.0").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(COUNTRY_ENDPOINT_URL, new String[] { ip }, "");
given().when().get(COUNTRY_ENDPOINT_URL, "1.300.0.0").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
given().when().get(COUNTRY_ENDPOINT_URL, "1.0.300.0").then().statusCode(400); }
given().when().get(COUNTRY_ENDPOINT_URL, "1.0.0.300").then().statusCode(400);
given().when().get(COUNTRY_ENDPOINT_URL, "sample").then().statusCode(400);
given().when().get(COUNTRY_ENDPOINT_URL, VALID_IPV4_ADDRESS + ":8080").then().statusCode(400);
// seems to be an issue with Google Guava code, only gets detected by MaxMind // seems to be an issue with Google Guava code, only gets detected by MaxMind
given().when().get(COUNTRY_ENDPOINT_URL, "0.1.1.1").then().statusCode(500); testCase = TestCaseHelper.prepareSuccessCase(COUNTRY_ENDPOINT_URL, new String[] { "0.1.1.1" }, "")
// loopback + unspecified address .setStatusCode(500).build();
given().when().get(COUNTRY_ENDPOINT_URL, "127.0.0.1").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
given().when().get(COUNTRY_ENDPOINT_URL, "0.0.0.0").then().statusCode(400);
// IPv6 tests // IPv6 test
given().when().get(COUNTRY_ENDPOINT_URL, "bad:ip:add::res").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(COUNTRY_ENDPOINT_URL, new String[] { "bad:ip:add::res" }, "");
// loopback + unspecified address RestAssuredTemplates.testGet(testCase);
given().when().get(COUNTRY_ENDPOINT_URL, "::").then().statusCode(400);
given().when().get(COUNTRY_ENDPOINT_URL, "::1").then().statusCode(400);
} }
@Test @Test
void testCountries_loopback() { void testCountries_loopback() {
EndpointTestCase testCase;
// loopback + unspecified address // loopback + unspecified address
given().when().get(COUNTRY_ENDPOINT_URL, "127.0.0.1").then().statusCode(400); String[] badIPV4s = new String[] { "127.0.0.1", "0.0.0.0" };
given().when().get(COUNTRY_ENDPOINT_URL, "0.0.0.0").then().statusCode(400); String[] badIPV6s = new String[] { "::", "::1" };
// loopback + unspecified address for (String ip : badIPV4s) {
given().when().get(COUNTRY_ENDPOINT_URL, "::").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(COUNTRY_ENDPOINT_URL, new String[] { ip }, "");
given().when().get(COUNTRY_ENDPOINT_URL, "::1").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
}
for (String ip : badIPV6s) {
testCase = TestCaseHelper.buildBadRequestCase(COUNTRY_ENDPOINT_URL, new String[] { ip }, "");
RestAssuredTemplates.testGet(testCase);
}
} }
} }
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
**********************************************************************/ **********************************************************************/
package org.eclipsefoundation.geoip.client.resources; package org.eclipsefoundation.geoip.client.resources;
import static io.restassured.RestAssured.given;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import org.eclipsefoundation.geoip.client.test.namespaces.SchemaNamespaceHelper; import org.eclipsefoundation.geoip.client.test.namespaces.SchemaNamespaceHelper;
import org.eclipsefoundation.testing.helpers.TestCaseHelper;
import org.eclipsefoundation.testing.templates.RestAssuredTemplates;
import org.eclipsefoundation.testing.templates.RestAssuredTemplates.EndpointTestCase;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
...@@ -30,35 +30,57 @@ import io.quarkus.test.junit.QuarkusTest; ...@@ -30,35 +30,57 @@ import io.quarkus.test.junit.QuarkusTest;
public class SubnetResourceTest { public class SubnetResourceTest {
public static final String SUBNETS_ENDPOINT_URL = "/subnets/{subnet}/{locale}"; public static final String SUBNETS_ENDPOINT_URL = "/subnets/{subnet}/{locale}";
public static final EndpointTestCase IPV4_SUCCESS = TestCaseHelper.buildSuccessCase(SUBNETS_ENDPOINT_URL,
new String[] { "ipv4", "ca" }, SchemaNamespaceHelper.IP_ADDRESSES_SCHEMA_PATH);
public static final EndpointTestCase IPV6_SUCCESS = TestCaseHelper.buildSuccessCase(SUBNETS_ENDPOINT_URL,
new String[] { "ipv6", "ca" }, SchemaNamespaceHelper.IP_ADDRESSES_SCHEMA_PATH);
@Test
void testSubnets_success() {
RestAssuredTemplates.testGet(IPV4_SUCCESS);
RestAssuredTemplates.testGet(IPV6_SUCCESS);
}
@Test @Test
public void testSubnets_success() { void testSubnets_success_validSchema() {
given().when().get(SUBNETS_ENDPOINT_URL, "ipv4", "ca").then().statusCode(200); RestAssuredTemplates.testGet_validateSchema(IPV4_SUCCESS);
given().when().get(SUBNETS_ENDPOINT_URL, "ipv6", "ca").then().statusCode(200); RestAssuredTemplates.testGet_validateSchema(IPV6_SUCCESS);
} }
@Test @Test
void testCities_format() { void testSubnets_success_validateResponseFormat() {
given().when().get(SUBNETS_ENDPOINT_URL, "ipv4", "ca").then().assertThat() RestAssuredTemplates.testGet_validateResponseFormat(IPV4_SUCCESS);
.body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.IP_ADDRESSES_SCHEMA_PATH)); RestAssuredTemplates.testGet_validateResponseFormat(IPV6_SUCCESS);
given().when().get(SUBNETS_ENDPOINT_URL, "ipv6", "ca").then().assertThat()
.body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.IP_ADDRESSES_SCHEMA_PATH));
} }
@Test @Test
public void testSubnetsBadLocaleEndpoint() { void testSubnets_failure_invalidLocales() {
EndpointTestCase testCase;
String[] badLocales = new String[] { "", "can", "01" };
// bad ipv4 calls // bad ipv4 calls
given().when().get(SUBNETS_ENDPOINT_URL, "ipv4", "").then().statusCode(400); for (String locale : badLocales) {
given().when().get(SUBNETS_ENDPOINT_URL, "ipv4", "can").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(SUBNETS_ENDPOINT_URL, new String[] { "ipv4", locale }, "");
given().when().get(SUBNETS_ENDPOINT_URL, "ipv4", "01").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
}
// bad ipv6 calls // bad ipv6 calls
given().when().get(SUBNETS_ENDPOINT_URL, "ipv6", "").then().statusCode(400); for (String locale : badLocales) {
given().when().get(SUBNETS_ENDPOINT_URL, "ipv6", "can").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(SUBNETS_ENDPOINT_URL, new String[] { "ipv6", locale }, "");
given().when().get(SUBNETS_ENDPOINT_URL, "ipv6", "01").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
}
}
@Test
void testSubnets_failure_invalidSubnets() {
EndpointTestCase testCase;
String[] badSubnets = new String[] { "ipv5", "ipvfour", "ipv" };
// check other permutations (regex endpoint) // check other permutations (regex endpoint)
given().when().get(SUBNETS_ENDPOINT_URL, "ipv5", "ca").then().statusCode(400); for (String subnet : badSubnets) {
given().when().get(SUBNETS_ENDPOINT_URL, "ipvfour", "ca").then().statusCode(400); testCase = TestCaseHelper.buildBadRequestCase(SUBNETS_ENDPOINT_URL, new String[] { subnet, "ca" }, "");
given().when().get(SUBNETS_ENDPOINT_URL, "ipv", "ca").then().statusCode(400); RestAssuredTemplates.testGet(testCase);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment