Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google-cloud-errorreporting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<scope>test</scope>
</dependency>

<!-- Need testing utility classes for generated gRPC clients tests -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.errorreporting.v1beta1.it;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.cloud.ServiceOptions;
import com.google.cloud.errorreporting.v1beta1.ErrorGroupServiceClient;
import com.google.cloud.errorreporting.v1beta1.ErrorStatsServiceClient;
import com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient;
import com.google.common.collect.Lists;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorEvent;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats;
import com.google.devtools.clouderrorreporting.v1beta1.GroupName;
import com.google.devtools.clouderrorreporting.v1beta1.ProjectName;
import com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange;
import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse;
import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class ITSystemTest {

private static ErrorGroupServiceClient errorGroupServiceClient;
private static ReportErrorsServiceClient reportErrorsServiceClient;
private static ErrorStatsServiceClient errorStatsServiceClient;

private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
private static final ProjectName PROJECT_NAME = ProjectName.of(PROJECT_ID);
private static final QueryTimeRange TIME_RANGE = QueryTimeRange.newBuilder().build();

@BeforeClass
public static void beforeClass() throws Exception {
errorGroupServiceClient = ErrorGroupServiceClient.create();
errorStatsServiceClient = ErrorStatsServiceClient.create();
reportErrorsServiceClient = ReportErrorsServiceClient.create();
}

@AfterClass
public static void afterClass() {
errorGroupServiceClient.close();
errorStatsServiceClient.close();
reportErrorsServiceClient.close();
}

@Test
public void listGroupStatsTest() {
ErrorStatsServiceClient.ListGroupStatsPagedResponse pagedListResponse =
errorStatsServiceClient.listGroupStats(PROJECT_NAME, TIME_RANGE);
List<ErrorGroupStats> errorGroupStats = Lists.newArrayList(pagedListResponse.iterateAll());
if (errorGroupStats.size() > 0) {
ErrorGroup group =
errorGroupServiceClient.getGroup(errorGroupStats.get(0).getGroup().getName());
assertNotNull(group);
assertEquals(errorGroupStats.get(0).getGroup(), group);
assertEquals(errorGroupStats.get(0).getGroup().getGroupId(), group.getGroupId());
assertEquals(errorGroupStats.get(0).getGroup().getName(), group.getName());
}
}

@Test
public void listEventsTest() {
ErrorStatsServiceClient.ListGroupStatsPagedResponse pagedListResponse =
errorStatsServiceClient.listGroupStats(PROJECT_NAME, TIME_RANGE);
List<ErrorGroupStats> errorGroupStats = Lists.newArrayList(pagedListResponse.iterateAll());
if (errorGroupStats.size() > 0) {
Iterable<ErrorEvent> errorEvent =
errorStatsServiceClient
.listEvents(PROJECT_NAME, errorGroupStats.get(0).getGroup().getGroupId())
.iterateAll();
assertNotNull(errorEvent);
assertTrue(errorEvent.iterator().hasNext());
assertNotNull(errorEvent.iterator().next());
}
}

@Test
public void getGroupTest() {
ErrorStatsServiceClient.ListGroupStatsPagedResponse pagedListResponse =
errorStatsServiceClient.listGroupStats(PROJECT_NAME, TIME_RANGE);
List<ErrorGroupStats> errorGroupStats = Lists.newArrayList(pagedListResponse.iterateAll());
if (errorGroupStats.size() > 0) {
ErrorGroup group =
errorGroupServiceClient.getGroup(errorGroupStats.get(0).getGroup().getName());
assertNotNull(group);
assertEquals(errorGroupStats.get(0).getGroup(), group);
assertEquals(errorGroupStats.get(0).getGroup().getGroupId(), group.getGroupId());
assertEquals(errorGroupStats.get(0).getGroup().getName(), group.getName());
}
}

@Test(expected = InvalidArgumentException.class)
public void getGroupExceptionTest() {
GroupName group = GroupName.of(PROJECT_ID, "DUMMY-GROUP");
errorGroupServiceClient.getGroup(group);
}

@Test
public void reportErrorEventTest() {
String message =
"{\n"
+ " \"context\": {\n"
+ " \"httpRequest\": {\n"
+ " \"responseStatusCode\": 500,\n"
+ " \"method\": \"GET\",\n"
+ " \"url\": \"http://example.com/product\"\n"
+ " },\n"
+ " \"user\": \"2247177\"\n"
+ " },\n"
+ " \"message\": \"org.springframework.web.client.HttpServerErrorException: 500 Server Error\n"
+ " at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java: 94)\n"
+ " \",\n"
+ " \"serviceContext\": {\n"
+ " \"service\": \"cart\",\n"
+ " \"version\": \"\"\n"
+ " }";
ReportedErrorEvent event = ReportedErrorEvent.newBuilder().setMessage(message).build();
ReportErrorEventResponse errorEventResponse =
reportErrorsServiceClient.reportErrorEvent(PROJECT_NAME, event);
assertNotNull(errorEventResponse);
assertTrue(errorEventResponse.isInitialized());
}

@Test(expected = InvalidArgumentException.class)
public void reportErrorEventExceptionTest() {
ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
reportErrorsServiceClient.reportErrorEvent(PROJECT_NAME, event);
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
<artifactId>proto-google-common-protos</artifactId>
<version>${google.common-protos.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>${google.core.version}</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
Expand Down