Search in sources :

Example 71 with StoreKey

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

the class DirectoryListingDTOTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    DirectoryListingEntryDTO firstIn = new DirectoryListingEntryDTO(new StoreKey(StoreType.remote, "test"), "/this/is/a/path.pom");
    DirectoryListingEntryDTO secondIn = new DirectoryListingEntryDTO(new StoreKey(StoreType.remote, "test"), "/this/is/another/path.pom");
    DirectoryListingDTO in = new DirectoryListingDTO(Arrays.asList(firstIn, secondIn));
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    DirectoryListingDTO out = mapper.readValue(json, DirectoryListingDTO.class);
    assertThat(out, notNullValue());
    List<DirectoryListingEntryDTO> items = out.getItems();
    assertThat(items.size(), equalTo(2));
    DirectoryListingEntryDTO firstOut = items.get(0);
    assertThat(firstOut.getKey(), equalTo(firstIn.getKey()));
    assertThat(firstOut.getPath(), equalTo(firstIn.getPath()));
    DirectoryListingEntryDTO secondOut = items.get(1);
    assertThat(secondOut.getKey(), equalTo(secondIn.getKey()));
    assertThat(secondOut.getPath(), equalTo(secondIn.getPath()));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 72 with StoreKey

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

the class NotFoundCacheDTOTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    String firstSectionOnePath = "/path/to/first/file.pom";
    String secondSectionOnePath = "/path/to/another/path.pom";
    NotFoundCacheSectionDTO sectionOne = new NotFoundCacheSectionDTO(new StoreKey(StoreType.remote, "test"), Arrays.asList(firstSectionOnePath, secondSectionOnePath));
    String firstSectionTwoPath = "/path/to/third/file.pom";
    String secondSectionTwoPath = "/path/to/fourth/path.pom";
    NotFoundCacheSectionDTO sectionTwo = new NotFoundCacheSectionDTO(new StoreKey(StoreType.remote, "test2"), Arrays.asList(firstSectionTwoPath, secondSectionTwoPath));
    NotFoundCacheDTO in = new NotFoundCacheDTO();
    in.addSection(sectionOne);
    in.addSection(sectionTwo);
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    NotFoundCacheDTO out = mapper.readValue(json, NotFoundCacheDTO.class);
    assertThat(out, notNullValue());
    Set<NotFoundCacheSectionDTO> sections = out.getSections();
    assertThat(sections, notNullValue());
    assertThat(sections.size(), equalTo(2));
    assertThat(sections.contains(sectionOne), equalTo(true));
    assertThat(sections.contains(sectionTwo), equalTo(true));
    sections.forEach((section) -> {
        StoreKey testKey;
        Set<String> testPaths;
        if (section.equals(sectionOne)) {
            testKey = sectionOne.getKey();
            testPaths = sectionOne.getPaths();
        } else {
            testKey = sectionTwo.getKey();
            testPaths = sectionTwo.getPaths();
        }
        assertThat(section.getKey(), equalTo(testKey));
        Set<String> paths = section.getPaths();
        assertThat(paths, notNullValue());
        assertThat(paths.size(), equalTo(testPaths.size()));
        testPaths.forEach((path) -> {
            assertThat(path + " NOT found in results for key: " + section.getKey(), paths.contains(path), equalTo(true));
        });
    });
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 73 with StoreKey

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

the class GroupTest method copyFidelity.

