Skip to content

Commit

Permalink
Minor test fixes, still quite a bit of red.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewins committed Apr 24, 2012
1 parent 4547b59 commit 0ede25f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 228 deletions.
20 changes: 12 additions & 8 deletions src/test/java/org/neo4j/smack/REST.java
Expand Up @@ -32,7 +32,7 @@
public class REST {
private final static JsonFactory jsonFactory = new JsonFactory(new ObjectMapper());
static Client client = Client.create();
static String URI = RestServiceTest.BASE_URI;
static String URI;
private WebResource.Builder resource;
private int status;
private URI location;
Expand Down Expand Up @@ -92,7 +92,7 @@ private REST handle(ClientResponse response) {
}

private void readEntityIfPossible(ClientResponse response) {
if (status != Response.Status.NO_CONTENT.getStatusCode()) {
if (status != Response.Status.NO_CONTENT.getStatusCode() && response.getLength() > 0) {
this.entity = readEntity(response, Object.class);
}
}
Expand Down Expand Up @@ -172,13 +172,17 @@ public REST expectUri(String path, Object value) {
}

private Object getPath(String path) {
final String[] parts = path.split("[./]");
Map map = (Map) entity;
for (int i = 0; i < parts.length - 1; i++) {
String part = parts[i];
map = (Map) map.get(part);
try {
final String[] parts = path.split("[./]");
Map map = (Map) entity;
for (int i = 0; i < parts.length - 1; i++) {
String part = parts[i];
map = (Map) map.get(part);
}
return map.get(parts[parts.length - 1]);
} catch(NullPointerException e) {
throw new RuntimeException("Expected response to the following path of keys: " + path);
}
return map.get(parts[parts.length - 1]);
}

public REST assertStatus(Response.Status expectedStatus) {
Expand Down
175 changes: 0 additions & 175 deletions src/test/java/org/neo4j/smack/SmackServerTest.java

This file was deleted.

@@ -1,54 +1,28 @@
package org.neo4j.smack;
package org.neo4j.smack.test.integration;

import static org.neo4j.helpers.collection.MapUtil.map;

import javax.ws.rs.core.Response;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.smack.api.DatabaseService;
import org.neo4j.test.ImpermanentGraphDatabase;
import org.neo4j.smack.REST;
import org.neo4j.smack.test.util.AbstractRestFunctionalTestBase;

/**
* @author mh
* @since 14.11.11
*/
public class RestServiceTest {
public static final String HOST = "localhost";
public static final int PORT = 7473;
public static final String BASE_URI = "http://" + HOST + ":" + PORT + "/";
public static final int ROOT_NODE_ID = 0;
public class NodeServiceIT extends AbstractRestFunctionalTestBase {

public static SmackServer server;

private static AbstractGraphDatabase gds;

@BeforeClass
public static void setUp() throws Exception {
gds = new ImpermanentGraphDatabase();
final Transaction tx = gds.beginTx();
gds.getReferenceNode().setProperty("name", "test");
tx.success();
tx.finish();
server = new SmackServer(HOST, PORT, new Database(gds));
final DatabaseService dataApi = new DatabaseService("");
server.addRoute("", dataApi);
server.start();
REST.init(BASE_URI,"",gds);
}

@AfterClass
public static void tearDown() throws Exception {
server.stop();
gds.shutdown();
@Before
public void setUp() throws Exception {
REST.init(getBaseUri(),"",graphdb());
}

@Test
public void testGetDbInfo() throws Exception {
REST.from("/").get().ok().expectUri("reference_node", "node/0");
REST.from("").get().ok().expectUri("reference_node", "node/0");
}

@Test
Expand Down Expand Up @@ -78,12 +52,12 @@ public void testReplaceNodeProperties() throws Exception {

@Test
public void testGetNode() throws Exception {
final String rootNodeUri = "node/" + ROOT_NODE_ID;
final String rootNodeUri = "node/0";
REST.from(rootNodeUri).get().ok().expectUri("self", rootNodeUri);
}

@Test
public void testGetNonExistingNode() throws Exception {
REST.from("node/" + 9999).get().notFound();
REST.from("/node/" + 9999).get().notFound();
}
}
@@ -1,5 +1,14 @@
package org.neo4j.smack.test.util;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import javax.ws.rs.core.Response.Status;

import org.codehaus.jackson.JsonParseException;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -12,14 +21,6 @@
import org.neo4j.test.TestData;
import org.neo4j.visualization.asciidoc.AsciidocHelper;

import javax.ws.rs.core.Response.Status;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import static org.junit.Assert.assertEquals;

public class AbstractRestFunctionalTestBase extends SharedSmackServerTestBase implements GraphHolder {
protected static final String NODES = "http://localhost:7473/db/data/node/";

Expand Down Expand Up @@ -111,15 +112,22 @@ protected String getDataUri()
{
return "http://localhost:7473/db/data/";
}

protected String getBaseUri()
{
return "http://localhost:7473";
}

protected String getNodeUri( Node node )
{
return getDataUri() + "node/" + node.getId();
}

protected String getRelationshipUri( Relationship node )
{
return getDataUri() + "relationship/" + node.getId();
}

protected String getNodeIndexUri( String indexName, String key, String value )
{
return postNodeIndexUri( indexName ) + "/" + key + "/" + value;
Expand Down

0 comments on commit 0ede25f

Please sign in to comment.