Skip to content

Commit

Permalink
Merge branch 'master' into install-instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
lroellin committed May 23, 2017
2 parents 354eb7f + 15cc438 commit f36f08c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@RunWith(Suite.class)
@SuiteClasses({
GroupEndpointControllerTest.class,
PeopleEndpointControllerTest.class
PersonEndpointControllerTest.class
})
public class EndpointControllerTestSuite {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -82,7 +84,7 @@ public void testPutGroup() {
.body(PARAM_UPDATE_TIME, is(notNullValue()))
.body(PARAM_CREATE_TIME, is(notNullValue()));
}

@Test
public void testDeleteGroup() {
given()
Expand All @@ -92,4 +94,19 @@ public void testDeleteGroup() {
.statusCode(200);
}

@Test
public void testInvalidCurrency() {
Map<String, String> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,35 @@

import io.restassured.http.ContentType;

public class PeopleEndpointControllerTest extends BaseEndpointControllerTest {
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;
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 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;
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 + 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;
private static final String INACTIVE_PERSON_NAME = "InactivePerson";

private static final String PARAM_NAME = "name";
private static final String PARAM_ID = "id";
private static final String PARAM_ACTIVE = "active";
Expand Down Expand Up @@ -87,7 +99,7 @@ public void testPutPerson() {
.body(PARAM_UPDATE_TIME, is(notNullValue()))
.body(PARAM_CREATE_TIME, is(notNullValue()));
}

@Test
public void testDeletePerson() {
given()
Expand All @@ -96,5 +108,42 @@ public void testDeletePerson() {
.then()
.statusCode(200);
}

@Test
public void testPersonNotFound() {
given()
.when()
.get(PERSON_URL + "/" + PERSON_NOT_FOUND_ID)
.then()
.statusCode(404);
}

@Test
public void testPeopleNameConflict() {
Map<String, String> 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);
}

@Test
public void testPersonInactive() {
Map<String, String> 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);
}

}
4 changes: 4 additions & 0 deletions src/test/resources/insert_test_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +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', 'spargrup', TRUE, NOW(), NOW());

SELECT SETVAL('person_id_seq', (SELECT MAX(id) FROM "person")); -- DO NOT REMOVE, ELSE: TRAVIS => BUMM

0 comments on commit f36f08c

Please sign in to comment.