From 050c571901e50813b4a6e11134e36745563d668f Mon Sep 17 00:00:00 2001 From: McDonnough Date: Tue, 23 May 2017 09:41:24 +0200 Subject: [PATCH 1/6] add test for invalid currency --- .../GroupEndpointControllerTest.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/teiler/server/endpoints/GroupEndpointControllerTest.java b/src/test/java/io/teiler/server/endpoints/GroupEndpointControllerTest.java index 78db9b1..b9a82f0 100644 --- a/src/test/java/io/teiler/server/endpoints/GroupEndpointControllerTest.java +++ b/src/test/java/io/teiler/server/endpoints/GroupEndpointControllerTest.java @@ -16,14 +16,16 @@ public class GroupEndpointControllerTest extends BaseEndpointControllerTest { private static final String GROUP_URL = URL_VERSION + "groups"; - + private static final String POST_GROUP_NAME = "Manamana"; private static final String GET_GROUP_ID = "gettgrup"; private static final String GET_GROUP_NAME = "GetGroup"; private static final String PUT_GROUP_ID = "puttgrup"; private static final String PUT_GROUP_NAME = "PutGroupABC"; private static final String DELETE_GROUP_ID = "deltgrup"; - + private static final String INVALID_CURRENCY_GROUP_NAME = "InvalidCurrency"; + private static final String INVALID_CURRENCY = "XYZ"; + private static final String PARAM_NAME = "name"; private static final String PARAM_ID = "id"; private static final String PARAM_CURRENCY = "currency"; @@ -82,7 +84,7 @@ public void testPutGroup() { .body(PARAM_UPDATE_TIME, is(notNullValue())) .body(PARAM_CREATE_TIME, is(notNullValue())); } - + @Test public void testDeleteGroup() { given() @@ -92,4 +94,19 @@ public void testDeleteGroup() { .statusCode(200); } + @Test + public void testInvalidCurrency() { + Map requestBody = new HashMap<>(); + requestBody.put(PARAM_NAME, INVALID_CURRENCY_GROUP_NAME); + requestBody.put(PARAM_CURRENCY, INVALID_CURRENCY); + + given() + .contentType(ContentType.JSON) + .body(requestBody) + .when() + .put(GROUP_URL + "/" + PUT_GROUP_ID) + .then() + .statusCode(416); + } + } From bab86e6044ee2007d580dc6e90b80f2aa77acfd8 Mon Sep 17 00:00:00 2001 From: McDonnough Date: Tue, 23 May 2017 09:43:26 +0200 Subject: [PATCH 2/6] change name to match the tested class --- .../server/endpoints/EndpointControllerTestSuite.java | 2 +- ...llerTest.java => PersonEndpointControllerTest.java} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/test/java/io/teiler/server/endpoints/{PeopleEndpointControllerTest.java => PersonEndpointControllerTest.java} (97%) diff --git a/src/test/java/io/teiler/server/endpoints/EndpointControllerTestSuite.java b/src/test/java/io/teiler/server/endpoints/EndpointControllerTestSuite.java index ad2e4e8..eedfb6c 100644 --- a/src/test/java/io/teiler/server/endpoints/EndpointControllerTestSuite.java +++ b/src/test/java/io/teiler/server/endpoints/EndpointControllerTestSuite.java @@ -8,7 +8,7 @@ @RunWith(Suite.class) @SuiteClasses({ GroupEndpointControllerTest.class, - PeopleEndpointControllerTest.class + PersonEndpointControllerTest.class }) public class EndpointControllerTestSuite { diff --git a/src/test/java/io/teiler/server/endpoints/PeopleEndpointControllerTest.java b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java similarity index 97% rename from src/test/java/io/teiler/server/endpoints/PeopleEndpointControllerTest.java rename to src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java index b06f22d..6d8aabd 100644 --- a/src/test/java/io/teiler/server/endpoints/PeopleEndpointControllerTest.java +++ b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java @@ -13,23 +13,23 @@ import io.restassured.http.ContentType; -public class PeopleEndpointControllerTest extends BaseEndpointControllerTest { +public class PersonEndpointControllerTest extends BaseEndpointControllerTest { private static final String GROUP_ID = "persgrup"; private static final String PERSON_URL = URL_VERSION + "groups/" + GROUP_ID + "/people"; - + private static final String POST_PERSON_NAME = "Richi"; private static final int PUT_PERSON_ID = 2; private static final String PUT_PERSON_NAME = "PutPersonABC"; private static final int DELETE_PERSON_ID = 3; - + private static final String PEOPLE_GROUP_ID = "piplgrup"; private static final String PERSON_PEOPLE_URL = URL_VERSION + "groups/" + PEOPLE_GROUP_ID + "/people"; private static final int GET_PERSON_1_ID = 7; private static final String GET_PERSON_1_NAME = "PeoplePerson1"; private static final int GET_PERSON_2_ID = 8; private static final String GET_PERSON_2_NAME = "PeoplePerson2"; - + private static final String PARAM_NAME = "name"; private static final String PARAM_ID = "id"; private static final String PARAM_ACTIVE = "active"; @@ -87,7 +87,7 @@ public void testPutPerson() { .body(PARAM_UPDATE_TIME, is(notNullValue())) .body(PARAM_CREATE_TIME, is(notNullValue())); } - + @Test public void testDeletePerson() { given() From 48ec2390ae23206b5c51c54622ac229e9ca8d77c Mon Sep 17 00:00:00 2001 From: McDonnough Date: Tue, 23 May 2017 09:46:19 +0200 Subject: [PATCH 3/6] add test for non-existent person --- .../endpoints/PersonEndpointControllerTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java index 6d8aabd..77cf70e 100644 --- a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java +++ b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java @@ -29,6 +29,8 @@ public class PersonEndpointControllerTest extends BaseEndpointControllerTest { private static final String GET_PERSON_1_NAME = "PeoplePerson1"; private static final int GET_PERSON_2_ID = 8; private static final String GET_PERSON_2_NAME = "PeoplePerson2"; + + private static final int PERSON_NOT_FOUND_ID = 666; private static final String PARAM_NAME = "name"; private static final String PARAM_ID = "id"; @@ -96,5 +98,14 @@ public void testDeletePerson() { .then() .statusCode(200); } + + @Test + public void testPersonNotFound() { + given() + .when() + .get(PERSON_URL + "/" + PERSON_NOT_FOUND_ID) + .then() + .statusCode(404); + } } From 356205b1b68c7affe586b7036f443a657e2185f5 Mon Sep 17 00:00:00 2001 From: McDonnough Date: Tue, 23 May 2017 10:08:41 +0200 Subject: [PATCH 4/6] add test for name conflict --- .../PersonEndpointControllerTest.java | 18 ++++++++++++++++++ src/test/resources/insert_test_data.sql | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java index 77cf70e..3b6a96c 100644 --- a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java +++ b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java @@ -31,6 +31,10 @@ public class PersonEndpointControllerTest extends BaseEndpointControllerTest { private static final String GET_PERSON_2_NAME = "PeoplePerson2"; private static final int PERSON_NOT_FOUND_ID = 666; + + private static final String PEOPLE_NAME_CONFLICT_GROUP_ID = "spargrup"; + private static final String PEOPLE_NAME_CONFLICT_URL = URL_VERSION + "groups/" + PEOPLE_NAME_CONFLICT_GROUP_ID + "/people"; + private static final String PEOPLE_NAME_CONFLICT_PERSON_NAME = "Spartacus"; private static final String PARAM_NAME = "name"; private static final String PARAM_ID = "id"; @@ -107,5 +111,19 @@ public void testPersonNotFound() { .then() .statusCode(404); } + + @Test + public void testPeopleNameConflict() { + Map requestBody = new HashMap<>(); + requestBody.put(PARAM_NAME, PEOPLE_NAME_CONFLICT_PERSON_NAME); + + given() + .contentType(ContentType.JSON) + .body(requestBody) + .when() + .post(PEOPLE_NAME_CONFLICT_URL) + .then() + .statusCode(409); + } } diff --git a/src/test/resources/insert_test_data.sql b/src/test/resources/insert_test_data.sql index 1a237fe..6af8631 100644 --- a/src/test/resources/insert_test_data.sql +++ b/src/test/resources/insert_test_data.sql @@ -1,3 +1,5 @@ +TRUNCATE TABLE "group" CASCADE; + -- test-data for groups INSERT INTO "group" VALUES ('gettgrup', 'GetGroup', 'CHF', NOW(), NOW()); INSERT INTO "group" VALUES ('puttgrup', 'EditGroup', 'CHF', NOW(), NOW()); @@ -13,4 +15,7 @@ INSERT INTO "group" VALUES ('piplgrup', 'PeopleGroup', 'CHF', NOW(), NOW()); INSERT INTO person VALUES (7, 'PeoplePerson1', 'piplgrup', TRUE, NOW(), NOW()); INSERT INTO person VALUES (8, 'PeoplePerson2', 'piplgrup', TRUE, NOW(), NOW()); +INSERT INTO "group" VALUES ('spargrup', 'Spartacus', 'CHF', NOW(), NOW()); +INSERT INTO person VALUES (9, 'Spartacus', TRUE, NOW(), NOW()); + SELECT SETVAL('person_id_seq', (SELECT MAX(id) FROM "person")); -- DO NOT REMOVE, ELSE: TRAVIS => BUMM \ No newline at end of file From 1316c173da02ceff3732e59bd4c67e118ce36cd1 Mon Sep 17 00:00:00 2001 From: McDonnough Date: Tue, 23 May 2017 10:20:59 +0200 Subject: [PATCH 5/6] add test for inactive person --- .../endpoints/PersonEndpointControllerTest.java | 17 +++++++++++++++++ src/test/resources/insert_test_data.sql | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java index 3b6a96c..8864fe3 100644 --- a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java +++ b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java @@ -35,6 +35,9 @@ public class PersonEndpointControllerTest extends BaseEndpointControllerTest { private static final String PEOPLE_NAME_CONFLICT_GROUP_ID = "spargrup"; private static final String PEOPLE_NAME_CONFLICT_URL = URL_VERSION + "groups/" + PEOPLE_NAME_CONFLICT_GROUP_ID + "/people"; private static final String PEOPLE_NAME_CONFLICT_PERSON_NAME = "Spartacus"; + + private static final int INACTIVE_PERSON_ID = 4; + private static final String INACTIVE_PERSON_NAME = "InactivePerson"; private static final String PARAM_NAME = "name"; private static final String PARAM_ID = "id"; @@ -125,5 +128,19 @@ public void testPeopleNameConflict() { .then() .statusCode(409); } + + @Test + public void testPersonInactive() { + Map requestBody = new HashMap<>(); + requestBody.put(PARAM_NAME, INACTIVE_PERSON_NAME + "ABC"); + + given() + .contentType(ContentType.JSON) + .body(requestBody) + .when() + .put(PERSON_URL + "/" + INACTIVE_PERSON_ID) + .then() + .statusCode(410); + } } diff --git a/src/test/resources/insert_test_data.sql b/src/test/resources/insert_test_data.sql index 6af8631..057bec2 100644 --- a/src/test/resources/insert_test_data.sql +++ b/src/test/resources/insert_test_data.sql @@ -1,5 +1,3 @@ -TRUNCATE TABLE "group" CASCADE; - -- test-data for groups INSERT INTO "group" VALUES ('gettgrup', 'GetGroup', 'CHF', NOW(), NOW()); INSERT INTO "group" VALUES ('puttgrup', 'EditGroup', 'CHF', NOW(), NOW()); @@ -10,12 +8,13 @@ INSERT INTO "group" VALUES ('persgrup', 'PersonGroup', 'CHF', NOW(), NOW()); INSERT INTO person VALUES (1, 'GetPerson', 'persgrup', TRUE, NOW(), NOW()); INSERT INTO person VALUES (2, 'PutPerson', 'persgrup', TRUE, NOW(), NOW()); INSERT INTO person VALUES (3, 'DeletePerson', 'persgrup', TRUE, NOW(), NOW()); +INSERT INTO person VALUES (4, 'InactivePerson', 'persgrup', FALSE, NOW(), NOW()); INSERT INTO "group" VALUES ('piplgrup', 'PeopleGroup', 'CHF', NOW(), NOW()); INSERT INTO person VALUES (7, 'PeoplePerson1', 'piplgrup', TRUE, NOW(), NOW()); INSERT INTO person VALUES (8, 'PeoplePerson2', 'piplgrup', TRUE, NOW(), NOW()); INSERT INTO "group" VALUES ('spargrup', 'Spartacus', 'CHF', NOW(), NOW()); -INSERT INTO person VALUES (9, 'Spartacus', TRUE, NOW(), NOW()); +INSERT INTO person VALUES (9, 'Spartacus', 'spargrup', TRUE, NOW(), NOW()); SELECT SETVAL('person_id_seq', (SELECT MAX(id) FROM "person")); -- DO NOT REMOVE, ELSE: TRAVIS => BUMM \ No newline at end of file From 8b31590e230db75eaf3d8ca7ce8f181ea308e83a Mon Sep 17 00:00:00 2001 From: McDonnough Date: Tue, 23 May 2017 11:37:24 +0200 Subject: [PATCH 6/6] Beni, yo --- .../server/endpoints/PersonEndpointControllerTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java index 8864fe3..6ff603f 100644 --- a/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java +++ b/src/test/java/io/teiler/server/endpoints/PersonEndpointControllerTest.java @@ -14,9 +14,12 @@ import io.restassured.http.ContentType; public class PersonEndpointControllerTest extends BaseEndpointControllerTest { + + private static final String GROUP_URL_PATH = "groups"; + private static final String PEOPLE_URL_PATH = "people"; private static final String GROUP_ID = "persgrup"; - private static final String PERSON_URL = URL_VERSION + "groups/" + GROUP_ID + "/people"; + private static final String PERSON_URL = URL_VERSION + GROUP_URL_PATH + "/" + GROUP_ID + "/" + PEOPLE_URL_PATH; private static final String POST_PERSON_NAME = "Richi"; private static final int PUT_PERSON_ID = 2; @@ -24,7 +27,7 @@ public class PersonEndpointControllerTest extends BaseEndpointControllerTest { private static final int DELETE_PERSON_ID = 3; private static final String PEOPLE_GROUP_ID = "piplgrup"; - private static final String PERSON_PEOPLE_URL = URL_VERSION + "groups/" + PEOPLE_GROUP_ID + "/people"; + private static final String PERSON_PEOPLE_URL = URL_VERSION + GROUP_URL_PATH + "/" + PEOPLE_GROUP_ID + "/" + PEOPLE_URL_PATH; private static final int GET_PERSON_1_ID = 7; private static final String GET_PERSON_1_NAME = "PeoplePerson1"; private static final int GET_PERSON_2_ID = 8; @@ -33,7 +36,7 @@ public class PersonEndpointControllerTest extends BaseEndpointControllerTest { private static final int PERSON_NOT_FOUND_ID = 666; private static final String PEOPLE_NAME_CONFLICT_GROUP_ID = "spargrup"; - private static final String PEOPLE_NAME_CONFLICT_URL = URL_VERSION + "groups/" + PEOPLE_NAME_CONFLICT_GROUP_ID + "/people"; + private static final String PEOPLE_NAME_CONFLICT_URL = URL_VERSION + GROUP_URL_PATH + "/" + PEOPLE_NAME_CONFLICT_GROUP_ID + "/" + PEOPLE_URL_PATH; private static final String PEOPLE_NAME_CONFLICT_PERSON_NAME = "Spartacus"; private static final int INACTIVE_PERSON_ID = 4;