PubsubIO { public static Write<String> writeStrings() { return Write.newBuilder( (String string) -> new PubsubMessage(string.getBytes(StandardCharsets.UTF_8), ImmutableMap.of())) .build(); } private  PubsubIO(); static Read<PubsubMessage> readMessages(); static Read<PubsubMessage> readMessagesWithMessageId(); static Read<PubsubMessage> readMessagesWithAttributes(); static Read<PubsubMessage> readMessagesWithAttributesAndMessageId(); static Read<String> readStrings(); static Read<T> readProtos(Class<T> messageClass); static Read<T> readAvros(Class<T> clazz); static Read<T> readMessagesWithCoderAndParseFn(
      Coder<T> coder, SimpleFunction<PubsubMessage, T> parseFn); @Experimental(Kind.SCHEMAS) static Read<GenericRecord> readAvroGenericRecords(org.apache.avro.Schema avroSchema); @Experimental(Kind.SCHEMAS) static Read<T> readAvrosWithBeamSchema(Class<T> clazz); static Write<PubsubMessage> writeMessages(); static Write<String> writeStrings(); static Write<T> writeProtos(Class<T> messageClass); static Write<T> writeAvros(Class<T> clazz);  }
@Test public void testWriteDisplayData() { String topic = "projects/project/topics/topic"; PubsubIO.Write<?> write = PubsubIO.writeStrings() .to(topic) .withTimestampAttribute("myTimestamp") .withIdAttribute("myId"); DisplayData displayData = DisplayData.from(write); assertThat(displayData, hasDisplayItem("topic", topic)); assertThat(displayData, hasDisplayItem("timestampAttribute", "myTimestamp")); assertThat(displayData, hasDisplayItem("idAttribute", "myId")); }
@Test public void testPrimitiveWriteDisplayData() { DisplayDataEvaluator evaluator = DisplayDataEvaluator.create(); PubsubIO.Write<?> write = PubsubIO.writeStrings().to("projects/project/topics/topic"); Set<DisplayData> displayData = evaluator.displayDataForPrimitiveTransforms(write); assertThat( "PubsubIO.Write should include the topic in its primitive display data", displayData, hasItem(hasDisplayItem("topic"))); }
@Test public void testWriteWithPubsubGrpcClientFactory() { String topic = "projects/project/topics/topic"; PubsubIO.Write<?> write = PubsubIO.writeStrings() .to(topic) .withClientFactory(PubsubGrpcClient.FACTORY) .withTimestampAttribute("myTimestamp") .withIdAttribute("myId"); DisplayData displayData = DisplayData.from(write); assertThat(displayData, hasDisplayItem("topic", topic)); assertThat(displayData, hasDisplayItem("timestampAttribute", "myTimestamp")); assertThat(displayData, hasDisplayItem("idAttribute", "myId")); }