JsonFileBasedLoader extends AbstractLoader<T> { @Override public boolean contains(Path directory, String objectId) throws IOException { Path objectPath = resolve(directory, objectId); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, "*")) { for (Path componentDirectory : directoryStream) { String id = componentDirectory.getFileName().toString(); Path componentFile = componentDirectory.resolve(id + ".json"); if (objectPath == null || !objectPath.equals(componentFile)) { byte[] content = readAllBytes(componentFile); if (indexOf(content, objectId.getBytes()) >= 0) { return true; } } } } return false; } JsonFileBasedLoader(JacksonObjectMapper objectMapper, Class<T> type); @Override List<T> findByObjectId(Path directory, String objectId); @Override Map<String, List<T>> findByObjectIds(Path directory, List<String> objectIds); @Override T getByUUID(Path directory, String uuid); @Override boolean contains(Path directory, String objectId);  }
@Test public void should_find_object_included_in_another() throws Exception { SimpleDesignerArtifact object1 = aSimpleObjectBuilder().id("objet1").build(); SimpleDesignerArtifact object2 = aSimpleObjectBuilder().id("objet2").another(object1).build(); addToRepository(object1, object2); assertThat(loader.contains(repoDirectory, "objet1")).isTrue(); }
@Test public void should_find_any_object_included_in_another() throws Exception { SimpleDesignerArtifact object1 = aSimpleObjectBuilder().id("objet1").build(); SimpleDesignerArtifact object2 = aSimpleObjectBuilder().id("objet2").another(object1).build(); addToRepository(object1, object2); assertThat(loader.contains(repoDirectory, "object2")).isFalse(); }