Skip to content

Commit

Permalink
Trying to fix tests.. again
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-munro committed Feb 28, 2022
1 parent f85c6d8 commit f70d72f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@

public class AddFileOwnerTest extends TestBase {

public static final String IT_SERVICE_ACCOUNT_EMAIL = System.getenv("IT_SERVICE_ACCOUNT_EMAIL");
public static final String newOwnerAccount =
"samples@java-docs-samples-testing.iam.gserviceaccount.com";

@Test
public void testAddFileOwner() {
// Check for user email before the actual test.
assertNotNull("Unable to determine user email", IT_SERVICE_ACCOUNT_EMAIL);

// Make sure the User has Ownership permissions on the bucket.
Acl bucketOwner = Acl.of(new User(IT_SERVICE_ACCOUNT_EMAIL), Role.OWNER);
Acl bucketOwner = Acl.of(new User(newOwnerAccount), Role.OWNER);
bucket.createAcl(bucketOwner);

// Add Ownership to the file.
AddFileOwner.addFileOwner(bucketName, IT_SERVICE_ACCOUNT_EMAIL, blobName);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(IT_SERVICE_ACCOUNT_EMAIL);
assertThat(blob.getAcl(new User(IT_SERVICE_ACCOUNT_EMAIL))).isNotNull();
AddFileOwner.addFileOwner(bucketName, newOwnerAccount, blobName);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(newOwnerAccount);
assertThat(blob.getAcl(new User(newOwnerAccount))).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,32 @@

public class RemoveFileOwnerTest extends TestBase {

public static final String IT_SERVICE_ACCOUNT_EMAIL = System.getenv("IT_SERVICE_ACCOUNT_EMAIL");
public static final String removeOwnerAccount =
"samples@java-docs-samples-testing.iam.gserviceaccount.com";

@Test
public void testRemoveFileOwner() {
// Check for user email before the actual test.
assertNotNull("Unable to determine user email", IT_SERVICE_ACCOUNT_EMAIL);

// Make sure the User has Ownership permissions on the bucket.
Acl bucketOwner = Acl.of(new User(IT_SERVICE_ACCOUNT_EMAIL), Role.OWNER);
Acl bucketOwner = Acl.of(new User(removeOwnerAccount), Role.OWNER);
bucket.createAcl(bucketOwner);

// Add User as Owner
Acl newFileOwner = Acl.of(new User(IT_SERVICE_ACCOUNT_EMAIL), Role.OWNER);
Acl newFileOwner = Acl.of(new User(removeOwnerAccount), Role.OWNER);
blob.createAcl(newFileOwner);

// Remove User as owner
RemoveFileOwner.removeFileOwner(bucketName, IT_SERVICE_ACCOUNT_EMAIL, blobName);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(IT_SERVICE_ACCOUNT_EMAIL);
RemoveFileOwner.removeFileOwner(bucketName, removeOwnerAccount, blobName);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(removeOwnerAccount);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("Removed user");
assertThat(blob.getAcl(new User(IT_SERVICE_ACCOUNT_EMAIL))).isNull();
assertThat(blob.getAcl(new User(removeOwnerAccount))).isNull();
}

@Test
public void testUserNotFound() {
// Remove User without Owner Permissions
RemoveFileOwner.removeFileOwner(bucketName, IT_SERVICE_ACCOUNT_EMAIL, blobName);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(IT_SERVICE_ACCOUNT_EMAIL);
RemoveFileOwner.removeFileOwner(bucketName, removeOwnerAccount, blobName);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(removeOwnerAccount);
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("was not found");
}
}

0 comments on commit f70d72f

Please sign in to comment.