add annotation to project to ignore unknwon attributes
authorymh <ymh.work@gmail.com>
Fri, 23 Oct 2015 13:49:15 +0200
changeset 586 e2e952fcaf7c
parent 585 700a1562486e
child 587 fb0041aa74d3
add annotation to project to ignore unknwon attributes
server/java/renkan-core/src/main/java/org/iri_research/renkan/models/Project.java
server/java/renkan-web/src/test/java/org/iri_research/renkan/test/rest/ProjectRestTest.java
server/java/renkan-web/src/test/resources/org/iri_research/renkan/test/rest/test-project-unknown-attribute.json
--- a/server/java/renkan-core/src/main/java/org/iri_research/renkan/models/Project.java	Mon Oct 19 14:19:49 2015 +0200
+++ b/server/java/renkan-core/src/main/java/org/iri_research/renkan/models/Project.java	Fri Oct 23 13:49:15 2015 +0200
@@ -25,9 +25,11 @@
 import org.springframework.data.mongodb.core.mapping.Field;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 @Document(collection = "projects")
+@JsonIgnoreProperties(ignoreUnknown=true)
 public class Project extends AbstractRenkanColoredModel<String> {
 
     private static Logger logger = LoggerFactory.getLogger(Project.class);
--- a/server/java/renkan-web/src/test/java/org/iri_research/renkan/test/rest/ProjectRestTest.java	Mon Oct 19 14:19:49 2015 +0200
+++ b/server/java/renkan-web/src/test/java/org/iri_research/renkan/test/rest/ProjectRestTest.java	Fri Oct 23 13:49:15 2015 +0200
@@ -317,4 +317,29 @@
 
     }
 
+    @Test
+    public void testPostProjectUnknownAttribute() throws IOException {
+        InputStream in = this.getClass().getResourceAsStream("/org/iri_research/renkan/test/rest/test-project-unknown-attribute.json");
+        StringWriter sw = new StringWriter();
+        IOUtils.copy(in, sw, "utf-8");
+
+        String jsonStr = sw.toString().replaceAll("\\<space_id\\>", this.spaceId);
+
+        WebTarget webResource = this.target();
+        Response resp = webResource.path("projects").request(MediaType.APPLICATION_JSON).post(Entity.entity(jsonStr, MediaType.APPLICATION_JSON), Response.class);
+
+        Assert.assertEquals("Status must be OK", 201, resp.getStatus());
+
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode node = mapper.readTree(resp.readEntity(String.class));
+
+        Assert.assertNotNull("Must have a project in response", node);
+
+        JsonNode idNode = node.findValue("id");
+        Assert.assertNotNull("Project must have an id", idNode);
+        String id = idNode.asText();
+        Assert.assertNotNull("Project must have an id not null", id);
+        Assert.assertNotEquals("Project must have an id not empty", "", id);
+    }
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/java/renkan-web/src/test/resources/org/iri_research/renkan/test/rest/test-project-unknown-attribute.json	Fri Oct 23 13:49:15 2015 +0200
@@ -0,0 +1,54 @@
+{
+  "title" : "Project Rest Post Test",
+  "description" : "",
+  "uri" : null,
+  "color" : "#ffffff",
+  "revCounter" : 6,
+  "nodes" : [ {
+    "@id" : "f286bae5-4303-49c1-8534-43520e117940",
+    "title" : "storytelling",
+    "description" : "Tag 'storytelling'",
+    "uri" : "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/search/?search=storytelling&field=all",
+    "style" : {
+        "color" : "#ffffff"
+    },
+    "position" : {
+      "x" : 7.5,
+      "y" : -76.0
+    },
+    "image" : "http://localhost:8080/renkan/static/img/ldt-tag.png",
+    "size" : 0,
+    "created_by" : "roster_user-084bccad-8030-4dcf-96a0-d7acc32a1503"
+  }, {
+    "@id" : "b49ee549-d98a-4b54-b6f0-73ef84a2eccb",
+    "title" : "Introduction générale par Hidetaka Ishida",
+    "description" : "石田英敬によるイントロダクション (langue française フランス語)",
+    "uri" : "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/e328e188-ff2f-11e0-b9e1-00145ea49a02/#id=s_A91AB45B-AB6B-EFCA-4A08-40B2F74F294F",
+    "style" : {
+        "color" : "#ffffff"
+    },
+    "position" : {
+      "x" : -283.5,
+      "y" : 39.0
+    },
+    "image" : "http://localhost:8080/renkan/static/img/ldt-segment.png",
+    "size" : 0,
+    "created_by" : "roster_user-084bccad-8030-4dcf-96a0-d7acc32a1503"
+  } ],
+  "edges" : [ {
+    "@id" : "15cedd4c-99be-4d83-b849-3ee7d9d26a2c",
+    "title" : "",
+    "description" : "",
+    "uri" : "",
+    "style" : {
+        "color" : "#ffffff"
+    },
+    "from" : "b49ee549-d98a-4b54-b6f0-73ef84a2eccb",
+    "to" : "f286bae5-4303-49c1-8534-43520e117940",
+    "created_by" : "roster_user-084bccad-8030-4dcf-96a0-d7acc32a1503"
+  } ],
+  "saved_at": "2015-10-22T12:19:59.982Z",
+  "views" : [ ],
+  "users" : [ ],
+  "space_id" : "<space_id>"
+}