You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2013/05/31 16:53:57 UTC

svn commit: r1488263 - in /sling/trunk/launchpad/integration-tests/src/main: java/org/apache/sling/launchpad/webapp/integrationtest/scripting/SlingJSPTaglibTest.java resources/integration-test/taglib-test.jsp

Author: dklco
Date: Fri May 31 14:53:56 2013
New Revision: 1488263

URL: http://svn.apache.org/r1488263
Log:
Adding integration tests for the new Resource Access Tags

Added:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/SlingJSPTaglibTest.java
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/taglib-test.jsp

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/SlingJSPTaglibTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/SlingJSPTaglibTest.java?rev=1488263&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/SlingJSPTaglibTest.java (added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/SlingJSPTaglibTest.java Fri May 31 14:53:56 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.launchpad.webapp.integrationtest.scripting;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.launchpad.webapp.integrationtest.JspTestBase;
+import org.apache.sling.servlets.post.SlingPostConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Integration test of the new taglibs. Sets up a Sling instance, posts a simple
+ * Test JSP and page to it and then checks to make sure the page responds with a
+ * 200 response.
+ */
+public class SlingJSPTaglibTest extends JspTestBase {
+	private static final Logger log = LoggerFactory
+			.getLogger(SlingJSPTaglibTest.class);
+	private String testPage;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		log.info("setUp");
+
+		final String testRootPath = HTTP_BASE_URL + "/"
+				+ getClass().getSimpleName() + "/" + System.currentTimeMillis();
+		log.info("Creating testing content...");
+		Map<String, String> props = new HashMap<String, String>() {
+			{
+				this.put("jcr:primaryType", "nt:unstructured");
+				this.put("sling:resourceType", "integration-test/taglib-test");
+			}
+		};
+		testPage = testClient.createNode(testRootPath
+				+ SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
+
+		log.info("Creating testing component...");
+		testClient.mkdir(HTTP_BASE_URL + "/apps/integration-test/taglib-test");
+		testClient.upload(
+				HTTP_BASE_URL
+						+ "/apps/integration-test/taglib-test/taglib-test.jsp",
+				SlingJSPTaglibTest.class.getClassLoader().getResourceAsStream(
+						"integration-test/taglib-test.jsp"));
+
+		log.info("Initialization successful");
+	}
+
+	/**
+	 * Tests the taglib.
+	 * 
+	 * @throws Exception
+	 */
+	public void testTaglib() throws Exception {
+		log.info("testTaglib");
+
+		log.info("Executing content check");
+
+		final String content = getContent(testPage + ".html", CONTENT_TYPE_HTML);
+		log.info(content);
+		assertContains(content, "All Tests Succeeded");
+
+		log.info("testTaglib - TEST SUCCESSFUL");
+	}
+
+}

Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/taglib-test.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/taglib-test.jsp?rev=1488263&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/taglib-test.jsp (added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/taglib-test.jsp Fri May 31 14:53:56 2013
@@ -0,0 +1,126 @@
+<%@page session="false" contentType="text/html; charset=utf-8"%>
+<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.3" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<sling:defineObjects/><c:set var="success" value="true" />
+AdaptTo Tag
+    Test 1: AdaptTo Tag
+    result: <sling:adaptTo adaptable="${resource}" adaptTo="org.apache.sling.api.resource.ValueMap" var="props" /><c:choose><c:when test="${not empty props}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 2: Test Non-Existent Class Handling
+    result: <sling:adaptTo adaptable="${resource}" adaptTo="org.apache.sling.api.resource.ValueMap2" var="props2" /><c:choose><c:when test="${empty props2}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 3: Test Null Adaptable Handling
+    result: <sling:adaptTo adaptable="${res}" adaptTo="org.apache.sling.api.resource.ValueMap" var="props3" /><c:choose><c:when test="${empty props3}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 4: Test Non-Adaptable Handling
+    result: <c:catch var="adaptionException"><sling:adaptTo adaptable="res" adaptTo="org.apache.sling.api.resource.ValueMap" var="props3" /></c:catch><c:choose><c:when test="${not empty adaptionException}">SUCCESS: ${adaptionException}</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+Find Resources Tag
+    Test 1: Find Resources
+    Result: <sling:findResources query="/jcr:root//element(*, nt:file) order by @jcr:score" language="xpath" var="foundResources" /><c:choose><c:when test="${not empty foundResources}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Invalid Query
+    Result: <c:catch var="queryException"><sling:findResources query="/jcr:rootelement(*, nt:file) order by @jcr:score" language="xpath" var="foundResources2" /></c:catch><c:choose><c:when test="${not empty queryException}">SUCCESS: ${queryException}</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 3: Invalid Language
+    Result: <c:catch var="queryException2"><sling:findResources query="/jcr:root//element(*, nt:file) order by @jcr:score" language="not-a-real-lang" var="foundResources3" /></c:catch><c:choose><c:when test="${not empty queryException2}">SUCCESS: ${queryException}</c:when><c:otherwise>SUCCESS: ${foundResources3}</c:otherwise></c:choose>
+    
+Get Property Tag
+<sling:getResource path="/apps/integration-test/taglib-test" var="component" /><sling:adaptTo var="componentProps" adaptable="${component}" adaptTo="org.apache.sling.api.resource.ValueMap" />
+    Test 1: Get Property
+    Result: <sling:getProperty properties="${componentProps}" key="jcr:created" var="property1" /><c:choose><c:when test="${not empty property1}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 2: Not Found Property
+    Result: <sling:getProperty properties="${componentProps}" key="sling:resourceType2" var="property2" /><c:choose><c:when test="${empty property2}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 3: Coercing Value
+    Result: <sling:getProperty properties="${componentProps}" key="jcr:created" var="property3" returnClass="java.util.Calendar" /><c:choose><c:when test="${not empty property3.time.month}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 4: Default Value
+    Result: <sling:getProperty properties="${componentProps}" key="emptyKey" var="property4" defaultValue="bob" /><c:choose><c:when test="${not empty property4}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+Get Resource Tag
+    Test 1: Get Resource
+    Result: <sling:getResource path="/apps/integration-test/" var="contentResource" /><c:choose><c:when test="${not empty contentResource.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Get Relative Resource
+    Result: <sling:getResource path="taglib-test" var="contentResource2" base="${contentResource}" /><c:choose><c:when test="${not empty contentResource2.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 3: Not Found Handling
+    Result: <sling:getResource path="/does/not/exist" var="nfResource" /><c:choose><c:when test="${empty nfResource.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 4: Bad Base Handling
+    Result: <sling:getResource path="does/not/exist" var="nfResource2" base="${nfResource}" /><c:choose><c:when test="${empty nfResource2.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+List Children Tag
+    Test 1: Get Children
+    Result: <sling:listChildren resource="${contentResource}" var="childResources" /><c:choose><c:when test="${not empty childResources}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Non-Existing Parent Handing
+    Result: <sling:listChildren resource="${nfResource}" var="childResources2" /><c:choose><c:when test="${empty childResources2}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 3: Bad Parent Handling
+    Result: <c:catch var="listException"><sling:listChildren resource="nfResource" var="childResources3" /></c:catch><c:choose><c:when test="${not empty listException}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    
+AdaptTo Function
+    Test 1: AdaptTo
+    result: <c:set var="props4" value="${sling:adaptTo(resource,'org.apache.sling.api.resource.ValueMap')}" /><c:choose><c:when test="${not empty props4}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 2: Test Non-Existent Class Handling
+    result: <c:set var="props5" value="${sling:adaptTo(resource,'org.apache.sling.api.resource.ValueMap2')}" /><c:choose><c:when test="${empty props5}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 3: Test Null Adaptable Handling
+    result: <c:set var="props6" value="${sling:adaptTo(res,'org.apache.sling.api.resource.ValueMap')}" /><c:choose><c:when test="${empty props6}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 4: Test Non-Adaptable Handling
+    result: <c:catch var="adaptionException2"><c:set var="props7" value="${sling:adaptTo('res','org.apache.sling.api.resource.ValueMap')}" /></c:catch><c:choose><c:when test="${not empty adaptionException2}">SUCCESS: ${adaptionException}</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+Find Resources Function
+    Test 1: Find Resources
+    Result: <c:set var="foundResources4" value="${sling:findResources(resourceResolver, '/jcr:root//element(*, nt:file) order by @jcr:score', 'xpath')}" /><c:choose><c:when test="${not empty foundResources4}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Invalid Query
+    Result: <c:catch var="queryException3"><c:set var="foundResources5" value="${sling:findResources(resourceResolver, '/jcr:rootelement(*, nt:file) order by @jcr:score', 'xpath')}" /></c:catch><c:choose><c:when test="${not empty queryException3}">SUCCESS: ${queryException}</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 3: Invalid Language
+    Result: <c:catch var="queryException4"><c:set var="foundResources6" value="${sling:findResources(resourceResolver, '/jcr:rootelement(*, nt:file) order by @jcr:score', 'xpath')}" /></c:catch><c:choose><c:when test="${not empty queryException4}">SUCCESS: ${queryException}</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+Get Relative Resource Function
+    Test 1: Get Relative Resource
+    Result: <c:set var="contentResource4" value="${sling:getRelativeResource(contentResource, 'taglib-test')}" /><c:choose><c:when test="${not empty contentResource4.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Bad Base Handling
+    Result: <c:set var="nfresource4" value="${sling:getRelativeResource(nfResource, 'test123123')}" /><c:choose><c:when test="${empty nfresource4.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 3: Not Found Handling
+    Result: <c:set var="nfresource5" value="${sling:getRelativeResource(contentResource, 'test123123')}" /><c:choose><c:when test="${empty nfresource5.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+Get Resource Function
+    Test 1: Get Resource
+    Result: <c:set var="contentResource5" value="${sling:getResource(resourceResolver, '/apps')}" /><c:choose><c:when test="${not empty contentResource5.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Bad Resolver
+    Result: <c:catch var="resourceException"><c:set var="nfresource6" value="${sling:getResource(badResolver, '/content')}" /></c:catch><c:choose><c:when test="${not empty resourceException}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+    Test 3: Not Found Handling
+    Result: <c:set var="nfresource7" value="${sling:getResource(resourceResolver, 'test123123')}" /><c:choose><c:when test="${empty nfresource7.path}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+List Children Function
+    Test 1: Get Children
+    Result: <c:set var="childResources4" value="${sling:listChildren(contentResource)}" /><c:choose><c:when test="${not empty childResources4}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 2: Non-Existing Parent Handing
+    Result: <c:set var="childResources5" value="${sling:listChildren(nfResource)}" /><c:choose><c:when test="${empty childResources5}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+
+    Test 3: Bad Parent Handling
+    Result: <c:catch var="listException2"><c:set var="childResources6" value="${sling:listChildren('noVar')}" /></c:catch><c:choose><c:when test="${not empty listException2}">SUCCESS</c:when><c:otherwise>ERROR<c:set var="success" value="false" /></c:otherwise></c:choose>
+    
+<c:choose>
+    <c:when test="${success}">
+        All Tests Succeeded
+    </c:when>
+    <c:otherwise>
+        Test Failures
+    </c:otherwise>
+</c:choose>
\ No newline at end of file