public Env() { try { this.repositories.put("spring-snapshots", new Repository("Spring Snapshots", new URL("https://repo.spring.io/snapshot"), true)); this.repositories.put("spring-milestones", new Repository("Spring Milestones", new URL("https://repo.spring.io/milestone"), false)); } catch (MalformedURLException ex) { throw new IllegalStateException("Cannot parse URL", ex); } }
Node item = nodes.item(i); if (item instanceof Element) { Repository repository = new Repository(); Element element = (Element) item; NodeList type = element.getElementsByTagName("id");
@Test void mapDependency() throws Exception { Dependency d = Dependency.withId("foo", "org.foo", "foo"); d.setRepository("my-repo"); d.setBom("my-bom"); Repository repository = new Repository(); repository.setName("foo-repo"); repository.setUrl(new URL("http://example.com/foo")); BillOfMaterials bom = BillOfMaterials.create("org.foo", "foo-bom", "1.0.0.RELEASE"); DependencyMetadata metadata = new DependencyMetadata( Version.parse("1.2.0.RELEASE"), Collections.singletonMap(d.getId(), d), Collections.singletonMap("repo-id", repository), Collections.singletonMap("bom-id", bom)); JSONObject content = new JSONObject(this.mapper.write(metadata)); assertThat(content.getJSONObject("dependencies").getJSONObject("foo") .getString("bom")).isEqualTo("my-bom"); assertThat(content.getJSONObject("dependencies").getJSONObject("foo") .getString("repository")).isEqualTo("my-repo"); assertThat(content.getJSONObject("repositories").getJSONObject("repo-id") .getString("name")).isEqualTo("foo-repo"); assertThat(content.getJSONObject("boms").getJSONObject("bom-id") .getString("artifactId")).isEqualTo("foo-bom"); assertThat(content.getJSONObject("boms").getJSONObject("bom-id") .getString("version")).isEqualTo("1.0.0.RELEASE"); }
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean snapshotsEnabled) { this.builder.withCustomizer((it) -> { Repository repo = new Repository(); repo.setName(name); try { repo.setUrl(new URL(url)); } catch (MalformedURLException ex) { throw new IllegalArgumentException("Cannot create URL", ex); } repo.setSnapshotsEnabled(snapshotsEnabled); it.getConfiguration().getEnv().getRepositories().put(id, repo); }); return this; }
@Test void invalidRepository() throws MalformedURLException { InitializrMetadata metadata = initializeMetadata(); Dependency foo = Dependency.withId("foo", "org.acme", "foo"); foo.setRepository("foo-repo"); addTestDependencyGroup(metadata, foo); metadata.getConfiguration().getEnv().getRepositories().put("my-repo", new Repository("repo", new URL("http://example.com/repo"), true)); assertThatExceptionOfType(InvalidInitializrMetadataException.class) .isThrownBy(metadata::validate).withMessageContaining("foo-repo") .withMessageContaining("my-repo"); }