ArtifactImporter { public ImportReport forceImport(Import anImport) { return tryToImportAndGenerateReport(anImport, true); } ArtifactImporter(Repository<T> repository, ArtifactService<T> artifactService, Loader<T> loader, DependencyImporter... dependencyImporters); ImportReport forceImport(Import anImport); ImportReport doImport(Import anImport);  }
@Test public void should_force_an_import() throws Exception { List<Widget> addedWidgets = wMocks.mockWidgetsAsAddedDependencies(); List<Widget> overriddenWidgets = wMocks.mockWidgetsAsOverridenDependencies(); Page page = pMocks.mockPageToBeImported(); when(pageRepository.exists(page.getId())).thenReturn(false); Import anImport = new Import(pageImporter, "import-uuid", pageImportPath); ImportReport report = pageImporter.forceImport(anImport); assertThat(report.getDependencies().getAdded().get("widget")).isEqualTo(addedWidgets); assertThat(report.getDependencies().getOverwritten().get("widget")).isEqualTo(overriddenWidgets); assertThat(report.getElement()).isEqualTo(page); assertThat(report.getUUID()).isEqualTo(anImport.getUUID()); assertThat(report.getStatus()).isEqualTo(ImportReport.Status.IMPORTED); verify(widgetRepository, never()).saveAll(overriddenWidgets); verify(pageRepository).updateLastUpdateAndSave(any(Page.class)); }
@Test public void should_force_an_import_overwriting_page() throws Exception { wMocks.mockWidgetsAsAddedDependencies(); Page page = pMocks.mockPageToBeImported(); Page existingPageInRepo = aPage().withUUID(page.getUUID()).withId("alreadyHere").withName("alreadyHere").build(); when(pageRepository.getByUUID(page.getUUID())).thenReturn(existingPageInRepo); when(pageRepository.get(existingPageInRepo.getId())).thenReturn(existingPageInRepo); when(pageRepository.exists(page.getId())).thenReturn(false); Import anImport = new Import(pageImporter, "import-uuid", pageImportPath); ImportReport report = pageImporter.forceImport(anImport); assertThat(report.getOverwrittenElement()).isEqualTo(existingPageInRepo); assertThat(report.isOverwritten()).isTrue(); assertThat(report.getStatus()).isEqualTo(ImportReport.Status.IMPORTED); assertThat(page.getId()).isEqualTo("id"); verify(pageRepository).delete(existingPageInRepo.getId()); verify(pageRepository).updateLastUpdateAndSave(any(Page.class)); }
@Test public void should_force_an_import_when_another_page_with_same_id_exist() throws Exception { wMocks.mockWidgetsAsAddedDependencies(); Page page = pMocks.mockPageToBeImported(); page.setName("myPage"); Page existingPageInRepo = aPage().withUUID(page.getUUID()).withId("alreadyHere").withName("alreadyHere").build(); when(pageRepository.getByUUID(page.getUUID())).thenReturn(existingPageInRepo); when(pageRepository.get(existingPageInRepo.getId())).thenReturn(existingPageInRepo); when(pageRepository.exists(page.getId())).thenReturn(true); when(pageRepository.getNextAvailableId(page.getName())).thenReturn("myPage1"); Import anImport = new Import(pageImporter, "import-uuid", pageImportPath); ImportReport report = pageImporter.forceImport(anImport); assertThat(report.getOverwrittenElement()).isEqualTo(existingPageInRepo); assertThat(report.isOverwritten()).isTrue(); assertThat(report.getStatus()).isEqualTo(ImportReport.Status.IMPORTED); assertThat(page.getId()).isEqualTo("myPage1"); verify(pageRepository).delete(existingPageInRepo.getId()); verify(pageRepository).updateLastUpdateAndSave(any(Page.class)); }