Search in sources :

Example 21 with IndyObjectMapper

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()));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 22 with IndyObjectMapper

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));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 23 with IndyObjectMapper

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();
    }
}
Also used : FileCacheProvider(org.commonjava.maven.galley.cache.FileCacheProvider) NoOpFileEventManager(org.commonjava.maven.galley.event.NoOpFileEventManager) NoOpTransferDecorator(org.commonjava.maven.galley.io.NoOpTransferDecorator) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) TemporaryFolder(org.junit.rules.TemporaryFolder) TransportManagerConfig(org.commonjava.maven.galley.config.TransportManagerConfig) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Example 24 with IndyObjectMapper

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));
        });
    });
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 25 with IndyObjectMapper

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);
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

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