Search in sources :

Example 66 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestRestEndpoint method testAddDocumentNullMessage.

@Test(expected = ServerErrorException.class)
public void testAddDocumentNullMessage() {
    CatalogFramework framework = mock(CatalogFramework.class);
    RESTEndpoint rest = new RESTEndpoint(framework);
    HttpHeaders headers = mock(HttpHeaders.class);
    rest.addDocument(headers, mock(UriInfo.class), mock(HttpServletRequest.class), mock(MultipartBody.class), null, null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHeaders(javax.ws.rs.core.HttpHeaders) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) CatalogFramework(ddf.catalog.CatalogFramework) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 67 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestRestEndpoint method testGetDocumentLocalNullQueryResponse.

/**
     * Tests local retrieve with a null QueryResponse
     *
     * @throws Exception
     */
@Test(expected = ServerErrorException.class)
public void testGetDocumentLocalNullQueryResponse() throws Exception {
    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
    String transformer = mockTestSetup(framework, TestType.QUERY_RESPONSE_TEST);
    executeTest(framework, transformer, true, null);
}
Also used : CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 68 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestRestEndpoint method testGetDocumentResourceFedSuccess.

/**
     * Tests retrieving a federated resource with a successful response
     *
     * @throws Exception
     */
@Test
public void testGetDocumentResourceFedSuccess() throws Exception {
    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
    String transformer = mockTestSetup(framework, TestType.RESOURCE_TEST);
    Response response = executeTest(framework, transformer, false, null);
    String responseMessage = IOUtils.toString((ByteArrayInputStream) response.getEntity());
    assertEquals(GET_STREAM, responseMessage);
    assertEquals(OK, response.getStatus());
    assertEquals(GET_TYPE_OUTPUT, response.getMetadata().toString());
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 69 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestRestEndpoint method testGetDocumentResourceLocalSuccess.

/**
     * Tests retrieving a local resource with a successful response
     *
     * @throws Exception
     */
@Test
public void testGetDocumentResourceLocalSuccess() throws Exception {
    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
    String transformer = mockTestSetup(framework, TestType.RESOURCE_TEST);
    Response response = executeTest(framework, transformer, true, null);
    String responseMessage = IOUtils.toString((ByteArrayInputStream) response.getEntity());
    assertEquals(GET_STREAM, responseMessage);
    assertEquals(OK, response.getStatus());
    assertEquals(GET_TYPE_OUTPUT, response.getMetadata().toString());
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 70 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestRestEndpoint method headTest.

private Response headTest(boolean local) throws CatalogTransformerException, URISyntaxException, UnsupportedEncodingException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    MetacardImpl metacard = null;
    List<Result> list = new ArrayList<Result>();
    Result result = mock(Result.class);
    InputStream inputStream = null;
    UriInfo uriInfo;
    Response response;
    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
    list.add(result);
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(list);
    when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).thenReturn(queryResponse);
    metacard = new MetacardImpl();
    metacard.setSourceId(GET_SITENAME);
    when(result.getMetacard()).thenReturn(metacard);
    Resource resource = mock(Resource.class);
    inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
    when(resource.getInputStream()).thenReturn(inputStream);
    when(resource.getMimeTypeValue()).thenReturn(GET_MIME_TYPE);
    when(resource.getName()).thenReturn(GET_FILENAME);
    when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(resource);
    RESTEndpoint restEndpoint = new RESTEndpoint(framework);
    restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    restEndpoint.setFilterBuilder(filterBuilder);
    uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
    if (local) {
        response = restEndpoint.getHeaders(GET_ID, uriInfo, null);
    } else {
        response = restEndpoint.getHeaders(null, GET_ID, uriInfo, null);
    }
    return response;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) FederationStrategy(ddf.catalog.federation.FederationStrategy) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) TikaMimeTypeResolver(ddf.mime.tika.TikaMimeTypeResolver) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CatalogFramework(ddf.catalog.CatalogFramework) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) UriInfo(javax.ws.rs.core.UriInfo)

Aggregations

CatalogFramework (ddf.catalog.CatalogFramework)80 Test (org.junit.Test)63 Matchers.anyString (org.mockito.Matchers.anyString)30 Metacard (ddf.catalog.data.Metacard)27 QueryResponse (ddf.catalog.operation.QueryResponse)20 ArrayList (java.util.ArrayList)20 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 Serializable (java.io.Serializable)18 ContentType (ddf.catalog.data.ContentType)17 URI (java.net.URI)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 HashMap (java.util.HashMap)14 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)12 Date (java.util.Date)12 BundleContext (org.osgi.framework.BundleContext)11 MimeType (javax.activation.MimeType)10 Response (javax.ws.rs.core.Response)10 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)9 ServiceReference (org.osgi.framework.ServiceReference)9 FilterBuilder (ddf.catalog.filter.FilterBuilder)8