usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [01/15] usergrid git commit: Initial commit for new JavaSDK.
Date Thu, 19 May 2016 17:17:15 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master e4beaead1 -> 8f8b46729


http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/test/java/org/apache/usergrid/client/SDKTestUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/test/java/org/apache/usergrid/client/SDKTestUtils.java b/sdks/java/src/test/java/org/apache/usergrid/client/SDKTestUtils.java
new file mode 100644
index 0000000..fc5a039
--- /dev/null
+++ b/sdks/java/src/test/java/org/apache/usergrid/client/SDKTestUtils.java
@@ -0,0 +1,108 @@
+/*
+ * 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.client;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SDKTestUtils {
+
+
+    public static Map<String, UsergridEntity> createColorShapes(String collection)
{
+
+        Map<String, Map<String, String>> entityMap = new HashMap<>(7);
+
+        Map<String, String> fields = new HashMap<>(3);
+        fields.put("color", "red");
+        fields.put("shape", "square");
+
+        entityMap.put("redsquare", fields);
+
+        fields = new HashMap<>(3);
+        fields.put("color", "blue");
+        fields.put("shape", "circle");
+
+        entityMap.put("bluecircle", fields);
+
+        fields = new HashMap<>(3);
+        fields.put("color", "yellow");
+        fields.put("shape", "triangle");
+
+        entityMap.put("yellowtriangle", fields);
+
+        return createEntities(collection, entityMap);
+    }
+
+    public static Map<String, UsergridEntity> createEntities(final String collection,
+                                                             final Map<String, Map<String,
String>> entities) {
+
+        Map<String, UsergridEntity> entityMap = new HashMap<>();
+
+        for (Map.Entry<String, Map<String, String>> entity : entities.entrySet())
{
+
+            UsergridEntity e = createEntity(collection, entity.getKey(), entity.getValue());
+            entityMap.put(e.getUuid(), e);
+        }
+
+        return entityMap;
+    }
+
+    public static UsergridEntity createEntity(final String collection,
+                                              final String name,
+                                              final Map<String, String> fields) {
+
+        UsergridEntity e = new UsergridEntity(collection, name);
+
+        if( fields != null ) {
+            for (Map.Entry<String, String> field : fields.entrySet()) {
+                e.putProperty(field.getKey(), field.getValue());
+            }
+        }
+
+        UsergridResponse r = Usergrid.getInstance().POST(e);
+
+        if (r.getResponseError() != null) {
+            assertTrue("UUID should not be null", e.getUuid() != null);
+            if( fields != null ) {
+                for (Map.Entry<String, String> field : fields.entrySet()) {
+                    assertEquals("attempted to set a property which did not persist on the
entity", e.getStringProperty(field.getKey()),field.getValue());
+                }
+            }
+        }
+
+        return r.first();
+    }
+
+    public static void sleep(long millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException ignore) {
+            ignore.printStackTrace();
+        }
+    }
+
+    public static void indexSleep() {
+        sleep(1000);
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/test/java/org/apache/usergrid/client/UsergridClientAuthTestCase.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/test/java/org/apache/usergrid/client/UsergridClientAuthTestCase.java
b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridClientAuthTestCase.java
new file mode 100644
index 0000000..82ca3c9
--- /dev/null
+++ b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridClientAuthTestCase.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.client;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.UsergridEnums;
+import org.apache.usergrid.java.client.UsergridRequest;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.model.UsergridUser;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.junit.After;
+import org.junit.Test;
+
+import java.util.List;
+
+public class UsergridClientAuthTestCase {
+
+    @After
+    public void after() {
+        Usergrid.reset();
+    }
+
+    @Test
+    public void clientAppInit() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL, SDKTestConfiguration.authFallBack);
+        Usergrid.authenticateApp(new UsergridAppAuth(SDKTestConfiguration.APP_CLIENT_ID,
SDKTestConfiguration.APP_CLIENT_SECRET));
+
+        //should fall back to using no authentication when currentUser is not authenticated
and authFallback is set to NONE
+        UsergridClient client = Usergrid.getInstance();
+//        client.config.authMode = UsergridEnums.UsergridAuthMode.NONE;
+
+        String[] segments = {client.getOrgId(), client.getAppId(), "users"};
+        UsergridRequest request = new UsergridRequest(UsergridEnums.UsergridHttpMethod.GET,
UsergridRequest.APPLICATION_JSON_MEDIA_TYPE,
+                client.getBaseUrl(), null, null, null, null, client.authForRequests(), segments);
+        client.sendRequest(request);
+    }
+
+    @Test
+    public void clientUserInit() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL);
+        Usergrid.authenticateUser(new UsergridUserAuth(SDKTestConfiguration.APP_UserName,
SDKTestConfiguration.APP_Password));
+        UsergridResponse getResponse = Usergrid.GET("user","eb8145ea-e171-11e5-a5e5-2bc0953f9fe6");
+        if( getResponse.getEntities() != null ) {
+            UsergridEntity entity = getResponse.first();
+            if( entity instanceof UsergridUser) {
+                UsergridUser user = (UsergridUser) entity;
+                System.out.print(user.toString());
+            }
+            List<UsergridUser> users = getResponse.users();
+            if( users != null ) {
+                System.out.print(users.get(0).toString());
+            }
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/test/java/org/apache/usergrid/client/UsergridInitTestCase.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/test/java/org/apache/usergrid/client/UsergridInitTestCase.java
b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridInitTestCase.java
new file mode 100644
index 0000000..980a3e7
--- /dev/null
+++ b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridInitTestCase.java
@@ -0,0 +1,48 @@
+/*
+ * 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.client;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.junit.After;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class UsergridInitTestCase {
+
+    @After
+    public void after() {
+        Usergrid.reset();
+    }
+
+    @Test
+    public void testInitAppUsergrid() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL);
+        Usergrid.authenticateApp(new UsergridAppAuth(SDKTestConfiguration.APP_CLIENT_ID,
SDKTestConfiguration.APP_CLIENT_SECRET));
+        assertTrue("usergrid should be an instance of usergrid client", Usergrid.getInstance().getClass()
== UsergridClient.class);
+    }
+
+    @Test
+    public void testInitUserUsergrid() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL);
+        Usergrid.authenticateUser(new UsergridUserAuth(SDKTestConfiguration.APP_UserName,
SDKTestConfiguration.APP_Password));
+        assertTrue("usergrid should be an instance of usergrid client", Usergrid.getInstance().getClass()
== UsergridClient.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseErrorTestCase.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseErrorTestCase.java
b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseErrorTestCase.java
new file mode 100644
index 0000000..3533805
--- /dev/null
+++ b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseErrorTestCase.java
@@ -0,0 +1,62 @@
+/*
+ * 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.client;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+public class UsergridResponseErrorTestCase {
+
+    @Before
+    public void before() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL, SDKTestConfiguration.authFallBack);
+        UsergridAppAuth appAuth = new UsergridAppAuth(SDKTestConfiguration.APP_CLIENT_ID,
SDKTestConfiguration.APP_CLIENT_SECRET);
+        Usergrid.authenticateApp(appAuth);
+    }
+
+    @After
+    public void after() {
+        Usergrid.reset();
+    }
+
+    @Test
+    public void testEntityCreationSuccess() {
+        String collectionName = "ect" + System.currentTimeMillis();
+
+        Map<String, String> fields = new HashMap<>(3);
+        fields.put("color", "red");
+        fields.put("shape", "square");
+
+        SDKTestUtils.createEntity(collectionName, "testEntity1", fields);
+        UsergridResponse eLookUp = Usergrid.GET(collectionName, "testEntity1");
+        assertNull("The returned entity is null!", eLookUp.getResponseError());
+
+        UsergridResponse response = Usergrid.GET(collectionName, "testEntityThatShouldNotExist");
+        assertFalse("Response returned should not be ok.",response.ok());
+        assertTrue("StatusCode equals than 404", response.getStatusCode() == 404);
+        assertNotNull("The returned entity is null!", response.getResponseError());
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseTestCase.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseTestCase.java
b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseTestCase.java
new file mode 100644
index 0000000..e158d85
--- /dev/null
+++ b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridResponseTestCase.java
@@ -0,0 +1,85 @@
+/*
+ * 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.client;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.UsergridEnums;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.apache.usergrid.java.client.response.UsergridResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class UsergridResponseTestCase {
+
+    @Before
+    public void before() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL, UsergridEnums.UsergridAuthMode.USER);
+        Usergrid.authenticateUser(new UsergridUserAuth(SDKTestConfiguration.APP_UserName,
SDKTestConfiguration.APP_Password));
+    }
+
+    @After
+    public void after() {
+        Usergrid.reset();
+    }
+
+    @Test
+    public void testLogoutUser() {
+        String collectionName = "ect" + System.currentTimeMillis();
+
+        Map<String, String> fields = new HashMap<>(3);
+        fields.put("color", "red");
+        fields.put("shape", "square");
+
+        SDKTestUtils.createEntity(collectionName, "testEntity1", fields);
+        UsergridResponse response = Usergrid.GET(collectionName, "testEntity1");
+        Object instanceObj = response.getStatusCode();
+        assertTrue("The returned statusCode is and object of integer", instanceObj instanceof
Integer);
+        instanceObj = response.ok();
+        assertTrue("The returned statusCode is and object of boolean", instanceObj instanceof
Boolean);
+
+        UsergridResponse resp = Usergrid.logoutUser(SDKTestConfiguration.APP_UserName,null);
+
+        response = Usergrid.GET(collectionName, "testEntity1");
+        assertNotNull("The response should throw an error",response.getResponseError());
+    }
+
+    @Test
+    public void testLogoutCurrentUser() {
+        String collectionName = "ect" + System.currentTimeMillis();
+
+        Map<String, String> fields = new HashMap<>(3);
+        fields.put("color", "red");
+        fields.put("shape", "square");
+
+        SDKTestUtils.createEntity(collectionName, "testEntity12", fields);
+        UsergridResponse response = Usergrid.GET(collectionName, "testEntity12");
+        assertNull("The response should not throw an error",response.getResponseError());
+
+        Usergrid.logoutCurrentUser();
+        response = Usergrid.GET(collectionName, "testEntity1");
+        assertNotNull("The response should throw an error",response.getResponseError());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/2e127e62/sdks/java/src/test/java/org/apache/usergrid/client/UsergridTestCase.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/test/java/org/apache/usergrid/client/UsergridTestCase.java b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridTestCase.java
new file mode 100644
index 0000000..5e1ab3a
--- /dev/null
+++ b/sdks/java/src/test/java/org/apache/usergrid/client/UsergridTestCase.java
@@ -0,0 +1,30 @@
+/*
+ * 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.client;
+
+import org.apache.usergrid.java.client.Usergrid;
+import org.apache.usergrid.java.client.auth.UsergridAppAuth;
+import org.junit.Before;
+import org.junit.Test;
+
+public class UsergridTestCase {
+
+    @Test
+    public void initialize() {
+        Usergrid.initSharedInstance(SDKTestConfiguration.ORG_NAME, SDKTestConfiguration.APP_NAME,
SDKTestConfiguration.USERGRID_URL);
+    }
+}


Mime
View raw message