Commit 935d30f7 by Dan Markwat

Fixed json parsing issues - guid is now extracted from the JSON payload

and the test parses the GUID as expected
parent c1af1456
...@@ -132,6 +132,11 @@ ...@@ -132,6 +132,11 @@
<artifactId>guice-servlet</artifactId> <artifactId>guice-servlet</artifactId>
<version>3.0</version> <version>3.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency> <dependency>
<groupId>com.sun.jersey.contribs</groupId> <groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-guice</artifactId> <artifactId>jersey-guice</artifactId>
...@@ -206,15 +211,15 @@ ...@@ -206,15 +211,15 @@
<artifactId>keytool-maven-plugin</artifactId> <artifactId>keytool-maven-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>clean</id>
<phase>generate-resources</phase> <phase>generate-resources</phase>
<id>clean-server</id>
<goals> <goals>
<goal>clean</goal> <goal>clean</goal>
</goals> </goals>
</execution> </execution>
<execution> <execution>
<id>genkey</id>
<phase>generate-resources</phase> <phase>generate-resources</phase>
<id>server</id>
<goals> <goals>
<goal>generateKeyPair</goal> <goal>generateKeyPair</goal>
</goals> </goals>
...@@ -251,6 +256,7 @@ ...@@ -251,6 +256,7 @@
</connector> </connector>
</connectors> </connectors>
<webApp>${project.build.directory}/metadata-webapp-${project.version}</webApp> <webApp>${project.build.directory}/metadata-webapp-${project.version}</webApp>
<contextPath>/</contextPath>
<useTestClasspath>true</useTestClasspath> <useTestClasspath>true</useTestClasspath>
<systemProperties> <systemProperties>
<systemProperty> <systemProperty>
......
...@@ -18,18 +18,22 @@ ...@@ -18,18 +18,22 @@
package org.apache.hadoop.metadata.web.resources; package org.apache.hadoop.metadata.web.resources;
import com.sun.jersey.api.client.ClientResponse; import java.util.HashMap;
import com.sun.jersey.api.client.WebResource; import java.util.Map;
import org.json.simple.JSONValue; import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map; import org.json.simple.JSONValue;
import java.util.UUID; import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
/** /**
* Integration tests for Entity Jersey Resource. * Integration tests for Entity Jersey Resource.
...@@ -44,6 +48,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -44,6 +48,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSubmitEntity() { public void testSubmitEntity() {
String entityStream = getTestEntityJSON(); String entityStream = getTestEntityJSON();
JsonParser parser = new JsonParser();
WebResource resource = service WebResource resource = service
.path("api/metadata/entities/submit") .path("api/metadata/entities/submit")
...@@ -54,11 +59,15 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -54,11 +59,15 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, entityStream); .method(HttpMethod.POST, ClientResponse.class, entityStream);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String response = clientResponse.getEntity(String.class); String response = clientResponse.getEntity(String.class);
Assert.assertNotNull(response); Assert.assertNotNull(response);
JsonElement elem = parser.parse(response);
String guid = elem.getAsJsonObject().get("GUID").getAsString();
try { try {
Assert.assertNotNull(UUID.fromString(response)); Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + response); Assert.fail("Response is not a guid, " + response);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment