use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class DelegateResourceTest method setup.
@Before
public void setup() throws LoginException, PersistenceException {
ResourceResolver adminResolver = null;
try {
adminResolver = rrFactory.getAdministrativeResourceResolver(null);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("text", "baseTESTValue");
properties.put("other", "baseOther");
properties.put(SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_TYPE, "sling/delegate/base");
ResourceUtil.getOrCreateResource(adminResolver, baseComponentPath, properties, null, false);
properties.clear();
properties.put("text", "extendedTESTValue");
properties.put("other", "extendedOther");
properties.put(SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_TYPE, "sling/delegate/extended");
ResourceUtil.getOrCreateResource(adminResolver, extendedComponentPath, properties, null, false);
properties.clear();
properties.put(SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE, "sling/delegate/base");
ResourceUtil.getOrCreateResource(adminResolver, "/apps/sling/delegate/extended", properties, null, false);
properties.clear();
adminResolver.commit();
} finally {
if (adminResolver != null && adminResolver.isLive()) {
adminResolver.close();
}
}
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ExporterTest method testDoubledServlets.
@Test
public void testDoubledServlets() throws Exception {
ResourceResolver resolver = null;
try {
resolver = rrFactory.getAdministrativeResourceResolver(null);
FakeResponse response = new FakeResponse();
slingRequestProcessor.processRequest(new FakeRequest(doubledComponentPath + ".firstmodel.json"), response, resolver);
JsonObject obj = Json.createReader(new StringReader((response.getStringWriter().toString()))).readObject();
Assert.assertEquals("application/json", response.getContentType());
Assert.assertEquals("first", obj.getString("value"));
response = new FakeResponse();
slingRequestProcessor.processRequest(new FakeRequest(doubledComponentPath + ".secondmodel.json"), response, resolver);
obj = Json.createReader(new StringReader((response.getStringWriter().toString()))).readObject();
Assert.assertEquals("application/json", response.getContentType());
Assert.assertEquals("second", obj.getString("value"));
} finally {
if (resolver != null && resolver.isLive()) {
resolver.close();
}
}
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ExporterTest method testExportToMap.
@Test
public void testExportToMap() throws Exception {
ResourceResolver resolver = null;
try {
resolver = rrFactory.getAdministrativeResourceResolver(null);
final Resource baseComponentResource = resolver.getResource(baseComponentPath);
Assert.assertNotNull(baseComponentResource);
Map<String, Object> data = modelFactory.exportModelForResource(baseComponentResource, "jackson", Map.class, Collections.<String, String>emptyMap());
Assert.assertEquals("Should have resource value", "baseTESTValue", data.get("sampleValue"));
Assert.assertEquals("Should have resource value", "BASETESTVALUE", data.get("UPPER"));
} finally {
if (resolver != null && resolver.isLive()) {
resolver.close();
}
}
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverInjectorTest method testFromResource.
@Test
public void testFromResource() {
Resource resource = mock(Resource.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
when(resource.getResourceResolver()).thenReturn(resourceResolver);
Object result = injector.getValue(resource, "resourceResolver", ResourceResolver.class, element, registry);
assertEquals(resourceResolver, result);
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverInjectorTest method testFromRequest.
@Test
public void testFromRequest() {
SlingHttpServletRequest request = mock(SlingHttpServletRequest.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
when(request.getResourceResolver()).thenReturn(resourceResolver);
Object result = injector.getValue(request, "resourceResolver", ResourceResolver.class, element, registry);
assertEquals(resourceResolver, result);
}
Aggregations