@Test public void testCreateBucketCreateBucketFails() throws Exception { doReturn(fakeProject).when(mockGet).execute(); doThrow(new IOException("badness")) .when(mockGcsUtil) .createBucket(any(String.class), any(Bucket.class)); thrown.expect(RuntimeException.class); thrown.expectMessage("Unable create default bucket"); GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); }
@Test public void testProjectMismatch() throws Exception { doReturn(fakeProject).when(mockGet).execute(); when(mockGcsUtil.bucketOwner(any(GcsPath.class))).thenReturn(5L); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Bucket owner does not match the project"); GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); }
@Test public void testCannotGetBucketOwner() throws Exception { doReturn(fakeProject).when(mockGet).execute(); when(mockGcsUtil.bucketOwner(any(GcsPath.class))).thenThrow(new IOException("badness")); thrown.expect(RuntimeException.class); thrown.expectMessage("Unable to determine the owner"); GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); }
@Test public void testCreateBucketProjectLookupFails() throws Exception { doThrow(new IOException("badness")).when(mockGet).execute(); thrown.expect(RuntimeException.class); thrown.expectMessage("Unable to verify project"); GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); }
@Test public void testCreateBucket() throws Exception { doReturn(fakeProject).when(mockGet).execute(); when(mockGcsUtil.bucketOwner(any(GcsPath.class))).thenReturn(1L); String bucket = GcpTempLocationFactory.tryCreateDefaultBucket(options, mockCrmClient); assertEquals("gs://dataflow-staging-us-north1-1/temp/", bucket); }
@Override public Project get(String projectId, Map<Option, ?> options) { try { return resourceManager .projects() .get(projectId) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { ResourceManagerException translated = translate(ex); if (translated.getCode() == HTTP_FORBIDDEN || translated.getCode() == HTTP_NOT_FOUND) { // Service can return either 403 or 404 to signify that the project doesn't exist. return null; } else { throw translated; } } }