public static JpegInputTransformer createTransformer()
      throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    JpegInputTransformer transformer = new JpegInputTransformer();
    ddf.catalog.CatalogFramework catalog = mock(ddf.catalog.CatalogFramework.class);
    when(catalog.query(any(QueryRequest.class)))
        .thenReturn(new QueryResponseImpl(null, "sourceId"));
    transformer.setCatalog(catalog);

    return transformer;
  }
  @Test
  /** Operation: DELETE Body contains: 12345678900987654321abcdeffedcba */
  public void testDeleteWithIngestException() throws Exception {
    resetMocks();

    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);

    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);

    // setup mock catalog framework
    final String[] metacardIds = new String[metacards.size()];
    for (int i = 0; i < metacards.size(); i++) {
      metacardIds[i] = metacards.get(i).getId();
    }

    DeleteRequest deleteRequest = new DeleteRequestImpl(metacardIds);
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap(), metacards);
    when(catalogFramework.delete(any(DeleteRequest.class))).thenThrow(new IngestException());

    // Exercise the route with a DELETE operation
    template.sendBodyAndHeader("direct:sampleInput", metacardIds, "Operation", "DELETE");

    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Update> cardsDeleted = (List<Update>) exchange.getIn().getBody();
    assertListSize(cardsDeleted, 0);

    mockVerifierEndpoint.assertIsSatisfied();
  }
  @Test
  /** Operation: CREATE Body contains: Metacard */
  public void testCreateWithIngestException() throws Exception {
    resetMocks();

    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);

    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);

    // Mock catalog framework
    final CreateRequest createRequest = new CreateRequestImpl(metacards);
    final CreateResponse createResponse =
        new CreateResponseImpl(createRequest, new HashMap(), metacards);
    when(catalogFramework.create(any(CreateRequest.class))).thenThrow(new IngestException());

    // Exercise the route with a CREATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "CREATE");

    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Metacard> cardsCreated = (List<Metacard>) exchange.getIn().getBody();
    assertListSize(cardsCreated, 0);

    mockVerifierEndpoint.assertIsSatisfied();
  }
示例#4
0
 private void store(List<Metacard> metacards) throws PluginExecutionException {
   try {
     catalogFramework.create(new CreateRequestImpl(metacards));
   } catch (SourceUnavailableException | IngestException e) {
     throw new PluginExecutionException(e);
   }
 }
