use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.
the class JsonObjectCreatorTest method testCreateArray.
@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).build();
assertEquals(0, json.getJsonArray("emptyArray").size());
JsonArray array;
array = json.getJsonArray("stringArray");
assertEquals("10", array.getString(0));
array = json.getJsonArray("intArray");
assertEquals(10, array.getInt(0));
array = json.getJsonArray("doubleArray");
assertEquals("10.0", array.getString(0));
array = json.getJsonArray("byteArray");
assertEquals("10", array.getString(0));
array = json.getJsonArray("floatArray");
assertEquals("10.0", array.getString(0));
array = json.getJsonArray("shortArray");
assertEquals("10", array.getString(0));
array = json.getJsonArray("longArray");
assertEquals(10L, array.getJsonNumber(0).longValue());
array = json.getJsonArray("booleanArray");
assertEquals(true, array.getBoolean(0));
array = json.getJsonArray("charArray");
assertEquals("a", array.getString(0));
}
use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.
the class ResourceTraversorTest method testGetJSONObject.
@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.getString("p1"));
}
use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.
the class JsonObjectCreatorTest method testCreate.
@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).build();
assertEquals(10, json.getInt("byte"));
assertEquals(10, json.getInt("int"));
assertEquals("10.0", json.getString("float"));
assertEquals("10.0", json.getString("double"));
assertEquals("10", json.getString("string"));
assertEquals(false, json.getBoolean("boolean"));
assertEquals("object", json.getString("object"));
}
use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.
the class MergedResourceTest method testResourceTypeByValueMap.
@Test
public void testResourceTypeByValueMap() throws Exception {
final ValueMap vm1 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vma"));
final MockResource r1 = new MockResource("/a", vm1, null);
final ValueMap vm2 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmb"));
final MockResource r2 = new MockResource("/b", vm2, null);
final ValueMap vm3 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmc"));
final MockResource r3 = new MockResource("/c", vm3, null);
final List<Resource> resources = new ArrayList<Resource>();
resources.add(r1);
resources.add(r2);
resources.add(r3);
final List<ValueMap> valueMaps = new ArrayList<ValueMap>();
valueMaps.add(vm1);
valueMaps.add(vm2);
valueMaps.add(vm3);
final MergedResource mr = new MergedResource(null, "/a", "a", resources, valueMaps);
assertEquals("vmc", mr.getResourceType());
assertNull(mr.getResourceSuperType());
}
use of org.apache.sling.testing.resourceresolver.MockResource in project sling by apache.
the class MergedResourceTest method testResourceTypeByMethod.
@Test
public void testResourceTypeByMethod() throws Exception {
final MockResource r1 = new MockResource("/a", null, null) {
@Override
public String getResourceType() {
return "a";
}
};
final MockResource r2 = new MockResource("/b", null, null) {
@Override
public String getResourceType() {
return "b";
}
};
final MockResource r3 = new MockResource("/c", null, null) {
@Override
public String getResourceType() {
return "c";
}
};
final List<Resource> resources = new ArrayList<Resource>();
resources.add(r1);
resources.add(r2);
resources.add(r3);
final MergedResource mr = new MergedResource(null, "/a", "a", resources, Collections.EMPTY_LIST);
assertEquals("c", mr.getResourceType());
assertNull(mr.getResourceSuperType());
}
Aggregations