Search in sources :

Example 1 with SourceDescriptorImpl

use of ddf.catalog.source.impl.SourceDescriptorImpl in project ddf by codice.

the class TestKmlEndpoint method setUp.

@BeforeClass
public static void setUp() throws IOException, URISyntaxException, SourceUnavailableException {
    when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://example.com"));
    URL bomberLocation = TestKmlEndpoint.class.getResource(ICONS_DIR + BOMBER_ICON);
    bomberPath = bomberLocation.getPath().replaceAll(BOMBER_ICON, "");
    bomberBytes = IOUtils.toByteArray(bomberLocation.openStream());
    URL jetLocation = TestKmlEndpoint.class.getResource(TEST_ICONS_DIR + JET_ICON);
    jetPath = jetLocation.getPath().replaceAll(JET_ICON, "");
    jetBtyes = IOUtils.toByteArray(jetLocation.openStream());
    System.setProperty(SystemBaseUrl.HOST, TEST_HOST);
    System.setProperty(SystemBaseUrl.HTTPS_PORT, TEST_PORT);
    System.setProperty(SystemBaseUrl.HTTP_PORT, TEST_PORT);
    System.setProperty(SystemBaseUrl.ROOT_CONTEXT, "/services");
    System.setProperty(SystemInfo.SITE_CONTACT, "example@example.com");
    when(mockFramework.getSourceInfo(any(SourceInfoRequest.class))).thenReturn(mockSourceInfoResponse);
    SourceDescriptorImpl localDescriptor = new SourceDescriptorImpl(LOCAL_SITE_NAME, null);
    SourceDescriptorImpl remoteDescriptor = new SourceDescriptorImpl(REMOTE_SITE_NAME, null);
    descriptors.add(localDescriptor);
    descriptors.add(remoteDescriptor);
    when(mockSourceInfoResponse.getSourceInfo()).thenReturn(descriptors);
    when(mockBranding.getProductName()).thenReturn("PRODUCT 0.0.1");
}
Also used : SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) URI(java.net.URI) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 2 with SourceDescriptorImpl

use of ddf.catalog.source.impl.SourceDescriptorImpl in project ddf by codice.

the class SourceDescriptorComparatorTest method setup.

@Before
public void setup() throws Exception {
    firstSource = new SourceDescriptorImpl("aSource", null, Collections.emptyList());
    nextSource = new SourceDescriptorImpl("bSource", null, Collections.emptyList());
    lastSource = new SourceDescriptorImpl("cSource", null, Collections.emptyList());
    nullSource = new SourceDescriptorImpl(null, null, Collections.emptyList());
}
Also used : SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) Before(org.junit.Before)

Example 3 with SourceDescriptorImpl

use of ddf.catalog.source.impl.SourceDescriptorImpl in project ddf by codice.

the class CatalogServiceImplTest method testGetDocumentSourcesSuccess.

/**
 * Tests getting source information
 */
