MongoSchemaFileStore implements MongoSchemaStore { static void validateDirectory(File file) throws IOException { if (!file.exists() && !file.mkdirs()) { throw new IOException("Schema store directory does not exist and could not be created: " + file.getAbsolutePath()); } if (file.isDirectory()) { if (!File.createTempFile("test", ".tmp", file).delete()) { throw new IOException("Unable to write to schema store directory: " + file.getAbsolutePath()); } } else { throw new IOException("Specified schema store directory exists but is not a directory: " + file.getAbsolutePath()); } } MongoSchemaFileStore(String uri);  MongoSchemaFileStore(URI uri);  MongoSchemaFileStore(File file); @Override void storeSchema(SimpleFeatureType schema); @Override SimpleFeatureType retrieveSchema(Name name); @Override void deleteSchema(Name name); @Override List<String> typeNames(); @Override void close();  }
@Test public void test_validateDirectory_Exists() throws IOException { File tempDirectory = new File(System.getProperty("java.io.tmpdir")); MongoSchemaFileStore.validateDirectory(tempDirectory); }
@Test public void test_validateDirectory_DoesNotExistAndNeedsCreation() throws IOException { File needsToBeCreated = createUniqueTempDirectory(); try { assertThat(needsToBeCreated.exists(), is(equalTo(false))); MongoSchemaFileStore.validateDirectory(needsToBeCreated); assertThat(needsToBeCreated.isDirectory(), is(equalTo(true))); assertThat(needsToBeCreated.exists(), is(equalTo(true))); } finally { needsToBeCreated.delete(); } }
@Ignore @Test(expected = IOException.class) public void test_validateDirectory_CanNotWrite() throws IOException { File root = new File("/"); MongoSchemaFileStore.validateDirectory(root); }
@Ignore @Test(expected = IOException.class) public void test_validateDirectory_CanNotCreate() throws IOException { File canNotCreate = File.createTempFile(getClass().getSimpleName(), "test", new File("/")); try { MongoSchemaFileStore.validateDirectory(canNotCreate); } finally { canNotCreate.delete(); } }
@Test(expected = IOException.class) public void test_validateDirectory_ExistsAndIsNotADirectory() throws IOException { File fileThatExists = File.createTempFile(getClass().getSimpleName(), "test"); try { MongoSchemaFileStore.validateDirectory(fileThatExists); } finally { fileThatExists.delete(); } }