AppSchemaConfiguration extends Configuration { public String getSchemaLocation() { return originalSchemaLocation; } AppSchemaConfiguration(String namespace, String schemaLocation,
            SchemaResolver resolver); String getSchemaLocation(); @Override void addDependency(Configuration dependency);  }
@Test public void catalog() throws Exception { Configuration configuration = new AppSchemaConfiguration( "http: "http: SchemaCatalog.build(getClass().getResource("/test-data/catalog.xml")))); SchemaIndex schemaIndex = null; try { schemaIndex = Schemas.findSchemas(configuration); Assert.assertEquals(3, schemaIndex.getSchemas().length); String schemaLocation = null; for (XSDSchema schema : schemaIndex.getSchemas()) { if (schema.getSchemaLocation().endsWith("catalog-test.xsd")) { schemaLocation = schema.getSchemaLocation(); break; } } Assert.assertNotNull(schemaLocation); Assert.assertTrue(schemaLocation.startsWith("file:")); Assert.assertTrue(DataUtilities.urlToFile(new URL(schemaLocation)).exists()); Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName( "http: Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName( "http: } finally { if (schemaIndex != null) { schemaIndex.destroy(); } } }
@Test public void classpath() { Configuration configuration = new AppSchemaConfiguration("urn:cgi:xmlns:CGI:GeoSciML:2.0", "http: SchemaIndex schemaIndex = null; try { schemaIndex = Schemas.findSchemas(configuration); Assert.assertEquals(3, schemaIndex.getSchemas().length); String schemaLocation = null; for (XSDSchema schema : schemaIndex.getSchemas()) { if (schema.getSchemaLocation().endsWith("geosciml.xsd")) { schemaLocation = schema.getSchemaLocation(); break; } } Assert.assertNotNull(schemaLocation); Assert.assertTrue(schemaLocation.startsWith("jar:file:")); } finally { if (schemaIndex != null) { schemaIndex.destroy(); } } }
@Test public void cache() throws Exception { File cacheDirectory = new File(DataUtilities.urlToFile(AppSchemaConfigurationTest.class .getResource("/test-data/cache")), "../cache"); SchemaResolver resolver = new SchemaResolver( new SchemaCache(cacheDirectory, false)); Configuration configuration = new AppSchemaConfiguration( "http: "http: SchemaIndex schemaIndex = null; try { schemaIndex = Schemas.findSchemas(configuration); Assert.assertEquals(3, schemaIndex.getSchemas().length); String schemaLocation = null; for (XSDSchema schema : schemaIndex.getSchemas()) { if (schema.getSchemaLocation().endsWith("cache-test.xsd")) { schemaLocation = schema.getSchemaLocation(); break; } } Assert.assertNotNull(schemaLocation); Assert.assertTrue(schemaLocation.startsWith("file:")); Assert.assertTrue(DataUtilities.urlToFile(new URL(schemaLocation)).exists()); Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName( "http: Assert.assertFalse(cacheDirectory.toString().equals( cacheDirectory.getCanonicalFile().toString())); Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName( "http: } finally { if (schemaIndex != null) { schemaIndex.destroy(); } } }
@Test public void catalogCache() throws Exception { File cacheDirectory = DataUtilities.urlToFile(AppSchemaConfigurationTest.class .getResource("/test-data/cache")); SchemaResolver resolver = new SchemaResolver(SchemaCatalog.build(getClass() .getResource("/test-data/catalog.xml")), new SchemaCache(cacheDirectory, false)); Configuration configuration = new AppSchemaConfiguration( "http: "http: SchemaIndex schemaIndex = null; try { schemaIndex = Schemas.findSchemas(configuration); Assert.assertEquals(3, schemaIndex.getSchemas().length); String schemaLocation = null; for (XSDSchema schema : schemaIndex.getSchemas()) { if (schema.getSchemaLocation().endsWith("catalog-cache-test.xsd")) { schemaLocation = schema.getSchemaLocation(); break; } } Assert.assertNotNull(schemaLocation); Assert.assertTrue(schemaLocation.startsWith("file:")); Assert.assertTrue(DataUtilities.urlToFile(new URL(schemaLocation)).exists()); Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName( "http: Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName( "http: } finally { if (schemaIndex != null) { schemaIndex.destroy(); } } }