use of org.commonjava.indy.model.core.io.IndyObjectMapper 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()));
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class EndpointViewListingTest method jsonRoundTrip.
@Test
public void jsonRoundTrip() throws IOException {
EndpointView first = new EndpointView(new RemoteRepository("test", "http://foo.com/repo"), "http://localhost:8080/api/remote/test");
EndpointView second = new EndpointView(new RemoteRepository("test2", "http://foo2.com/repo2"), "http://localhost:8080/api/remote/test2");
EndpointViewListing in = new EndpointViewListing(Arrays.asList(first, second));
IndyObjectMapper mapper = new IndyObjectMapper(true);
String json = mapper.writeValueAsString(in);
EndpointViewListing out = mapper.readValue(json, EndpointViewListing.class);
assertThat(out, notNullValue());
List<EndpointView> items = out.getItems();
assertThat(items, notNullValue());
assertThat(items.size(), equalTo(2));
int i = 0;
EndpointView view = items.get(i++);
assertThat(view.getKey(), equalTo(first.getKey()));
assertThat(view.getName(), equalTo(first.getName()));
assertThat(view.getResourceUri(), equalTo(first.getResourceUri()));
assertThat(view.getStoreKey(), equalTo(first.getStoreKey()));
assertThat(view.getStoreType(), equalTo(first.getStoreType()));
assertThat(view, equalTo(first));
view = items.get(i++);
assertThat(view.getKey(), equalTo(second.getKey()));
assertThat(view.getName(), equalTo(second.getName()));
assertThat(view.getResourceUri(), equalTo(second.getResourceUri()));
assertThat(view.getStoreKey(), equalTo(second.getStoreKey()));
assertThat(view.getStoreType(), equalTo(second.getStoreType()));
assertThat(view, equalTo(second));
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class TestProvider method setup.
// private Http http;
//
// private IndyLocationExpander locationExpander;
//
// private IndyLocationResolver locationResolver;
@PostConstruct
public void setup() {
storeDataManager = new MemoryStoreDataManager(true);
nfc = new MemoryNotFoundCache();
objectMapper = new IndyObjectMapper(false);
fileEventManager = new NoOpFileEventManager();
transferDecorator = new NoOpTransferDecorator();
transportManagerConfig = new TransportManagerConfig();
temp = new TemporaryFolder();
try {
temp.create();
cacheProvider = new FileCacheProvider(temp.newFolder("storage"), indyPathGenerator, fileEventManager, transferDecorator);
} catch (IOException e) {
fail("Cannot initialize temporary directory structure");
temp.delete();
}
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper 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));
});
});
}
use of org.commonjava.indy.model.core.io.IndyObjectMapper in project indy by Commonjava.
the class RemoteRepositoryTest method serializeRemoteWithKeyPemAndPassword.
@Test
public void serializeRemoteWithKeyPemAndPassword() throws JsonProcessingException {
RemoteRepository remote = new RemoteRepository("test", "http://test.com/repo");
remote.setKeyCertPem("AAAAFFFASDFADSFASDFSADFa");
remote.setKeyPassword("testme");
String json = new IndyObjectMapper(true).writeValueAsString(remote);
System.out.println(json);
}
Aggregations