From 5fb6ca5b83b78946244855bc27c6f66cf4ed902a Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Fri, 29 Jul 2022 10:46:50 -0400 Subject: [PATCH 1/5] Update spec --- spec/openapi.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/openapi.yaml b/spec/openapi.yaml index 94586bb..0c22b7d 100644 --- a/spec/openapi.yaml +++ b/spec/openapi.yaml @@ -109,7 +109,9 @@ components: type: string description: the URL for the homepage of this working group WorkingGroupParticipationAgreement: - type: object + type: + - object + - 'null' properties: document_id: $ref: '#/components/schemas/ObjectID' -- GitLab From c6a62213b7dbce7112915767ef3e960d82a28d08 Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Fri, 29 Jul 2022 10:49:28 -0400 Subject: [PATCH 2/5] Add 404 on invalid group name --- .../wg/resources/WorkingGroupsResource.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java b/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java index afed922..ddf99db 100644 --- a/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java +++ b/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java @@ -13,6 +13,7 @@ package org.eclipsefoundation.wg.resources; import java.util.List; +import java.util.Objects; import javax.inject.Inject; import javax.ws.rs.Consumes; @@ -24,6 +25,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.eclipsefoundation.wg.models.WorkingGroupMap.WorkingGroup; import org.eclipsefoundation.wg.services.WorkingGroupsService; /** @@ -47,8 +49,13 @@ public class WorkingGroupsResource { @GET @Path("{name}") - public Response getWorkingGroup(@PathParam("name") String name) { - // return the results as a response - return Response.ok(wgService.getByName(name)).build(); + public Response getWorkingGroup(@PathParam("name") String name) { + WorkingGroup wg = wgService.getByName(name); + + if(Objects.isNull(wg)) { + return Response.status(404).build(); + } + + return Response.ok(wg).build(); } } -- GitLab From 0a56a12ef6cecf694ebdc7dd2a19311e43aa16b6 Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Fri, 29 Jul 2022 10:51:23 -0400 Subject: [PATCH 3/5] feat: Add endpoint testing + testing resources --- .../resources/WorkingGroupsResourceTest.java | 139 ++++++++++++++++++ .../test/helpers/SchemaNamespaceHelper.java | 12 ++ src/test/resources/working_groups.json | 136 +++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java create mode 100644 src/test/java/org/eclipsefoundation/wg/test/helpers/SchemaNamespaceHelper.java create mode 100644 src/test/resources/working_groups.json diff --git a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java new file mode 100644 index 0000000..e2537f1 --- /dev/null +++ b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java @@ -0,0 +1,139 @@ +package org.eclipsefoundation.wg.resources; + +import static io.restassured.RestAssured.given; +import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; + +import org.eclipsefoundation.wg.test.helpers.SchemaNamespaceHelper; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; + + +@QuarkusTest +class WorkingGroupsResourceTest { + + public final static String WGS_BASE_URL = "/working_groups"; + + public final static String WG_BASE_URL = WGS_BASE_URL + "/{name}"; + public final static String WG_STATUS_URL = WGS_BASE_URL + "?status={param}"; + public final static String WG_STATUSES_URL = WGS_BASE_URL + "?status={param1}&status={param2}"; + + @Test + void getAll_success() { + given() + .contentType(ContentType.JSON) + .when() + .get(WGS_BASE_URL) + .then() + .statusCode(200); + } + + @Test + void getAll_success_matchingSpec() { + given() + .contentType(ContentType.JSON) + .when() + .get(WGS_BASE_URL) + .then() + .assertThat() + .body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.WORKING_GROUPS_SCHEMA_PATH)); + } + + @Test + void getAll_failure_invalidFormat() { + given() + .contentType(ContentType.JSON) + .accept(ContentType.TEXT) + .when() + .get(WGS_BASE_URL) + .then() + .statusCode(500); + } + + @Test + void getAllBySingleStatus_success() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_STATUS_URL, "active") + .then() + .statusCode(200); + } + + @Test + void getAllBySingleStatus_success_matchingSpec() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_STATUS_URL, "active") + .then() + .assertThat() + .body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.WORKING_GROUPS_SCHEMA_PATH)); + } + + @Test + void getAllByMultiStatus_success() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_STATUSES_URL, "active", "archived") + .then() + .statusCode(200); + } + + @Test + void getAllByMultiStatus_success_matchingSpec() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_STATUSES_URL, "active", "archived") + .then() + .assertThat() + .body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.WORKING_GROUPS_SCHEMA_PATH)); + } + + @Test + void getByName_success() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_BASE_URL, "ImportantGroup") + .then() + .contentType(ContentType.JSON) + .statusCode(200); + } + + @Test + void getByName_success_matchingSpec() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_BASE_URL, "ImportantGroup") + .then() + .assertThat() + .contentType(ContentType.JSON) + .body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.WORKING_GROUP_SCHEMA_PATH)); + } + + @Test + void getByName_failure_invalidName() { + given() + .contentType(ContentType.JSON) + .when() + .get(WG_BASE_URL, "JimBob") + .then() + .statusCode(404); + } + + @Test + void getByName_failure_invalidFormat() { + given() + .contentType(ContentType.JSON) + .accept(ContentType.TEXT) + .when() + .get(WG_BASE_URL, "ImportantGroup") + .then() + .statusCode(500); + } +} diff --git a/src/test/java/org/eclipsefoundation/wg/test/helpers/SchemaNamespaceHelper.java b/src/test/java/org/eclipsefoundation/wg/test/helpers/SchemaNamespaceHelper.java new file mode 100644 index 0000000..691be9f --- /dev/null +++ b/src/test/java/org/eclipsefoundation/wg/test/helpers/SchemaNamespaceHelper.java @@ -0,0 +1,12 @@ +package org.eclipsefoundation.wg.test.helpers; + +public class SchemaNamespaceHelper { + + public static final String BASE_SCHEMA_PATH = "schemas/"; + public static final String BASE_SCHEMA_PATH_SUFFIX = "-schema.json"; + + public static final String WORKING_GROUP_SCHEMA_PATH = BASE_SCHEMA_PATH + "working-group" + + BASE_SCHEMA_PATH_SUFFIX; + public static final String WORKING_GROUPS_SCHEMA_PATH = BASE_SCHEMA_PATH + "working-groups" + + BASE_SCHEMA_PATH_SUFFIX; +} diff --git a/src/test/resources/working_groups.json b/src/test/resources/working_groups.json new file mode 100644 index 0000000..5cc281d --- /dev/null +++ b/src/test/resources/working_groups.json @@ -0,0 +1,136 @@ +{ + "working_groups": { + "ImportantGroup": { + "alias": "important-group", + "title": "Super Important Group", + "status": "active", + "parent_organization": "eclipse", + "logo": "https://www.google.com", + "description": "This group is super important. And don't you forget it.", + "resources": { + "charter": "https://www.google.com", + "participation_agreements": { + "individual": null, + "organization": { + "document_id": "cacsoivnp23o423r", + "pdf": "https://www.google.com" + } + }, + "website": "https://www.google.com", + "members": "https://www.google.com", + "sponsorship": "https://www.google.com", + "contact_form": "https://www.google.com" + }, + "levels": [ + { + "relation": "WGSD", + "description": "Strategic Member" + }, + { + "relation": "WGDSA", + "description": "Enterprise Member" + }, + { + "relation": "WGAPS", + "description": "Participant Member" + }, + { + "relation": "WGFHA", + "description": "Committer Member" + }, + { + "relation": "WGSAP", + "description": "Guest Member" + } + ] + }, + "MediocreGroup": { + "alias": "mediocre-group", + "title": "Mediocre Group", + "status": "incubating", + "parent_organization": "random-group", + "logo": "https://www.google.com", + "description": "This group is super important. And don't you forget it.", + "resources": { + "charter": "https://www.google.com", + "participation_agreements": { + "individual": null, + "organization": { + "document_id": "cacsoivnp23o423r", + "pdf": "https://www.google.com" + } + }, + "website": "https://www.google.com", + "members": "https://www.google.com", + "sponsorship": "https://www.google.com", + "contact_form": "https://www.google.com" + }, + "levels": [ + { + "relation": "WGSD", + "description": "Strategic Member" + }, + { + "relation": "WGDSA", + "description": "Enterprise Member" + }, + { + "relation": "WGAPS", + "description": "Participant Member" + }, + { + "relation": "WGFHA", + "description": "Committer Member" + }, + { + "relation": "WGSAP", + "description": "Guest Member" + } + ] + }, + "AwfulGroup": { + "alias": "awful-group", + "title": "Awful Group", + "status": "archived", + "parent_organization": "some-other-org", + "logo": "https://www.google.com", + "description": "This group isn't that great, actually. But that's ok", + "resources": { + "charter": "https://www.google.com", + "participation_agreements": { + "individual": null, + "organization": { + "document_id": "8ufdaoisdhf3298jf", + "pdf": "https://www.google.com" + } + }, + "website": "https://www.google.com", + "members": "https://www.google.com", + "sponsorship": "https://www.google.com", + "contact_form": "https://www.google.com" + }, + "levels": [ + { + "relation": "WGSD", + "description": "Strategic Member" + }, + { + "relation": "WGDSA", + "description": "Enterprise Member" + }, + { + "relation": "WGAPS", + "description": "Participant Member" + }, + { + "relation": "WGFHA", + "description": "Committer Member" + }, + { + "relation": "WGSAP", + "description": "Guest Member" + } + ] + } + } +} -- GitLab From 774be1acf1d99e7177a490542c5498ced2a5f5ba Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Fri, 29 Jul 2022 13:23:22 -0400 Subject: [PATCH 4/5] Update name to alias --- .../wg/resources/WorkingGroupsResource.java | 6 +++--- .../wg/services/WorkingGroupsService.java | 4 ++-- .../wg/services/impl/DefaultWorkingGroupsService.java | 4 ++-- .../wg/resources/WorkingGroupsResource.java | 5 ----- .../wg/resources/WorkingGroupsResourceTest.java | 10 +++++----- 5 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java diff --git a/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java b/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java index ddf99db..7f39f49 100644 --- a/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java +++ b/src/main/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java @@ -48,9 +48,9 @@ public class WorkingGroupsResource { } @GET - @Path("{name}") - public Response getWorkingGroup(@PathParam("name") String name) { - WorkingGroup wg = wgService.getByName(name); + @Path("{alias}") + public Response getWorkingGroup(@PathParam("alias") String alias) { + WorkingGroup wg = wgService.getByAlias(alias); if(Objects.isNull(wg)) { return Response.status(404).build(); diff --git a/src/main/java/org/eclipsefoundation/wg/services/WorkingGroupsService.java b/src/main/java/org/eclipsefoundation/wg/services/WorkingGroupsService.java index d536e7b..db1b37d 100644 --- a/src/main/java/org/eclipsefoundation/wg/services/WorkingGroupsService.java +++ b/src/main/java/org/eclipsefoundation/wg/services/WorkingGroupsService.java @@ -28,14 +28,14 @@ import org.eclipsefoundation.wg.models.WorkingGroupMap; public interface WorkingGroupsService { /** - * Returns a set of working groups, with an optional filter of the parent organization and project status. + * Returns a set of working groups, with an optional filter of the project status. * * @param projectStatus optional, statuses to include in result set * @return set of working groups matching optional filters if present, otherwise all available working groups */ public Set get(List projectStatus); - public WorkingGroupMap.WorkingGroup getByName(String name); + public WorkingGroupMap.WorkingGroup getByAlias(String alias); public Map> getWGPADocumentIDs(); } diff --git a/src/main/java/org/eclipsefoundation/wg/services/impl/DefaultWorkingGroupsService.java b/src/main/java/org/eclipsefoundation/wg/services/impl/DefaultWorkingGroupsService.java index e9d915e..e46efe1 100644 --- a/src/main/java/org/eclipsefoundation/wg/services/impl/DefaultWorkingGroupsService.java +++ b/src/main/java/org/eclipsefoundation/wg/services/impl/DefaultWorkingGroupsService.java @@ -87,8 +87,8 @@ public class DefaultWorkingGroupsService implements WorkingGroupsService { } @Override - public WorkingGroup getByName(String name) { - return workingGroups.get(name); + public WorkingGroup getByAlias(String alias) { + return workingGroups.get(alias); } @Override diff --git a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java deleted file mode 100644 index 088cfdf..0000000 --- a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResource.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.eclipsefoundation.wg.resources; - -public class WorkingGroupsResource { - -} diff --git a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java index e2537f1..928f141 100644 --- a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java +++ b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java @@ -15,7 +15,7 @@ class WorkingGroupsResourceTest { public final static String WGS_BASE_URL = "/working_groups"; - public final static String WG_BASE_URL = WGS_BASE_URL + "/{name}"; + public final static String WG_BASE_URL = WGS_BASE_URL + "/{alias}"; public final static String WG_STATUS_URL = WGS_BASE_URL + "?status={param}"; public final static String WG_STATUSES_URL = WGS_BASE_URL + "?status={param1}&status={param2}"; @@ -94,7 +94,7 @@ class WorkingGroupsResourceTest { } @Test - void getByName_success() { + void getByAlias_success() { given() .contentType(ContentType.JSON) .when() @@ -105,7 +105,7 @@ class WorkingGroupsResourceTest { } @Test - void getByName_success_matchingSpec() { + void getByAlias_success_matchingSpec() { given() .contentType(ContentType.JSON) .when() @@ -117,7 +117,7 @@ class WorkingGroupsResourceTest { } @Test - void getByName_failure_invalidName() { + void getByAlias_failure_invalidName() { given() .contentType(ContentType.JSON) .when() @@ -127,7 +127,7 @@ class WorkingGroupsResourceTest { } @Test - void getByName_failure_invalidFormat() { + void getByAlias_failure_invalidFormat() { given() .contentType(ContentType.JSON) .accept(ContentType.TEXT) -- GitLab From da9a64955e26a572522848b5d2632685b485f2cf Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Tue, 2 Aug 2022 13:41:58 -0400 Subject: [PATCH 5/5] More thorough testing + fix resource alias names --- .../resources/WorkingGroupsResourceTest.java | 89 ++++++++++++++++--- src/test/resources/working_groups.json | 8 +- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java index 928f141..ee27311 100644 --- a/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java +++ b/src/test/java/org/eclipsefoundation/wg/resources/WorkingGroupsResourceTest.java @@ -18,9 +18,18 @@ class WorkingGroupsResourceTest { public final static String WG_BASE_URL = WGS_BASE_URL + "/{alias}"; public final static String WG_STATUS_URL = WGS_BASE_URL + "?status={param}"; public final static String WG_STATUSES_URL = WGS_BASE_URL + "?status={param1}&status={param2}"; - + @Test void getAll_success() { + given() + .when() + .get(WGS_BASE_URL) + .then() + .statusCode(200); + } + + @Test + void getAll_success_validRequestFormat() { given() .contentType(ContentType.JSON) .when() @@ -29,10 +38,19 @@ class WorkingGroupsResourceTest { .statusCode(200); } + @Test + void getAll_success_validResponseFormat() { + given() + .when() + .get(WGS_BASE_URL) + .then() + .contentType(ContentType.JSON) + .statusCode(200); + } + @Test void getAll_success_matchingSpec() { given() - .contentType(ContentType.JSON) .when() .get(WGS_BASE_URL) .then() @@ -53,6 +71,15 @@ class WorkingGroupsResourceTest { @Test void getAllBySingleStatus_success() { + given() + .when() + .get(WG_STATUS_URL, "active") + .then() + .statusCode(200); + } + + @Test + void getAllBySingleStatus_success_validRequestFormat() { given() .contentType(ContentType.JSON) .when() @@ -61,10 +88,19 @@ class WorkingGroupsResourceTest { .statusCode(200); } + @Test + void getAllBySingleStatus_success_validResponseFormat() { + given() + .when() + .get(WG_STATUS_URL, "active") + .then() + .contentType(ContentType.JSON) + .statusCode(200); + } + @Test void getAllBySingleStatus_success_matchingSpec() { given() - .contentType(ContentType.JSON) .when() .get(WG_STATUS_URL, "active") .then() @@ -74,6 +110,15 @@ class WorkingGroupsResourceTest { @Test void getAllByMultiStatus_success() { + given() + .when() + .get(WG_STATUSES_URL, "active", "archived") + .then() + .statusCode(200); + } + + @Test + void getAllByMultiStatus_success_validRequestFormat() { given() .contentType(ContentType.JSON) .when() @@ -82,10 +127,19 @@ class WorkingGroupsResourceTest { .statusCode(200); } + @Test + void getAllByMultiStatus_success_validResponseFormat() { + given() + .when() + .get(WG_STATUSES_URL, "active", "archived") + .then() + .contentType(ContentType.JSON) + .statusCode(200); + } + @Test void getAllByMultiStatus_success_matchingSpec() { given() - .contentType(ContentType.JSON) .when() .get(WG_STATUSES_URL, "active", "archived") .then() @@ -95,10 +149,28 @@ class WorkingGroupsResourceTest { @Test void getByAlias_success() { + given() + .when() + .get(WG_BASE_URL, "important-group") + .then() + .statusCode(200); + } + + @Test + void getByAlias_success_validRequestFormat() { given() .contentType(ContentType.JSON) .when() - .get(WG_BASE_URL, "ImportantGroup") + .get(WG_BASE_URL, "important-group") + .then() + .statusCode(200); + } + + @Test + void getByAlias_success_validResponseFormat() { + given() + .when() + .get(WG_BASE_URL, "important-group") .then() .contentType(ContentType.JSON) .statusCode(200); @@ -107,19 +179,16 @@ class WorkingGroupsResourceTest { @Test void getByAlias_success_matchingSpec() { given() - .contentType(ContentType.JSON) .when() - .get(WG_BASE_URL, "ImportantGroup") + .get(WG_BASE_URL, "important-group") .then() .assertThat() - .contentType(ContentType.JSON) .body(matchesJsonSchemaInClasspath(SchemaNamespaceHelper.WORKING_GROUP_SCHEMA_PATH)); } @Test void getByAlias_failure_invalidName() { given() - .contentType(ContentType.JSON) .when() .get(WG_BASE_URL, "JimBob") .then() @@ -132,7 +201,7 @@ class WorkingGroupsResourceTest { .contentType(ContentType.JSON) .accept(ContentType.TEXT) .when() - .get(WG_BASE_URL, "ImportantGroup") + .get(WG_BASE_URL, "important-group") .then() .statusCode(500); } diff --git a/src/test/resources/working_groups.json b/src/test/resources/working_groups.json index 5cc281d..423e11d 100644 --- a/src/test/resources/working_groups.json +++ b/src/test/resources/working_groups.json @@ -1,6 +1,6 @@ { "working_groups": { - "ImportantGroup": { + "important-group": { "alias": "important-group", "title": "Super Important Group", "status": "active", @@ -44,7 +44,7 @@ } ] }, - "MediocreGroup": { + "mediocre-group": { "alias": "mediocre-group", "title": "Mediocre Group", "status": "incubating", @@ -88,7 +88,7 @@ } ] }, - "AwfulGroup": { + "awful-group": { "alias": "awful-group", "title": "Awful Group", "status": "archived", @@ -133,4 +133,4 @@ ] } } -} +} \ No newline at end of file -- GitLab