You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/02/27 17:17:25 UTC
incubator-usergrid git commit: 1. Couple of simple tests to help
diagnose the problem,
2. ability to log JSON response from Usergrid and 3. fix to make
JacksonCustomMapperProvider get called.
Repository: incubator-usergrid
Updated Branches:
refs/heads/usergrid-429 80cd97ec0 -> f29e3e994
1. Couple of simple tests to help diagnose the problem, 2. ability to log JSON response from Usergrid and 3. fix to make JacksonCustomMapperProvider get called.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f29e3e99
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f29e3e99
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f29e3e99
Branch: refs/heads/usergrid-429
Commit: f29e3e9943af80993f22d91e8761dd488d9d0563
Parents: 80cd97e
Author: Dave Johnson <sn...@apache.org>
Authored: Fri Feb 27 11:17:22 2015 -0500
Committer: Dave Johnson <sn...@apache.org>
Committed: Fri Feb 27 11:17:22 2015 -0500
----------------------------------------------------------------------
.../org/apache/usergrid/SerializationTest.java | 47 +++++++
.../rest/JacksonCustomMapperProvider.java | 47 +++++--
.../apache/usergrid/rest/SerializationTest.java | 59 +++++++++
.../org/apache/usergrid/rest/SimplestTest.java | 40 +++++-
.../applications/queries/GeoPagingTest.java | 44 +++----
.../endpoints/CollectionEndpoint.java | 127 +++++++++++++++----
.../endpoints/mgmt/OrgResource.java | 88 ++++++++++---
.../rest/test/resource2point0/model/Entity.java | 10 +-
8 files changed, 373 insertions(+), 89 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/core/src/test/java/org/apache/usergrid/SerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/SerializationTest.java b/stack/core/src/test/java/org/apache/usergrid/SerializationTest.java
new file mode 100644
index 0000000..7cf10be
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/SerializationTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.usergrid.persistence.DynamicEntity;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class SerializationTest {
+ private static final Logger logger = LoggerFactory.getLogger(SerializationTest.class);
+
+ @Test
+ public void testSerialization() throws JsonProcessingException {
+
+ DynamicEntity entity = new DynamicEntity();
+ entity.setName("bertha");
+ entity.setType("cat");
+ entity.setDynamicProperty("dynaprop1", "dynavalue1");
+ entity.setProperty("plainprop1", "plainprop1");
+
+ ObjectMapper mapper = new ObjectMapper();
+ String entityString = mapper.writeValueAsString( entity );
+
+ assertEquals("{\"type\":\"cat\",\"name\":\"bertha\",\"dynaprop1\":\"dynavalue1\",\"plainprop1\":\"plainprop1\"}", entityString);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/main/java/org/apache/usergrid/rest/JacksonCustomMapperProvider.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/JacksonCustomMapperProvider.java b/stack/rest/src/main/java/org/apache/usergrid/rest/JacksonCustomMapperProvider.java
index a0d7948..e18b03d 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/JacksonCustomMapperProvider.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/JacksonCustomMapperProvider.java
@@ -19,36 +19,55 @@ package org.apache.usergrid.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
-
@Provider
-@Component
-@Scope("singleton")
+//@Consumes(MediaType.APPLICATION_JSON) // NOTE: required to support "non-standard" JSON variants
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
-public class JacksonCustomMapperProvider implements ContextResolver<ObjectMapper> {
-
+public class JacksonCustomMapperProvider extends JacksonJsonProvider {
private static final Logger logger = LoggerFactory.getLogger( JacksonCustomMapperProvider.class );
ObjectMapper mapper = new ObjectMapper();
-
public JacksonCustomMapperProvider() {
logger.info( "JacksonCustomMapperProvider installed" );
- mapper.configure( SerializationFeature.INDENT_OUTPUT, true); // pretty print
+ mapper.configure( SerializationFeature.INDENT_OUTPUT, true); // pretty print
}
-
@Override
- public ObjectMapper getContext( Class<?> aClass ) {
+ protected ObjectMapper _locateMapperViaProvider(Class<?> type, MediaType mediaType) {
return mapper;
}
}
+
+
+//@Provider
+//@Component
+//@Scope("singleton")
+//@Consumes(MediaType.APPLICATION_JSON) // NOTE: required to support "non-standard" JSON variants
+//@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
+//public class JacksonCustomMapperProvider implements ContextResolver<ObjectMapper> {
+//
+// private static final Logger logger = LoggerFactory.getLogger( JacksonCustomMapperProvider.class );
+//
+// ObjectMapper mapper = new ObjectMapper();
+//
+//
+// public JacksonCustomMapperProvider() {
+// logger.info( "JacksonCustomMapperProvider installed" );
+// mapper.configure( SerializationFeature.INDENT_OUTPUT, true); // pretty print
+// }
+//
+//
+// @Override
+// public ObjectMapper getContext( Class<?> aClass ) {
+// return mapper;
+// }
+//}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/test/java/org/apache/usergrid/rest/SerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/SerializationTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/SerializationTest.java
new file mode 100644
index 0000000..2d4cb7b
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/SerializationTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.rest;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.jersey.api.json.JSONWithPadding;
+import org.apache.usergrid.persistence.DynamicEntity;
+import org.apache.usergrid.persistence.Entity;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+
+
+/**
+ * Simple test verifies that serialization works in the REST tier.
+ */
+public class SerializationTest {
+ private static final Logger logger = LoggerFactory.getLogger(SerializationTest.class);
+
+ @Test
+ public void testSerialization() throws JsonProcessingException {
+
+ DynamicEntity entity = new DynamicEntity();
+ entity.setName("bertha");
+ entity.setType("cat");
+ entity.setDynamicProperty("dynaprop1", "dynavalue1");
+ entity.setProperty("plainprop1", "plainprop1");
+
+ ApiResponse response = new ApiResponse();
+ response.setEntities(Collections.singletonList( (Entity)entity ));
+
+ ObjectMapper mapper = new ObjectMapper();
+ String responseString = mapper.writeValueAsString( response );
+
+ logger.info( responseString );
+
+ JSONWithPadding jpad = new JSONWithPadding( response, "callback");
+
+ logger.info( jpad.getJsonSource().toString() );
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
index 6703c1b..27898a9 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/SimplestTest.java
@@ -16,20 +16,56 @@
*/
package org.apache.usergrid.rest;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.usergrid.persistence.DynamicEntity;
+import org.apache.usergrid.rest.test.resource2point0.model.Collection;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
+import org.apache.usergrid.utils.MapUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
/**
- * Simplest test verifies if REST test infrastructure is functioning.
+ * Simple test verifies if REST test infrastructure is functioning.
*/
public class SimplestTest extends org.apache.usergrid.rest.test.resource2point0.AbstractRestIT {
- private static final Logger log = LoggerFactory.getLogger(SimplestTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(SimplestTest.class);
@Test
public void getGetToken() {
assertNotNull( getAdminToken() );
}
+
+ @Test
+ public void testEntityPost() {
+
+ Entity cat = new Entity();
+ cat.put("name", "Bertha");
+ cat.put("property1", "value1");
+ Entity savedCat = this.app().collection("cats").post(cat);
+
+ assertEquals( cat.get("property1"), savedCat.get("property1"));
+ }
+
+ @Test
+ public void testEntityPostAndGet() {
+
+ Entity dog = new Entity();
+ dog.put("name", "Pokey");
+ dog.put("property1", "value1");
+ this.app().collection("dogs").post(dog);
+ refreshIndex();
+
+ Collection savedDogs = this.app().collection("dogs").get();
+ Entity savedDog = (Entity)savedDogs.iterator().next();
+ assertEquals( dog.get("property1"), savedDog.get("property1"));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
index 6c48af2..f9fe5b3 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/queries/GeoPagingTest.java
@@ -152,55 +152,47 @@ public class GeoPagingTest extends AbstractRestIT {
}
/**
- * Test that geolocation returns entities with consistent ordering
- * 1. Create several entities
- * 2. Query a subset of the entities
- * 3. Test that the entities were returned in the order expected
- *
- * @throws IOException
+ * Test that geo-query returns co-located entities in expected order.
*/
@Test // USERGRID-1401
public void groupQueriesWithConsistentResults() throws IOException {
int maxRangeLimit = 20;
- Entity[] saved = new Entity[maxRangeLimit];
- //Our base entity that the others will derive from
- Entity actor = new Entity();
- actor.put("displayName", "Erin");
- actor.put("location", new MapUtils.HashMapBuilder<String, Double>()
- .map("latitude", 37.0)
- .map("longitude", -75.0));
- Entity props = new Entity();
+ Entity[] cats = new Entity[maxRangeLimit];
- props.put("actor", actor);
- props.put("verb", "go");
- props.put("content", "bragh");
// 1. Create several entities
for (int i = 0; i < 20; i++) {
- String newPath = String.format("/kero" + i);
- props.put("path", newPath);
- props.put("ordinal", i);
- saved[i] = this.app().collection("groups").post(props);
+ Entity cat = new Entity();
+ cat.put("name", "cat" + i);
+ cat.put("location", new MapUtils.HashMapBuilder<String, Double>()
+ .map("latitude", 37.0)
+ .map("longitude", -75.0));
+ cat.put("ordinal", i);
+ cats[i] = cat;
+ this.app().collection("cats").post(cat);
}
this.refreshIndex();
QueryParameters params = new QueryParameters();
for (int consistent = 0; consistent < 20; consistent++) {
+
// 2. Query a subset of the entities
String query = String.format(
- "select * where location within 100 of 37, -75 and ordinal >= %d and ordinal < %d",
- saved[7].get("ordinal"), saved[10].get("ordinal"));
+ "select * where location within 100 of 37, -75 and ordinal >= %s and ordinal < %s",
+ cats[7].get("ordinal"), cats[10].get("ordinal"));
params.setQuery(query);
- Collection collection = this.app().collection("groups").get(params);
+ Collection collection = this.app().collection("cats").get(params);
assertEquals(3, collection.getResponse().getEntityCount());
List entities = collection.getResponse().getEntities();
+
// 3. Test that the entities were returned in the order expected
for (int i = 0; i < 3; i++) {
+
// shouldn't start at 10 since you're excluding it above in the query, it should return 9,8,7
Entity entity = (Entity)entities.get(i);
- Entity savedEntity = saved[7 + i];
- assertEquals(savedEntity.get("uuid"), entity.get("uuid"));
+ Entity savedEntity = cats[7 + i];
+ assertEquals(savedEntity.get("ordinal"), entity.get("ordinal"));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
index 6f62a20..cc91c9a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/CollectionEndpoint.java
@@ -16,14 +16,19 @@
*/
package org.apache.usergrid.rest.test.resource2point0.endpoints;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.api.client.WebResource;
import org.apache.usergrid.rest.test.resource2point0.model.*;
import org.apache.usergrid.rest.test.resource2point0.model.Collection;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
import org.apache.usergrid.services.ServiceParameter;
import org.apache.usergrid.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.io.StringReader;
import java.util.*;
@@ -31,6 +36,7 @@ import java.util.*;
* //myorg/myapp/mycollection
*/
public class CollectionEndpoint extends NamedResource {
+ private static final Logger logger = LoggerFactory.getLogger(CollectionEndpoint.class);
protected List<String> acceptHeaders = new ArrayList<String> ();
@@ -77,9 +83,7 @@ public class CollectionEndpoint extends NamedResource {
/**
* Get a list of entities
- * @return
*
- * @usage
* //with token
* app.collection("users").get(); //return entity
* GET /users?token=<token>
@@ -115,8 +119,21 @@ public class CollectionEndpoint extends NamedResource {
WebResource resource = getResource(useToken);
resource = addParametersToResource(resource, parameters);
- ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
- .get(ApiResponse.class);
+
+ // use string type so we can log actual response from server
+ String responseString = resource.type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(acceptHeader)
+ .get(String.class);
+
+ logger.debug("Response from get: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
return new Collection(response);
}
@@ -178,54 +195,104 @@ public class CollectionEndpoint extends NamedResource {
return delete(parameters, true);
}
- public ApiResponse delete(final QueryParameters parameters, final boolean useToken){
+ public ApiResponse delete(final QueryParameters parameters, final boolean useToken) {
+
String acceptHeader = MediaType.APPLICATION_JSON;
+
if (this.acceptHeaders.size() > 0) {
acceptHeader = StringUtils.join(this.acceptHeaders, ',');
}
WebResource resource = getResource(useToken);
resource = addParametersToResource(resource, parameters);
- return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
- .delete(ApiResponse.class);
+ return resource.type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(acceptHeader)
+ .delete(ApiResponse.class);
}
/**
- * Post an entity to a collection
- * @param payload
- * @return
+ * Post an entity to a collection.
*
* app.collection("users").post(entity);
* POST /users {"color","red"}
- *
*/
public Entity post(Entity payload){
+
String acceptHeader = MediaType.APPLICATION_JSON;
if (this.acceptHeaders.size() > 0) {
acceptHeader = StringUtils.join(this.acceptHeaders, ',');
}
- ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
- .post(ApiResponse.class, payload);
+
+ // use string type so we can log actual response from server
+ String responseString = getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(acceptHeader)
+ .post(String.class, payload);
+
+ logger.debug("Response from post: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
return new Entity(response);
}
- public Entity post(){
+ public Entity post() {
+
String acceptHeader = MediaType.APPLICATION_JSON;
+
if (this.acceptHeaders.size() > 0) {
acceptHeader = StringUtils.join(this.acceptHeaders, ',');
}
- ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
- .post(ApiResponse.class);
+
+ // use string type so we can log actual response from server
+ String responseString = getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(acceptHeader)
+ .post(String.class);
+
+ logger.debug("Response from post: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
return new Entity(response);
}
- public ApiResponse post(List<Entity> entityList){
+ public ApiResponse post(List<Entity> entityList) {
+
String acceptHeader = MediaType.APPLICATION_JSON;
+
if (this.acceptHeaders.size() > 0) {
acceptHeader = StringUtils.join(this.acceptHeaders, ',');
}
- ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
- .post(ApiResponse.class,entityList);
+
+ // use string type so we can log actual response from server
+ String responseString = getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(acceptHeader)
+ .post(String.class, entityList );
+
+ logger.debug("Response from post: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
return response;
}
@@ -243,19 +310,31 @@ public class CollectionEndpoint extends NamedResource {
return put(parameters, true, entity);
}
- public ApiResponse put(final QueryParameters parameters, final boolean useToken, Entity entity){
+ public ApiResponse put(final QueryParameters parameters, final boolean useToken, Entity entity) {
+
String acceptHeader = MediaType.APPLICATION_JSON;
if (this.acceptHeaders.size() > 0) {
acceptHeader = StringUtils.join(this.acceptHeaders, ',');
}
+
WebResource resource = getResource(useToken);
addParametersToResource(getResource(), parameters);
- return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
- .put(ApiResponse.class, entity);
- }
-
+ // use string type so we can log actual response from server
+ String responseString = resource.type(MediaType.APPLICATION_JSON_TYPE)
+ .accept(acceptHeader)
+ .post(String.class, entity);
+ logger.debug("Response from put: " + responseString);
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+ return response;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
index 839f2cd..0537d99 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
import javax.ws.rs.core.MediaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
@@ -30,13 +31,19 @@ import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.representation.Form;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.io.StringReader;
-//TODO: add error checking to each of the rest calls.
+
+//TODO: add error checking to each of the REST calls.
/**
* Manages the Management/ORG endpoint.
*/
public class OrgResource extends NamedResource {
+ private static final Logger logger = LoggerFactory.getLogger(OrgResource.class);
public OrgResource( final ClientContext context, final UrlResource parent ) {
super( "orgs", context, parent );
@@ -49,14 +56,14 @@ public class OrgResource extends NamedResource {
/**
* This post is for the POST params case, where the entire call is made using queryParameters
- * @return
*/
public Organization post(Form form){
- //Seems like an apiresponse can't handle what gets returned from the from urlended media type
- ApiResponse response = getResource().type( MediaType.APPLICATION_FORM_URLENCODED )
- .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class, form );
+ // Seems like an apiresponse can't handle what gets returned from the from urlended media type
+ ApiResponse response = getResource().type( MediaType.APPLICATION_FORM_URLENCODED )
+ .accept(MediaType.APPLICATION_JSON)
+ .post(ApiResponse.class, form);
Organization organization = new Organization(response);
organization.setOwner( response );
@@ -65,24 +72,57 @@ public class OrgResource extends NamedResource {
/**
* This post is for the POST params case, where the entire call is made using queryParameters
- * @return
*/
public Organization post(QueryParameters parameters){
- //Seems like an apiresponse can't handle what gets returned from the from urlended media type
+
+ // Seems like an ApiResponse can't handle what gets returned from the from URL encoded media type
WebResource resource = addParametersToResource( getResource(), parameters);
- ApiResponse response = resource.type( MediaType.APPLICATION_FORM_URLENCODED )
- .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class );
+// ApiResponse response = resource.type( MediaType.APPLICATION_FORM_URLENCODED )
+// .accept(MediaType.APPLICATION_JSON)
+// .post(ApiResponse.class);
+ // use string type so we can log actual response from server
+ String responseString = resource.type(MediaType.APPLICATION_JSON_TYPE)
+ .accept(MediaType.APPLICATION_JSON)
+ .post(String.class);
+
+ logger.debug("Response from post: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
Organization org = new Organization(response);
org.setOwner( response );
+
return org;
}
public Organization post(Organization organization){
- ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
- .post( ApiResponse.class,organization );
+
+// ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+// .accept(MediaType.APPLICATION_JSON)
+// .post(ApiResponse.class, organization);
+
+ // use string type so we can log actual response from server
+ String responseString = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(MediaType.APPLICATION_JSON)
+ .post(String.class, organization);
+
+ logger.debug("Response from post: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
Organization org = new Organization(response);
org.setOwner( response );
@@ -91,8 +131,25 @@ public class OrgResource extends NamedResource {
}
public Organization put(Organization organization){
- ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
- .put(ApiResponse.class, organization);
+
+// ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+// .accept(MediaType.APPLICATION_JSON)
+// .put(ApiResponse.class, organization);
+
+ // use string type so we can log actual response from server
+ String responseString = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(MediaType.APPLICATION_JSON)
+ .put(String.class, organization);
+
+ logger.debug("Response from put: " + responseString);
+
+ ObjectMapper mapper = new ObjectMapper();
+ ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
Organization org = new Organization(response);
org.setOwner( response );
@@ -106,8 +163,9 @@ public class OrgResource extends NamedResource {
}
public void delete(){
- ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
- .delete(ApiResponse.class);
+ ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(MediaType.APPLICATION_JSON)
+ .delete(ApiResponse.class);
}
public CredentialsResource credentials(){
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f29e3e99/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
index b616be8..e3a147c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
@@ -1,6 +1,3 @@
-/**
- * Created by ApigeeCorporation on 12/4/14.
- */
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,10 +15,8 @@
* limitations under the License.
*/
-
package org.apache.usergrid.rest.test.resource2point0.model;
-
import java.io.Serializable;
import java.util.*;
@@ -35,10 +30,9 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
/**
- * Contains a model that can be deconstructed from the api response. This is a base level value that contains the bare
- * minumum of what other classes use. Such as . users or groups.
+ * Contains a model that can be deconstructed from the api response.
+ * This is a base level value that contains the bare minimum of what other classes use, such as users or groups.
*/
-
public class Entity implements Serializable, Map<String,Object> {