Search in sources :

Example 1 with TestResource

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

the class PutRepositoryTest method addsNewRepo.

@Test
void addsNewRepo() {
    final var resp = Mockito.mock(Response.class);
    final var rqs = Mockito.mock(Request.class);
    Mockito.when(rqs.params(GetRepository.NAME_PARAM.toString())).thenReturn("my-rpm");
    Mockito.when(rqs.attribute(RequestAttr.Standard.USER_ID.attrName())).thenReturn("any");
    Mockito.when(rqs.body()).thenReturn(new String(new TestResource("PutRepositoryTest/request.json").asBytes(), StandardCharsets.UTF_8));
    MatcherAssert.assertThat("Failed to return empty response", new PutRepository(new RepoSettings("flat", this.blsto)).handle(rqs, resp), new IsAnything<>());
    Mockito.verify(resp).status(HttpStatus.CREATED_201);
    MatcherAssert.assertThat(new String(this.blsto.value(new Key.From("my-rpm.yml")), StandardCharsets.UTF_8), new IsEqual<>(String.join(System.lineSeparator(), "repo:", "  type: rpm", "  storage:", "    type: fs", "    path: /var/artipie/data/", "  settings:", "    digest: sha1", "    filelists: false", "  permissions:", "    alice:", "      - read", "      - write", "    bob:", "      - read")));
}
Also used : RepoSettings(com.artipie.front.settings.RepoSettings) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TestResource

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

the class NugetITCase method shouldPushAndInstallPackage.

@Test
void shouldPushAndInstallPackage() throws Exception {
    final String pckgname = UUID.randomUUID().toString();
    this.containers.putBinaryToClient(new TestResource("nuget/newtonsoft.json/12.0.3/newtonsoft.json.12.0.3.nupkg").asBytes(), String.format("/w/%s", pckgname));
    this.containers.assertExec("Package was not pushed", new ContainerResultMatcher(new IsEqual<>(0), new StringContains("Your package was pushed.")), "dotnet", "nuget", "push", pckgname, "-s", "http://artipie:8080/my-nuget/index.json");
    this.containers.assertExec("New project was not created", new ContainerResultMatcher(), "dotnet", "new", "console", "-n", "TestProj");
    this.containers.assertExec("Package was not added", new ContainerResultMatcher(new IsEqual<>(0), new StringContainsInOrder(Arrays.asList(// @checkstyle LineLengthCheck (1 line)
    "PackageReference for package 'newtonsoft.json' version '12.0.3' added to file '/w/TestProj/TestProj.csproj'", "Restored /w/TestProj/TestProj.csproj"))), "dotnet", "add", "TestProj", "package", "newtonsoft.json", "--version", "12.0.3", "-s", "http://artipie:8080/my-nuget/index.json");
}
Also used : StringContainsInOrder(org.hamcrest.text.StringContainsInOrder) TestResource(com.artipie.asto.test.TestResource) ContainerResultMatcher(com.artipie.test.ContainerResultMatcher) IsEqual(org.hamcrest.core.IsEqual) StringContains(org.hamcrest.core.StringContains) Test(org.junit.jupiter.api.Test)

Example 3 with TestResource

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

the class MavenITCase method deploysArtifact.

@ParameterizedTest
@CsvSource({ "helloworld,0.1,0.1", "snapshot,1.0-SNAPSHOT" })
void deploysArtifact(final String type, final String vers) throws Exception {
    this.containers.putBinaryToClient(new TestResource(String.format("%s-src/pom.xml", type)).asBytes(), "/w/pom.xml");
    this.containers.assertExec("Deploy failed", new ContainerResultMatcher(ContainerResultMatcher.SUCCESS), "mvn", "-B", "-q", "-s", "settings.xml", "deploy", "-Dmaven.install.skip=true");
    this.containers.assertExec("Download failed", new ContainerResultMatcher(ContainerResultMatcher.SUCCESS), "mvn", "-B", "-q", "-s", "settings.xml", "-U", "dependency:get", String.format("-Dartifact=com.artipie:%s:%s", type, vers));
}
Also used : TestResource(com.artipie.asto.test.TestResource) ContainerResultMatcher(com.artipie.test.ContainerResultMatcher) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TestResource

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

the class CachedCredsTest method getsOriginForSameConfigurationButDifferentStorages.

@Test
void getsOriginForSameConfigurationButDifferentStorages() {
    final String path = "_credentials.yaml";
    final Key key = new Key.From(path);
    final CredsConfigCache configs = new CachedCreds(this.cache);
    final Storage another = new InMemoryStorage();
    new TestResource(path).saveTo(this.storage);
    new BlockingStorage(another).save(key, "credentials: another val".getBytes(StandardCharsets.UTF_8));
    final YamlMapping frst = configs.credentials(this.storage, key).toCompletableFuture().join();
    final YamlMapping scnd = configs.credentials(another, key).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) TestResource(com.artipie.asto.test.TestResource) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 5 with TestResource

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

the class UsersFromStorageYamlTest method readsCredentialsFromCache.

@Test
void readsCredentialsFromCache() {
    final CachedCreds cache = new CachedCreds();
    new TestResource("_credentials.yaml").saveTo(this.storage, this.key);
    final UsersFromStorageYaml creds = new UsersFromStorageYaml(this.storage, this.key, cache);
    creds.yaml().toCompletableFuture().join();
    this.saveCreds(Users.PasswordFormat.PLAIN, Pair.of(new Users.User("pol"), "newpswd"));
    MatcherAssert.assertThat(creds.yaml().toCompletableFuture().join().yamlMapping("credentials").keys().stream().map(YamlNode::asScalar).map(Scalar::value).toList(), Matchers.containsInAnyOrder("bob", "alice"));
}
Also used : TestResource(com.artipie.asto.test.TestResource) CachedCreds(com.artipie.cache.CachedCreds) Scalar(com.amihaiemil.eoyaml.Scalar) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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