Skip to content

Commit

Permalink
Add setProjectId method to JobId and update JobInfo's
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Aug 31, 2016
1 parent 7cd60df commit 2a4e63d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public String toString() {
return toPb().toString();
}

JobId setProjectId(String projectId) {
return project() != null ? this : JobId.of(projectId, job());
}

JobReference toPb() {
return new JobReference().setProjectId(project).setJobId(job);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ public boolean equals(Object obj) {
}

JobInfo setProjectId(String projectId) {
return toBuilder().configuration(configuration.setProjectId(projectId)).build();
Builder builder = toBuilder();
if (jobId != null) {
builder.jobId(jobId.setProjectId(projectId));
}
return builder.configuration(configuration.setProjectId(projectId)).build();
}

Job toPb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void testToPbAndFromPb() {
compareJobs(JOB_COMPLETE, JobId.fromPb(JOB_COMPLETE.toPb()));
}

@Test
public void testSetProjectId() {
assertEquals(JOB_COMPLETE, JOB.setProjectId("project"));
}

private void compareJobs(JobId expected, JobId value) {
assertEquals(expected, value);
assertEquals(expected.hashCode(), value.hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,24 @@ public void testToPbAndFromPb() {

@Test
public void testSetProjectId() {
CopyJobConfiguration copyConfiguration = COPY_JOB.setProjectId("p").configuration();
JobInfo jobInfo = COPY_JOB.setProjectId("p");
assertEquals("p", jobInfo.jobId().project());
CopyJobConfiguration copyConfiguration = jobInfo.configuration();
assertEquals("p", copyConfiguration.destinationTable().project());
for (TableId sourceTable : copyConfiguration.sourceTables()) {
assertEquals("p", sourceTable.project());
}
ExtractJobConfiguration extractConfiguration = EXTRACT_JOB.setProjectId("p").configuration();
jobInfo = EXTRACT_JOB.setProjectId("p");
assertEquals("p", jobInfo.jobId().project());
ExtractJobConfiguration extractConfiguration = jobInfo.configuration();
assertEquals("p", extractConfiguration.sourceTable().project());
LoadJobConfiguration loadConfiguration = LOAD_JOB.setProjectId("p").configuration();
jobInfo = LOAD_JOB.setProjectId("p");
assertEquals("p", jobInfo.jobId().project());
LoadJobConfiguration loadConfiguration = jobInfo.configuration();
assertEquals("p", loadConfiguration.destinationTable().project());
QueryJobConfiguration queryConfiguration = QUERY_JOB.setProjectId("p").configuration();
jobInfo = QUERY_JOB.setProjectId("p");
assertEquals("p", jobInfo.jobId().project());
QueryJobConfiguration queryConfiguration = jobInfo.configuration();
assertEquals("p", queryConfiguration.defaultDataset().project());
assertEquals("p", queryConfiguration.destinationTable().project());
}
Expand Down

0 comments on commit 2a4e63d

Please sign in to comment.