You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2017/01/16 13:51:22 UTC
svn commit: r1779030 - in
/sling/trunk/contrib/extensions/resource-inventory: ./ src/test/
src/test/java/ src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/sling/ src/test/java/org/apache/sling/resource/
src/test/java/org/apache/sli...
Author: tmaret
Date: Mon Jan 16 13:51:21 2017
New Revision: 1779030
URL: http://svn.apache.org/viewvc?rev=1779030&view=rev
Log:
SLING-6468 - Improve code coverage for Sling Inventory Printer
Added:
sling/trunk/contrib/extensions/resource-inventory/src/test/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/JsonObjectCreatorTest.java
sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/ResourceTraversorTest.java
Modified:
sling/trunk/contrib/extensions/resource-inventory/pom.xml
Modified: sling/trunk/contrib/extensions/resource-inventory/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resource-inventory/pom.xml?rev=1779030&r1=1779029&r2=1779030&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resource-inventory/pom.xml (original)
+++ sling/trunk/contrib/extensions/resource-inventory/pom.xml Mon Jan 16 13:51:21 2017
@@ -94,5 +94,24 @@
<version>3.0</version>
<scope>provided</scope>
</dependency>
+ <!-- TESTING -->
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
+ <version>1.1.16</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Added: sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/JsonObjectCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/JsonObjectCreatorTest.java?rev=1779030&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/JsonObjectCreatorTest.java (added)
+++ sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/JsonObjectCreatorTest.java Mon Jan 16 13:51:21 2017
@@ -0,0 +1,131 @@
+/*
+ * 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.sling.resource.inventory.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.json.JSONArray;
+import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.testing.resourceresolver.MockHelper;
+import org.apache.sling.testing.resourceresolver.MockResource;
+import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JsonObjectCreatorTest {
+
+ private ResourceResolver resolver;
+
+ @Before
+ public void setup() throws LoginException {
+ resolver = new MockResourceResolverFactory()
+ .getAdministrativeResourceResolver(null);
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("byte", 0x0A);
+ properties.put("int", 10);
+ properties.put("long", 10L);
+ properties.put("float", 10.0f);
+ properties.put("double", 10.0d);
+ properties.put("string", "10");
+ properties.put("boolean", false);
+ properties.put("object", new Object(){
+ public String toString() {
+ return "object";
+ }
+ });
+ Resource resource = new MockResource("/some/path", properties, resolver);
+
+ JSONObject json = JsonObjectCreator.create(resource);
+
+ assertEquals(10, json.get("byte"));
+ assertEquals(10, json.get("int"));
+ assertEquals("10.0", json.get("float"));
+ assertEquals("10.0", json.get("double"));
+ assertEquals("10", json.get("string"));
+ assertEquals(false, json.get("boolean"));
+ assertEquals("object", json.get("object"));
+ }
+
+ @Test
+ public void testCreateArray() throws Exception {
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("emptyArray", new Object[]{});
+ properties.put("stringArray", new String[]{"10","100"});
+ properties.put("intArray", new int[]{10, 100});
+ properties.put("doubleArray", new double[]{10d, 100d});
+ properties.put("byteArray", new byte[]{0x0A, 0x64});
+ properties.put("floatArray", new float[]{10.0f, 100.0f});
+ properties.put("shortArray", new short[]{10, 100});
+ properties.put("longArray", new long[]{10, 100});
+ properties.put("booleanArray", new boolean[]{true, false});
+ properties.put("charArray", new char[]{'a', 'b'});
+ Resource resource = new MockResource("/some/path", properties, resolver);
+
+ JSONObject json = JsonObjectCreator.create(resource);
+ assertEquals(0, json.getJSONArray("emptyArray").length());
+ JSONArray array;
+ array = json.getJSONArray("stringArray");
+ assertEquals("10", array.get(0));
+ array = json.getJSONArray("intArray");
+ assertEquals(10, array.get(0));
+ array = json.getJSONArray("doubleArray");
+ assertEquals("10.0", array.get(0));
+ array = json.getJSONArray("byteArray");
+ assertEquals("10", array.get(0));
+ array = json.getJSONArray("floatArray");
+ assertEquals("10.0", array.get(0));
+ array = json.getJSONArray("shortArray");
+ assertEquals("10", array.get(0));
+ array = json.getJSONArray("longArray");
+ assertEquals(10L, array.get(0));
+ array = json.getJSONArray("booleanArray");
+ assertEquals(true, array.get(0));
+ array = json.getJSONArray("charArray");
+ assertEquals("a", array.get(0));
+
+ }
+
+ @Test
+ public void testCreateDeep() throws Exception {
+
+ MockHelper.create(resolver)
+ .resource("/some")
+ .p("p1", "v1")
+ .resource("/some/path")
+ .p("p2", "v2")
+ .commit();
+ Resource resource = resolver.getResource("/some");
+
+ JSONObject json = JsonObjectCreator.create(resource);
+ assertEquals("v1", json.get("p1"));
+ JSONObject path = json.getJSONObject("path");
+ assertEquals("v2", path.get("p2"));
+
+ }
+}
\ No newline at end of file
Added: sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/ResourceTraversorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/ResourceTraversorTest.java?rev=1779030&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/ResourceTraversorTest.java (added)
+++ sling/trunk/contrib/extensions/resource-inventory/src/test/java/org/apache/sling/resource/inventory/impl/ResourceTraversorTest.java Mon Jan 16 13:51:21 2017
@@ -0,0 +1,71 @@
+/*
+ * 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.sling.resource.inventory.impl;
+
+import java.util.Collections;
+
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.testing.resourceresolver.MockHelper;
+import org.apache.sling.testing.resourceresolver.MockResource;
+import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class ResourceTraversorTest {
+
+ private ResourceResolver resolver;
+
+ @Before
+ public void setup() throws LoginException {
+ resolver = new MockResourceResolverFactory()
+ .getAdministrativeResourceResolver(null);
+ }
+
+ @Test
+ public void testCollectResources() throws Exception {
+ MockHelper.create(resolver)
+ .resource("/some")
+ .p("p1", "v1")
+ .resource("/some/path")
+ .p("p2", "v2")
+ .commit();
+ Resource resource = resolver.getResource("/some");
+ ResourceTraversor traversor = new ResourceTraversor(resource);
+ traversor.collectResources();
+ JSONObject json = traversor.getJSONObject();
+ assertEquals("v1", json.get("p1"));
+ JSONObject path = json.getJSONObject("path");
+ assertNotNull(path);
+ assertEquals("v2", path.get("p2"));
+
+ }
+
+ @Test
+ public void testGetJSONObject() throws Exception {
+ Resource resource = new MockResource("/some/path", Collections.<String, Object>singletonMap("p1", "v1"), resolver);
+ JSONObject json = new ResourceTraversor(resource).getJSONObject();
+ assertEquals("v1", json.get("p1"));
+
+ }
+
+}
\ No newline at end of file