@Test
  public void checkDatasetWithServiceNameInMetadataElement()
      throws URISyntaxException, ThreddsXmlParserException {
    String docBaseUriString =
        "http://test/thredds/catalog2/xml/parser/ServiceNameInheritanceTest/metadataElement.xml";
    URI docBaseUri = new URI(docBaseUriString);
    String catalogAsString = setupDatasetWithServiceNameInMetadataElement();

    CatalogBuilder catBuilder =
        CatalogXmlUtils.parseCatalogIntoBuilder(docBaseUri, catalogAsString);

    CatalogXmlUtils.assertCatalogWithCompoundServiceAsExpected(catBuilder, docBaseUri, null);
    assertDatasetOneHasOdapAccess(catBuilder);
  }
  @Test
  public void checkDatasetNotInheritingServiceNameFromParentAuthorityAttribute()
      throws URISyntaxException, ThreddsXmlParserException {
    String docBaseUriString =
        "http://test/thredds/catalog2/xml/parser/ServiceNameInheritanceTest/notInheritAttribute.xml";
    URI docBaseUri = new URI(docBaseUriString);
    String catalogAsString = setupDatasetNotInheritingServiceNameFromParentAuthorityAttribute();

    CatalogBuilder catBuilder =
        CatalogXmlUtils.parseCatalogIntoBuilder(docBaseUri, catalogAsString);

    CatalogXmlUtils.assertCatalogWithCompoundServiceAsExpected(catBuilder, docBaseUri, null);
    assertDatasetOneHasOdapAccess(catBuilder);
    assertDatasetTwoHasNoAccess(catBuilder);
  }
 private static String setupDatasetWithServiceNameAttribute() {
   StringBuilder sb =
       new StringBuilder()
           .append("<dataset name='ds1' ID='DS1' urlPath='dir/file1.nc' serviceName='odap' />");
   return CatalogXmlUtils.wrapThreddsXmlInCatalogWithCompoundService(
       sb.toString(), null, null, null);
 }
 private static String setupDatasetWithServiceNameInChildElement() {
   StringBuilder sb =
       new StringBuilder()
           .append("<dataset name='ds1' ID='DS1' urlPath='dir/file1.nc'>")
           .append("    <serviceName>odap</serviceName>")
           .append("</dataset>");
   return CatalogXmlUtils.wrapThreddsXmlInCatalogWithCompoundService(
       sb.toString(), null, null, null);
 }
 private static String setupDatasetNotInheritingServiceNameFromParentAuthorityAttribute() {
   StringBuilder sb =
       new StringBuilder()
           .append("<dataset name='ds1' ID='DS1' urlPath='dir/file1.nc' serviceName='odap'>")
           .append("  <dataset name='dataset 2' ID='DS2' />")
           .append("</dataset>");
   return CatalogXmlUtils.wrapThreddsXmlInCatalogWithCompoundService(
       sb.toString(), null, null, null);
 }
 private static String setupDatasetAccessWithInheritedMetadataServiceNameElement() {
   StringBuilder sb =
       new StringBuilder()
           .append("<dataset name='ds1' ID='DS1'>")
           .append("  <metadata inherited='true'>")
           .append("    <serviceName>odap</serviceName>")
           .append("  </metadata>")
           .append("  <access urlPath='dir/file1.nc' />")
           .append("</dataset>");
   return CatalogXmlUtils.wrapThreddsXmlInCatalogWithCompoundService(
       sb.toString(), null, null, null);
 }
 private static String setupDatasetOverridingInheritedServiceNameWithAttribute() {
   StringBuilder sb =
       new StringBuilder()
           .append("<dataset name='ds1' ID='DS1' urlPath='dir/file1.nc'>")
           .append("  <metadata inherited='true'>")
           .append("    <serviceName>odap</serviceName>")
           .append("  </metadata>")
           .append("  <dataset name='ds2' ID='DS2' urlPath='dir/file2.nc' serviceName='wcs' />")
           .append("</dataset>");
   return CatalogXmlUtils.wrapThreddsXmlInCatalogWithCompoundService(
       sb.toString(), null, null, null);
 }
 private static String setupDatasetNotInheritingServiceNameFromParentMetadataElement() {
   StringBuilder sb =
       new StringBuilder()
           .append("<dataset name='ds1' ID='DS1' urlPath='dir/file1.nc'>")
           .append("  <metadata>")
           .append("    <serviceName>odap</serviceName>")
           .append("  </metadata>")
           .append("  <dataset name='dataset 2' ID='DS2' />")
           .append("</dataset>");
   return CatalogXmlUtils.wrapThreddsXmlInCatalogWithCompoundService(
       sb.toString(), null, null, null);
 }