@Test
public void copyFidelity() {
    Group src = new Group(GENERIC_PKG_KEY, "test");
    src.setMetadata("key", "value");
    src.setDescription("some description");
    src.setDisableTimeout(500);
    src.setDisabled(true);
    src.setTransientMetadata("transient", "someval");
    src.setPathStyle(PathStyle.hashed);
    src.addConstituent(new StoreKey(GENERIC_PKG_KEY, remote, "foo"));
    Group target = src.copyOf();
    Stream.of(Group.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 : CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Test(org.junit.Test) Group(org.commonjava.indy.model.core.Group) InvocationTargetException(java.lang.reflect.InvocationTargetException) Assert.assertThat(org.junit.Assert.assertThat) Stream(java.util.stream.Stream) HostedRepository(org.commonjava.indy.model.core.HostedRepository) StoreType.remote(org.commonjava.indy.model.core.StoreType.remote) GenericPackageTypeDescriptor(org.commonjava.indy.model.core.GenericPackageTypeDescriptor) Assert.fail(org.junit.Assert.fail) PathStyle(org.commonjava.indy.model.core.PathStyle) GENERIC_PKG_KEY(org.commonjava.indy.model.core.GenericPackageTypeDescriptor.GENERIC_PKG_KEY) Collections(java.util.Collections) StoreKey(org.commonjava.indy.model.core.StoreKey) Group(org.commonjava.indy.model.core.Group) StoreKey(org.commonjava.indy.model.core.StoreKey) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 74 with StoreKey

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

the class PromotionValidationTools method addLocations.

public void addLocations(final List<Location> locations, final StoreKey... extraLocations) throws IndyDataException {
    for (StoreKey extra : extraLocations) {
        ArtifactStore store = getArtifactStore(extra);
        locations.add(LocationUtils.toLocation(store));
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 75 with StoreKey

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

the class PromotionValidationTools method getValidationStoreKeys.

public StoreKey[] getValidationStoreKeys(final ValidationRequest request, final boolean includeSource, final boolean includeTarget) throws PromotionValidationException {
    String verifyStores = request.getValidationParameter(PromotionValidationTools.AVAILABLE_IN_STORES);
    if (verifyStores == null) {
        verifyStores = request.getValidationParameter(PromotionValidationTools.AVAILABLE_IN_STORE_KEY);
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Got extra validation keys string: '{}'", verifyStores);
    List<StoreKey> verifyStoreKeys = new ArrayList<>();
    if (includeSource) {
        verifyStoreKeys.add(request.getSourceRepository().getKey());
    }
    if (includeTarget) {
        verifyStoreKeys.add(request.getTarget());
    }
    if (verifyStores == null) {
        logger.warn("No external store (availableInStoreKey parameter) specified for validating path availability in rule-set: {}. Using target: {} instead.", request.getRuleSet().getName(), request.getTarget());
    } else {
        List<StoreKey> extras = Stream.of(verifyStores.split("\\s*,\\s*")).map(StoreKey::fromString).filter(item -> item != null).collect(Collectors.toList());
        if (extras.isEmpty()) {
            throw new PromotionValidationException("No valid StoreKey instances could be parsed from '%s'", verifyStores);
        } else {
            verifyStoreKeys.addAll(extras);
        }
    }
    logger.debug("Using validation StoreKeys: {}", verifyStoreKeys);
    return verifyStoreKeys.toArray(new StoreKey[verifyStoreKeys.size()]);
}
Also used : MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) Arrays(java.util.Arrays) ContentDigester(org.commonjava.indy.content.ContentDigester) ValidationRequest(org.commonjava.indy.promote.validate.model.ValidationRequest) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ReadOnlyTransfer.readOnlyWrapper(org.commonjava.indy.promote.validate.util.ReadOnlyTransfer.readOnlyWrapper) ReadOnlyTransfer.readOnlyWrappers(org.commonjava.indy.promote.validate.util.ReadOnlyTransfer.readOnlyWrappers) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) MavenModelProcessor(org.commonjava.maven.galley.maven.rel.MavenModelProcessor) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) FORCE_CHECKSUM(org.commonjava.maven.galley.io.ChecksummingTransferDecorator.FORCE_CHECKSUM) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) TransferManager(org.commonjava.maven.galley.TransferManager) MavenPomReader(org.commonjava.maven.galley.maven.parse.MavenPomReader) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) ModelProcessorConfig(org.commonjava.maven.galley.maven.rel.ModelProcessorConfig) Map(java.util.Map) ContentDigest(org.commonjava.maven.galley.io.checksum.ContentDigest) URI(java.net.URI) StoreKey(org.commonjava.indy.model.core.StoreKey) Location(org.commonjava.maven.galley.model.Location) ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) ArtifactPathUtils(org.commonjava.maven.galley.maven.util.ArtifactPathUtils) LocationUtils(org.commonjava.indy.util.LocationUtils) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Set(java.util.Set) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) Collectors(java.util.stream.Collectors) ContentManager(org.commonjava.indy.content.ContentManager) List(java.util.List) MavenMetadataReader(org.commonjava.maven.galley.maven.parse.MavenMetadataReader) Stream(java.util.stream.Stream) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TypeMapper(org.commonjava.maven.galley.maven.spi.type.TypeMapper) StoreResource(org.commonjava.indy.content.StoreResource) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) TransferException(org.commonjava.maven.galley.TransferException) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

StoreKey (org.commonjava.indy.model.core.StoreKey)186 Test (org.junit.Test)92 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)40 StoreType (org.commonjava.indy.model.core.StoreType)39 InputStream (java.io.InputStream)33 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)32 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)31 IndyDataException (org.commonjava.indy.data.IndyDataException)30 Group (org.commonjava.indy.model.core.Group)29 Transfer (org.commonjava.maven.galley.model.Transfer)27 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)24 Response (javax.ws.rs.core.Response)23 IOException (java.io.IOException)22 Logger (org.slf4j.Logger)21 ApiOperation (io.swagger.annotations.ApiOperation)20 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)19 ApiResponse (io.swagger.annotations.ApiResponse)18 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)18