incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1489337 - in /sling/trunk/launchpad: integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
Date Tue, 04 Jun 2013 08:40:11 GMT
Author: rombert
Date: Tue Jun  4 08:40:10 2013
New Revision: 1489337

URL: http://svn.apache.org/r1489337
Log:
SLING-2893 - Add documentation and integration tests to verify XML
parsing functionality

Added DomTest

Added:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java
  (with props)
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
  (with props)

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java?rev=1489337&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java
Tue Jun  4 08:40:10 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.xml;
+
+import java.io.IOException;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/**
+ * The <tt>DomTest</tt> verifies that simple DOM executions are successful
+ * 
+ */
+public class DomTest extends HttpTestBase {
+
+
+    public void testDomExecutionIsSuccessful() throws IOException {
+
+        String content = getContent(HTTP_BASE_URL + "/bin/dom.xml", CONTENT_TYPE_PLAIN);
+
+        assertEquals(content, "DOM");
+    }
+
+}

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/xml/DomTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java?rev=1489337&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
Tue Jun  4 08:40:10 2013
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * ADOBE CONFIDENTIAL
+ * __________________
+ *
+ *  Copyright 2013 Adobe Systems Incorporated
+ *  All Rights Reserved.
+ *
+ * NOTICE:  All information contained herein is, and remains
+ * the property of Adobe Systems Incorporated and its suppliers,
+ * if any.  The intellectual and technical concepts contained
+ * herein are proprietary to Adobe Systems Incorporated and its
+ * suppliers and are protected by trade secret or copyright law.
+ * Dissemination of this information or reproduction of this material
+ * is strictly forbidden unless prior written permission is obtained
+ * from Adobe Systems Incorporated.
+ **************************************************************************/
+package org.apache.sling.launchpad.testservices.servlets;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.servlet.ServletException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.felix.scr.annotations.sling.SlingServlet;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * The <tt>DomServlet</tt> evaluates a simple XML document using DOM APIs.
+ * 
+ */
+@SlingServlet(paths = "/bin/dom", extensions = "xml")
+public class DomServlet extends SlingAllMethodsServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final String XML_INPUT = "<content><name>DOM</name></content>";
+
+    @Override
+    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException,
+            IOException {
+
+        try {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder builder = factory.newDocumentBuilder();
+
+            Document document = builder.parse(new InputSource(new StringReader(XML_INPUT)));
+
+            NodeList contentNodeList = document.getElementsByTagName("content");
+            Node contentNode = contentNodeList.item(0);
+            Node nameNode = contentNode.getFirstChild();
+            String result = nameNode.getTextContent();
+
+            response.setContentType("text/plain");
+            response.getWriter().write(result);
+        } catch (ParserConfigurationException e) {
+            throw new ServletException(e);
+        } catch (SAXException e) {
+            throw new ServletException(e);
+        }
+    }
+
+}

Propchange: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/DomServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message