Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bigquery export samples #7

Closed
wants to merge 11 commits into from
Closed

Conversation

rafaelMurata
Copy link
Owner

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved


package vtwo.bigquery;

// [START securitycenter_create_bigquery_export_v2]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tag should enclose only the function public static void createBigQueryExport(, no?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes sense if we follow the same example we used in GetIamPolicies:
https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/security-command-center/snippets/src/main/java/vtwo/iam/GetIamPolicies.java

but I'm worried about the change, as the same PR is already approved in the same syntax.
GoogleCloudPlatform#9291

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, no problem

Comment on lines +56 to +59
SecurityCenterClient client = mock(SecurityCenterClient.class);
try (MockedStatic<SecurityCenterClient> clientMock = Mockito.mockStatic(
SecurityCenterClient.class)) {
clientMock.when(SecurityCenterClient::create).thenReturn(client);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these lines could be put in a @before method, once it's used in all of the tests.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try (MockedStatic<SecurityCenterClient> clientMock = Mockito.mockStatic(
SecurityCenterClient.class)) {
clientMock.when(SecurityCenterClient::create).thenReturn(client);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line here

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// Define test data.
String filter = "test-filter";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Build the parent of the request.
OrganizationLocationName organizationName = OrganizationLocationName.of(ORGANIZATION_ID,
LOCATION);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.setFilter(filter)
.setDataset(String.format("projects/%s/datasets/%s", PROJECT_ID, BQ_DATASET_NAME))
.build();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.setBigQueryExport(expectedExport)
.setBigQueryExportId(BQ_EXPORT_ID)
.build();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete extra line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

@Test
public void testDeleteBigQueryExport() throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do the same I asked for the first test on the tests below

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

BQ_DATASET_NAME, BQ_EXPORT_ID);

// Verify that the createBigQueryExport method was called with the expected request.
Mockito.verify(client).createBigQueryExport(expectedRequest);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please statically import Mockito.verify() so you can write this line as verify(client).createBigQueryExport(expectedRequest);

Same below!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.build();

// Mock the createBigQueryExport method to return the expected response.
Mockito.when(client.createBigQueryExport(any())).thenReturn(expectedExport);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please statically import Mockito.when() so you can write this line as when(client.createBigQueryExport(any())).thenReturn(expectedExport);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


package vtwo.bigquery;

// [START securitycenter_create_bigquery_export_v2]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, no problem

.build();
// Mock the deleteBigQueryExport method to return successfully.
doNothing().when(client).deleteBigQueryExport(bigQueryExportRequest);
// Call the deleteBigQueryExport method.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

doNothing().when(client).deleteBigQueryExport(bigQueryExportRequest);
// Call the deleteBigQueryExport method.
DeleteBigQueryExport.deleteBigQueryExport(ORGANIZATION_ID, LOCATION, BQ_EXPORT_ID);
// Verify that the deleteBigQueryExport method was called with the expected request.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment on lines 70 to 71
SecurityCenterClient client = mock(SecurityCenterClient.class);
clientMock.when(SecurityCenterClient::create).thenReturn(client);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also move these two lines to the setUp() method? (same for other methods)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way to move the two lines. The other attempts didn't work.

rafaelMurata and others added 6 commits May 29, 2024 18:48
…eleteBigQueryExport.java

Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
…etBigQueryExport.java

Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
…istBigQueryExports.java

Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
…pdateBigQueryExport.java

Co-authored-by: Sita Lakshmi Sangameswaran <sitalakshmi@google.com>
@rafaelMurata rafaelMurata deleted the bigquery-samples-v2 branch June 12, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants