Example #1
0
 @Test
 @Graph(value = {"I know you"})
 public void runSimpleQuery() throws Exception {
   Node i = data.get().get("I");
   Representation result = testQuery("start n=node(" + i.getId() + ") return n");
   assertTrue(json.assemble(result).contains("I"));
 }
 @Test
 public void canProvideJsonOutputFormat() throws Exception {
   OutputFormat format =
       repository.outputFormat(asList(MediaType.APPLICATION_JSON_TYPE), null, null);
   assertNotNull(format);
   assertEquals("\"test\"", format.assemble(ValueRepresentation.string("test")));
 }
 @Test
 public void canFormatEmptyObject() throws Exception {
   json.assemble(
       new MappingRepresentation("empty") {
         @Override
         protected void serialize(MappingSerializer serializer) {}
       });
   assertEquals(JsonHelper.createJsonFrom(Collections.emptyMap()), stream.toString());
 }
 @Test
 public void canFormatNode() throws Exception {
   GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
   try {
     final Node refNode = db.getReferenceNode();
     json.assemble(new NodeRepresentation(refNode));
   } finally {
     db.shutdown();
   }
   assertTrue(stream.toString().contains("\"self\" : \"http://localhost/node/0\","));
 }
 @Test
 public void canFormatObjectWithStringField() throws Exception {
   json.assemble(
       new MappingRepresentation("string") {
         @Override
         protected void serialize(MappingSerializer serializer) {
           serializer.putString("key", "expected string");
         }
       });
   assertEquals(
       JsonHelper.createJsonFrom(Collections.singletonMap("key", "expected string")),
       stream.toString());
 }
  @Test
  public void canFormatObjectWithUriField() throws Exception {
    json.assemble(
        new MappingRepresentation("uri") {
          @Override
          protected void serialize(MappingSerializer serializer) {
            serializer.putUri("URL", "subpath");
          }
        });

    assertEquals(
        JsonHelper.createJsonFrom(Collections.singletonMap("URL", "http://localhost/subpath")),
        stream.toString());
  }
 @Test
 public void canFormatObjectWithNestedObject() throws Exception {
   json.assemble(
       new MappingRepresentation("nesting") {
         @Override
         protected void serialize(MappingSerializer serializer) {
           serializer.putMapping(
               "nested",
               new MappingRepresentation("data") {
                 @Override
                 protected void serialize(MappingSerializer nested) {
                   nested.putString("data", "expected data");
                 }
               });
         }
       });
   assertEquals(
       JsonHelper.createJsonFrom(
           Collections.singletonMap("nested", Collections.singletonMap("data", "expected data"))),
       stream.toString());
 }
Example #8
0
 @Test
 @Graph(
     value = {"I know you", "I know him"},
     nodes = {
       @NODE(
           name = "you",
           properties = {
             @PROP(key = "bool", value = "true", type = GraphDescription.PropType.BOOLEAN),
             @PROP(key = "name", value = "you"),
             @PROP(key = "int", value = "1", type = GraphDescription.PropType.INTEGER)
           })
     })
 public void checkColumns() throws Exception {
   Node i = data.get().get("I");
   Representation result =
       testQuery(
           "start x =node(" + i.getId() + ") match (x) -- (n) return n, n.name?, n.bool?, n.int?");
   String formatted = json.assemble(result);
   System.out.println(formatted);
   assertTrue(formatted.contains("columns"));
   assertTrue(formatted.contains("name"));
 }
 @Test
 public void canFormatInteger() throws Exception {
   json.assemble(ValueRepresentation.number(10));
   assertEquals("10", stream.toString());
 }
 @Test
 public void canFormatListOfStrings() throws Exception {
   json.assemble(ListRepresentation.strings("hello", "world"));
   String expectedString = JsonHelper.createJsonFrom(Arrays.asList("hello", "world"));
   assertEquals(expectedString, stream.toString());
 }
 @Test
 public void canFormatString() throws Exception {
   json.assemble(ValueRepresentation.string("expected value"));
   assertEquals(stream.toString(), "\"expected value\"");
 }