001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/enterprise/servlet/CSWHandlerTest.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.enterprise.servlet;
045:
046: import java.io.IOException;
047: import java.io.StringReader;
048: import java.io.StringWriter;
049: import java.util.HashMap;
050: import java.util.Map;
051:
052: import javax.servlet.http.HttpServletResponse;
053:
054: import junit.framework.Test;
055: import junit.framework.TestCase;
056: import junit.framework.TestSuite;
057:
058: import org.deegree.enterprise.ServiceException;
059: import org.deegree.framework.xml.XMLTools;
060: import org.deegree.ogcwebservices.OGCWebServiceException;
061: import org.deegree.ogcwebservices.OGCWebServiceRequest;
062: import org.deegree.ogcwebservices.csw.CSWFactory;
063: import org.deegree.ogcwebservices.csw.capabilities.CatalogueGetCapabilities;
064: import org.deegree.ogcwebservices.csw.configuration.CatalogueConfiguration;
065: import org.deegree.ogcwebservices.csw.configuration.CatalogueConfigurationDocument;
066: import org.w3c.dom.Document;
067: import org.xml.sax.SAXException;
068:
069: import alltests.AllTests;
070: import alltests.Configuration;
071:
072: /**
073: * Test with mock object to perform http get/post request.
074: *
075: * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe </a>
076: *
077: * @author last edited by: $Author: apoth $
078: *
079: * @version 2.0, $Revision: 9336 $, $Date: 2007-12-27 03:31:18 -0800 (Thu, 27 Dec 2007) $
080: *
081: * @since 2.0
082: */
083: public class CSWHandlerTest extends TestCase {
084: private StringWriter writer;
085:
086: public static Test suite() {
087: return new TestSuite(CSWHandlerTest.class);
088: }
089:
090: /*
091: * @see TestCase#setUp()
092: */
093: protected void setUp() throws Exception {
094: super .setUp();
095: CatalogueConfigurationDocument configDocument = new CatalogueConfigurationDocument();
096: configDocument.load(Configuration.getCSWConfigurationURL());
097: System.out.println(Configuration.getCSWConfigurationURL());
098: CatalogueConfiguration config = configDocument
099: .getConfiguration();
100: CSWFactory.setConfiguration(config);
101: writer = new StringWriter();
102: }
103:
104: /*
105: * @see TestCase#tearDown()
106: */
107: protected void tearDown() throws Exception {
108: super .tearDown();
109: writer.flush();
110: writer.close();
111: writer = null;
112: }
113:
114: public void testPerformGetCapabilities()
115: throws OGCWebServiceException, ServiceException,
116: IOException, SAXException {
117: CSWHandler handler = new CSWHandler();
118: assertNotNull(handler);
119: Map<String, String> kvpRequest = new HashMap<String, String>();
120: kvpRequest.put("ID", this .getName());
121: kvpRequest.put("VERSION", "2.0.0");
122: kvpRequest.put("ACCEPTVERSION", "2.0.0");
123: kvpRequest.put("OUTPUTFORMAT", "text/xml");
124: OGCWebServiceRequest request = CatalogueGetCapabilities
125: .create(kvpRequest);
126: assertNotNull(request);
127: HttpServletResponse response = new MockHttpServletResponse(
128: writer);
129: handler.perform(request, response);
130: String responseAsXml = writer.toString();
131: AllTests.LOG.logDebug(responseAsXml);
132: assertNotNull(responseAsXml);
133: assertTrue(responseAsXml.length() > 0);
134: StringReader reader = new StringReader(responseAsXml);
135: Document responseAsDom = XMLTools.parse(reader);
136: assertNotNull(responseAsDom);
137: assertEquals("csw:Capabilities", responseAsDom
138: .getDocumentElement().getNodeName());
139: assertEquals("2.0.0", responseAsDom.getDocumentElement()
140: .getAttribute("version"));
141: }
142:
143: }
|