@Test
  public void testCall() {
    List<Context> contextList =
        Arrays.asList(
            Context.create().with("cacheManagerName", "myCM1").with("cacheName", "aCache1"),
            Context.create().with("cacheManagerName", "myCM1").with("cacheName", "aCache4"),
            Context.create().with("cacheManagerName", "myCM2").with("cacheName", "aCache2"),
            Context.create().with("cacheManagerName", "myCM55").with("cacheName", "aCache55"));

    cacheManager1.getCache("aCache1", Long.class, String.class).put(1L, "1");
    cacheManager2.getCache("aCache2", Long.class, String.class).put(2L, "2");

    assertThat(cacheManager1.getCache("aCache1", Long.class, String.class).get(1L), equalTo("1"));
    assertThat(cacheManager2.getCache("aCache2", Long.class, String.class).get(2L), equalTo("2"));

    CacheConfiguration<Long, String> cacheConfiguration =
        CacheConfigurationBuilder.newCacheConfigurationBuilder()
            .withResourcePools(
                ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).build())
            .buildConfig(Long.class, String.class);
    cacheManager1.createCache("aCache4", cacheConfiguration);

    cacheManager1.getCache("aCache4", Long.class, String.class).put(4L, "4");
    assertThat(cacheManager1.getCache("aCache4", Long.class, String.class).get(4L), equalTo("4"));

    ResultSet<ContextualReturn<Void>> results =
        service.withCapability("ActionsCapability").call("clear").on(contextList).build().execute();

    assertThat(results.size(), Matchers.equalTo(4));

    assertThat(results.getResult(contextList.get(0)).hasValue(), is(true));
    assertThat(results.getResult(contextList.get(1)).hasValue(), is(true));
    assertThat(results.getResult(contextList.get(2)).hasValue(), is(true));
    assertThat(results.getResult(contextList.get(3)).hasValue(), is(false));

    assertThat(results.getResult(contextList.get(0)).getValue(), is(nullValue()));
    assertThat(results.getResult(contextList.get(1)).getValue(), is(nullValue()));
    assertThat(results.getResult(contextList.get(2)).getValue(), is(nullValue()));

    try {
      results.getResult(contextList.get(3)).getValue();
      fail();
    } catch (Exception e) {
      assertThat(e, instanceOf(NoSuchElementException.class));
    }

    assertThat(
        cacheManager1.getCache("aCache1", Long.class, String.class).get(1L),
        is(Matchers.nullValue()));
    assertThat(
        cacheManager2.getCache("aCache2", Long.class, String.class).get(2L),
        is(Matchers.nullValue()));
    assertThat(
        cacheManager1.getCache("aCache4", Long.class, String.class).get(4L),
        is(Matchers.nullValue()));
  }
Ejemplo n.º 2
0
  @Test
  public void testGetByIdOrNull() throws Exception {
    assertThat(service.getByIdOrNull(new TransUnitId(2)), Matchers.equalTo(data.get(1)));

    // not in current page
    assertThat(service.getByIdOrNull(new TransUnitId(99)), Matchers.nullValue());
  }
Ejemplo n.º 3
0
 @Test(expected = NoSuchDaleqFieldException.class)
 public void getValuesOfField_ifFieldDoesNotExist_sould_fail() {
   final TableData table =
       Daleq.aTable(TheTable.class).withRowsUntil(5).build(new SimpleContext());
   final Iterable<Optional<String>> result = table.getValuesOfField("DOES_NOT_EXIST");
   // should have failed
   assertThat(result, Matchers.nullValue());
 }
  @Test
  public void testGetWorkflowInstanceMetadata2() throws Exception {
    WorkflowInstance wf = (WorkflowInstance) fmc.getFirstPage().getPageWorkflows().get(0);

    assertThat(wf, is(not(Matchers.nullValue())));

    Metadata meta = fmc.getWorkflowInstanceMetadata(wf.getId());

    assertNotNull(meta);
  }
Ejemplo n.º 5
0
  @Test
  public void testGetSelectedOrNull() throws Exception {
    service.init(initContext);

    assertThat(service.getSelectedOrNull(), Matchers.nullValue());

    service.selectByRowIndex(1);

    assertThat(service.getSelectedOrNull(), Matchers.equalTo(data.get(1)));
  }
  @Test
  public void testGetWorkflowCurrentTaskWallClockMinutes() throws Exception {
    XmlRpcWorkflowManagerClient fmc =
        new XmlRpcWorkflowManagerClient(new URL("http://localhost:" + WM_PORT));

    List<WorkflowInstance> wfinstances = fmc.getWorkflowInstances();

    assertNotNull(wfinstances);

    double clock = fmc.getWorkflowCurrentTaskWallClockMinutes(wfinstances.get(0).getId());

    assertThat(clock, is(not(Matchers.nullValue())));
  }
