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));
}
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));
}
}
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));
}
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());
}
}
}
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;
}
Aggregations