use of com.artipie.asto.Content in project maven-adapter by artipie.
the class CachedProxySlice method response.
@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final RequestLineFrom req = new RequestLineFrom(line);
final Key key = new KeyFromPath(req.uri().getPath());
return new AsyncResponse(new RepoHead(this.client).head(req.uri().getPath()).thenCompose(head -> this.cache.load(key, new Remote.WithErrorHandling(() -> {
final CompletableFuture<Optional<? extends Content>> promise = new CompletableFuture<>();
this.client.response(line, Headers.EMPTY, Content.EMPTY).send((rsstatus, rsheaders, rsbody) -> {
final CompletableFuture<Void> term = new CompletableFuture<>();
if (rsstatus.success()) {
final Flowable<ByteBuffer> res = Flowable.fromPublisher(rsbody).doOnError(term::completeExceptionally).doOnTerminate(() -> term.complete(null));
promise.complete(Optional.of(new Content.From(res)));
} else {
promise.complete(Optional.empty());
}
return term;
});
return promise;
}), new CacheControl.All(StreamSupport.stream(head.orElse(Headers.EMPTY).spliterator(), false).map(Header::new).map(CachedProxySlice::checksumControl).collect(Collectors.toUnmodifiableList()))).handle((content, throwable) -> {
final Response result;
if (throwable == null && content.isPresent()) {
result = new RsWithBody(StandardRs.OK, new Content.From(content.get()));
} else {
result = StandardRs.NOT_FOUND;
}
return result;
})));
}
use of com.artipie.asto.Content in project maven-adapter by artipie.
the class AstoMavenTest method generatesMetadataForFirstArtifact.
@Test
void generatesMetadataForFirstArtifact() {
final String version = "1.0";
new TestResource("maven-metadata.xml.example").saveTo(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"));
new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.LGR_UPLOAD, version), AstoMavenTest.LGR).toCompletableFuture().join();
MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.LGR, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.test']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'logger']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions[count(//version) = 1]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.LGR_UPLOAD, version)).join().size(), new IsEqual<>(0));
}
use of com.artipie.asto.Content in project maven-adapter by artipie.
the class AstoMavenTest method generatesWithSnapshotMetadata.
@Test
void generatesWithSnapshotMetadata() throws Exception {
final String snapshot = "1.0-SNAPSHOT";
final Predicate<String> cond = item -> !item.contains(snapshot);
this.addFilesToStorage(cond, AstoMavenTest.ASTO);
this.addFilesToStorage(cond.negate(), AstoMavenTest.ASTO_UPLOAD);
this.metadataAndVersions(snapshot, "0.20.2");
new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.ASTO_UPLOAD, snapshot), AstoMavenTest.ASTO).toCompletableFuture().get();
MatcherAssert.assertThat(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() = '1.0-SNAPSHOT']"), 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/version[text() = '1.0-SNAPSHOT']"), XhtmlMatchers.hasXPath("metadata/versioning/versions[count(//version) = 6]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
MatcherAssert.assertThat("Artifacts were not moved to the correct location", this.storage.list(new Key.From(AstoMavenTest.ASTO, snapshot)).join().size(), new IsEqual<>(12));
MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.ASTO_UPLOAD, snapshot)).join().size(), new IsEqual<>(0));
}
use of com.artipie.asto.Content 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.Content 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)));
}
Aggregations