@Test
@SuppressWarnings({ "unchecked" })
public void testGetDocumentSourcesSuccess() throws Exception {
    final String localSourceId = "local";
    final String fed1SourceId = "fed1";
    final String fed2SourceId = "fed2";
    final String version = "4.0";
    final String jsonMimeTypeString = "application/json";
    Set<ContentType> contentTypes = new HashSet<>();
    contentTypes.add(new ContentTypeImpl("ct1", "v1"));
    contentTypes.add(new ContentTypeImpl("ct2", "v2"));
    contentTypes.add(new ContentTypeImpl("ct3", null));
    JSONArray contentTypesInJSON = new JSONArray();
    for (ContentType ct : contentTypes) {
        JSONObject ob = new JSONObject();
        ob.put("name", ct.getName());
        ob.put("version", ct.getVersion() != null ? ct.getVersion() : "");
        contentTypesInJSON.add(ob);
    }
    Set<SourceDescriptor> sourceDescriptors = new HashSet<>();
    SourceDescriptorImpl localDescriptor = new SourceDescriptorImpl(localSourceId, contentTypes, Collections.emptyList());
    localDescriptor.setVersion(version);
    localDescriptor.setAvailable(true);
    SourceDescriptorImpl fed1Descriptor = new SourceDescriptorImpl(fed1SourceId, contentTypes, Collections.emptyList());
    fed1Descriptor.setVersion(version);
    fed1Descriptor.setAvailable(true);
    SourceDescriptorImpl fed2Descriptor = new SourceDescriptorImpl(fed2SourceId, null, Collections.emptyList());
    fed2Descriptor.setAvailable(true);
    sourceDescriptors.add(localDescriptor);
    sourceDescriptors.add(fed1Descriptor);
    sourceDescriptors.add(fed2Descriptor);
    SourceInfoResponse sourceInfoResponse = new SourceInfoResponseImpl(null, null, sourceDescriptors);
    CatalogFramework framework = mock(CatalogFramework.class);
    when(framework.getSourceInfo(isA(SourceInfoRequestEnterprise.class))).thenReturn(sourceInfoResponse);
    CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry);
    BinaryContent content = catalogService.getSourcesInfo();
    assertEquals(jsonMimeTypeString, content.getMimeTypeValue());
    String responseMessage = IOUtils.toString(content.getInputStream());
    JSONArray srcList = (JSONArray) new JSONParser().parse(responseMessage);
    assertEquals(3, srcList.size());
    for (Object o : srcList) {
        JSONObject src = (JSONObject) o;
        assertEquals(true, src.get("available"));
        String id = (String) src.get("id");
        if (id.equals(localSourceId)) {
            assertThat((Iterable<Object>) src.get("contentTypes"), hasItems(contentTypesInJSON.toArray()));
            assertEquals(contentTypes.size(), ((JSONArray) src.get("contentTypes")).size());
            assertEquals(version, src.get("version"));
        } else if (id.equals(fed1SourceId)) {
            assertThat((Iterable<Object>) src.get("contentTypes"), hasItems(contentTypesInJSON.toArray()));
            assertEquals(contentTypes.size(), ((JSONArray) src.get("contentTypes")).size());
            assertEquals(version, src.get("version"));
        } else if (id.equals(fed2SourceId)) {
            assertEquals(0, ((JSONArray) src.get("contentTypes")).size());
            assertEquals("", src.get("version"));
        } else {
            fail("Invalid ID returned");
        }
    }
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ContentType(ddf.catalog.data.ContentType) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) JSONArray(net.minidev.json.JSONArray) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) JSONObject(net.minidev.json.JSONObject) CatalogFramework(ddf.catalog.CatalogFramework) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) JSONParser(net.minidev.json.parser.JSONParser) JSONObject(net.minidev.json.JSONObject) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SourceDescriptorImpl

use of ddf.catalog.source.impl.SourceDescriptorImpl in project ddf by codice.

the class KmlEndpointTest method setUp.

@BeforeClass
public static void setUp() throws IOException, URISyntaxException, SourceUnavailableException {
    when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://example.com"));
    URL bomberLocation = KmlEndpointTest.class.getResource(ICONS_DIR + BOMBER_ICON);
    bomberPath = bomberLocation.getPath().replaceAll(BOMBER_ICON, "");
    bomberBytes = IOUtils.toByteArray(bomberLocation.openStream());
    URL jetLocation = KmlEndpointTest.class.getResource(TEST_ICONS_DIR + JET_ICON);
    jetPath = jetLocation.getPath().replaceAll(JET_ICON, "");
    jetBtyes = IOUtils.toByteArray(jetLocation.openStream());
    System.setProperty(SystemBaseUrl.EXTERNAL_HOST, TEST_HOST);
    System.setProperty(SystemBaseUrl.EXTERNAL_HTTPS_PORT, TEST_PORT);
    System.setProperty(SystemBaseUrl.EXTERNAL_HTTP_PORT, TEST_PORT);
    System.setProperty(SystemBaseUrl.INTERNAL_ROOT_CONTEXT, "/services");
    System.setProperty(SystemInfo.SITE_CONTACT, "example@example.com");
    when(mockFramework.getSourceInfo(any(SourceInfoRequest.class))).thenReturn(mockSourceInfoResponse);
    SourceDescriptorImpl localDescriptor = new SourceDescriptorImpl(LOCAL_SITE_NAME, null, Collections.emptyList());
    SourceDescriptorImpl remoteDescriptor = new SourceDescriptorImpl(REMOTE_SITE_NAME, null, Collections.emptyList());
    descriptors.add(localDescriptor);
    descriptors.add(remoteDescriptor);
    when(mockSourceInfoResponse.getSourceInfo()).thenReturn(descriptors);
    when(mockBranding.getProductName()).thenReturn("PRODUCT 0.0.1");
}
Also used : SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) URI(java.net.URI) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 5 with SourceDescriptorImpl

use of ddf.catalog.source.impl.SourceDescriptorImpl in project ddf by codice.

the class TestRestEndpoint method testGetDocumentSourcesSuccess.

/**
     * Tests getting source information
     *
     * @throws Exception
     */
