Package org.neo4j.smack.serialization

Examples of org.neo4j.smack.serialization.JsonSerializer


    @Test
    public void shouldSerializeNodeWithNoProperties() {
       
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        JsonSerializer serializer = new JsonSerializer(new JsonFactory(), buffer);
       
        Node mockNode = mock(Node.class);
        when(mockNode.getId()).thenReturn(0l);
        when(mockNode.getPropertyKeys()).thenReturn(Collections.<String> emptyList());
       
        NodeSerializationStrategy strategy = new NodeSerializationStrategy();
        strategy.serialize(mockNode, serializer);
        serializer.flush();
       
        assertThat(new String(buffer.toByteArray()),is("{" +
                "\"data\":{}," +
                "\"self\":\"/db/data/node/0\"," +
                "\"extensions\":{}" +
View Full Code Here


   
    @Test
    public void shouldSerializeNodeWithProperties() {
       
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        JsonSerializer serializer = new JsonSerializer(new JsonFactory(), buffer);
       
        Node mockNode = mock(Node.class);
        when(mockNode.getId()).thenReturn(0l);
        when(mockNode.getPropertyKeys()).thenReturn(new ArrayList<String>() {
            private static final long serialVersionUID = 1248180220593789023L;
        {
            add("name");
            add("age");
            add("favorite_numbers");
        }});
       
        when(mockNode.getProperty("name")).thenReturn("bob");
        when(mockNode.getProperty("age")).thenReturn(12);
        when(mockNode.getProperty("favorite_numbers")).thenReturn(new int [] {1,2,3});
       
        NodeSerializationStrategy strategy = new NodeSerializationStrategy();
        strategy.serialize(mockNode, serializer);
        serializer.flush();
       
        assertThat(new String(buffer.toByteArray()),is(
                "{" +
                  "\"data\":{" +
                    "\"name\":\"bob\"," +
View Full Code Here

    @Test
    public void shouldSerializeRelationshipWithNoProperties() {
       
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        JsonSerializer serializer = new JsonSerializer(new JsonFactory(), buffer);
       
        Node fromNode = mock(Node.class);
        when(fromNode.getId()).thenReturn(0l);
       
        Node toNode = mock(Node.class);
        when(toNode.getId()).thenReturn(1l);
       
        Relationship mockRel = mock(Relationship.class);
        when(mockRel.getId()).thenReturn(0l);
        when(mockRel.getType()).thenReturn(DynamicRelationshipType.withName("LOVES"));
        when(mockRel.getStartNode()).thenReturn(fromNode);
        when(mockRel.getEndNode()).thenReturn(toNode);
       
        when(mockRel.getPropertyKeys()).thenReturn(Collections.<String> emptyList());
       
        RelationshipSerializationStrategy strategy = new RelationshipSerializationStrategy();
        strategy.serialize(mockRel, serializer);
        serializer.flush();
       
        assertThat(new String(buffer.toByteArray()),is("{" +
                "\"self\":\"/db/data/relationship/0\"," +
                "\"type\":\"LOVES\"," +
                "\"start\":\"/db/data/node/0\"," +
View Full Code Here

   
    @Test
    public void shouldSerializeNodeWithProperties() {
       
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        JsonSerializer serializer = new JsonSerializer(new JsonFactory(), buffer);
       
        Node fromNode = mock(Node.class);
        when(fromNode.getId()).thenReturn(0l);
       
        Node toNode = mock(Node.class);
        when(toNode.getId()).thenReturn(1l);
       
        Relationship mockRel = mock(Relationship.class);
        when(mockRel.getId()).thenReturn(0l);
        when(mockRel.getType()).thenReturn(DynamicRelationshipType.withName("LOVES"));
        when(mockRel.getStartNode()).thenReturn(fromNode);
        when(mockRel.getEndNode()).thenReturn(toNode);
       
        when(mockRel.getPropertyKeys()).thenReturn(new ArrayList<String>() {
            private static final long serialVersionUID = 1248180220593789023L;
        {
            add("name");
            add("age");
            add("favorite_numbers");
        }});
       
        when(mockRel.getProperty("name")).thenReturn("bob");
        when(mockRel.getProperty("age")).thenReturn(12);
        when(mockRel.getProperty("favorite_numbers")).thenReturn(new int [] {1,2,3});
       
        RelationshipSerializationStrategy strategy = new RelationshipSerializationStrategy();
        strategy.serialize(mockRel, serializer);
        serializer.flush();
       
        assertThat(new String(buffer.toByteArray()),is(
                "{" +
                  "\"self\":\"/db/data/relationship/0\"," +
                  "\"type\":\"LOVES\"," +
View Full Code Here

TOP

Related Classes of org.neo4j.smack.serialization.JsonSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.