@RunWithCustomExecutor @Test public void should_return_request_offset_when_mongo_exception() throws Exception { when(offsetRepository.findOffsetBy(10, VitamConfiguration.getDefaultStrategy(), LOGBOOK)).thenReturn(100L); when(restoreBackupService.getListing(VitamConfiguration.getDefaultStrategy(), 100L, requestItem.getLimit())) .thenReturn(IteratorUtils.singletonIterator(Arrays.asList(getOfferLog(100), getOfferLog(101)))); when(restoreBackupService.loadData(VitamConfiguration.getDefaultStrategy(), "100", 100L)) .thenReturn(getLogbokBackupModel("100", 100L)); when(restoreBackupService.loadData(VitamConfiguration.getDefaultStrategy(), "101", 101L)) .thenReturn(getLogbokBackupModel("101", 101L)); Mockito.doThrow(new DatabaseException("mongo error")).when(mongoRepository).save(Mockito.any(List.class)); when(adminManagementClient.createOrUpdateAccessionRegister(Mockito.any())).thenReturn( new RequestResponseOK<AccessionRegisterDetailModel>().setHttpCode(Status.CREATED.getStatusCode())); ReconstructionService reconstructionService = new ReconstructionService(vitamRepositoryProvider, restoreBackupService, adminManagementClientFactory, new LogbookTransformData(), offsetRepository); ReconstructionResponseItem realResponseItem = reconstructionService.reconstruct(requestItem); assertThat(realResponseItem).isNotNull(); verify(offsetRepository).createOrUpdateOffset(10, VitamConfiguration.getDefaultStrategy(), LOGBOOK, 101L); assertThat(realResponseItem.getTenant()).isEqualTo(10); assertThat(realResponseItem.getStatus()).isEqualTo(StatusCode.OK); }
public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) throws DatabaseException { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MONDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MONDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", DataCategory.BACKUP_OPERATION.name(), reconstructionItem.getTenant())); return reconstructCollection(reconstructionItem.getTenant(), reconstructionItem.getLimit()); }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) throws DatabaseException { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MONDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MONDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", DataCategory.BACKUP_OPERATION.name(), reconstructionItem.getTenant())); return reconstructCollection(reconstructionItem.getTenant(), reconstructionItem.getLimit()); } }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) throws DatabaseException { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MONDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MONDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", DataCategory.BACKUP_OPERATION.name(), reconstructionItem.getTenant())); return reconstructCollection(reconstructionItem.getTenant(), reconstructionItem.getLimit()); } ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBackupService, AdminManagementClientFactory adminManagementClientFactory,
        LogbookTransformData logbookTransformData,
        OffsetRepository offsetRepository); }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) throws DatabaseException { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MONDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MONDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", DataCategory.BACKUP_OPERATION.name(), reconstructionItem.getTenant())); return reconstructCollection(reconstructionItem.getTenant(), reconstructionItem.getLimit()); } ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBackupService, AdminManagementClientFactory adminManagementClientFactory,
        LogbookTransformData logbookTransformData,
        OffsetRepository offsetRepository); ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem); }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) throws DatabaseException { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MONDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MONDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", DataCategory.BACKUP_OPERATION.name(), reconstructionItem.getTenant())); return reconstructCollection(reconstructionItem.getTenant(), reconstructionItem.getLimit()); } ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBackupService, AdminManagementClientFactory adminManagementClientFactory,
        LogbookTransformData logbookTransformData,
        OffsetRepository offsetRepository); ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem); static final String LOGBOOK; }