Search in sources :

Example 66 with ProjectName

use of com.google.phishingprotection.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listGroupStatsTest.

@Test
@SuppressWarnings("all")
public void listGroupStatsTest() {
    String nextPageToken = "";
    ErrorGroupStats errorGroupStatsElement = ErrorGroupStats.newBuilder().build();
    List<ErrorGroupStats> errorGroupStats = Arrays.asList(errorGroupStatsElement);
    ListGroupStatsResponse expectedResponse = ListGroupStatsResponse.newBuilder().setNextPageToken(nextPageToken).addAllErrorGroupStats(errorGroupStats).build();
    mockErrorStatsService.addResponse(expectedResponse);
    ProjectName projectName = ProjectName.create("[PROJECT]");
    QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
    ListGroupStatsPagedResponse pagedListResponse = client.listGroupStats(projectName, timeRange);
    List<ErrorGroupStats> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getErrorGroupStatsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockErrorStatsService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGroupStatsRequest actualRequest = (ListGroupStatsRequest) actualRequests.get(0);
    Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName());
    Assert.assertEquals(timeRange, actualRequest.getTimeRange());
}
Also used : ErrorGroupStats(com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats) ListGroupStatsRequest(com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest) ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ListGroupStatsResponse(com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse) ListGroupStatsPagedResponse(com.google.cloud.errorreporting.spi.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse) QueryTimeRange(com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 67 with ProjectName

use of com.google.phishingprotection.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventTest() {
    ReportErrorEventResponse expectedResponse = ReportErrorEventResponse.newBuilder().build();
    mockReportErrorsService.addResponse(expectedResponse);
    ProjectName projectName = ProjectName.create("[PROJECT]");
    ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
    ReportErrorEventResponse actualResponse = client.reportErrorEvent(projectName, event);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockReportErrorsService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ReportErrorEventRequest actualRequest = (ReportErrorEventRequest) actualRequests.get(0);
    Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName());
    Assert.assertEquals(event, actualRequest.getEvent());
}
Also used : ReportErrorEventRequest(com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest) ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorEventResponse(com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 68 with ProjectName

use of com.google.phishingprotection.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventExceptionTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockReportErrorsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
        client.reportErrorEvent(projectName, event);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 69 with ProjectName

use of com.google.phishingprotection.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method createGroupTest.

@Test
@SuppressWarnings("all")
public void createGroupTest() {
    GroupName name2 = GroupName.create("[PROJECT]", "[GROUP]");
    String displayName = "displayName1615086568";
    GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]");
    String filter = "filter-1274492040";
    boolean isCluster = false;
    Group expectedResponse = Group.newBuilder().setNameWithGroupName(name2).setDisplayName(displayName).setParentNameWithGroupName(parentName).setFilter(filter).setIsCluster(isCluster).build();
    mockGroupService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    Group group = Group.newBuilder().build();
    Group actualResponse = client.createGroup(name, group);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateGroupRequest actualRequest = (CreateGroupRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
    Assert.assertEquals(group, actualRequest.getGroup());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Group(com.google.monitoring.v3.Group) ProjectName(com.google.monitoring.v3.ProjectName) CreateGroupRequest(com.google.monitoring.v3.CreateGroupRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 70 with ProjectName

use of com.google.phishingprotection.v1beta1.ProjectName in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method createGroupExceptionTest.

@Test
@SuppressWarnings("all")
public void createGroupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        Group group = Group.newBuilder().build();
        client.createGroup(name, group);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Group(com.google.monitoring.v3.Group) ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)178 StatusRuntimeException (io.grpc.StatusRuntimeException)89 AbstractMessage (com.google.protobuf.AbstractMessage)76 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)74 ProjectName (com.google.monitoring.v3.ProjectName)62 ProjectName (com.google.pubsub.v1.ProjectName)44 ProjectName (com.google.logging.v2.ProjectName)31 ArrayList (java.util.ArrayList)31 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)20 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15