Ejemplo n.º 1
0
  @Test
  public void testOdata() throws Exception {
    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"Loopy\" version=\"1\">\n"
            + "    <model name=\"MarketData\">\n"
            + "        <source name=\"text-connector2\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE G1 (e1 string, e2 integer PRIMARY KEY);\n"
            + "                CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) OPTIONS (UPDATABLE 'true');\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));

    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://*****:*****@mm://localhost:31000;user=user;password=user", null);

    PreparedStatement ps =
        conn.prepareCall(
            "select t.* from xmltable('/*:Edmx/*:DataServices/*:Schema[@Alias=\"MarketData\"]' passing xmlparse(document cast(? as clob))) as t");
    ps.setAsciiStream(1, (InputStream) response.getEntity());

    ResultSet rs = ps.executeQuery();
    rs.next();

    assertEquals(
        ObjectConverterUtil.convertFileToString(
            UnitTestUtil.getTestDataFile("loopy-metadata4-results.txt")),
        rs.getString(1));

    conn.close();

    // try an invalid url
    client = WebClient.create("http://localhost:8080/odata/x/y$metadata");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.invoke("GET", null);
    assertEquals(500, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
Ejemplo n.º 2
0
  @Test
  public void testIsAvailableSubjectExperation() throws Exception {
    when(webclient.invoke(eq("HEAD"), isNull())).thenReturn(response);
    when(mockSecurity.getExpires(subject))
        .thenReturn(new Date(System.currentTimeMillis() + 600000L))
        .thenReturn(new Date(System.currentTimeMillis() + 600000L))
        .thenReturn(new Date());
    sendEvent.setSubject(subject);
    boolean available = false;
    while (!sendEvent.ping()) {}

    long lastPing = sendEvent.getLastPing();
    // sleep incase the test runs too fast we want to make sure their is a time difference
    Thread.sleep(1);
    // run within the expiration period of the assertion
    available = sendEvent.ping();
    assertTrue(available);
    assertEquals(lastPing, sendEvent.getLastPing());
    // sleep incase the test runs too fast we want to make sure their is a time difference
    Thread.sleep(1);
    // run with expired assertion
    available = sendEvent.ping();
    assertTrue(available);
    assertNotEquals(lastPing, sendEvent.getLastPing());
  }
Ejemplo n.º 3
0
  // TEIID-3914 - test the olingo-patch work
  public void testCompositeKeyTimestamp() throws Exception {

    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"northwind\" version=\"1\">\n"
            + "    <model name=\"m\">\n"
            + "        <source name=\"x1\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE x (a string, b timestamp, c integer, primary key (a, b)) options (updatable true);\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));
    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://localhost:8080/odata4/m/x(a='a',b=2011-09-11T00:00:00Z)");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    Response response = client.invoke("GET", null);
    assertEquals(200, response.getStatus());

    client = WebClient.create("http://localhost:8080/odata4/m/x");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.post("{\"a\":\"b\", \"b\":\"2000-02-02T22:22:22Z\"}");
    assertEquals(204, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
Ejemplo n.º 4
0
  @Before
  public void setUp() throws Exception {
    System.setProperty("ddf.home", ".");
    callbackURI = new URL("https://localhost:12345/services/csw/subscription/event");
    ObjectFactory objectFactory = new ObjectFactory();
    request = new GetRecordsType();
    request.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    request.setResultType(ResultType.RESULTS);
    request.getResponseHandler().add(callbackURI.toString());
    queryType = new QueryType();
    elementSetNameType = new ElementSetNameType();
    elementSetNameType.setValue(ElementSetType.BRIEF);
    queryType.setElementSetName(elementSetNameType);
    request.setAbstractQuery(objectFactory.createAbstractQuery(queryType));
    transformerManager = mock(TransformerManager.class);
    transformer = mock(QueryResponseTransformer.class);
    binaryContent = mock(BinaryContent.class);
    when(transformerManager.getTransformerBySchema(
            Matchers.contains(CswConstants.CSW_OUTPUT_SCHEMA)))
        .thenReturn(transformer);
    when(transformer.transform(any(SourceResponse.class), anyMap())).thenReturn(binaryContent);
    when(binaryContent.getByteArray()).thenReturn("byte array with message contents".getBytes());
    query = mock(QueryRequest.class);

    metacard = mock(Metacard.class);
    webclient = mock(WebClient.class);
    mockCxfClientFactory = mock(SecureCxfClientFactory.class);
    response = mock(Response.class);
    subject = mock(Subject.class);

    mockSecurity = mock(Security.class);
    headers.put(Subject.class.toString(), Arrays.asList(new Subject[] {subject}));
    AccessPlugin accessPlugin = mock(AccessPlugin.class);
    accessPlugins.add(accessPlugin);
    when(mockCxfClientFactory.getWebClient()).thenReturn(webclient);
    //        when(webclient.head()).thenReturn(response);
    when(webclient.invoke(anyString(), any(QueryResponse.class))).thenReturn(response);
    when(response.getHeaders()).thenReturn(headers);
    when(accessPlugin.processPostQuery(any(QueryResponse.class)))
        .thenAnswer(
            new Answer<QueryResponse>() {
              @Override
              public QueryResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
                return (QueryResponse) invocationOnMock.getArguments()[0];
              }
            });

    sendEvent = new SendEventExtension(transformerManager, request, query, mockCxfClientFactory);
    sendEvent.setSubject(subject);
  }
Ejemplo n.º 5
0
  @Test
  public void testIsAvailableNoExperation() throws Exception {
    long lastPing = sendEvent.getLastPing();
    when(webclient.invoke(eq("HEAD"), isNull())).thenReturn(response);
    boolean available = false;
    while (!sendEvent.ping()) {}

    assertNotEquals(lastPing, sendEvent.getLastPing());
    lastPing = sendEvent.getLastPing();
    Thread.sleep(1);
    // run within the expiration period of the assertion
    available = sendEvent.ping();
    assertTrue(available);
    assertEquals(lastPing, sendEvent.getLastPing());
  }
Ejemplo n.º 6
0
  private Response sendEvent(String operation, Metacard... metacards) {
    try {
      List<Result> results =
          Arrays.asList(metacards).stream().map(ResultImpl::new).collect(Collectors.toList());

      SourceResponse queryResponse = new QueryResponseImpl(query, results, true, metacards.length);

      LOGGER.debug(
          "Attempting to transform an Event with mime-type: {} & outputSchema: {}",
          mimeType,
          outputSchema);

      QueryResponseTransformer transformer;
      Map<String, Serializable> arguments = new HashMap<>();
      if (StringUtils.isBlank(outputSchema)
          && StringUtils.isNotBlank(mimeType)
          && !XML_MIME_TYPES.contains(mimeType)) {
        transformer = transformerManager.getTransformerByMimeType(mimeType);
      } else {
        transformer = transformerManager.getTransformerBySchema(CswConstants.CSW_OUTPUT_SCHEMA);
        if (elementName != null) {
          arguments.put(CswConstants.ELEMENT_NAMES, elementName.toArray());
        }
        arguments.put(CswConstants.OUTPUT_SCHEMA_PARAMETER, outputSchema);
        arguments.put(CswConstants.ELEMENT_SET_TYPE, elementSetType);
        arguments.put(CswConstants.IS_BY_ID_QUERY, false);
        arguments.put(CswConstants.GET_RECORDS, request);
        arguments.put(CswConstants.RESULT_TYPE_PARAMETER, resultType);
        arguments.put(CswConstants.WRITE_NAMESPACES, false);
      }
      if (transformer == null) {
        throw new WebApplicationException(
            new CatalogTransformerException("Unable to locate Transformer."));
      }

      BinaryContent binaryContent = transformer.transform(queryResponse, arguments);

      if (binaryContent == null) {
        throw new WebApplicationException(
            new CatalogTransformerException("Transformer returned null."));
      }

      return webClient.invoke(operation, binaryContent.getByteArray());
    } catch (IOException | CatalogTransformerException | RuntimeException e) {
      LOGGER.error("Error sending event to {}.", callbackUrl, e);
    }
    return null;
  }
Ejemplo n.º 7
0
 @Test
 public void testIsAvailableRetryBackoff() throws Exception {
   when(webclient.invoke(eq("HEAD"), isNull())).thenThrow(new RuntimeException("test"));
   sendEvent.setSubject(subject);
   long lastPing = sendEvent.getLastPing();
   boolean available = true;
   // loop until we get to a backoff that will be long enough not to cause intermitent test
   // failures
   while (sendEvent.getRetryCount() < 7) {
     available = sendEvent.ping();
   }
   assertFalse(available);
   assertNotEquals(lastPing, sendEvent.getLastPing());
   lastPing = sendEvent.getLastPing();
   Thread.sleep(1);
   // run again this time within a backoff period and verify that it doesn't retry this is
   available = sendEvent.ping();
   assertFalse(available);
   assertEquals(7, sendEvent.getRetryCount());
   assertEquals(lastPing, sendEvent.getLastPing());
 }