use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.
the class AstoMavenTest method generatesMetadata.
@Test
void generatesMetadata() {
final String latest = "0.20.2";
this.addFilesToStorage(item -> !item.contains("1.0-SNAPSHOT") && !item.contains(latest), AstoMavenTest.ASTO);
this.addFilesToStorage(item -> item.contains(latest), AstoMavenTest.ASTO_UPLOAD);
this.metadataAndVersions(latest);
new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.ASTO_UPLOAD, latest), AstoMavenTest.ASTO).toCompletableFuture().join();
MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.ASTO, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(// @checkstyle LineLengthCheck (20 lines)
XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.artipie']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'asto']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.15']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.11.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.18']"), XhtmlMatchers.hasXPath("metadata/versioning/versions[count(//version) = 5]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
MatcherAssert.assertThat("Artifacts were not moved to the correct location", this.storage.list(new Key.From(AstoMavenTest.ASTO, latest)).join().size(), new IsEqual<>(3));
MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.ASTO_UPLOAD, latest)).join().size(), new IsEqual<>(0));
}
use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.
the class RepositoryChecksumsTest method generatesChecksums.
@Test
void generatesChecksums() {
final Storage storage = new InMemoryStorage();
final Key key = new Key.From("my-artifact.jar");
final byte[] content = "my artifact content".getBytes();
storage.save(key, new Content.From(content));
new RepositoryChecksums(storage).generate(key).toCompletableFuture().join();
MatcherAssert.assertThat("Generates sha1", new PublisherAs(storage.value(new Key.From(String.format("%s.sha1", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha1Hex(content)));
MatcherAssert.assertThat("Generates sha256", new PublisherAs(storage.value(new Key.From(String.format("%s.sha256", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha256Hex(content)));
MatcherAssert.assertThat("Generates sha512", new PublisherAs(storage.value(new Key.From(String.format("%s.sha512", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha512Hex(content)));
MatcherAssert.assertThat("Generates md5", new PublisherAs(storage.value(new Key.From(String.format("%s.md5", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.md5Hex(content)));
}
use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.
the class HeadProxySliceTest method performsRequestWithEmptyHeaderAndBody.
@Test
void performsRequestWithEmptyHeaderAndBody() {
new HeadProxySlice(new SliceSimple(StandardRs.EMPTY)).response("HEAD /some/path HTTP/1.1", new Headers.From("some", "value"), new Content.From("000".getBytes())).send((status, headers, body) -> {
MatcherAssert.assertThat("Headers are empty", headers, new IsEmptyIterable<>());
MatcherAssert.assertThat("Body is empty", new PublisherAs(body).bytes().toCompletableFuture().join(), new IsEqual<>(new byte[] {}));
return CompletableFuture.allOf();
});
}
use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.
the class PutMetadataSlice method response.
@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final Response res;
final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
if (matcher.matches()) {
final Key pkg = new KeyFromPath(matcher.group("pkg"));
res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
final Key key;
if (snapshot.isPresent()) {
key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
} else {
key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
}
return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
}).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
} else {
res = new RsWithStatus(RsStatus.BAD_REQUEST);
}
return res;
}
use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.
the class MavenITCase method deploysSnapshot.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void deploysSnapshot(final boolean anonymous) throws Exception {
this.init(anonymous);
this.copyHellowordSourceToContainer();
MatcherAssert.assertThat("Failed to set version 1.0-SNAPSHOT", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "versions:set", "-DnewVersion=1.0-SNAPSHOT"), new StringContains("BUILD SUCCESS"));
MatcherAssert.assertThat("Failed to deploy version 1.0-SNAPSHOT", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "deploy"), new StringContains("BUILD SUCCESS"));
this.clean();
this.verifySnapshotAdded("1.0-SNAPSHOT");
MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From("com/artipie/helloworld/maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '1.0-SNAPSHOT']"))));
}
Aggregations