示例#1
0
  @Test
  public void shouldSkipMotechPropertyThatHasJsonObjectAsValue() {
    MotechProperties motechProperties =
        (MotechProperties)
            reader.readFromFile("/complex-motech-properties.json", MotechProperties.class);

    assertThat(motechProperties.size(), IsEqual.equalTo(5));
    assertThat(motechProperties, not(Matchers.hasKey("edd")));
    assertThat(motechProperties, not(Matchers.hasKey("next_due")));
    assertThat(motechProperties, not(Matchers.hasKey("next_form")));
    assertThat(motechProperties, not(Matchers.hasKey("partner_name")));
    assertThat(motechProperties, not(Matchers.hasKey("village")));
  }
 /**
  * ArrayMap can make a map fluently.
  *
  * @throws Exception If some problem inside
  */
 @Test
 public void buildsMapFluently() throws Exception {
   MatcherAssert.assertThat(
       new ArrayMap<Integer, String>()
           .with(Tv.FIVE, "four")
           .with(Tv.FIVE, Integer.toString(Tv.FIVE))
           .with(Tv.FORTY, "fourty")
           .without(Tv.FORTY)
           .with(Tv.TEN, "ten"),
       Matchers.allOf(
           Matchers.not(Matchers.hasKey(Tv.FORTY)),
           Matchers.hasValue(Integer.toString(Tv.FIVE)),
           Matchers.hasKey(Tv.FIVE),
           Matchers.hasEntry(Tv.FIVE, Integer.toString(Tv.FIVE))));
 }
 /**
  * WebLinkingResponse can recognize Links in headers.
  *
  * @throws Exception If something goes wrong inside
  */
 @Test
 @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
 public void parsesLinksInHeaders() throws Exception {
   final String[] headers = {
     "</hey/foo>; title=\"Hi!\"; rel=foo",
     "</hey/foo>; title=\"\u20ac\"; rel=\"foo\"; media=\"text/xml\"",
   };
   for (final String header : headers) {
     final WebLinkingResponse response =
         new WebLinkingResponse(new FakeRequest().withHeader("Link", header).fetch());
     final WebLinkingResponse.Link link = response.links().get("foo");
     MatcherAssert.assertThat(link.uri(), Matchers.hasToString("/hey/foo"));
     MatcherAssert.assertThat(link, Matchers.hasKey("title"));
     MatcherAssert.assertThat(response.links(), Matchers.not(Matchers.hasKey("something else")));
   }
 }
  void assertRealtimeGetWorks(String indexName) {
    assertAcked(
        client()
            .admin()
            .indices()
            .prepareUpdateSettings(indexName)
            .setSettings(Settings.builder().put("refresh_interval", -1).build()));
    SearchRequestBuilder searchReq =
        client().prepareSearch(indexName).setQuery(QueryBuilders.matchAllQuery());
    SearchHit hit = searchReq.get().getHits().getAt(0);
    String docId = hit.getId();
    // foo is new, it is not a field in the generated index
    client().prepareUpdate(indexName, "doc", docId).setDoc("foo", "bar").get();
    GetResponse getRsp = client().prepareGet(indexName, "doc", docId).get();
    Map<String, Object> source = getRsp.getSourceAsMap();
    assertThat(source, Matchers.hasKey("foo"));

    assertAcked(
        client()
            .admin()
            .indices()
            .prepareUpdateSettings(indexName)
            .setSettings(
                Settings.builder()
                    .put("refresh_interval", EngineConfig.DEFAULT_REFRESH_INTERVAL)
                    .build()));
  }
 /**
  * ArrayMap can add maps.
  *
  * @throws Exception If some problem inside
  */
 @Test
 public void appendsEntireMapToItself() throws Exception {
   MatcherAssert.assertThat(
       new ArrayMap<Integer, String>()
           .with(Tv.FIVE, "")
           .with(new ArrayMap<Integer, String>().with(Tv.TEN, "")),
       Matchers.hasKey(Tv.TEN));
 }
  @Test
  public void testE2EBigtableWrite() throws Exception {
    final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId);
    final String instanceName = bigtableOptions.getInstanceName().toString();
    final int numRows = 1000;
    final List<KV<ByteString, ByteString>> testData = generateTableData(numRows);

    createEmptyTable(instanceName, tableId);

    Pipeline p = Pipeline.create(options);
    p.apply(CountingInput.upTo(numRows))
        .apply(
            ParDo.of(
                new DoFn<Long, KV<ByteString, Iterable<Mutation>>>() {
                  @ProcessElement
                  public void processElement(ProcessContext c) {
                    int index = c.element().intValue();

                    Iterable<Mutation> mutations =
                        ImmutableList.of(
                            Mutation.newBuilder()
                                .setSetCell(
                                    Mutation.SetCell.newBuilder()
                                        .setValue(testData.get(index).getValue())
                                        .setFamilyName(COLUMN_FAMILY_NAME))
                                .build());
                    c.output(KV.of(testData.get(index).getKey(), mutations));
                  }
                }))
        .apply(BigtableIO.write().withBigtableOptions(bigtableOptions).withTableId(tableId));
    p.run();

    // Test number of column families and column family name equality
    Table table = getTable(tableName);
    assertThat(table.getColumnFamilies().keySet(), Matchers.hasSize(1));
    assertThat(table.getColumnFamilies(), Matchers.hasKey(COLUMN_FAMILY_NAME));

    // Test table data equality
    List<KV<ByteString, ByteString>> tableData = getTableData(tableName);
    assertThat(tableData, Matchers.containsInAnyOrder(testData.toArray()));
  }