Search in sources :

Example 11 with IndyObjectMapper

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

the class ValidationResultTest method assertRoundTrip.

private void assertRoundTrip(ValidationResult in, Consumer<ValidationResult> extraAssertions) throws IOException {
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    ValidationResult out = mapper.readValue(json, ValidationResult.class);
    assertThat(out, notNullValue());
    assertThat(out.isValid(), equalTo(in.isValid()));
    assertThat(out.getRuleSet(), equalTo(in.getRuleSet()));
    if (extraAssertions != null) {
        extraAssertions.accept(out);
    }
    assertThat(out, equalTo(in));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper)

Example 12 with IndyObjectMapper

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

the class ValidationRuleDTOTest method jsonRoundTrip.

@Test
public void jsonRoundTrip() throws IOException {
    try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("no-snapshots.groovy")) {
        String spec = IOUtils.toString(stream);
        ValidationRuleDTO in = new ValidationRuleDTO("test", spec);
        IndyObjectMapper mapper = new IndyObjectMapper(true);
        String json = mapper.writeValueAsString(in);
        ValidationRuleDTO out = mapper.readValue(json, ValidationRuleDTO.class);
        assertThat(out, notNullValue());
        assertThat(out.getName(), equalTo(in.getName()));
        assertThat(out.getSpec(), equalTo(in.getSpec()));
        assertThat(out, equalTo(in));
    }
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 13 with IndyObjectMapper

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

the class AutoProxCalculationTest method jsonRoundTrip_RemoteRepoCreation.

@Test
public void jsonRoundTrip_RemoteRepoCreation() throws IOException {
    RemoteRepository repo = new RemoteRepository("test", "http://foo.com/test");
    AutoProxCalculation in = new AutoProxCalculation(repo, "test-rule.groovy");
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    AutoProxCalculation out = mapper.readValue(json, AutoProxCalculation.class);
    assertThat(out, notNullValue());
    assertThat(out.getRuleName(), equalTo(in.getRuleName()));
    assertThat(out.getStore(), equalTo(in.getStore()));
    assertThat(out, equalTo(in));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 14 with IndyObjectMapper

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

the class ProxyRemoteKojiContentTest method proxyBinaryRemoteKojiArtifact.

@Ignore
@Test
public void proxyBinaryRemoteKojiArtifact() throws Exception {
    final String path = "org/apache/apache/18/apache-18.pom";
    Indy client = new Indy("http://localhost:8080/api", new IndyObjectMapper(Collections.emptySet()), Collections.emptySet()).connect();
    long elapse = getContent("build-x", client, path);
    // the remote store should have been added to brew-binaries group
    StoreListingDTO<RemoteRepository> repos = client.stores().listRemoteRepositories();
    for (RemoteRepository repo : repos.getItems()) {
        logger.debug("Repo " + repo.getName());
        if (repo.getName().startsWith(KOJI_ORIGIN)) {
            logger.debug("Koji repo patterns: " + repo.getPathMaskPatterns());
        }
    }
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Indy(org.commonjava.indy.client.core.Indy) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with IndyObjectMapper

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

the class PackageMetadataMerger method merge.

public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Generating merged metadata in: {}:{}", group.getKey(), path);
    InputStream stream = null;
    boolean merged = false;
    final PackageMetadata packageMetadata = new PackageMetadata();
    final IndyObjectMapper mapper = new IndyObjectMapper(true);
    for (final Transfer src : sources) {
        if (!src.exists()) {
            continue;
        }
        try {
            stream = src.openInputStream();
            String content = IOUtils.toString(stream);
            logger.debug("Adding in metadata content from: {}\n\n{}\n\n", src, content);
            PackageMetadata md = mapper.readValue(content, PackageMetadata.class);
            merged = packageMetadata.merge(md) || merged;
        } catch (final IOException e) {
            final StoreKey key = getKey(src);
            logger.error(String.format("Cannot read metadata: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
        } finally {
            closeQuietly(stream);
        }
    }
    if (metadataProviders != null) {
        for (PackageMetadataProvider provider : metadataProviders) {
            try {
                PackageMetadata toMerge = provider.getMetadata(group.getKey(), path);
                if (toMerge != null) {
                    merged = packageMetadata.merge(toMerge) || merged;
                }
            } catch (IndyWorkflowException e) {
                logger.error(String.format("Cannot read metadata: %s from metadata provider: %s. Reason: %s", path, provider.getClass().getSimpleName(), e.getMessage()), e);
            }
        }
    }
    if (merged) {
        String output = null;
        try {
            output = mapper.writeValueAsString(packageMetadata);
        } catch (JsonProcessingException e) {
            logger.error(String.format("Cannot convert from metadata: %s to String. Reason: %s", packageMetadata, e.getMessage()), e);
        }
        return output.getBytes();
    }
    return null;
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) InputStream(java.io.InputStream) PackageMetadata(org.commonjava.indy.pkg.npm.model.PackageMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)59 Test (org.junit.Test)41 StoreKey (org.commonjava.indy.model.core.StoreKey)16 HostedRepository (org.commonjava.indy.model.core.HostedRepository)10 Group (org.commonjava.indy.model.core.Group)9 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)8 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)8 Transfer (org.commonjava.maven.galley.model.Transfer)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 MemoryStoreDataManager (org.commonjava.indy.mem.data.MemoryStoreDataManager)7 DataFileManager (org.commonjava.indy.subsys.datafile.DataFileManager)6 DataFileEventManager (org.commonjava.indy.subsys.datafile.change.DataFileEventManager)6 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 Before (org.junit.Before)6 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)5 MemoryNotFoundCache (org.commonjava.maven.galley.nfc.MemoryNotFoundCache)5 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)4 Indy (org.commonjava.indy.client.core.Indy)4 DirectContentAccess (org.commonjava.indy.content.DirectContentAccess)4 DefaultContentDigester (org.commonjava.indy.core.content.DefaultContentDigester)4