BigQueryResourceNaming { static String createJobIdPrefix(String jobName, String stepUuid, JobType type, String random) { jobName = jobName.replaceAll("-", ""); String result = BIGQUERY_JOB_TEMPLATE .replaceFirst("\\{TYPE}", type.toString()) .replaceFirst("\\{JOB_ID}", jobName) .replaceFirst("\\{STEP}", stepUuid); if (random != null) { return result.replaceFirst("\\{RANDOM}", random); } else { return result.replaceFirst("_\\{RANDOM}", ""); } }    }
@Test public void testJobTypesInNames() { assertEquals( "beam_bq_job_EXPORT_beamappjobtest_abcd", BigQueryResourceNaming.createJobIdPrefix("beamapp-job-test", "abcd", JobType.EXPORT)); assertEquals( "beam_bq_job_LOAD_beamappjobtest_abcd", BigQueryResourceNaming.createJobIdPrefix("beamapp-job-test", "abcd", JobType.LOAD)); assertEquals( "beam_bq_job_QUERY_beamappjobtest_abcd", BigQueryResourceNaming.createJobIdPrefix("beamapp-job-test", "abcd", JobType.QUERY)); assertEquals( "beam_bq_job_COPY_beamappjobtest_abcd", BigQueryResourceNaming.createJobIdPrefix("beamapp-job-test", "abcd", JobType.COPY)); }
@Test public void testJobRandomInNames() { assertEquals( "beam_bq_job_EXPORT_beamappjobtest_abcd_RANDOME", BigQueryResourceNaming.createJobIdPrefix( "beamapp-job-test", "abcd", JobType.EXPORT, "RANDOME")); }
@Test public void testMatchesBigQueryJobTemplate() { assertThat( BigQueryResourceNaming.createJobIdPrefix( "beamapp-job-test", "abcd", JobType.EXPORT, "RANDOME"), matchesPattern(BQ_JOB_PATTERN_REGEXP)); assertThat( BigQueryResourceNaming.createJobIdPrefix("beamapp-job-test", "abcd", JobType.COPY), matchesPattern(BQ_JOB_PATTERN_REGEXP)); }