ImporterResolver { public ArtifactImporter getImporter(String artifactType) { ArtifactImporter importer = artifactImporters.get(artifactType); if (importer == null) { throw new NotFoundException(); } return importer; } @Inject  ImporterResolver(@Value("#{artifactImporters}") Map<String, ArtifactImporter> artifactImporters); ArtifactImporter getImporter(String artifactType); ArtifactImporter getImporter(Path extractDir);  }
@Test public void should_get_page_importer_from_artifact_type() throws Exception { ArtifactImporter importer = importerResolver.getImporter("page"); assertThat(importer).isEqualTo(pageArtifactImporter); }
@Test public void should_get_widget_importer_from_artifact_type() throws Exception { ArtifactImporter importer = importerResolver.getImporter("widget"); assertThat(importer).isEqualTo(widgetArtifactImporter); }
@Test(expected = NotFoundException.class) public void should_throw_NotFoundException_for_an_unknown_artifact_type() throws Exception { importerResolver.getImporter("unknown"); }
@Test public void should_get_page_importer_from_path() throws Exception { Path resources = tempDir.newFolderPath("resources"); Files.createFile(resources.resolve("page.json")); ArtifactImporter importer = importerResolver.getImporter(tempDir.toPath()); assertThat(importer).isEqualTo(pageArtifactImporter); }
@Test public void should_get_widget_importer_from_path() throws Exception { Path resources = tempDir.newFolderPath("resources"); Files.createFile(resources.resolve("widget.json")); ArtifactImporter importer = importerResolver.getImporter(tempDir.toPath()); assertThat(importer).isEqualTo(widgetArtifactImporter); }
@Test public void should_get_ImportException_while_resources_folder_is_absent() throws Exception { exception.expect(ImportException.class); exception.expect(hasType(UNEXPECTED_ZIP_STRUCTURE)); exception.expectMessage("Incorrect zip structure resources folder is needed"); importerResolver.getImporter(tempDir.toPath()); }
@Test public void should_get_ImportException_while_no_importer_found_from_path() throws Exception { tempDir.newFolderPath("resources"); try { importerResolver.getImporter(tempDir.toPath()); failBecauseExceptionWasNotThrown(ImportException.class); } catch (ImportException e) { assertThat(e.getMessage()).isEqualTo("Could not load component, artifact model file not found"); assertThat(e.getType()).isEqualTo(MODEL_NOT_FOUND); assertThat((Collection<String>) e.getInfos().get("modelfiles")).containsOnly("page.json", "widget.json"); } }