001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/ogcwebservices/csw/configuration/CatalogConfigurationDocumentTest.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.ogcwebservices.csw.configuration;
045:
046: import java.io.File;
047: import java.io.FileOutputStream;
048: import java.io.IOException;
049: import java.net.MalformedURLException;
050: import java.net.URI;
051: import java.net.URISyntaxException;
052: import java.net.URL;
053:
054: import junit.framework.Test;
055: import junit.framework.TestCase;
056: import junit.framework.TestSuite;
057:
058: import org.deegree.datatypes.xlink.SimpleLink;
059: import org.deegree.framework.util.CharsetUtils;
060: import org.deegree.framework.xml.XMLFragment;
061: import org.deegree.model.filterencoding.capabilities.FilterCapabilities;
062: import org.deegree.model.filterencoding.capabilities.FilterCapabilitiesTest;
063: import org.deegree.model.metadata.iso19115.Linkage;
064: import org.deegree.model.metadata.iso19115.OnlineResource;
065: import org.deegree.ogcbase.CommonNamespaces;
066: import org.deegree.ogcwebservices.csw.XMLFactory_2_0_0;
067: import org.deegree.ogcwebservices.csw.capabilities.CatalogueContents;
068: import org.deegree.ogcwebservices.csw.capabilities.CatalogueOperationsMetadata;
069: import org.deegree.ogcwebservices.getcapabilities.Contents;
070: import org.deegree.ogcwebservices.getcapabilities.DCPType;
071: import org.deegree.ogcwebservices.getcapabilities.HTTP;
072: import org.deegree.ogcwebservices.getcapabilities.Operation;
073: import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
074: import org.deegree.ogcwebservices.getcapabilities.ServiceIdentification;
075: import org.deegree.ogcwebservices.getcapabilities.ServiceIdentificationTest;
076: import org.deegree.ogcwebservices.getcapabilities.ServiceProvider;
077: import org.deegree.ogcwebservices.getcapabilities.ServiceProviderTest;
078: import org.deegree.owscommon.OWSDomainType;
079: import org.w3c.dom.Node;
080:
081: import alltests.AllTests;
082: import alltests.Configuration;
083:
084: /**
085: * Test case to validate the structure and creation of a CWS configuration document. Includes
086: * creation of an empty document, saving a document and reading a document. Tests the modifying
087: * (getter/setter) of the different components of the document.
088: *
089: * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe </a>
090: * @author last edited by: $Author: apoth $
091: *
092: * @version $Revision: 9420 $, $Date: 2008-01-07 11:01:25 -0800 (Mon, 07 Jan 2008) $
093: */
094: public class CatalogConfigurationDocumentTest extends TestCase {
095:
096: private CatalogueConfigurationDocument doc;
097:
098: private File generatedCapabilities;
099:
100: public static Test suite() {
101: return new TestSuite(CatalogConfigurationDocumentTest.class);
102: }
103:
104: @Override
105: protected void setUp() throws Exception {
106: super .setUp();
107: this .generatedCapabilities = new File(Configuration
108: .getGeneratedCSWCapabilitiesURL().getFile());
109: this .doc = new CatalogueConfigurationDocument();
110: this .writeConfigDoc();
111: }
112:
113: @Override
114: protected void tearDown() throws Exception {
115: super .tearDown();
116: File generatedFile = generatedCapabilities;
117: if (generatedFile.exists() && generatedFile.canWrite()) {
118: // generatedFile.delete();
119: // AllTests.LOG.logDebug("Configuration document "
120: // + generatedFile.getCanonicalPath() + " deleted");
121: }
122: this .doc = null;
123: }
124:
125: /**
126: * Constructor for CatalogConfigurationDocumentTest.
127: *
128: * @param arg0
129: */
130: public CatalogConfigurationDocumentTest(String arg0) {
131: super (arg0);
132: }
133:
134: /**
135: * Test deegreeParams section
136: *
137: */
138: public void testGetDeegreeParams() {
139: try {
140: assertNotNull(doc.getDeegreeParams());
141: assertEquals(createConfiguration().getDeegreeParams()
142: .getDefaultOnlineResource().getLinkage().getHref(),
143: doc.getDeegreeParams().getDefaultOnlineResource()
144: .getLinkage().getHref());
145: assertEquals(doc.getDeegreeParams().getRequestTimeLimit(),
146: 60);
147: } catch (Exception e) {
148: AllTests.LOG.logError("Unit test failed", e);
149: fail("Error: " + e.getMessage());
150: }
151:
152: }
153:
154: /**
155: * Create an empty configuration document with default settings.
156: *
157: */
158: public void testCreateEmptyDocument() {
159: try {
160: doc.createEmptyDocument();
161: Node rootNode = doc.getRootElement();
162: assertNotNull(rootNode);
163: assertEquals("Capabilities", rootNode.getLocalName());
164: URI namespace = new URI(rootNode.getNamespaceURI());
165: assertEquals(CommonNamespaces.CSWNS, namespace);
166: } catch (Exception e) {
167: AllTests.LOG.logError("Unit test failed", e);
168: fail("Error: " + e.getMessage());
169: }
170: }
171:
172: /**
173: * Test the document root element
174: *
175: */
176: public void testDocumentRootNode() {
177: assertNotNull(doc.parseVersion());
178: assertEquals("2.0.0", doc.parseVersion());
179: assertNotNull(doc.parseUpdateSequence());
180: assertEquals("0", doc.parseUpdateSequence());
181: }
182:
183: /**
184: * To test the loading from an input stream
185: */
186: public void testLoadInputStream() {
187: try {
188: File inFile = generatedCapabilities;
189: assertTrue("File not exists", inFile.exists());
190: doc.load(inFile.toURL());
191: assertEquals(doc.getRootElement().getLocalName(),
192: "Capabilities");
193: } catch (Exception e) {
194: AllTests.LOG.logError("Unit test failed", e);
195: fail("Error: " + e.getMessage());
196: }
197: }
198:
199: /**
200: * To test to save a configuration to an output stream
201: */
202: public void testSaveOutputStreamNode() {
203: try {
204: XMLFragment doc = XMLFactory_2_0_0
205: .export(createConfiguration());
206: FileOutputStream outStream = new FileOutputStream(
207: generatedCapabilities);
208: doc.write(outStream);
209: outStream.close();
210: assertTrue(generatedCapabilities.exists());
211: assertTrue(generatedCapabilities.canRead());
212: assertTrue(generatedCapabilities.length() > 0);
213: } catch (Exception e) {
214: AllTests.LOG.logError("Unit test failed", e);
215: fail("Error: " + e.getMessage());
216: }
217:
218: }
219:
220: /**
221: * Load examples configuration resources/csw
222: *
223: */
224: public void testLoadExampleConfiguration() {
225: try {
226: // File -> CatalogConfigurationDocument
227: AllTests.LOG.logDebug("Example capabilities = "
228: + Configuration.getCSWConfigurationURL());
229: assertNotNull(Configuration.getCSWConfigurationURL());
230: File configurationFile = new File(Configuration
231: .getCSWConfigurationURL().getFile());
232: assertTrue(configurationFile.exists());
233: assertTrue(configurationFile.canRead());
234: doc.load(Configuration.getCSWConfigurationURL());
235: assertNotNull(doc.getRootElement());
236: assertEquals("2.0.0", doc.parseVersion());
237: assertEquals("Capabilities", doc.getRootElement()
238: .getLocalName());
239: assertEquals("CSW", doc.getServiceIdentification()
240: .getServiceType().getCode());
241: // CatalogConfigurationDocument -> CatalogConfiguration
242: CatalogueConfiguration config = doc.getConfiguration();
243: assertNotNull(config);
244:
245: // CatalogConfiguration -> CatalogConfigurationDocument
246: CatalogueConfigurationDocument generatedDocument = XMLFactory_2_0_0
247: .export(config);
248: assertNotNull(generatedDocument.getRootElement());
249: assertEquals("2.0.0", generatedDocument.parseVersion());
250: assertEquals("Capabilities", generatedDocument
251: .getRootElement().getLocalName());
252: assertEquals("CSW", generatedDocument
253: .getServiceIdentification().getServiceType()
254: .getCode());
255: } catch (Exception e) {
256: AllTests.LOG.logError("Unit test failed", e);
257: fail(e.getMessage());
258: }
259: }
260:
261: private void writeConfigDoc() throws IOException,
262: URISyntaxException {
263: FileOutputStream outStream = new FileOutputStream(
264: generatedCapabilities);
265: doc = XMLFactory_2_0_0.export(createConfiguration());
266: doc.write(outStream);
267: outStream.close();
268: }
269:
270: public static CatalogueConfiguration createConfiguration()
271: throws MalformedURLException, URISyntaxException {
272: URL cswUrl = Configuration.getCSWURL();
273: URL systemId = Configuration.getCSWBaseDir();
274: String version = "2.0.0";
275: String updateSequence = "0";
276: OnlineResource onlineRes = new OnlineResource(new Linkage(
277: cswUrl));
278: URL cswInternalWFSURL = new URL(Configuration.getCSWBaseDir(),
279: Configuration.CSW_INTERNALWFS_FILE);
280: SimpleLink wfsOnlineRes = new SimpleLink(new URI(
281: cswInternalWFSURL.toString()));
282: ServiceIdentification serviceIdentification = ServiceIdentificationTest
283: .getTestInstance("CSW", version);
284: ServiceProvider serviceProvider = ServiceProviderTest
285: .getTestInstance();
286: DCPType[] dcpTypes = new DCPType[] { new DCPType(new HTTP(
287: new URL[] { cswUrl }, new URL[] { cswUrl })) };
288: OWSDomainType[] getRecordParameters = new OWSDomainType[] {
289: new CatalogueTypeNameSchemaParameter(
290: "TypeName",
291: new CatalogueTypeNameSchemaValue[] { new CatalogueTypeNameSchemaValue(
292: "csw:Record", "dublincore.xsd") }, null),
293: new OWSDomainType("outputFormat",
294: new String[] { "text/xml" }, null),
295: new CatalogueOutputSchemaParameter(
296: "outputSchema",
297: new CatalogueOutputSchemaValue[] { new CatalogueOutputSchemaValue(
298: "DublinCore", "inDC.xsl", "outDC.xsl") },
299: null),
300: new OWSDomainType("resultType",
301: new String[] { "RESULTS" }, null),
302: new OWSDomainType("ElementSetName", new String[] {
303: "brief", "summary", "full" }, null) };
304: OWSDomainType[] describeRecordParameters = new OWSDomainType[] {
305: new OWSDomainType("TypeName",
306: new String[] { "csw:Record" }, null),
307: new OWSDomainType("outputFormat",
308: new String[] { "text/xml" }, null),
309: new OWSDomainType("schemaLanguage",
310: new String[] { "XMLSCHEMA" }, null) };
311: Operation getCapabilitiesOperation = new Operation(
312: OperationsMetadata.GET_CAPABILITIES_NAME, dcpTypes);
313: Operation describeRecordOperation = new Operation(
314: CatalogueOperationsMetadata.DESCRIBE_RECORD_NAME,
315: dcpTypes, describeRecordParameters);
316: Operation getDomainOperation = new Operation(
317: CatalogueOperationsMetadata.GET_DOMAIN_NAME, dcpTypes);
318: Operation getRecordsOperation = new Operation(
319: CatalogueOperationsMetadata.GET_RECORDS_NAME, dcpTypes,
320: getRecordParameters);
321: Operation getRecordByIdOperation = new Operation(
322: CatalogueOperationsMetadata.GET_RECORD_BY_ID_NAME,
323: dcpTypes);
324: Operation transactionOperation = new Operation(
325: CatalogueOperationsMetadata.TRANSACTION_NAME, dcpTypes);
326: Operation harvestOperation = new Operation(
327: CatalogueOperationsMetadata.HARVEST_NAME, dcpTypes);
328:
329: OperationsMetadata operationsMetadata = new CatalogueOperationsMetadata(
330: getCapabilitiesOperation, describeRecordOperation,
331: getDomainOperation, getRecordsOperation,
332: getRecordByIdOperation, transactionOperation,
333: harvestOperation, null, null);
334: Contents contents = new CatalogueContents();
335: FilterCapabilities filterCapabilities = FilterCapabilitiesTest
336: .getTestInstance();
337: CatalogueDeegreeParams catalogDeegreeParams = new CatalogueDeegreeParams(
338: onlineRes, 1, 60, CharsetUtils.getSystemCharset(),
339: wfsOnlineRes, new OnlineResource[] { onlineRes }, null,
340: null, null, null);
341: return new CatalogueConfiguration(version, updateSequence,
342: serviceIdentification, serviceProvider,
343: operationsMetadata, contents, filterCapabilities,
344: catalogDeegreeParams, systemId);
345: }
346: }
|