use of com.artipie.asto.Content in project maven-adapter by artipie.
the class PutMetadataChecksumSliceTest method foundsCorrespondingMetadataAndSavesChecksum.
@ParameterizedTest
@ValueSource(strings = { "md5", "sha1", "sha256", "sha512" })
void foundsCorrespondingMetadataAndSavesChecksum(final String alg) {
final byte[] xml = new MetadataXml("com.example", "abc").get(new MetadataXml.VersionTags("0.1")).getBytes(StandardCharsets.UTF_8);
this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.1/meta/maven-metadata.xml"), new Content.From(xml)).join();
this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.2/meta/maven-metadata.xml"), new Content.From("any".getBytes())).join();
final byte[] mdfive = new ContentDigest(new Content.From(xml), Digests.valueOf(alg.toUpperCase(Locale.US))).hex().toCompletableFuture().join().getBytes(StandardCharsets.US_ASCII);
final Maven.Fake mvn = new Maven.Fake();
MatcherAssert.assertThat("Incorrect response status, CREATED is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(), mvn), new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, String.format("/com/example/abc/maven-metadata.xml.%s", alg)), Headers.EMPTY, new Content.From(mdfive)));
MatcherAssert.assertThat("Incorrect content was saved to storage", this.asto.value(new Key.From(String.format(".upload/com/example/abc/0.1/meta/maven-metadata.xml.%s", alg))).join(), new ContentIs(mdfive));
MatcherAssert.assertThat("Repository update was not started", mvn.wasUpdated(), new IsEqual<>(true));
}
use of com.artipie.asto.Content in project maven-adapter by artipie.
the class PutMetadataChecksumSliceTest method returnsCreatedWhenRepositoryIsNotReady.
@Test
void returnsCreatedWhenRepositoryIsNotReady() {
final byte[] xml = new MetadataXml("com.example", "abc").get(new MetadataXml.VersionTags("0.1")).getBytes(StandardCharsets.UTF_8);
this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.1/meta/maven-metadata.xml"), new Content.From(xml)).join();
this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.2/meta/maven-metadata.xml"), new Content.From("any".getBytes())).join();
final String alg = "sha1";
final byte[] mdfive = new ContentDigest(new Content.From(xml), Digests.valueOf(alg.toUpperCase(Locale.US))).hex().toCompletableFuture().join().getBytes(StandardCharsets.US_ASCII);
final Maven.Fake mvn = new Maven.Fake();
MatcherAssert.assertThat("Incorrect response status, BAD_REQUEST is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(false, false), mvn), new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, String.format("/com/example/abc/maven-metadata.xml.%s", alg)), Headers.EMPTY, new Content.From(mdfive)));
MatcherAssert.assertThat("Incorrect content was saved to storage", this.asto.value(new Key.From(String.format(".upload/com/example/abc/0.1/meta/maven-metadata.xml.%s", alg))).join(), new ContentIs(mdfive));
MatcherAssert.assertThat("Repository update was started when it does not supposed to", mvn.wasUpdated(), new IsEqual<>(false));
}
use of com.artipie.asto.Content in project maven-adapter by artipie.
the class AstoMavenTest method updatesCorrectlyWhenVersionIsDowngraded.
@Test
void updatesCorrectlyWhenVersionIsDowngraded() {
final String version = "1.0";
new MetadataXml("com.test", "logger").addXmlToStorage(this.storage, new Key.From(AstoMavenTest.LGR, "maven-metadata.xml"), new MetadataXml.VersionTags("2.0", "2.0", new ListOf<>("2.0")));
this.storage.save(new Key.From(AstoMavenTest.LGR, "2.0", "logger-2.0.jar"), Content.EMPTY).join();
new MetadataXml("com.test", "logger").addXmlToStorage(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"), new MetadataXml.VersionTags("2.0", "1.0", new ListOf<>("2.0", "1.0")));
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() = '2.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '2.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '2.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions[count(//version) = 2]"), 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 artipie by artipie.
the class ConfigFile method valueFrom.
/**
* Obtains contents from the specified storage. If files with both extensions
* exists, the file with `.yaml` extension will be obtained.
* @param storage Storage from which the file is obtained
* @return Content of the file.
*/
public CompletionStage<Content> valueFrom(final Storage storage) {
if (!(this.isYamlOrYml() || this.extension().isEmpty())) {
throw new IllegalStateException(String.format("Filename `%s` should have `.yaml` or `.yml` extension or be without extension", this.filename));
}
final String name = this.name();
final Key yaml = Extension.YAML.key(name);
return storage.exists(yaml).thenCompose(exists -> {
final CompletionStage<Content> result;
if (exists) {
result = storage.value(yaml);
} else {
final Key yml = Extension.YML.key(name);
result = storage.value(yml);
}
return result;
});
}
Aggregations