P2ArtifactReader { public static P2ArtifactCoordinates getArtifact(String repositoryBaseDir, String bundle) throws IOException { P2Repository p2Repository = null; final P2ArtifactCoordinates artifactToFind = P2ArtifactCoordinates.create(bundle); for (P2Artifact p2Artifact : p2Repository.getArtifacts().getArtifacts()) { P2ArtifactCoordinates foundArtifact = new P2ArtifactCoordinates(p2Artifact.getId(), p2Artifact.getVersion(), p2Artifact.getClassifier()); if (foundArtifact.equals(artifactToFind)) { addProperties(foundArtifact, p2Artifact, repositoryBaseDir); String bundleFilename = P2ArtifactRuleProcessor.getFilename(p2Repository.getMappings(), foundArtifact); foundArtifact.setFilename(bundleFilename); return foundArtifact; } } return null; }  static P2ArtifactCoordinates getArtifact(String repositoryBaseDir,
                                                    String bundle);  }
@Test public void testGetArtifact() throws URISyntaxException, IOException { P2ArtifactCoordinates foundArtifact = getArtifact(); assertThat(foundArtifact.getClassifier()).isEqualTo(CLASSIFIER); assertThat(foundArtifact.getId()).isEqualTo(ID); assertThat(foundArtifact.getVersion()).isEqualTo(VERSION); }
@Test public void testNullPath() throws IOException { assertThatExceptionOfType(FileNotFoundException.class) .isThrownBy(() -> assertThat(P2ArtifactReader.getArtifact(".", null)).isNull()); }
@Test public void testNullBaseDir() throws IOException { assertThatExceptionOfType(FileNotFoundException.class) .isThrownBy(() -> assertThat(P2ArtifactReader.getArtifact(null, "")).isNull()); }
@Test public void testNullParameters() throws IOException { assertThatExceptionOfType(FileNotFoundException.class) .isThrownBy(() -> assertThat(P2ArtifactReader.getArtifact(null, null)).isNull()); }
@Test public void testInvalidPath() throws IOException { assertThatExceptionOfType(FileNotFoundException.class) .isThrownBy( () -> { assertThat(P2ArtifactReader.getArtifact(".", "some/invalid@path")).isNull(); assertThat(P2ArtifactReader.getArtifact(".", "somePath")).isNull(); assertThat(P2ArtifactReader.getArtifact(".", "")).isNull(); assertThat(P2ArtifactReader.getArtifact(".", "osgi.bundle/missingName/1.0.1")).isNull(); }); }
@Test public void testInvalidBaseDir() throws IOException { assertThatExceptionOfType(FileNotFoundException.class) .isThrownBy( () -> assertThat(P2ArtifactReader.getArtifact("inavlidRoot!", "somePath")).isNull()); }
@Test public void testEmpryParameters() throws IOException { assertThatExceptionOfType(FileNotFoundException.class) .isThrownBy( () -> assertThat(P2ArtifactReader.getArtifact("", "")).isNull()); }
@Test public void testArtifactProperties() throws URISyntaxException, IOException { P2ArtifactCoordinates foundArtifact = getArtifact(); Map<String, String> properties = foundArtifact.getProperties(); assertThat(properties).isNotNull(); Map<String, String> expectedProperties = new HashMap<>(); expectedProperties.put("id", ID); expectedProperties.put("version", VERSION); expectedProperties.put("classifier", CLASSIFIER); expectedProperties.put("download.size", "1"); expectedProperties.forEach( (key, value) -> { assertThat(properties.containsKey(key)).as(key + " not found").isTrue(); assertThat(value).isEqualTo(properties.get(key)); }); }
@Test public void testMapping() throws URISyntaxException, IOException { final String repoDir = getRepoDir(); P2ArtifactCoordinates foundArtifact = getArtifact(repoDir); final String expectedFilename = String.format("%s/plugins/%s_%s.jar", repoDir, ID, VERSION); assertThat(foundArtifact.getFilename()).isEqualTo(expectedFilename); }