more tag tests

This commit is contained in:
Benjamin Gamard 2018-03-10 17:58:37 +01:00
parent 740476460f
commit ebfd860458

View File

@ -152,7 +152,7 @@ public class TestTagResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.get(JsonObject.class); .get(JsonObject.class);
tags = json.getJsonArray("tags"); tags = json.getJsonArray("tags");
Assert.assertTrue(tags.size() > 0); Assert.assertTrue(tags.size() == 2);
Assert.assertEquals("Tag4", tags.getJsonObject(1).getString("name")); Assert.assertEquals("Tag4", tags.getJsonObject(1).getString("name"));
Assert.assertEquals("#00ff00", tags.getJsonObject(1).getString("color")); Assert.assertEquals("#00ff00", tags.getJsonObject(1).getString("color"));
Assert.assertEquals(tag3Id, tags.getJsonObject(1).getString("parent")); Assert.assertEquals(tag3Id, tags.getJsonObject(1).getString("parent"));
@ -170,13 +170,30 @@ public class TestTagResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.get(JsonObject.class); .get(JsonObject.class);
tags = json.getJsonArray("tags"); tags = json.getJsonArray("tags");
Assert.assertTrue(tags.size() > 0); Assert.assertTrue(tags.size() == 2);
Assert.assertEquals("UpdatedName", tags.getJsonObject(1).getString("name")); Assert.assertEquals("UpdatedName", tags.getJsonObject(1).getString("name"));
Assert.assertEquals("#0000ff", tags.getJsonObject(1).getString("color")); Assert.assertEquals("#0000ff", tags.getJsonObject(1).getString("color"));
Assert.assertNull(tags.getJsonObject(1).get("parent")); Assert.assertNull(tags.getJsonObject(1).get("parent"));
// Update a tag
json = target().path("/tag/" + tag4Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.post(Entity.form(new Form()
.param("name", "UpdatedName")
.param("color", "#0000ff")
.param("parent", tag3Id)), JsonObject.class);
Assert.assertEquals(tag4Id, json.getString("id"));
// Get all tags
json = target().path("/tag/list").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.get(JsonObject.class);
tags = json.getJsonArray("tags");
Assert.assertTrue(tags.size() == 2);
Assert.assertEquals(tag3Id, tags.getJsonObject(1).getString("parent"));
// Deletes a tag // Deletes a tag
target().path("/tag/" + tag4Id).request() target().path("/tag/" + tag3Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.delete(); .delete();
@ -186,5 +203,7 @@ public class TestTagResource extends BaseJerseyTest {
.get(JsonObject.class); .get(JsonObject.class);
tags = json.getJsonArray("tags"); tags = json.getJsonArray("tags");
Assert.assertTrue(tags.size() == 1); Assert.assertTrue(tags.size() == 1);
Assert.assertEquals("UpdatedName", tags.getJsonObject(0).getString("name"));
Assert.assertNull(tags.getJsonObject(0).get("parent"));
} }
} }