Search in sources :

Example 11 with TestResource

use of com.artipie.asto.test.TestResource in project maven-adapter by artipie.

the class AstoMavenTest method addsMetadataChecksums.

@Test
void addsMetadataChecksums() {
    final String version = "0.1";
    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(this.storage.list(AstoMavenTest.LGR).join().stream().map(key -> new KeyLastPart(key).get()).filter(key -> key.contains("maven-metadata.xml")).toArray(String[]::new), Matchers.arrayContainingInAnyOrder("maven-metadata.xml", "maven-metadata.xml.sha1", "maven-metadata.xml.sha256", "maven-metadata.xml.sha512", "maven-metadata.xml.md5"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataXml(com.artipie.maven.MetadataXml) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) AllOf(org.hamcrest.core.AllOf) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) ListOf(org.cactoos.list.ListOf) IsEqual(org.hamcrest.core.IsEqual) TestResource(com.artipie.asto.test.TestResource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Predicate(java.util.function.Predicate) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Matchers(org.hamcrest.Matchers) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) PublisherAs(com.artipie.asto.ext.PublisherAs) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) XML(com.jcabi.xml.XML) KeyLastPart(com.artipie.asto.ext.KeyLastPart) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 12 with TestResource

use of com.artipie.asto.test.TestResource in project maven-adapter by artipie.

the class MavenProxySliceITCase method downloadsJarFromCache.

@Test
void downloadsJarFromCache() throws Exception {
    new TestResource("com/artipie/helloworld").addFilesTo(this.storage, new Key.From("com", "artipie", "helloworld"));
    final HttpURLConnection con = (HttpURLConnection) new URL(String.format("http://localhost:%s/com/artipie/helloworld/0.1/helloworld-0.1.jar", this.port)).openConnection();
    con.setRequestMethod("GET");
    MatcherAssert.assertThat("Response status is 200", con.getResponseCode(), new IsEqual<>(Integer.parseInt(RsStatus.OK.code())));
    con.disconnect();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 13 with TestResource

use of com.artipie.asto.test.TestResource in project front by artipie.

the class GetRepositoryTest method returnsRepositorySettings.

@ParameterizedTest
@CsvSource({ "yaml,my-maven", "yml,my-npm-proxy" })
void returnsRepositorySettings(final String ext, final String name) throws Exception {
    final BlockingStorage blsto = new BlockingStorage(new InMemoryStorage());
    final String file = String.format("%s.%s", name, ext);
    blsto.save(new Key.From(file), new TestResource(String.format("GetRepositoryTest/%s", file)).asBytes());
    final var resp = Mockito.mock(Response.class);
    final var rqs = Mockito.mock(Request.class);
    Mockito.when(rqs.params(GetRepository.NAME_PARAM.toString())).thenReturn(name);
    Mockito.when(rqs.attribute(RequestAttr.Standard.USER_ID.attrName())).thenReturn("any");
    JSONAssert.assertEquals(new GetRepository(new RepoSettings("flat", blsto)).handle(rqs, resp), new String(new TestResource(String.format("GetRepositoryTest/%s.json", name)).asBytes(), StandardCharsets.UTF_8), true);
    Mockito.verify(resp).type("application/json");
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RepoSettings(com.artipie.front.settings.RepoSettings) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with TestResource

use of com.artipie.asto.test.TestResource in project maven-adapter by artipie.

the class MavenProxySliceAuthIT method setUp.

@BeforeEach
void setUp() throws Exception {
    final Storage storage = new InMemoryStorage();
    new TestResource("com/artipie/helloworld").addFilesTo(storage, new Key.From("com", "artipie", "helloworld"));
    final String username = "alice";
    final String password = "qwerty";
    this.server = new VertxSliceServer(MavenProxySliceAuthIT.VERTX, new LoggingSlice(new MavenSlice(storage, (user, action) -> user.name().equals(username), new Authentication.Single(username, password))));
    final int port = this.server.start();
    this.client.start();
    this.proxy = new LoggingSlice(new MavenProxySlice(this.client, URI.create(String.format("http://localhost:%d", port)), new BasicAuthenticator(username, password), Cache.NOP));
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) BeforeEach(org.junit.jupiter.api.BeforeEach) Headers(com.artipie.http.Headers) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Slice(com.artipie.http.Slice) LoggingSlice(com.artipie.http.slice.LoggingSlice) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Disabled(org.junit.jupiter.api.Disabled) RsHasStatus(com.artipie.http.hm.RsHasStatus) Test(org.junit.jupiter.api.Test) RequestLine(com.artipie.http.rq.RequestLine) Vertx(io.vertx.reactivex.core.Vertx) AfterEach(org.junit.jupiter.api.AfterEach) MatcherAssert(org.hamcrest.MatcherAssert) Storage(com.artipie.asto.Storage) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) VertxSliceServer(com.artipie.vertx.VertxSliceServer) BasicAuthenticator(com.artipie.http.client.auth.BasicAuthenticator) Cache(com.artipie.asto.cache.Cache) URI(java.net.URI) Authentication(com.artipie.http.auth.Authentication) TestResource(com.artipie.asto.test.TestResource) TestResource(com.artipie.asto.test.TestResource) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) VertxSliceServer(com.artipie.vertx.VertxSliceServer) BasicAuthenticator(com.artipie.http.client.auth.BasicAuthenticator) Key(com.artipie.asto.Key) LoggingSlice(com.artipie.http.slice.LoggingSlice) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with TestResource

