Search in sources :

Example 56 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class RepositoryPathMaskMetadataTest method run.

/**
     *  Case where user requests maven-metadata.xml which is allowed by path mask
     *   - Should include versions from the member that has a path mask
     */
@Test
public void run() throws Exception {
    final String path_metadata = "org/bar/bar-project/maven-metadata.xml";
    final String remote1 = "remote1";
    final String hosted1 = "hosted1";
    server.expect(server.formatUrl(remote1, path_metadata), 200, meta1);
    RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
    Set<String> pathMaskPatterns = new HashSet<>();
    // regex patterns
    pathMaskPatterns.add("r|org/bar.*|");
    remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
    remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
    HostedRepository hostedRepo1 = new HostedRepository(hosted1);
    pathMaskPatterns = new HashSet<>();
    pathMaskPatterns.add("org/bar.*");
    hostedRepo1.setPathMaskPatterns(pathMaskPatterns);
    hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
    client.content().store(hosted, hosted1, path_metadata, new ByteArrayInputStream(meta2.getBytes()));
    Group g = new Group("group1", remoteRepo1.getKey(), hostedRepo1.getKey());
    g = client.stores().create(g, "adding group1", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    InputStream stream = null;
    String str = null;
    // get metadata from hosted1
    stream = client.content().get(hosted, hostedRepo1.getName(), path_metadata);
    assertThat(stream, notNullValue());
    str = IOUtils.toString(stream);
    System.out.println("hosted1.metadata >>>> " + str);
    stream.close();
    // get metadata from remote1
    stream = client.content().get(remote, remoteRepo1.getName(), path_metadata);
    assertThat(stream, notNullValue());
    str = IOUtils.toString(stream);
    System.out.println("remote1.metadata >>>> " + str);
    stream.close();
    // get metadata from group1
    stream = client.content().get(group, g.getName(), path_metadata);
    assertThat(stream, notNullValue());
    // return aggregated versions from all repositories with valid mask
    str = IOUtils.toString(stream);
    System.out.println("group1.metadata >>>> " + str);
    assertThat(str.trim(), equalTo(aggregatedMeta));
    stream.close();
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HashSet(java.util.HashSet) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 57 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class StoreListingDTOTest method deserializeStoreListingDTO.

@Test
public void deserializeStoreListingDTO() throws Exception {
    /* @formatter:off */
    final String json = "{\n" + "  \"items\" : [ {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:eSPeEZPG\",\n" + "    \"snapshotTimeoutSeconds\" : 0,\n" + "    \"name\" : \"eSPeEZPG\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : false,\n" + "    \"allow_releases\" : true\n" + "  }, {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:qI3Cq2OZ\",\n" + "    \"snapshotTimeoutSeconds\" : 0,\n" + "    \"name\" : \"qI3Cq2OZ\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : false,\n" + "    \"allow_releases\" : true\n" + "  }, {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:local-deployments\",\n" + "    \"snapshotTimeoutSeconds\" : 86400,\n" + "    \"name\" : \"local-deployments\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : true,\n" + "    \"allow_releases\" : true\n" + "  }, {\n" + "    \"type\": \"hosted\",\n" + "    \"key\" : \"maven:hosted:AFhJnQLW\",\n" + "    \"snapshotTimeoutSeconds\" : 0,\n" + "    \"name\" : \"AFhJnQLW\",\n" + "    \"doctype\" : \"hosted\",\n" + "    \"allow_snapshots\" : false,\n" + "    \"allow_releases\" : true\n" + "  } ]\n" + "}";
    /* @formatter:on */
    final StoreListingDTO<HostedRepository> value = new IndyObjectMapper(true).readValue(json, new TypeReference<StoreListingDTO<HostedRepository>>() {
    });
    final List<HostedRepository> items = value.getItems();
    assertThat(items.size(), equalTo(4));
    int i = 0;
    assertThat(items.get(i++).getName(), equalTo("eSPeEZPG"));
    assertThat(items.get(i++).getName(), equalTo("qI3Cq2OZ"));
    assertThat(items.get(i++).getName(), equalTo("local-deployments"));
    assertThat(items.get(i++).getName(), equalTo("AFhJnQLW"));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 58 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class HostedRepositoryTest method copyFidelity.

@Test
public void copyFidelity() {
    HostedRepository src = new HostedRepository(GenericPackageTypeDescriptor.GENERIC_PKG_KEY, "test");
    src.setMetadata("key", "value");
    src.setAllowReleases(false);
    src.setAllowSnapshots(false);
    src.setDescription("some description");
    src.setDisableTimeout(500);
    src.setDisabled(true);
    src.setPathMaskPatterns(Collections.singleton("some/path"));
    src.setTransientMetadata("transient", "someval");
    src.setSnapshotTimeoutSeconds(600);
    src.setStorage("/path/to/storage");
    src.setPathStyle(PathStyle.hashed);
    HostedRepository target = src.copyOf();
    Stream.of(HostedRepository.class.getMethods()).filter(m -> m.getName().startsWith("get") && m.isAccessible() && m.getParameterCount() == 0).forEach(m -> {
        try {
            assertThat(m.getName() + " didn't get copied correctly!", m.invoke(target), equalTo(m.invoke(src)));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            fail("Failed to invoke: " + m.getName());
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    });
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) Stream(java.util.stream.Stream) HostedRepository(org.commonjava.indy.model.core.HostedRepository) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) GenericPackageTypeDescriptor(org.commonjava.indy.model.core.GenericPackageTypeDescriptor) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathStyle(org.commonjava.indy.model.core.PathStyle) Collections(java.util.Collections) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 59 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class AddAndDeleteHostedRepoTest method addMinimalHostedRepositoryAndDeleteIt.

@Test
public void addMinimalHostedRepositoryAndDeleteIt() throws Exception {
    final HostedRepository repo = new HostedRepository(newName());
    final HostedRepository result = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
    assertThat(result.getName(), equalTo(repo.getName()));
    assertThat(result.equals(repo), equalTo(true));
    client.stores().delete(StoreType.hosted, repo.getName(), name.getMethodName());
    assertThat(client.stores().exists(StoreType.hosted, repo.getName()), equalTo(false));
}
Also used : HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 60 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class GroupAdjustmentToMemberDeletionTest method groupAdjustsToConstituentDeletion.

@Test
@Category(EventDependent.class)
public void groupAdjustsToConstituentDeletion() throws Exception {
    final HostedRepository repo = new HostedRepository(newName());
    final Group group = new Group(newName());
    group.addConstituent(repo);
    assertThat(client.stores().create(repo, name.getMethodName(), HostedRepository.class), notNullValue());
    assertThat(client.stores().create(group, name.getMethodName(), Group.class), notNullValue());
    client.stores().delete(repo.getKey().getType(), repo.getName(), name.getMethodName());
    waitForEventPropagation();
    final Group result = client.stores().load(group.getKey().getType(), group.getName(), Group.class);
    assertThat(result.getConstituents() == null || result.getConstituents().isEmpty(), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

HostedRepository (org.commonjava.indy.model.core.HostedRepository)77 Test (org.junit.Test)47 Group (org.commonjava.indy.model.core.Group)44 ByteArrayInputStream (java.io.ByteArrayInputStream)37 Transfer (org.commonjava.maven.galley.model.Transfer)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)18 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Before (org.junit.Before)15 InputStream (java.io.InputStream)13 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)11 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)10 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)9 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)7 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)7 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)7 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)6 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)6 MetadataXpp3Reader (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader)6 IndyDataException (org.commonjava.indy.data.IndyDataException)6