@Test
public void testGetDocumentSourcesSuccess() throws Exception {
    final String localSourceId = "local";
    final String fed1SourceId = "fed1";
    final String fed2SourceId = "fed2";
    final String version = "4.0";
    final String jsonMimeTypeString = "application/json";
    Set<ContentType> contentTypes = new HashSet<ContentType>();
    contentTypes.add(new ContentTypeImpl("ct1", "v1"));
    contentTypes.add(new ContentTypeImpl("ct2", "v2"));
    contentTypes.add(new ContentTypeImpl("ct3", null));
    JSONArray contentTypesInJSON = new JSONArray();
    for (ContentType ct : contentTypes) {
        JSONObject ob = new JSONObject();
        ob.put("name", ct.getName());
        ob.put("version", ct.getVersion() != null ? ct.getVersion() : "");
        contentTypesInJSON.add(ob);
    }
    Set<SourceDescriptor> sourceDescriptors = new HashSet<SourceDescriptor>();
    SourceDescriptorImpl localDescriptor = new SourceDescriptorImpl(localSourceId, contentTypes);
    localDescriptor.setVersion(version);
    localDescriptor.setAvailable(true);
    SourceDescriptorImpl fed1Descriptor = new SourceDescriptorImpl(fed1SourceId, contentTypes);
    fed1Descriptor.setVersion(version);
    fed1Descriptor.setAvailable(true);
    SourceDescriptorImpl fed2Descriptor = new SourceDescriptorImpl(fed2SourceId, null);
    fed2Descriptor.setAvailable(true);
    sourceDescriptors.add(localDescriptor);
    sourceDescriptors.add(fed1Descriptor);
    sourceDescriptors.add(fed2Descriptor);
    SourceInfoResponse sourceInfoResponse = new SourceInfoResponseImpl(null, null, sourceDescriptors);
    CatalogFramework framework = mock(CatalogFramework.class);
    when(framework.getSourceInfo(isA(SourceInfoRequestEnterprise.class))).thenReturn(sourceInfoResponse);
    RESTEndpoint restEndpoint = new RESTEndpoint(framework);
    Response response = restEndpoint.getDocument(null, null);
    assertEquals(OK, response.getStatus());
    assertEquals(jsonMimeTypeString, response.getMetadata().get("Content-Type").get(0));
    String responseMessage = IOUtils.toString((ByteArrayInputStream) response.getEntity());
    JSONArray srcList = (JSONArray) new JSONParser().parse(responseMessage);
    assertEquals(3, srcList.size());
    for (Object o : srcList) {
        JSONObject src = (JSONObject) o;
        assertEquals(true, src.get("available"));
        String id = (String) src.get("id");
        if (id.equals(localSourceId)) {
            assertThat((Iterable<Object>) src.get("contentTypes"), hasItems(contentTypesInJSON.toArray()));
            assertEquals(contentTypes.size(), ((JSONArray) src.get("contentTypes")).size());
            assertEquals(version, src.get("version"));
        } else if (id.equals(fed1SourceId)) {
            assertThat((Iterable<Object>) src.get("contentTypes"), hasItems(contentTypesInJSON.toArray()));
            assertEquals(contentTypes.size(), ((JSONArray) src.get("contentTypes")).size());
            assertEquals(version, src.get("version"));
        } else if (id.equals(fed2SourceId)) {
            assertEquals(0, ((JSONArray) src.get("contentTypes")).size());
            assertEquals("", src.get("version"));
        } else {
            fail("Invalid ID returned");
        }
    }
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ContentType(ddf.catalog.data.ContentType) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) JSONArray(net.minidev.json.JSONArray) Matchers.anyString(org.mockito.Matchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) JSONObject(net.minidev.json.JSONObject) CatalogFramework(ddf.catalog.CatalogFramework) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) JSONParser(net.minidev.json.parser.JSONParser) JSONObject(net.minidev.json.JSONObject) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SourceDescriptorImpl (ddf.catalog.source.impl.SourceDescriptorImpl)10 SourceDescriptor (ddf.catalog.source.SourceDescriptor)6 SourceInfoResponseImpl (ddf.catalog.operation.impl.SourceInfoResponseImpl)4 ContentType (ddf.catalog.data.ContentType)3 SourceInfoRequest (ddf.catalog.operation.SourceInfoRequest)3 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)3 SourceDescriptorComparator (ddf.catalog.util.impl.SourceDescriptorComparator)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 CatalogFramework (ddf.catalog.CatalogFramework)2 ContentTypeImpl (ddf.catalog.data.impl.ContentTypeImpl)2 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)2 FederatedSource (ddf.catalog.source.FederatedSource)2 Source (ddf.catalog.source.Source)2 URI (java.net.URI)2 URL (java.net.URL)2 TreeSet (java.util.TreeSet)2 JSONArray (net.minidev.json.JSONArray)2 JSONObject (net.minidev.json.JSONObject)2 JSONParser (net.minidev.json.parser.JSONParser)2