/*
* Copyright 1998-2009 University Corporation for Atmospheric Research/Unidata
*
* Portions of this software were developed by the Unidata Program at the
* University Corporation for Atmospheric Research.
*
* Access and use of this software shall impose the following obligations
* and understandings on the user. The user is granted the right, without
* any fee or cost, to use, copy, modify, alter, enhance and distribute
* this software, and any derivative works thereof, and its supporting
* documentation for any purpose whatsoever, provided that this entire
* notice appears in all copies of the software, derivative works and
* supporting documentation. Further, UCAR requests that the user credit
* UCAR/Unidata in any publications that result from the use of this
* software or in any product that includes this software. The names UCAR
* and/or Unidata, however, may not be used in any advertising or publicity
* to endorse or promote any products or commercial entity unless specific
* written permission is obtained from UCAR/Unidata. The user also
* understands that UCAR/Unidata is not obligated to provide the user with
* any support, consulting, training or assistance of any kind with regard
* to the use, operation and performance of this software nor to provide
* the user with any updates, revisions, new versions or "bug fixes."
*
* THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package thredds.catalog2.xml.parser;
import org.junit.Test;
import static org.junit.Assert.*;
import thredds.catalog2.xml.parser.ThreddsXmlParser;
import thredds.catalog2.xml.parser.ThreddsXmlParserException;
import thredds.catalog2.xml.parser.stax.StaxThreddsXmlParser;
import thredds.catalog2.xml.writer.ThreddsXmlWriterFactory;
import thredds.catalog2.xml.writer.ThreddsXmlWriter;
import thredds.catalog2.xml.writer.ThreddsXmlWriterException;
import thredds.catalog2.*;
import thredds.catalog2.builder.CatalogBuilder;
import thredds.catalog2.builder.DatasetNodeBuilder;
import thredds.catalog2.builder.ThreddsMetadataBuilder;
import thredds.catalog2.builder.BuilderException;
import thredds.catalog.ServiceType;
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
/**
* _more_
*
* @author edavis
* @since 4.0
*/
public class TestCatalogParser
{
// private ThreddsXmlParser me;
public TestCatalogParser() { }
@Test
public void testCatalog()
throws URISyntaxException,
ThreddsXmlParserException,
BuilderException
{
String docBaseUriString = "http://test/thredds/catalog2/xml/parser/TestCatalogParser/testCatalog.xml";
URI docBaseUri = new URI( docBaseUriString);
StringBuilder doc = new StringBuilder( "<?xml version='1.0' encoding='UTF-8'?>\n" )
.append( "<catalog xmlns='http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0'" )
.append( " xmlns:xlink='http://www.w3.org/1999/xlink'" )
.append( " name='Unidata THREDDS Data Server' version='1.0.1'>\n" )
.append( " <service name='all' serviceType='Compound' base=''>\n" )
.append( " <service name='odap' serviceType='OPENDAP' base='/thredds/dodsC/' />\n" )
.append( " <service name='wcs' serviceType='WCS' base='/thredds/wcs/'>\n" )
.append( " <property name='someInfo' value='good stuff' />\n" )
.append( " </service>" )
.append( " </service>" )
.append( " <property name='moreInfo' value='more good stuff' />\n" )
.append( " <dataset name='fred'>" )
.append( " <access urlPath='fred.nc' serviceName='odap' />" )
.append( " </dataset>" )
.append( " <dataset name='fred2' serviceName='odap' urlPath='fred2.nc' />" )
.append( " <dataset name=\"Realtime data from IDD\">\n" )
.append( " <catalogRef xlink:href=\"idd/models.xml\" xlink:title=\"NCEP Model Data\" name=\"\" />\n" )
.append( " <catalogRef xlink:href=\"idd/radars.xml\" xlink:title=\"NEXRAD Radar\" name=\"\" />\n" )
.append( " <catalogRef xlink:href=\"idd/obsData.xml\" xlink:title=\"Station Data\" name=\"\" />\n" )
.append( " <catalogRef xlink:href=\"idd/satellite.xml\" xlink:title=\"Satellite Data\" name=\"\" />\n" )
.append( " </dataset>\n" )
.append( " <dataset name=\"Other Unidata Data\">\n" )
.append( "\n" )
.append( " <catalogRef xlink:href=\"idd/rtmodel.xml\" xlink:title=\"Unidata Real-time Regional Model\" name=\"\" />\n" )
.append( " <catalogRef xlink:href=\"galeon/catalog.xml\" xlink:title=\"Unidata GALEON Experimental Web Coverage Service (WCS) datasets\" name=\"\" />\n" )
.append( " <dataset name=\"Test Restricted Dataset\" ID=\"testRestrictedDataset\" urlPath=\"restrict/testData.nc\" restrictAccess=\"tiggeData\">\n" )
.append( " <serviceName>odap</serviceName>\n" )
.append( " <dataType>Grid</dataType>\n" )
.append( " </dataset>\n" )
.append( " </dataset>\n" )
.append( "</catalog>" );
CatalogBuilder catBldr = CatalogXmlUtils.parseCatalogIntoBuilder( docBaseUri, doc.toString() );
String catName = "Unidata THREDDS Data Server";
assertTrue( "Catalog name [" + catBldr.getName() + "] not as expected [" + catName + "].",
catBldr.getName().equals( catName ) );
// ToDo More testing.
Catalog cat = catBldr.build();
cat.getServices();
CatalogXmlUtils.writeCatalogXml( cat );
}
}