@Test
public void cache() throws Exception {

    // intentionally use a non-canonical cache path to ensure these handled correctly
    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://schemas.example.org/cache-test",
            "http://schemas.example.org/cache-test/cache-test.xsd", resolver);
    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://schemas.example.org/demo", "GeologicUnit")));
        // test that cache path is not canonical
        Assert.assertFalse(cacheDirectory.toString().equals(
                cacheDirectory.getCanonicalFile().toString()));
        // test that relative include can be resolved despite non-canonical cache path
        Assert.assertNotNull(schemaIndex.getElementDeclaration(new QName(
                "http://schemas.example.org/demo", "InnerGeologicUnit")));
    } finally {
        if (schemaIndex != null) {
            schemaIndex.destroy();
        }
    }
}