Ejemplo n.º 7
0
 @Test
 public void adhocIMChat4() {
   Setup.startTest("Checking no further IM notifications for user 2 ");
   String url = (Setup.channelURL[2].split("username\\=")[0]) + "username="******"notificationList", Matchers.nullValue())
           .post(url);
   System.out.println(
       "Response = " + notifications2.getStatusCode() + " / " + notifications2.asString());
   Setup.endTest();
 }
  @Test
  public void testAdocParsing() throws Exception {
    FXPlatform.invokeLater(() -> adocEditor.editor.setText("= Title\n== more"));
    FXPlatform.invokeLater(() -> adocEditor.tabPane.getSelectionModel().select(1));
    JunitMatchers.withRetry(() -> adocEditor.preview.getCurrentHtml() != null);
    assertNotNull("preview string is null", adocEditor.preview.getCurrentHtml());

    WebEngine engine = adocEditor.preview.getWebView().getEngine();
    JunitMatchers.withRetry(() -> adocEditor.preview.getWebView().getEngine() != null);
    Condition.waitFor5s(() -> engine.getDocument(), Matchers.nullValue());

    FXPlatform.invokeLater(() -> adocEditor.tabPane.getSelectionModel().select(1));
    JunitMatchers.withRetry(() -> engine.getDocument() != null);
    assertNotNull("document did not load, is still null", engine.getDocument());

    FXPlatform.invokeLater(() -> adocEditor.tabPane.getSelectionModel().select(0));
    FXPlatform.waitForFX();
    //    assertTrue(adocEditor.editor.isFocused()); FIXME doesn't work in jdk8u11 but jdk8u20
  }
  @Test
  public void testCall() {
    CacheConfiguration<Long, String> cacheConfiguration =
        CacheConfigurationBuilder.newCacheConfigurationBuilder()
            .withResourcePools(
                ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).build())
            .buildConfig(Long.class, String.class);

    ManagementRegistry managementRegistry =
        new DefaultManagementRegistry(
            new DefaultManagementRegistryConfiguration().setCacheManagerAlias("myCM"));

    CacheManager cacheManager1 =
        CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("aCache1", cacheConfiguration)
            .withCache("aCache2", cacheConfiguration)
            .using(managementRegistry)
            .build(true);

    Map<String, String> context =
        new HashMap<String, String>() {
          {
            put("cacheManagerName", "myCM");
            put("cacheName", "aCache1");
          }
        };

    cacheManager1.getCache("aCache1", Long.class, String.class).put(1L, "1");

    assertThat(cacheManager1.getCache("aCache1", Long.class, String.class).get(1L), equalTo("1"));

    Object result =
        managementRegistry.callAction(
            context, "ActionsCapability", "clear", new String[0], new Object[0]);
    assertThat(result, is(nullValue()));

    assertThat(
        cacheManager1.getCache("aCache1", Long.class, String.class).get(1L),
        is(Matchers.nullValue()));
  }
