DLPDeidentifyText extends PTransform<
        PCollection<KV<String, String>>, PCollection<KV<String, DeidentifyContentResponse>>> { public static DLPDeidentifyText.Builder newBuilder() { return new AutoValue_DLPDeidentifyText.Builder(); }  abstract @Nullable String getInspectTemplateName(); abstract @Nullable String getDeidentifyTemplateName(); abstract @Nullable InspectConfig getInspectConfig(); abstract @Nullable DeidentifyConfig getDeidentifyConfig(); abstract @Nullable PCollectionView<List<String>> getHeaderColumns(); abstract @Nullable String getColumnDelimiter(); abstract Integer getBatchSizeBytes(); abstract String getProjectId(); static DLPDeidentifyText.Builder newBuilder(); @Override PCollection<KV<String, DeidentifyContentResponse>> expand(
      PCollection<KV<String, String>> input); static final Integer DLP_PAYLOAD_LIMIT_BYTES; }
@Test public void throwsExceptionWhenDeidentifyConfigAndTemplatesAreEmpty() { assertThrows( "Either deidentifyConfig or deidentifyTemplateName need to be set!", IllegalArgumentException.class, () -> DLPDeidentifyText.newBuilder() .setProjectId(PROJECT_ID) .setBatchSizeBytes(BATCH_SIZE_SMALL) .setColumnDelimiter(DELIMITER) .build()); }
@Test public void throwsExceptionWhenDelimiterIsNullAndHeadersAreSet() { PCollectionView<List<String>> header = testPipeline.apply(Create.of("header")).apply(View.asList()); assertThrows( "Column delimiter should be set if headers are present.", IllegalArgumentException.class, () -> DLPDeidentifyText.newBuilder() .setProjectId(PROJECT_ID) .setBatchSizeBytes(BATCH_SIZE_SMALL) .setDeidentifyTemplateName(TEMPLATE_NAME) .setHeaderColumns(header) .build()); testPipeline.run().waitUntilFinish(); }
@Test public void throwsExceptionWhenBatchSizeIsTooLarge() { assertThrows( String.format( "Batch size is too large! It should be smaller or equal than %d.", DLPDeidentifyText.DLP_PAYLOAD_LIMIT_BYTES), IllegalArgumentException.class, () -> DLPDeidentifyText.newBuilder() .setProjectId(PROJECT_ID) .setBatchSizeBytes(Integer.MAX_VALUE) .setDeidentifyTemplateName(TEMPLATE_NAME) .setColumnDelimiter(DELIMITER) .build()); }
@Test public void throwsExceptionWhenDelimiterIsSetAndHeadersAreNot() { assertThrows( "Column headers should be supplied when delimiter is present.", IllegalArgumentException.class, () -> DLPDeidentifyText.newBuilder() .setProjectId(PROJECT_ID) .setBatchSizeBytes(BATCH_SIZE_SMALL) .setDeidentifyTemplateName(TEMPLATE_NAME) .setColumnDelimiter(DELIMITER) .build()); }