use of com.artipie.asto.test.TestResource in project artipie by artipie.

the class GemITCase method gemPushAndInstallWorks.

@Test
void gemPushAndInstallWorks() throws IOException {
    this.containers.assertExec("Packages was not pushed", new ContainerResultMatcher(new IsEqual<>(0), new StringContainsInOrder(new ListOf<String>("POST http://artipie:8080/my-gem/api/v1/gems", "201 Created"))), "env", String.format("GEM_HOST_API_KEY=%s", new Base64Encoded("any:any").asString()), "gem", "push", "-v", "/w/rails-6.0.2.2.gem", "--host", "http://artipie:8080/my-gem");
    this.containers.assertArtipieContent("Package was not added to storage", String.format("/var/artipie/data/my-gem/gems/%s", GemITCase.RAILS), new IsEqual<>(new TestResource(String.format("gem/%s", GemITCase.RAILS)).asBytes()));
    this.containers.assertExec("rubygems.org was not removed from sources", new ContainerResultMatcher(), "gem", "sources", "--remove", "https://rubygems.org/");
    this.containers.assertExec("Package was not installed", new ContainerResultMatcher(new IsEqual<>(0), new StringContainsInOrder(new ListOf<String>(String.format("GET http://artipie:8080/my-gem/quick/Marshal.4.8/%sspec.rz", GemITCase.RAILS), "200 OK", "Successfully installed rails-6.0.2.2", "1 gem installed"))), "gem", "install", GemITCase.RAILS, "--source", "http://artipie:8080/my-gem", "--ignore-dependencies", "-V");
}
Also used : StringContainsInOrder(org.hamcrest.text.StringContainsInOrder) ContainerResultMatcher(com.artipie.test.ContainerResultMatcher) TestResource(com.artipie.asto.test.TestResource) Base64Encoded(org.cactoos.text.Base64Encoded) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Aggregations

TestResource (com.artipie.asto.test.TestResource)20 Test (org.junit.jupiter.api.Test)16 IsEqual (org.hamcrest.core.IsEqual)10 Key (com.artipie.asto.Key)9 ContainerResultMatcher (com.artipie.test.ContainerResultMatcher)9 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)6 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)6 Storage (com.artipie.asto.Storage)5 StringContains (org.hamcrest.core.StringContains)5 StringContainsInOrder (org.hamcrest.text.StringContainsInOrder)5 Content (com.artipie.asto.Content)3 FileStorage (com.artipie.asto.fs.FileStorage)3 MatcherAssert (org.hamcrest.MatcherAssert)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 KeyLastPart (com.artipie.asto.ext.KeyLastPart)2 PublisherAs (com.artipie.asto.ext.PublisherAs)2 RepoSettings (com.artipie.front.settings.RepoSettings)2 JettyClientSlices (com.artipie.http.client.jetty.JettyClientSlices)2 MetadataXml (com.artipie.maven.MetadataXml)2