Ejemplo n.º 10
0
  @Test
  public void testParentRelationship() throws Exception {
    GcsPath path = GcsPath.fromComponents("bucket", "then/object");
    assertEquals("bucket", path.getBucket());
    assertEquals("then/object", path.getObject());
    assertEquals(3, path.getNameCount());
    assertTrue(path.endsWith("object"));
    assertTrue(path.startsWith("bucket/then"));

    GcsPath parent = path.getParent(); // gs://bucket/then/
    assertEquals("bucket", parent.getBucket());
    assertEquals("then/", parent.getObject());
    assertEquals(2, parent.getNameCount());
    assertThat(path, Matchers.not(Matchers.equalTo(parent)));
    assertTrue(path.startsWith(parent));
    assertFalse(parent.startsWith(path));
    assertTrue(parent.endsWith("then/"));
    assertTrue(parent.startsWith("bucket/then"));
    assertTrue(parent.isAbsolute());

    GcsPath root = path.getRoot();
    assertEquals(0, root.getNameCount());
    assertEquals("gs://", root.toString());
    assertEquals("", root.getBucket());
    assertEquals("", root.getObject());
    assertTrue(root.isAbsolute());
    assertThat(root, Matchers.equalTo(parent.getRoot()));

    GcsPath grandParent = parent.getParent(); // gs://bucket/
    assertEquals(1, grandParent.getNameCount());
    assertEquals("gs://bucket/", grandParent.toString());
    assertTrue(grandParent.isAbsolute());
    assertThat(root, Matchers.equalTo(grandParent.getParent()));
    assertThat(root.getParent(), Matchers.nullValue());

    assertTrue(path.startsWith(path.getRoot()));
    assertTrue(parent.startsWith(path.getRoot()));
  }
 /** ImmutabilityChecker should check recursive classes. */
 @Test
 public void checksRecursiveClasses() {
   MatcherAssert.assertThat(new Recursive(null).getNext(), Matchers.nullValue());
 }
 /** Assert there is no content at the underlying JSON path. */
 public ResultMatcher doesNotExist() {
   return result(Matchers.nullValue());
 }
  private void checkAllInfo(
      int numDocs,
      String[] values,
      int[] freq,
      int[][] pos,
      int[][] startOffset,
      int[][] endOffset,
      int i)
      throws IOException {
    TermVectorsRequestBuilder resp =
        client()
            .prepareTermVectors("test", "type1", Integer.toString(i))
            .setPayloads(true)
            .setOffsets(true)
            .setPositions(true)
            .setFieldStatistics(true)
            .setTermStatistics(true)
            .setSelectedFields();
    assertThat(resp.request().fieldStatistics(), equalTo(true));
    TermVectorsResponse response = resp.execute().actionGet();
    assertThat("doc id: " + i + " doesn't exists but should", response.isExists(), equalTo(true));
    Fields fields = response.getFields();
    assertThat(fields.size(), equalTo(1));
    Terms terms = fields.terms("field");
    assertThat(terms.size(), equalTo(8l));
    assertThat(terms.getSumTotalTermFreq(), Matchers.equalTo((long) (9 * numDocs)));
    assertThat(terms.getDocCount(), Matchers.equalTo(numDocs));
    assertThat(terms.getSumDocFreq(), equalTo((long) numDocs * values.length));
    TermsEnum iterator = terms.iterator();
    for (int j = 0; j < values.length; j++) {
      String string = values[j];
      BytesRef next = iterator.next();
      assertThat(next, Matchers.notNullValue());
      assertThat("expected " + string, string, equalTo(next.utf8ToString()));
      assertThat(next, Matchers.notNullValue());
      if (string.equals("the")) {
        assertThat(
            "expected ttf of " + string, numDocs * 2, equalTo((int) iterator.totalTermFreq()));
      } else {
        assertThat("expected ttf of " + string, numDocs, equalTo((int) iterator.totalTermFreq()));
      }

      PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
      assertThat(docsAndPositions.nextDoc(), equalTo(0));
      assertThat(freq[j], equalTo(docsAndPositions.freq()));
      assertThat(iterator.docFreq(), equalTo(numDocs));
      int[] termPos = pos[j];
      int[] termStartOffset = startOffset[j];
      int[] termEndOffset = endOffset[j];
      assertThat(termPos.length, equalTo(freq[j]));
      assertThat(termStartOffset.length, equalTo(freq[j]));
      assertThat(termEndOffset.length, equalTo(freq[j]));
      for (int k = 0; k < freq[j]; k++) {
        int nextPosition = docsAndPositions.nextPosition();
        assertThat("term: " + string, nextPosition, equalTo(termPos[k]));
        assertThat("term: " + string, docsAndPositions.startOffset(), equalTo(termStartOffset[k]));
        assertThat("term: " + string, docsAndPositions.endOffset(), equalTo(termEndOffset[k]));
        assertThat("term: " + string, docsAndPositions.getPayload(), equalTo(new BytesRef("word")));
      }
    }
    assertThat(iterator.next(), Matchers.nullValue());

    XContentBuilder xBuilder = XContentFactory.jsonBuilder();
    xBuilder.startObject();
    response.toXContent(xBuilder, ToXContent.EMPTY_PARAMS);
    xBuilder.endObject();
    BytesStream bytesStream = xBuilder.bytesStream();
    String utf8 = bytesStream.bytes().toUtf8().replaceFirst("\"took\":\\d+,", "");
    ;
    String expectedString =
        "{\"_index\":\"test\",\"_type\":\"type1\",\"_id\":\""
            + i
            + "\",\"_version\":1,\"found\":true,\"term_vectors\":{\"field\":{\"field_statistics\":{\"sum_doc_freq\":120,\"doc_count\":15,\"sum_ttf\":135},\"terms\":{\"brown\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":2,\"start_offset\":10,\"end_offset\":15,\"payload\":\"d29yZA==\"}]},\"dog\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":8,\"start_offset\":40,\"end_offset\":43,\"payload\":\"d29yZA==\"}]},\"fox\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":3,\"start_offset\":16,\"end_offset\":19,\"payload\":\"d29yZA==\"}]},\"jumps\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":4,\"start_offset\":20,\"end_offset\":25,\"payload\":\"d29yZA==\"}]},\"lazy\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":7,\"start_offset\":35,\"end_offset\":39,\"payload\":\"d29yZA==\"}]},\"over\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":5,\"start_offset\":26,\"end_offset\":30,\"payload\":\"d29yZA==\"}]},\"quick\":{\"doc_freq\":15,\"ttf\":15,\"term_freq\":1,\"tokens\":[{\"position\":1,\"start_offset\":4,\"end_offset\":9,\"payload\":\"d29yZA==\"}]},\"the\":{\"doc_freq\":15,\"ttf\":30,\"term_freq\":2,\"tokens\":[{\"position\":0,\"start_offset\":0,\"end_offset\":3,\"payload\":\"d29yZA==\"},{\"position\":6,\"start_offset\":31,\"end_offset\":34,\"payload\":\"d29yZA==\"}]}}}}}";
    assertThat(utf8, equalTo(expectedString));
  }