You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/07/15 19:28:23 UTC
[6/8] incubator-usergrid git commit: remove old test framework
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
deleted file mode 100644
index 0f49dcc..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/GroupsCollection.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.test.resource.app;
-
-
-import java.util.Map;
-import java.util.UUID;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.Me;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.utils.MapUtils;
-
-
-/** @author rockerston */
-public class GroupsCollection extends CollectionResource {
-
-
- public GroupsCollection( NamedResource parent ) {
- super( "groups", parent );
- }
-
-
- public Group group( String username ) {
- return new Group( username, this );
- }
-
-
- public Group group( UUID id ) {
- return new Group( id, this );
- }
-
-
- /** Create the group */
- public JsonNode create( String path, String title ) throws IOException {
- Map<String, String> data =
- MapUtils.hashMap( "path", path ).map( "title", title );
-
- JsonNode response = this.postInternal( data );
-
- return getEntity( response, 0 );
- }
-
-
-
-
- public Me me() {
- return new Me( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java
deleted file mode 100644
index b60ef56..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/Role.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.test.resource.app;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.rest.test.resource.EntityResource;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.rest.test.resource.app.queue.DevicesCollection;
-
-
-/**
- * A resource for testing queues
- *
- * @author rockerston
- */
-public class Role
- extends EntityResource {
-
- /**
- * @param entityId
- * @param parent
- */
- public Role( UUID entityId, NamedResource parent ) {
- super( entityId, parent );
- }
-
-
- /**
- * @param entityName
- * @param parent
- */
- public Role( String entityName, NamedResource parent ) {
- super( entityName, parent );
- }
-
-
- public DevicesCollection devices() {
- return new DevicesCollection( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java
deleted file mode 100644
index dd3e737..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/RolesCollection.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.test.resource.app;
-
-
-import java.util.Map;
-import java.util.UUID;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.Me;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.utils.MapUtils;
-
-
-/** @author rockerston */
-public class RolesCollection extends CollectionResource {
-
-
- public RolesCollection( NamedResource parent ) {
- super( "roles", parent );
- }
-
-
- public Role role( String name ) {
- return new Role( name, this );
- }
-
-
- public Role role( UUID id ) {
- return new Role( id, this );
- }
-
-
- /** Create the role */
- public JsonNode create( String name, String title ) throws IOException {
- Map<String, String> data =
- MapUtils.hashMap( "name", name ).map( "title", title );
-
- JsonNode response = this.postInternal( data );
-
- return getEntity( response, 0 );
- }
-
-
- public Me me() {
- return new Me( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/User.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/User.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/User.java
deleted file mode 100644
index 0b261ee..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/User.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.test.resource.app;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.rest.test.resource.EntityResource;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.rest.test.resource.app.queue.DevicesCollection;
-
-
-/**
- * A resource for testing queues
- *
- * @author tnine
- */
-public class User extends EntityResource {
-
- /**
- * @param entityId
- * @param parent
- */
- public User( UUID entityId, NamedResource parent ) {
- super( entityId, parent );
- }
-
-
- /**
- * @param entityName
- * @param parent
- */
- public User( String entityName, NamedResource parent ) {
- super( entityName, parent );
- }
-
-
- public DevicesCollection devices() {
- return new DevicesCollection( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
deleted file mode 100644
index d7b4293..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/UsersCollection.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.test.resource.app;
-
-
-import java.util.Map;
-import java.util.UUID;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.Me;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.utils.MapUtils;
-
-
-/** @author tnine */
-public class UsersCollection extends Collection {
-
-
- public UsersCollection( NamedResource parent ) {
- super( "users", parent );
- }
-
-
- public User user( String username ) {
- return new User( username, this );
- }
-
-
- public User user( UUID id ) {
- return new User( id, this );
- }
-
-
- /** Create the user */
- public JsonNode post( String username, String email, String password ) throws IOException {
- Map<String, String> data =
- MapUtils.hashMap( "username", username ).map( "email", email ).map( "password", password );
-
- JsonNode response = this.postInternal( data );
-
- return getEntity( response, 0 );
- }
-
- /** Create the user */
- public JsonNode post( String username, String email, String password, Map entityData ) throws IOException {
- Map<String, String> data =
- MapUtils.hashMap( "username", username ).map( "email", email ).map( "password", password );
- data.putAll(entityData);
-
- JsonNode response = this.postInternal( data );
-
- return getEntity( response, 0 );
- }
-
-
- /** Create the user */
- //TODO: delete create method once rest calls are implemented
- public JsonNode create( String username, String email, String password ) throws IOException {
- Map<String, String> data =
- MapUtils.hashMap( "username", username ).map( "email", email ).map( "password", password );
-
- JsonNode response = this.postInternal( data );
-
- return getEntity( response, 0 );
- }
-
- public Me me() {
- return new Me( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/DevicesCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/DevicesCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/DevicesCollection.java
deleted file mode 100644
index b02ab3e..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/DevicesCollection.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.test.resource.app.queue;
-
-
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.rest.test.resource.ValueResource;
-import org.apache.usergrid.rest.test.resource.app.Device;
-
-
-/** @author tnine */
-public class DevicesCollection extends ValueResource {
-
-
- public DevicesCollection( NamedResource parent ) {
- super( "devices", parent );
- }
-
-
- public Device device( String deviceName ) {
- return new Device( deviceName, this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Queue.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Queue.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Queue.java
deleted file mode 100644
index aa2c060..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Queue.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * 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.test.resource.app.queue;
-
-
-import java.util.List;
-import java.util.Map;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-
-import com.sun.jersey.api.client.WebResource;
-import java.io.IOException;
-
-
-/**
- * A resource for testing queues
- *
- * @author tnine
- */
-public class Queue extends CollectionResource {
-
- private String clientId;
- private int limit = 0;
- private long timeout = 0;
- private String position;
- private String last;
- private String[] filters = { };
-
-
- /**
- *
- */
- public Queue( String queueName, NamedResource parent ) {
- super( queueName, parent );
- }
-
-
- /** Set the client id with the string */
- public Queue withClientId( String clientId ) {
- this.clientId = clientId;
- return this;
- }
-
-
- /** Set this with the next page size */
- public Queue withLimit( int limit ) {
- this.limit = limit;
- return this;
- }
-
-
- public Queue withPosition( String position ) {
- this.position = position;
- return this;
- }
-
-
- public Queue withLast( String last ) {
- this.last = last;
- return this;
- }
-
-
- public Queue withTimeout( long timeout ) {
- this.timeout = timeout;
- return this;
- }
-
-
- public Queue withFilters( String... filters ) {
- this.filters = filters;
- return this;
- }
-
-
- /**
- * @return
- */
- public SubscribersCollection subscribers() {
- return new SubscribersCollection( this );
- }
-
-
- /**
- * @return
- */
- public TransactionsCollection transactions() {
- return new TransactionsCollection( this );
- }
-
-
- public JsonNode post( Map<String, ?> payload ) throws IOException {
- JsonNode node = super.postInternal( payload );
- return node;
- }
-
-
- /**
- *
- * @param payload
- * @return
- */
- public JsonNode post( Map<String, ?>[] payload ) throws IOException {
- JsonNode node = super.postInternal( payload );
- return node;
- }
-
-
- /** Get entities in this collection. Cursor is optional */
- public JsonNode get() {
- try {
- return mapper.readTree( jsonMedia( withQueueParams( withToken( resource() ) ) ).get( String.class ));
- } catch (IOException ex) {
- throw new RuntimeException("Cannot parse JSON data", ex);
- }
- }
-
-
- /** post to the entity set */
- public JsonNode delete() {
- try {
- return mapper.readTree( jsonMedia( withToken( resource() ) ).delete( String.class ));
- } catch (IOException ex) {
- throw new RuntimeException("Cannot parse JSON data", ex);
- }
- }
-
-
- /** Set the queue client ID if set */
- private WebResource withQueueParams( WebResource resource ) {
- if ( clientId != null ) {
- resource = resource.queryParam( "consumer", clientId );
- }
- if ( position != null ) {
- resource = resource.queryParam( "pos", position );
- }
- if ( last != null ) {
- resource = resource.queryParam( "last", last );
- }
-
- if ( limit > 0 ) {
- resource = resource.queryParam( "limit", String.valueOf( limit ) );
- }
-
- if ( timeout > 0 ) {
- resource = resource.queryParam( "timeout", String.valueOf( timeout ) );
- }
-
- for ( String filter : filters ) {
- resource = resource.queryParam( "filter", filter );
- }
-
- return resource;
- }
-
-
- /** Get the next entry in the queue. Returns null if one doesn't exist */
- public JsonNode getNextEntry() {
- List<JsonNode> messages = getNodesAsList( "messages", get() );
-
- return messages.size() == 1 ? messages.get( 0 ) : null;
- }
-
-
- /** Get the json response of the messages nodes */
- public List<JsonNode> getNextPage() {
- JsonNode response = get();
-
- JsonNode last = response.get( "last" );
-
- if ( last != null ) {
- this.last = last.asText();
- }
-
- return getNodesAsList( "messages", response );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/QueuesCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/QueuesCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/QueuesCollection.java
deleted file mode 100644
index 3c6704d..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/QueuesCollection.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.test.resource.app.queue;
-
-
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.rest.test.resource.ValueResource;
-
-
-/** @author tnine */
-public class QueuesCollection extends ValueResource {
-
-
- public QueuesCollection( NamedResource parent ) {
- super( "queues", parent );
- }
-
-
- public Queue queue( String queueName ) {
- return new Queue( queueName, this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/SubscribersCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/SubscribersCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/SubscribersCollection.java
deleted file mode 100644
index 029ee225..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/SubscribersCollection.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.test.resource.app.queue;
-
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-
-
-/** @author tnine */
-public class SubscribersCollection extends CollectionResource {
-
- private String queueName;
-
-
- public SubscribersCollection( NamedResource parent ) {
- super( "subscribers", parent );
- }
-
-
- public JsonNode subscribe( String queueName ) throws IOException {
- this.queueName = queueName;
- return mapper.readTree( jsonMedia( withToken( resource() ) ).put( String.class ));
- }
-
-
- public JsonNode unsubscribe( String queueName ) throws IOException {
- this.queueName = queueName;
- return mapper.readTree( jsonMedia( withToken( resource() ) ).delete( String.class ));
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.rest.test.resource.ValueResource#addToUrl(java.lang.StringBuilder
- * )
- */
- @Override
- public void addToUrl( StringBuilder buffer ) {
- super.addToUrl( buffer );
- buffer.append( SLASH ).append( queueName );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Transaction.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Transaction.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Transaction.java
deleted file mode 100644
index 20d104b..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/Transaction.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.test.resource.app.queue;
-
-
-import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.usergrid.rest.test.resource.CollectionResource;
-import org.apache.usergrid.rest.test.resource.NamedResource;
-
-import com.sun.jersey.api.client.WebResource;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-
-/**
- * A resource for testing queues
- *
- * @author tnine
- */
-public class Transaction extends CollectionResource {
-
- private String clientId;
- private long timeout = 0;
-
-
- /**
- *
- */
- public Transaction( String transactionName, NamedResource parent ) {
- super( transactionName, parent );
- }
-
-
- /** Set the client id with the string */
- public Transaction withClientId( String clientId ) {
- this.clientId = clientId;
- return this;
- }
-
-
- /** post to the entity set */
- public JsonNode delete() {
- try {
- return mapper.readTree( jsonMedia( withParams( withToken( resource() ) ) ).delete( String.class ));
- } catch (IOException ex) {
- throw new RuntimeException("Cannot parse JSON data", ex);
- }
- }
-
-
- /** Renew this transaction to the set timeout */
- public JsonNode renew( long timeout ) throws IOException {
- this.timeout = timeout;
- return super.putInternal( null );
- }
-
-
- /** Set the queue client ID if set */
- protected WebResource withParams( WebResource resource ) {
- if ( clientId != null ) {
- resource = resource.queryParam( "consumer", clientId );
- }
- if ( timeout > 0 ) {
- resource = resource.queryParam( "timeout", String.valueOf( timeout ) );
- }
-
- return resource;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/TransactionsCollection.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/TransactionsCollection.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/TransactionsCollection.java
deleted file mode 100644
index 6aa4bbf..0000000
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/app/queue/TransactionsCollection.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.test.resource.app.queue;
-
-
-import org.apache.usergrid.rest.test.resource.NamedResource;
-import org.apache.usergrid.rest.test.resource.ValueResource;
-
-
-/** @author tnine */
-public class TransactionsCollection extends ValueResource {
-
-
- public TransactionsCollection( NamedResource parent ) {
- super( "transactions", parent );
- }
-
-
- public Transaction transaction( String id ) {
- return new Transaction( id, this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/ApplicationsResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/ApplicationsResource.java
new file mode 100644
index 0000000..78f906f
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/ApplicationsResource.java
@@ -0,0 +1,73 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import org.apache.usergrid.rest.test.resource.endpoints.mgmt.CredentialsResource;
+import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+
+
+/**
+ * Holds the information required for building and chaining application objects to collections.
+ * app("applications").post();
+ */
+public class ApplicationsResource extends NamedResource {
+
+
+ public ApplicationsResource( final String name, final ClientContext context, final UrlResource parent ) {
+ super( name, context, parent );
+ }
+
+
+ public CollectionEndpoint collection(String name) {
+ return new CollectionEndpoint(name,context,this);
+ }
+
+
+ public TokenResource token() {
+ return new TokenResource( context, this );
+ }
+
+
+ /**
+ * Delete this application.
+ */
+ public ApiResponse delete() {
+ return getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON )
+ .delete( ApiResponse.class );
+ }
+
+ public CredentialsResource credentials(){
+ return new CredentialsResource( context ,this );
+ }
+
+
+ /**
+ * Used to get an application entity.
+ */
+ public ApiResponse get() {
+ return getResource(true)
+ .type(MediaType.APPLICATION_JSON_TYPE)
+ .accept( MediaType.APPLICATION_JSON )
+ .get(ApiResponse.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
new file mode 100644
index 0000000..c3190dc
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
@@ -0,0 +1,355 @@
+/*
+ * 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.test.resource.endpoints;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.usergrid.rest.test.resource.model.*;
+import org.apache.usergrid.rest.test.resource.model.Collection;
+import org.apache.usergrid.rest.test.resource.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.*;
+
+
+/**
+ * //myorg/myapp/mycollection
+ */
+public class CollectionEndpoint extends NamedResource {
+ private static final Logger logger = LoggerFactory.getLogger(CollectionEndpoint.class);
+
+ protected List<String> acceptHeaders = new ArrayList<String> ();
+ private String matrix;
+
+ public CollectionEndpoint(String name, ClientContext context, UrlResource parent) {
+ super(name, context, parent);
+ }
+
+ public EntityEndpoint uniqueID(final String identifier){
+ return new EntityEndpoint(identifier, context, this);
+ }
+
+ public EntityEndpoint entity(final org.apache.usergrid.rest.test.resource.model.Entity entity){
+ String identifier = (String) entity.get("uuid");
+ return entity(identifier);
+ }
+
+ public EntityEndpoint entity(final UUID identifier ){
+ return entity(identifier.toString());
+ }
+
+
+ public EntityEndpoint entity(final String identifier ){
+ return uniqueID(identifier);
+ }
+
+ public CollectionEndpoint withAcceptHeader(final String acceptHeader) {
+ this.acceptHeaders.add(acceptHeader);
+ return this;
+ }
+
+ /**
+ * <pre>
+ * app.collection("users").uniqueID("fred").connection("following").collection("users").uniqueID("barney").post();
+ * POST /users/fred/following/users/barney?token=<token>
+ *
+ * app.collection("users").uniqueID("fred").connection().collection("users").uniqueID("barney").post();
+ * POST /users/fred/groups/theitcrowd?token=<token>
+ * </pre>
+ */
+ public CollectionEndpoint collection(final String identifier){
+ return new CollectionEndpoint(identifier, context, this);
+ }
+
+
+
+ /**
+ * Get a list of entities.
+ *
+ * <pre>
+ * //with token
+ * app.collection("users").get(); //return entity
+ * GET /users?token=<token>
+ *
+ * //with query and token
+ * collection = app.collection("users").get(queryparam); //return collection (list of entities)
+ * GET /users?ql=select * where created > 0&token=<token>
+ *
+ * //with query and no token
+ * collection = app.collection("users").get(queryparam, false); //return collection (list of entities)
+ * GET /users?ql=select * where created > 0
+ *
+ * //with no query and no token
+ * collection = app.collection("users").get(null, false); //return collection (list of entities)
+ * GET /users
+ *
+ * collection = app.collection("users").get(collection);
+ * <pre>
+ */
+ public Collection get(){
+ return new Collection( get(org.apache.usergrid.rest.test.resource.model.ApiResponse.class,null,true));
+ }
+
+ public Collection get( final org.apache.usergrid.rest.test.resource.model.QueryParameters parameters ){
+ return get(parameters, true);
+ }
+
+ public Collection get(final org.apache.usergrid.rest.test.resource.model.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);
+
+ // 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();
+ org.apache.usergrid.rest.test.resource.model.ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
+ return new Collection(response);
+ }
+
+ /**
+ * Gets the next page using only default settings with the passed in collection.
+ *
+ * <pre>
+ * Collection usersCollection = app.collection("users").get();
+ * //iterate through the collection
+ * while(usersCollection.hasNext()){
+ * Entity bob = usersCollection.next();
+ * assert("blah",bob.get("words"));
+ * }
+ * usersCollection = app.collections("users").getNextPage(usersCollection.cursor);
+ * </pre>
+ */
+ //TODO: add queryParameters here
+ public Collection getNextPage(Collection collection, org.apache.usergrid.rest.test.resource.model.QueryParameters passedParameters ,final boolean useToken) {
+ String acceptHeader = MediaType.APPLICATION_JSON;
+ if (this.acceptHeaders.size() > 0) {
+ acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+ }
+
+ WebResource resource = getResource(useToken);
+ org.apache.usergrid.rest.test.resource.model.QueryParameters queryParameters = passedParameters;
+ if( queryParameters == null){
+ queryParameters = new org.apache.usergrid.rest.test.resource.model.QueryParameters();
+ }
+
+ queryParameters.setCursor(collection.getCursor());
+ resource = addParametersToResource(resource, queryParameters);
+
+ org.apache.usergrid.rest.test.resource.model.ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(acceptHeader)
+ .get(org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+
+ return new Collection(response);
+ }
+
+ /**
+ * DELETE on a collection endpoint with query (use DELETE on entity for single entity delete).
+ *
+ * <pre>
+ * //with token
+ * app.collection("users").delete(parameters);
+ * DELETE /users?ql=select * where created > 0&token=<token>
+ *
+ * //without token
+ * app.collection("users").delete(parameters, false);
+ * DELETE /users?ql=select * where created > 0
+ *
+ * app.collection("users").delete(null, false);
+ * DELETE /users
+ * </pre>
+ */
+ public org.apache.usergrid.rest.test.resource.model.ApiResponse delete( final org.apache.usergrid.rest.test.resource.model.QueryParameters parameters ){
+ return delete(parameters, true);
+ }
+
+ public org.apache.usergrid.rest.test.resource.model.ApiResponse delete(final org.apache.usergrid.rest.test.resource.model.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(org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+ }
+
+ /**
+ * Post an entity to a collection.
+ *
+ * <pre>
+ * app.collection("users").post(entity);
+ * POST /users {"color","red"}
+ * </pre>
+ */
+ public org.apache.usergrid.rest.test.resource.model.Entity post(org.apache.usergrid.rest.test.resource.model.Entity payload){
+
+ String acceptHeader = MediaType.APPLICATION_JSON;
+ if (this.acceptHeaders.size() > 0) {
+ acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+ }
+
+ // 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();
+ org.apache.usergrid.rest.test.resource.model.ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
+ return new org.apache.usergrid.rest.test.resource.model.Entity(response);
+ }
+
+ public org.apache.usergrid.rest.test.resource.model.Entity post() {
+
+ String acceptHeader = MediaType.APPLICATION_JSON;
+
+ if (this.acceptHeaders.size() > 0) {
+ acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+ }
+
+ // 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();
+ org.apache.usergrid.rest.test.resource.model.ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
+ return new org.apache.usergrid.rest.test.resource.model.Entity(response);
+ }
+
+ public org.apache.usergrid.rest.test.resource.model.ApiResponse post(List<org.apache.usergrid.rest.test.resource.model.Entity> entityList) {
+
+ String acceptHeader = MediaType.APPLICATION_JSON;
+
+ if (this.acceptHeaders.size() > 0) {
+ acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+ }
+
+ // 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();
+ org.apache.usergrid.rest.test.resource.model.ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
+ return response;
+ }
+
+ /**
+ * PUT a payload to a collection.
+ *
+ * <pre>
+ * app.collection("users").put(entity, param);
+ * PUT /users?ql=select * where created > 0&token=<token>
+ *
+ * app.collection("users").put(entity, false, param);
+ * PUT /users?ql=select * where created > 0
+ * </pre>
+ */
+ public org.apache.usergrid.rest.test.resource.model.ApiResponse put( final org.apache.usergrid.rest.test.resource.model.QueryParameters parameters, org.apache.usergrid.rest.test.resource.model.Entity entity ){
+ return put(parameters, true, entity);
+ }
+
+ public org.apache.usergrid.rest.test.resource.model.ApiResponse put(final org.apache.usergrid.rest.test.resource.model.QueryParameters parameters, final boolean useToken, org.apache.usergrid.rest.test.resource.model.Entity entity) {
+
+ String acceptHeader = MediaType.APPLICATION_JSON;
+ if (this.acceptHeaders.size() > 0) {
+ acceptHeader = StringUtils.join(this.acceptHeaders, ',');
+ }
+
+ WebResource resource = getResource(useToken);
+ addParametersToResource(getResource(), parameters);
+
+ // 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();
+ org.apache.usergrid.rest.test.resource.model.ApiResponse response;
+ try {
+ response = mapper.readValue( new StringReader(responseString), org.apache.usergrid.rest.test.resource.model.ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
+ return response;
+ }
+
+ public CollectionEndpoint matrix(org.apache.usergrid.rest.test.resource.model.QueryParameters parameters) {
+ this.matrix = getMatrixValue(parameters);
+ return this;
+ }
+
+ @Override
+ public String getMatrix(){
+ return matrix != null ? matrix : "";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/DatabaseResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/DatabaseResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/DatabaseResource.java
new file mode 100644
index 0000000..e1dcd9c
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/DatabaseResource.java
@@ -0,0 +1,39 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.usergrid.persistence.cassandra.Setup;
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+
+/**
+ * Contains methods pertaining to system/database/*
+ */
+public class DatabaseResource extends NamedResource {
+
+ public DatabaseResource( final ClientContext context, final UrlResource parent ) {
+ super( "database", context, parent );
+ }
+
+ public SetupResource setup(){
+ return new SetupResource (context, this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/EntityEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/EntityEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/EntityEndpoint.java
new file mode 100644
index 0000000..70b2c3a
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/EntityEndpoint.java
@@ -0,0 +1,174 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. 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. For additional information regarding
+ * * copyright in this work, please see the NOTICE file in the top level
+ * * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.rest.test.resource.endpoints;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.apache.usergrid.rest.test.resource.model.QueryParameters;
+import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+
+public class EntityEndpoint extends NamedResource {
+
+ public EntityEndpoint(String identifier, ClientContext context, UrlResource parent) {
+ super(identifier, context, parent);
+ }
+
+
+ /**
+ *
+ * GET a single entity
+ *
+ * @return Entity
+ *
+ *
+ * entity = app.collection("users").uniqueID("fred").get(); //return one entity
+ * GET /users/fred
+ *
+ * entity = app.collection("users").entity(entity).get(); //return one entity
+ * GET /users/username_in_entity_obj
+ *
+ */
+ public Entity get(){
+ return get(true);
+ }
+
+ public Entity get(final boolean useToken){
+ return get(useToken,null);
+ }
+ public Entity get(final Token token){
+ return get(true,token);
+ }
+
+ public Entity get(final boolean useToken, final Token token){
+ WebResource resource = getResource(useToken,token);
+ ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ .get(ApiResponse.class);
+
+ return new Entity(response);
+ }
+
+ //For testing purposes only
+ public Entity get(QueryParameters parameters, final boolean useToken){
+ WebResource resource = getResource(useToken);
+ resource = addParametersToResource(resource, parameters);
+ ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ .get(ApiResponse.class);
+
+ return new Entity(response);
+ }
+
+
+ /**
+ * DELETE a single entity
+ *
+ *
+ * app.collection("users").entity(entity).delete();
+ * DELETE /users/username?token=<token>
+ *
+ * app.collection("users").entity(entity).delete(false);
+ * DELETE /users/uuid
+ */
+ public ApiResponse delete(){
+ return delete(true);
+ }
+
+ public ApiResponse delete(final boolean useToken){
+ WebResource resource = getResource(useToken);
+ return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ .delete(ApiResponse.class);
+ }
+
+ /**
+ * Put the entity to the collection
+ * @param entity
+ * @return
+ *
+ * app.collection("users").entity(entity).put(entity);
+ * PUT /users/uuid {}
+ *
+ * app.collection("users").uniqueID("fred").put(entity);
+ * PUT /users/fred {"color":"red"}
+ */
+ public Entity put(Entity entity){
+ ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ .put(ApiResponse.class, entity);
+ return new Entity(response);
+ }
+
+
+ /**
+ * POST with no payload
+ *
+ * app.collection("users").uniqueID("fred").connection("following").collection("users").uniqueID("barney").post();
+ * POST /users/fred/following/users/barney?token=<token>
+ *
+ * app.collection("users").uniqueID("fred").connection("following").collection("users").uniqueID("barney").post(false);
+ * POST /users/fred/following/users/barney
+ *
+ */
+ public Entity post(){
+ return post(true);
+ }
+
+ public Entity post(final boolean useToken){
+ WebResource resource = getResource(useToken);
+ ApiResponse response = resource.type(MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ .post(ApiResponse.class);
+
+ return new Entity(response);
+ }
+
+ /**
+ *
+ * app.collection("users").uniqueID("fred").connection("following).get();
+ * GET /users/fred/following
+ *
+ * app.collection("users").uniqueID("fred").connection("following").collection("users").uniqueID("barney").post();
+ * POST /users/fred/following/users/barney?token=<token>
+ *
+ * app.collection("users").uniqueID("fred").connection().collection("users").uniqueID("barney").post();
+ * POST /users/fred/following/users/barney?token=<token>
+ *
+ */
+ public CollectionEndpoint connection(final String connection,final String collection) {
+ return new CollectionEndpoint(connection+"/"+collection, context, this);
+ }
+ public CollectionEndpoint connection(final String connection) {
+ return new CollectionEndpoint(connection, context, this);
+
+ }
+ public CollectionEndpoint collection(final String identifier) {
+ return new CollectionEndpoint(identifier, context, this);
+ }
+ public CollectionEndpoint connection(){
+ return new CollectionEndpoint("", context, this);
+ }
+
+
+ public CollectionEndpoint activities() {
+ return collection("activities");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
new file mode 100644
index 0000000..2258312
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/NamedResource.java
@@ -0,0 +1,358 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import com.sun.jersey.api.client.GenericType;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import com.sun.jersey.api.representation.Form;
+import com.sun.jersey.multipart.FormDataMultiPart;
+import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.apache.usergrid.rest.test.resource.model.QueryParameters;
+import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * Base class that is extended by named endpoints.
+ * The NamedResource stores the parent of the class, the context in which the class operates and then Name of this resource
+ */
+public class NamedResource implements UrlResource {
+
+ public static String SLASH ="/" ;
+
+ protected final String name;
+ protected final ClientContext context;
+ /* Stores the path of the parent that called it.
+ i.e If we had a ApplicationResource ( an instance of a namedResource ) this would contain the OrganizationResource.
+ */
+ protected final UrlResource parent;
+
+
+ public NamedResource( final String name, final ClientContext context, final UrlResource parent ) {
+ this.name = name;
+ this.context = context;
+ this.parent = parent;
+ }
+
+
+ @Override
+ public String getPath() {
+ return name + getMatrix();
+ }
+
+ @Override
+ public WebResource getResource() {
+ return getResource(false);
+ }
+ public WebResource getResource(boolean useToken) {
+ return getResource(useToken,null);
+ }
+ public WebResource getResource(boolean useToken,Token token) {
+ WebResource resource = parent.getResource().path( getPath() );
+ token = token !=null ? token : this.context.getToken();
+ //error checking
+ if (token == null) {
+ return resource;
+ }
+ return useToken ? resource.queryParam("access_token",token.getAccessToken()) : resource;
+ }
+
+ protected WebResource addParametersToResource(WebResource resource, final QueryParameters parameters){
+
+ if(parameters == null){
+ return resource;
+ }
+ if ( parameters.getQuery() != null ) {
+ resource = resource.queryParam( "ql", parameters.getQuery() );
+ }
+
+ if ( parameters.getCursor() != null ) {
+ resource = resource.queryParam( "cursor", parameters.getCursor() );
+ }
+
+ if ( parameters.getStart() != null ) {
+ resource = resource.queryParam("start", parameters.getStart().toString());
+ }
+
+ if ( parameters.getLimit() != null ) {
+ resource = resource.queryParam("limit", parameters.getLimit().toString());
+ }
+ //We can also post the params as queries
+ if ( parameters.getFormPostData().size() > 0){
+ Map<String,String> formData = parameters.getFormPostData();
+ Set<String> keySet = formData.keySet();
+ Iterator<String> keyIterator = keySet.iterator();
+
+
+ while(keyIterator.hasNext()){
+ String key = keyIterator.next();
+ String value = formData.get( key );
+ resource = resource.queryParam( key, value );
+ }
+ }
+ return resource;
+ }
+
+ protected String getMatrixValue(final QueryParameters parameters) {
+
+ StringBuilder sb = new StringBuilder();
+ if (parameters == null) {
+ return null;
+ }
+ if (parameters.getQuery() != null) {
+ sb.append(";");
+ sb.append("ql").append("=").append(parameters.getQuery());
+ }
+
+ if (parameters.getCursor() != null) {
+ sb.append(";");
+ sb.append("cursor").append("=").append(parameters.getCursor());
+ }
+ if (parameters.getStart() != null) {
+ sb.append(";");
+ sb.append("start").append("=").append(parameters.getStart());
+ }
+ if (parameters.getLimit() != null) {
+ sb.append(";");
+ sb.append("limit").append("=").append(parameters.getLimit());
+ }
+ //We can also post the params as queries
+ if (parameters.getFormPostData().size() > 0) {
+ Map<String, String> formData = parameters.getFormPostData();
+ Set<String> keySet = formData.keySet();
+ Iterator<String> keyIterator = keySet.iterator();
+
+
+ while (keyIterator.hasNext()) {
+ if (sb.length() > 0)
+ sb.append(";");
+ String key = keyIterator.next();
+ String value = formData.get(key);
+ sb.append(key).append("=").append(value);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Need to refactor all instances of tokens to either be passed in or manually set during the test.
+ * There isn't any reason we would want a rest forwarding framework to set something on behave of the user.
+ * @param map
+ * @return
+ */
+ //For edge cases like Organizations and Tokens
+ public ApiResponse post(Map map) {
+ return post( true, ApiResponse.class, map, null, false );
+
+ }
+
+ //For edge cases like Organizations and Tokens
+ public ApiResponse post(boolean useToken, Map map, QueryParameters queryParameters) {
+ return post( useToken, ApiResponse.class, map, queryParameters, false );
+
+ }
+
+ /**
+ * Need to refactor all instances of tokens to either be passed in or manually set during the test.
+ * There isn't any reason we would want a rest forwarding framework to set something on behave of the user.
+ * @param type
+ * @param <T>
+ * @return
+ */
+ //For edge cases like Organizations and Tokens
+ public <T> T post(Class<T> type) {
+ return post(true,type,null,null,false);
+
+ }
+
+ /**
+ * Need to refactor all instances of tokens to either be passed in or manually set during the test.
+ * There isn't any reason we would want a rest forwarding framework to set something on behave of the user.
+ * @param type
+ * @param requestEntity
+ * @param <T>
+ * @return
+ */
+ //For edge cases like Organizations and Tokens
+ public <T> T post(Class<T> type, Entity requestEntity) {
+ return post(true,type,requestEntity,null,false);
+
+ }
+
+ /**
+ * Need to refactor all instances of tokens to either be passed in or manually set during the test.
+ * There isn't any reason we would want a rest forwarding framework to set something on behave of the user.
+ * @param type
+ * @param requestEntity
+ * @param <T>
+ * @return
+ */
+ //For edge cases like Organizations and Tokens
+ public <T> T post(Class<T> type, Map requestEntity) {
+ return post(true,type,requestEntity,null,false);
+
+ }
+
+ public <T> T post( boolean useToken, Class<T> type, Map requestEntity) {
+ return post(useToken, type, requestEntity, null, false);
+
+ }
+
+ /**
+ * Used to test POST using form payloads.
+ * @param type
+ * @param requestEntity
+ * @param <T>
+ * @return
+ */
+ public <T> T post(Class<T> type, Form requestEntity) {
+ GenericType<T> gt = new GenericType<>((Class) type);
+ return getResource()
+ .accept(MediaType.APPLICATION_JSON)
+ .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
+ .entity(requestEntity, MediaType.APPLICATION_FORM_URLENCODED_TYPE)
+ .post(gt.getRawClass());
+
+ }
+
+
+ //Used for empty posts
+ public <T> T post( boolean useToken, Class<T> type, Map entity, final QueryParameters queryParameters) {
+ WebResource resource = getResource(useToken);
+ resource = addParametersToResource(resource, queryParameters);
+ WebResource.Builder builder = resource
+ .type(MediaType.APPLICATION_JSON_TYPE)
+ .accept( MediaType.APPLICATION_JSON );
+
+ if(entity!=null){
+ builder.entity(entity);
+ }
+ GenericType<T> gt = new GenericType<>((Class) type);
+ return builder
+ .post(gt.getRawClass());
+
+ }
+
+ //Used for empty posts
+ public <T> T post( boolean useToken, Class<T> type, Map entity, final QueryParameters queryParameters, boolean useBasicAuthentication ) {
+ WebResource resource = getResource(useToken);
+ resource = addParametersToResource(resource, queryParameters);
+ WebResource.Builder builder = resource
+ .type(MediaType.APPLICATION_JSON_TYPE)
+ .accept( MediaType.APPLICATION_JSON );
+
+ if(entity!=null){
+ builder.entity(entity);
+ }
+
+ if(useBasicAuthentication){
+ //added httpBasicauth filter to all setup calls because they all do verification this way.
+ HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( "superuser","superpassword" );
+ resource.addFilter( httpBasicAuthFilter );
+ }
+
+ GenericType<T> gt = new GenericType<>((Class) type);
+ return builder.post( gt.getRawClass() );
+
+ }
+
+ //For edge cases like Organizations and Tokens without any payload
+ public <T> T get(Class<T> type) {
+ return get(type,null,true);
+
+ }
+
+ //For edge cases like Organizations and Tokens without any payload
+ public <T> T get(Class<T> type, boolean useToken) {
+ return get( type, null, useToken );
+ }
+
+
+
+ public <T> T get(Class<T> type,QueryParameters queryParameters) {
+ return get( type, queryParameters, true );
+ }
+
+ public <T> T get(Class<T> type,QueryParameters queryParameters, boolean useToken) {
+ WebResource resource = getResource(useToken);
+ if(queryParameters!=null) {
+ resource = addParametersToResource(resource, queryParameters);
+ }
+ GenericType<T> gt = new GenericType<>((Class) type);
+ return resource.type(MediaType.APPLICATION_JSON_TYPE)
+ .accept( MediaType.APPLICATION_JSON )
+ .get( gt.getRawClass() );
+
+ }
+
+ public String getMatrix() {
+ return "";
+ }
+
+ public ApiResponse post( boolean useToken, FormDataMultiPart multiPartForm ) {
+ WebResource resource = getResource( useToken );
+ return resource.type( MediaType.MULTIPART_FORM_DATA_TYPE ).post( ApiResponse.class, multiPartForm );
+ }
+
+ public ApiResponse post( FormDataMultiPart multiPartForm ) {
+ return post( true, multiPartForm );
+ }
+
+ public ApiResponse put( boolean useToken, byte[] data, MediaType type ) {
+ WebResource resource = getResource(useToken);
+ return resource.type( type ).put( ApiResponse.class, data );
+ }
+
+ public ApiResponse put( byte[] data, MediaType type ) {
+ return put( true, data, type );
+ }
+
+ public ApiResponse put( boolean useToken, FormDataMultiPart multiPartForm ) {
+ WebResource resource = getResource(useToken);
+ return resource.type( MediaType.MULTIPART_FORM_DATA_TYPE ).put( ApiResponse.class, multiPartForm );
+ }
+
+ public ApiResponse put( FormDataMultiPart multiPartForm ) {
+ return put( true, multiPartForm );
+ }
+
+ public InputStream getAssetAsStream( boolean useToken ) {
+ WebResource resource = getResource(useToken);
+ return resource.accept( MediaType.APPLICATION_OCTET_STREAM_TYPE ).get( InputStream.class );
+ }
+
+ public InputStream getAssetAsStream() {
+ return getAssetAsStream( true );
+ }
+
+ public ApiResponse delete( ) {
+ return delete(true);
+ }
+
+ public ApiResponse delete( boolean useToken ) {
+ return getResource(useToken).delete( ApiResponse.class );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/OrganizationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/OrganizationResource.java
new file mode 100644
index 0000000..4338677
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/OrganizationResource.java
@@ -0,0 +1,49 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import java.util.Map;
+import java.util.UUID;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.model.Organization;
+import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+
+/**
+ * Holds the information required for building and chaining organization objects to applications.
+ * Should also contain the GET,PUT,POST,DELETE methods of functioning in here.
+ */
+public class OrganizationResource extends NamedResource {
+
+
+ public OrganizationResource( final String name, final ClientContext context, final UrlResource parent ) {
+ super( name, context, parent );
+ }
+
+ public ApplicationsResource app(final String name){
+ return new ApplicationsResource( name, context ,this );
+ }
+
+ public Organization get(){
+ throw new UnsupportedOperationException("service doesn't exist");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
new file mode 100644
index 0000000..8537251
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/RootResource.java
@@ -0,0 +1,86 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import org.apache.usergrid.rest.test.resource.endpoints.mgmt.ManagementResource;
+import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import com.sun.jersey.api.client.WebResource;
+
+
+/**
+ * Contains the root element for classes. Contains the client context that holds a token for the management calls,
+ * and also contains the serverUrl so we know what endpoint we need to hit.
+ * Contains the two top level functions that can be called from the "root" ( actual root is the serverUrl )
+ * 1.) Is the management resource i.e /management/org/blah/...
+ * 2.) Is the organization resource i.e /<orgname>/<appname>...
+ * This is where top level elements are contained and managemend
+ */
+//TODO: check to see if this actually ever gets called. It doesn't seem like so remove once verified.
+public class RootResource implements UrlResource {
+
+
+ private final String serverUrl;
+ private final ClientContext context;
+
+
+ /**
+ *
+ * @param serverUrl The serverurl that has stood up the UG instance i.e localhost:8080
+ * @param context Contains the token that will be used for the following resources.
+ */
+ public RootResource( final String serverUrl, final ClientContext context ) {
+ this.serverUrl = serverUrl;
+ this.context = context;
+ }
+
+
+ /**
+ * Returns the serverUrl that the root resource is pointing to.
+ * @return serverUrl
+ */
+ @Override
+ public String getPath() {
+ return serverUrl;
+ }
+
+ @Override
+ public WebResource getResource() {
+ //TODO: fix this to return the proper resource in the scope we expect it, might not be needed here.
+ return null;
+ }
+
+ /**
+ * Get the management resource
+ * @return
+ */
+ public ManagementResource management(){
+ return new ManagementResource( context, this);
+ }
+
+
+ /**
+ * Get the organization resource
+ * @param orgName
+ * @return OrganizationResource Returns an instance of the OrganizationResource to continue builder pattern
+ */
+ public OrganizationResource org(final String orgName){
+ return new OrganizationResource( orgName,context, this );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SetupResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SetupResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SetupResource.java
new file mode 100644
index 0000000..b374cdc
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SetupResource.java
@@ -0,0 +1,52 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.apache.usergrid.rest.test.resource.model.QueryParameters;
+import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+
+
+/**
+ * Functions as the endpoint for all resources that hit /system/ * /setup
+ */
+public class SetupResource extends NamedResource {
+
+ public SetupResource( final ClientContext context, final UrlResource parent ) {
+ super("setup",context,parent);
+ }
+
+ public Entity get(QueryParameters queryParameters){
+
+ WebResource resource = getResource();
+ resource = addParametersToResource( resource, queryParameters );
+
+ //added httpBasicauth filter to all setup calls because they all do verification this way.
+ HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( "superuser","superpassword" );
+ resource.addFilter( httpBasicAuthFilter );
+
+ return resource.type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
+ .get( Entity.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SystemResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SystemResource.java
new file mode 100644
index 0000000..6a97dad
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/SystemResource.java
@@ -0,0 +1,57 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.usergrid.rest.test.resource.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource.model.Entity;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+
+/**
+ * Handles making rest calls to system resources.
+ */
+public class SystemResource extends NamedResource {
+
+ public SystemResource(final ClientContext context, final UrlResource parent ) {
+ super( "system",context, parent );
+ }
+
+ //Dirty hack for path resource in new branch of two-dot-o
+ public SystemResource(final String name,final ClientContext context, final UrlResource parent ) {
+ super( name,context, parent );
+ }
+
+
+ public DatabaseResource database() {
+ return new DatabaseResource(context, this);
+ }
+
+ public SystemResource addToPath( String pathPart ) {
+ return new SystemResource( pathPart, context, this );
+ }
+
+ public ApiResponse put(){
+ ApiResponse
+ response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ .put(ApiResponse.class);
+ return response;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/TokenResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/TokenResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/TokenResource.java
new file mode 100644
index 0000000..59ad354
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/TokenResource.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. 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. For additional information regarding
+ * * copyright in this work, please see the NOTICE file in the top level
+ * * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.rest.test.resource.endpoints;
+
+
+import com.sun.jersey.api.client.WebResource;
+import org.apache.usergrid.rest.test.resource.model.QueryParameters;
+import org.apache.usergrid.rest.test.resource.model.Token;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Classy class class.
+ */
+public class TokenResource extends NamedResource {
+ public TokenResource(final ClientContext context, final UrlResource parent) {
+ super("token", context, parent);
+ }
+
+
+ /**
+ * Obtains an access token and sets the token for the context to use in later calls
+ *
+ * @return
+ */
+ public Token post(QueryParameters params) {
+ WebResource resource = getResource(false);
+ resource = addParametersToResource(resource, params);
+ Token token = resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
+ .get(Token.class);
+
+ this.context.setToken(token);
+ return token;
+ }
+
+ /**
+ * Obtains an access token and sets the token for the context to use in later calls
+ *
+ * @return
+ */
+ public Token post() {
+ Token token = getResource().accept(MediaType.APPLICATION_JSON).post(Token.class);
+ this.context.setToken(token);
+ return token;
+ }
+
+ /**
+ * Obtains an access token and sets the token for the context to use in later calls
+ *
+ * @param token
+ * @return
+ */
+ public Token post(Token token) {
+ token = getResource(false).type(MediaType.APPLICATION_JSON_TYPE)
+ .accept(MediaType.APPLICATION_JSON).post(Token.class, token);
+ this.context.setToken(token);
+ return token;
+ }
+
+ public TokenResource setToken(Token token) {
+ this.context.setToken(token);
+ return this;
+ }
+
+ public TokenResource clearToken() {
+ this.context.setToken(null);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/876dc8d3/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
new file mode 100644
index 0000000..eb16d4d
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/UrlResource.java
@@ -0,0 +1,44 @@
+/*
+ * 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.test.resource.endpoints;
+
+
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+
+import com.sun.jersey.api.client.WebResource;
+
+
+/**
+ * Interface that returns the path that is currently being pointed to.
+ */
+public interface UrlResource {
+
+ /**
+ * Get the url path to this resource
+ * example: http://localhost:8080/management/orgs/<org_name>
+ * @return
+ */
+ public String getPath();
+
+ /**
+ * Get the resource
+ * @return
+ */
+ public WebResource getResource();
+
+
+}