/** * Creates a matcher that matches if the examined {@link DisplayData.Item} has the specified * label. */ public static Matcher<DisplayData.Item> hasLabel(String label) { return hasLabel(is(label)); }
@Test public void testUnspecifiedOptionalProperties() { DisplayData data = DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(DisplayData.Builder builder) { builder.add(DisplayData.item("foo", "bar")); } }); assertThat( data, hasDisplayItem(allOf(hasLabel(nullValue(String.class)), hasUrl(nullValue(String.class))))); }
@Test public void testItemProperties() { final Instant value = Instant.now(); DisplayData data = DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(DisplayData.Builder builder) { builder.add( DisplayData.item("now", value) .withLabel("the current instant") .withLinkUrl("http://time.gov") .withNamespace(DisplayDataTest.class)); } }); @SuppressWarnings("unchecked") DisplayData.Item item = (DisplayData.Item) data.items().toArray()[0]; @SuppressWarnings("unchecked") Matcher<Item> matchesAllOf = allOf( hasNamespace(DisplayDataTest.class), hasKey("now"), hasType(DisplayData.Type.TIMESTAMP), hasValue(ISO_FORMATTER.print(value)), hasShortValue(nullValue(String.class)), hasLabel("the current instant"), hasUrl(is("http://time.gov"))); assertThat(item, matchesAllOf); }
@Test public void testPopulateDisplayData() { DisplayData displayData = DisplayData.from( config.withProjectId(PROJECT_ID).withInstanceId(INSTANCE_ID).withTableId(TABLE_ID) ::populateDisplayData); assertThat( displayData, hasDisplayItem( allOf( hasKey("projectId"), hasLabel("Bigtable Project Id"), hasValue(PROJECT_ID.get())))); assertThat( displayData, hasDisplayItem( allOf( hasKey("instanceId"), hasLabel("Bigtable Instance Id"), hasValue(INSTANCE_ID.get())))); assertThat( displayData, hasDisplayItem( allOf(hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue(TABLE_ID.get())))); }
allOf( hasKey("projectId"), hasLabel("Bigtable Project Id"), hasValue("RuntimeValueProvider{propertyName=bigtableProject, default=null}")))); assertThat( allOf( hasKey("instanceId"), hasLabel("Bigtable Instance Id"), hasValue("RuntimeValueProvider{propertyName=bigtableInstanceId, default=null}")))); assertThat( allOf( hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue("RuntimeValueProvider{propertyName=bigtableTableId, default=null}"))));
@Test public void testReadingDisplayData() { RowFilter rowFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("foo.*")).build(); ByteKeyRange keyRange = ByteKeyRange.ALL_KEYS.withEndKey(ByteKey.of(0xab, 0xcd)); BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId("fooTable") .withRowFilter(rowFilter) .withKeyRange(keyRange); DisplayData displayData = DisplayData.from(read); assertThat( displayData, hasDisplayItem( allOf(hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue("fooTable")))); assertThat(displayData, hasDisplayItem("rowFilter", rowFilter.toString())); assertThat(displayData, hasDisplayItem("keyRange 0", keyRange.toString())); // BigtableIO adds user-agent to options; assert only on key and not value. assertThat(displayData, hasDisplayItem("bigtableOptions")); }