@Test public void testSaveBulk() throws DatabaseException { VitamRepositoryProvider vitamRepositoryProvider = Mockito.mock(VitamRepositoryProvider.class); VitamMongoRepository vitamMongoRepository = Mockito.mock(VitamMongoRepository.class); VitamElasticsearchRepository vitamElasticsearchRepository = Mockito.mock(VitamElasticsearchRepository.class); LogbookRepositoryService logbookRepositoryService = new LogbookRepositoryService(vitamRepositoryProvider); Mockito.when(vitamRepositoryProvider.getVitamMongoRepository(any())).thenReturn(vitamMongoRepository); Mockito.doNothing().when(vitamMongoRepository).saveOrUpdate(any(List.class)); Mockito.when(vitamRepositoryProvider.getVitamESRepository(any())).thenReturn(vitamElasticsearchRepository); Mockito.doNothing().when(vitamElasticsearchRepository).saveOrUpdate(any(List.class)); List<JsonNode> logbookItems = new ArrayList<>(); logbookItems.add(JsonHandler.createObjectNode()); logbookItems.add(JsonHandler.createObjectNode()); assertThatCode(() -> { logbookRepositoryService.saveBulk(LogbookCollections.LIFECYCLE_UNIT, logbookItems); }).doesNotThrowAnyException(); assertThatCode(() -> { logbookRepositoryService.saveBulk(LogbookCollections.LIFECYCLE_OBJECTGROUP, logbookItems); }).doesNotThrowAnyException(); assertThatCode(() -> { logbookRepositoryService.saveBulk(LogbookCollections.OPERATION, logbookItems); }).doesNotThrowAnyException(); }
public void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems) throws DatabaseException { List<Document> documents = logbookItems.stream() .map(item -> Document.parse(JsonHandler.unprettyPrint(item))).collect(Collectors.toList()); vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()).saveOrUpdate(documents); if (LogbookCollections.OPERATION.equals(collection)) { vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()).save(documents); } }
LogbookRepositoryService { public void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems) throws DatabaseException { List<Document> documents = logbookItems.stream() .map(item -> Document.parse(JsonHandler.unprettyPrint(item))).collect(Collectors.toList()); vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()).saveOrUpdate(documents); if (LogbookCollections.OPERATION.equals(collection)) { vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()).save(documents); } } }
LogbookRepositoryService { public void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems) throws DatabaseException { List<Document> documents = logbookItems.stream() .map(item -> Document.parse(JsonHandler.unprettyPrint(item))).collect(Collectors.toList()); vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()).saveOrUpdate(documents); if (LogbookCollections.OPERATION.equals(collection)) { vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()).save(documents); } } LogbookRepositoryService(VitamRepositoryProvider vitamRepositoryProvider); }
LogbookRepositoryService { public void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems) throws DatabaseException { List<Document> documents = logbookItems.stream() .map(item -> Document.parse(JsonHandler.unprettyPrint(item))).collect(Collectors.toList()); vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()).saveOrUpdate(documents); if (LogbookCollections.OPERATION.equals(collection)) { vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()).save(documents); } } LogbookRepositoryService(VitamRepositoryProvider vitamRepositoryProvider); void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems); }
LogbookRepositoryService { public void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems) throws DatabaseException { List<Document> documents = logbookItems.stream() .map(item -> Document.parse(JsonHandler.unprettyPrint(item))).collect(Collectors.toList()); vitamRepositoryProvider.getVitamMongoRepository(collection.getVitamCollection()).saveOrUpdate(documents); if (LogbookCollections.OPERATION.equals(collection)) { vitamRepositoryProvider.getVitamESRepository(collection.getVitamCollection()).save(documents); } } LogbookRepositoryService(VitamRepositoryProvider vitamRepositoryProvider); void saveBulk(LogbookCollections collection, List<JsonNode> logbookItems);  }