Skip to content

Commit

Permalink
adding create tag test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Apr 1, 2017
1 parent 4087138 commit 2325cfd
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ A Neo4j Based Twitter Clone Backend
:GET /v1/users/{username}/timeline
:GET /v1/users/{username}/recommendations/friends
:GET /v1/users/{username}/recommendations/follows
:GET /v1/tags/{tag}


7. Query Parameters:

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maxdemarzi/tags/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Response getTags(@PathParam("hashtag") final String hashtag,
for (Relationship r1 : tag.getRelationships(Direction.INCOMING, relType)) {
Node post = r1.getStartNode();
Map<String, Object> result = post.getAllProperties();
Long time = (Long) r1.getProperty("time");
Long time = (Long) result.get("time");

if (count < limit && time < latest) {
Node author = getAuthor(post, time);
Expand Down
68 changes: 68 additions & 0 deletions src/test/java/com/maxdemarzi/tags/CreateTagTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.maxdemarzi.tags;

import com.maxdemarzi.posts.Posts;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.neo4j.harness.junit.Neo4jRule;
import org.neo4j.test.server.HTTP;

import java.util.ArrayList;
import java.util.HashMap;

import static com.maxdemarzi.Properties.*;
import static java.lang.Thread.sleep;

public class CreateTagTest {
@Rule
public Neo4jRule neo4j = new Neo4jRule()
.withFixture(FIXTURE)
.withExtension("/v1", Posts.class)
.withExtension("/v1", Tags.class);

@Test
public void shouldCreateTag() throws InterruptedException {
HTTP.POST(neo4j.httpURI().resolve("/v1/schema/create").toString());

HTTP.Response response = HTTP.POST(neo4j.httpURI().resolve("/v1/users/maxdemarzi/posts").toString(), input);
HashMap actual = response.content();
Assert.assertEquals(expected.get(STATUS), actual.get(STATUS));
Assert.assertTrue(actual.containsKey(TIME));
sleep(1000); // Needed due to artifact in testing
response = HTTP.GET(neo4j.httpURI().resolve("/v1/tags/neo4j").toString());
ArrayList<HashMap> actual2 = response.content();
expected2.get(0).put(TIME, actual2.get(0).get(TIME));
Assert.assertEquals(expected2, actual2);

Assert.assertEquals("maxdemarzi", actual2.get(0).get(USERNAME));
Assert.assertEquals("Max De Marzi", actual2.get(0).get(NAME));
Assert.assertEquals("Hello World! #neo4j", actual2.get(0).get(STATUS));
}

private static final String FIXTURE =
"CREATE (max:User {username:'maxdemarzi', " +
"email: 'maxdemarzi@hotmail.com', " +
"name: 'Max De Marzi'," +
"hash: '0bd90aeb51d5982062f4f303a62df935'," +
"password: 'swordfish'})";

private static final HashMap input = new HashMap<String, Object>() {{
put(STATUS, "Hello World! #neo4j");
}};

private static final HashMap expected = new HashMap<String, Object>() {{
put(STATUS, "Hello World! #neo4j");
}};

private static final ArrayList<HashMap<String, Object>> expected2 = new ArrayList<HashMap<String, Object>>() {
{
add(new HashMap<String, Object>() {{
put("username", "maxdemarzi");
put("name", "Max De Marzi");
put("hash", "0bd90aeb51d5982062f4f303a62df935");
put("status", "Hello World! #neo4j");
put("likes", 0);
put("reposts", 0);
}});
}};
}

0 comments on commit 2325cfd

Please sign in to comment.