示例#5
0
  /**
   * Creates a list of {@link NetworkLink}s, one for each {@link ddf.catalog.source.Source}
   * including the local catalog.
   *
   * @param uriInfo - injected resource provding the URI.
   * @return - {@link Kml} containing a folder of {@link NetworkLink}s.
   */
  @GET
  @Path(FORWARD_SLASH + "sources")
  @Produces(KML_MIME_TYPE)
  public Kml getAvailableSources(@Context UriInfo uriInfo) {
    try {
      SourceInfoResponse response = framework.getSourceInfo(new SourceInfoRequestEnterprise(false));

      Kml kml = KmlFactory.createKml();
      Folder folder = kml.createAndSetFolder();
      folder.setOpen(true);
      for (SourceDescriptor descriptor : response.getSourceInfo()) {
        UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
        builder =
            generateEndpointUrl(
                servicesContextRoot
                    + FORWARD_SLASH
                    + CATALOG_URL_PATH
                    + FORWARD_SLASH
                    + OPENSEARCH_URL_PATH,
                builder);
        builder = builder.queryParam(SOURCE_PARAM, descriptor.getSourceId());
        builder = builder.queryParam(OPENSEARCH_SORT_KEY, OPENSEARCH_DEFAULT_SORT);
        builder = builder.queryParam(OPENSEARCH_FORMAT_KEY, KML_TRANSFORM_PARAM);
        NetworkLink networkLink =
            generateViewBasedNetworkLink(builder.build().toURL(), descriptor.getSourceId());
        folder.getFeature().add(networkLink);
      }

      return kml;
    } catch (SourceUnavailableException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (UnknownHostException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (MalformedURLException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (IllegalArgumentException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (UriBuilderException e) {
      throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
  }
  @Test
  /** Operation: UPDATE Body contains: Metacard */
  public void testUpdateWithSingleMetacard() throws Exception {
    resetMocks();

    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);

    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);

    // setup mock catalog framework
    final Update update = new UpdateImpl(metacard1, metacard2);
    List<Update> updates = new ArrayList<Update>();
    updates.add(update);

    final String[] metacardIds = new String[metacards.size()];
    for (int i = 0; i < metacards.size(); i++) {
      metacardIds[i] = metacards.get(i).getId();
    }

    UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacards);
    UpdateResponse updateResponse = new UpdateResponseImpl(updateRequest, new HashMap(), updates);
    when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse);

    // Exercise the route with a UPDATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "UPDATE");

    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Update> cardsUpdated = (List<Update>) exchange.getIn().getBody();
    assertListSize(cardsUpdated, 1);

    mockVerifierEndpoint.assertIsSatisfied();
  }
  /**
   * Test method for {@link
   * org.codice.ddf.endpoints.OpenSearchEndpoint#processQuery(java.lang.String, java.lang.String,
   * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
   * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
   * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
   * java.lang.String, javax.ws.rs.core.UriInfo, java.lang.String, java.lang.String)} .
   *
   * <p>This test will verify that the string "local" in the sources passed to
   * OpenSearchEndpoint.processQuery is replaced with the local site name (in this case the mocked
   * name "TestSiteName"). The QueryRequest object is checked when the framework.query is called to
   * retrieve the OpenSearchQuery, which contains the Set of sites. An assertion within the Answer
   * object for the call framework.query checks that the sites Set is contains the TEST_SITE_NAME.
   *
   * @throws URISyntaxException
   * @throws FederationException
   * @throws SourceUnavailableException
   * @throws UnsupportedQueryException
   * @throws UnsupportedEncodingException
   * @throws CatalogTransformerException
   */
  @SuppressWarnings("unchecked")
  @Test
  public void testProcessQueryForProperHandlingOfSiteNameLOCAL()
      throws URISyntaxException, UnsupportedQueryException, SourceUnavailableException,
          FederationException, UnsupportedEncodingException, CatalogTransformerException {

    // ***Test setup***
    final String TEST_SITE_NAME = "TestSiteName";

    CatalogFramework mockFramework = mock(CatalogFramework.class);
    FilterBuilder mockFilterBuilder = mock(FilterBuilder.class);

    AttributeBuilder mockAB = mock(AttributeBuilder.class);
    ExpressionBuilder mockEB = mock(ExpressionBuilder.class);
    ContextualExpressionBuilder mockCEB = mock(ContextualExpressionBuilder.class);
    Filter mockFilter = mock(Filter.class);

    when(mockFilterBuilder.attribute(anyString())).thenReturn(mockAB);
    when(mockAB.is()).thenReturn(mockEB);
    when(mockEB.like()).thenReturn(mockCEB);
    when(mockCEB.text(anyString())).thenReturn(mockFilter);

    String searchTerms = "searchForThis";

    // "local" MUST be included
    String sources = "test, local";
    String count = "200";

    // dummy UriInfo, not really used functionally
    UriInfo mockUriInfo = mock(UriInfo.class);
    URI uri = new URI("test");
    when(mockUriInfo.getRequestUri()).thenReturn(uri);

    MultivaluedMap<String, String> mockMVMap = mock(MultivaluedMap.class);
    when(mockMVMap.get("subscription")).thenReturn(null);
    when(mockMVMap.get("interval")).thenReturn(null);
    when(mockUriInfo.getQueryParameters()).thenReturn(mockMVMap);

    @SuppressWarnings("unused")
    BinaryContent mockByteContent = mock(BinaryContent.class);

    // Check on the sites passed in to framework.query
    when(mockFramework.query(any(QueryRequest.class)))
        .thenAnswer(
            new Answer<Object>() {
              public Object answer(InvocationOnMock invocation) {
                QueryRequest queryRequest = (QueryRequest) invocation.getArguments()[0];

                // ***Test verification***
                // This assert is the whole point of this unit test
                Assert.assertTrue(
                    ((OpenSearchQuery) queryRequest.getQuery())
                        .getSiteIds()
                        .contains(TEST_SITE_NAME));

                return new QueryResponseImpl(queryRequest);
              }
            });

    // setup the BinaryContent for the call to Response.ok(...)
    // This is just needed to get the method to complete, the
    BinaryContent mockBinaryContent = mock(BinaryContent.class);
    InputStream is = new ByteArrayInputStream("Test String From InputStream".getBytes("UTF-8"));
    when(mockBinaryContent.getInputStream()).thenReturn(is);
    when(mockBinaryContent.getMimeTypeValue()).thenReturn("text/plain");

    when(mockFramework.transform(any(QueryResponse.class), anyString(), anyMap()))
        .thenReturn(mockBinaryContent);

    OpenSearchEndpoint osEndPoint = new OpenSearchEndpoint(mockFramework, mockFilterBuilder);

    // Call ddfConfigurationUpdated to set the id values to the site name we want
    // local to be replaced with
    Map<String, String> ddfProperties = new HashMap<String, String>();
    ddfProperties.put("id", TEST_SITE_NAME);
    osEndPoint.configurationUpdateCallback(ddfProperties);

    // ***Test Execution***
    osEndPoint.processQuery(
        searchTerms,
        null,
        sources,
        null,
        null,
        count,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        mockUriInfo,
        null,
        null,
        null);
  }