|
15 | 15 | */
|
16 | 16 | package com.google.cloud.monitoring.dashboard.v1;
|
17 | 17 |
|
| 18 | +import static com.google.cloud.monitoring.dashboard.v1.DashboardsServiceClient.ListDashboardsPagedResponse; |
| 19 | + |
18 | 20 | import com.google.api.gax.core.NoCredentialsProvider;
|
| 21 | +import com.google.api.gax.grpc.GaxGrpcProperties; |
19 | 22 | import com.google.api.gax.grpc.testing.LocalChannelProvider;
|
20 | 23 | import com.google.api.gax.grpc.testing.MockGrpcService;
|
21 | 24 | import com.google.api.gax.grpc.testing.MockServiceHelper;
|
| 25 | +import com.google.api.gax.rpc.ApiClientHeaderProvider; |
| 26 | +import com.google.api.gax.rpc.InvalidArgumentException; |
| 27 | +import com.google.common.collect.Lists; |
| 28 | +import com.google.monitoring.dashboard.v1.CreateDashboardRequest; |
| 29 | +import com.google.monitoring.dashboard.v1.Dashboard; |
| 30 | +import com.google.monitoring.dashboard.v1.DeleteDashboardRequest; |
| 31 | +import com.google.monitoring.dashboard.v1.GetDashboardRequest; |
| 32 | +import com.google.monitoring.dashboard.v1.ListDashboardsRequest; |
| 33 | +import com.google.monitoring.dashboard.v1.ListDashboardsResponse; |
| 34 | +import com.google.monitoring.dashboard.v1.UpdateDashboardRequest; |
| 35 | +import com.google.protobuf.AbstractMessage; |
| 36 | +import com.google.protobuf.Empty; |
| 37 | +import io.grpc.Status; |
| 38 | +import io.grpc.StatusRuntimeException; |
22 | 39 | import java.io.IOException;
|
23 | 40 | import java.util.Arrays;
|
| 41 | +import java.util.List; |
24 | 42 | import java.util.UUID;
|
25 | 43 | import org.junit.After;
|
26 | 44 | import org.junit.AfterClass;
|
| 45 | +import org.junit.Assert; |
27 | 46 | import org.junit.Before;
|
28 | 47 | import org.junit.BeforeClass;
|
| 48 | +import org.junit.Test; |
29 | 49 |
|
30 | 50 | @javax.annotation.Generated("by GAPIC")
|
31 | 51 | public class DashboardsServiceClientTest {
|
@@ -64,4 +84,232 @@ public void setUp() throws IOException {
|
64 | 84 | public void tearDown() throws Exception {
|
65 | 85 | client.close();
|
66 | 86 | }
|
| 87 | + |
| 88 | + @Test |
| 89 | + @SuppressWarnings("all") |
| 90 | + public void createDashboardTest() { |
| 91 | + String name = "name3373707"; |
| 92 | + String displayName = "displayName1615086568"; |
| 93 | + String etag = "etag3123477"; |
| 94 | + Dashboard expectedResponse = |
| 95 | + Dashboard.newBuilder().setName(name).setDisplayName(displayName).setEtag(etag).build(); |
| 96 | + mockDashboardsService.addResponse(expectedResponse); |
| 97 | + |
| 98 | + String parent = "parent-995424086"; |
| 99 | + Dashboard dashboard = Dashboard.newBuilder().build(); |
| 100 | + CreateDashboardRequest request = |
| 101 | + CreateDashboardRequest.newBuilder().setParent(parent).setDashboard(dashboard).build(); |
| 102 | + |
| 103 | + Dashboard actualResponse = client.createDashboard(request); |
| 104 | + Assert.assertEquals(expectedResponse, actualResponse); |
| 105 | + |
| 106 | + List<AbstractMessage> actualRequests = mockDashboardsService.getRequests(); |
| 107 | + Assert.assertEquals(1, actualRequests.size()); |
| 108 | + CreateDashboardRequest actualRequest = (CreateDashboardRequest) actualRequests.get(0); |
| 109 | + |
| 110 | + Assert.assertEquals(parent, actualRequest.getParent()); |
| 111 | + Assert.assertEquals(dashboard, actualRequest.getDashboard()); |
| 112 | + Assert.assertTrue( |
| 113 | + channelProvider.isHeaderSent( |
| 114 | + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 115 | + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + @SuppressWarnings("all") |
| 120 | + public void createDashboardExceptionTest() throws Exception { |
| 121 | + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 122 | + mockDashboardsService.addException(exception); |
| 123 | + |
| 124 | + try { |
| 125 | + String parent = "parent-995424086"; |
| 126 | + Dashboard dashboard = Dashboard.newBuilder().build(); |
| 127 | + CreateDashboardRequest request = |
| 128 | + CreateDashboardRequest.newBuilder().setParent(parent).setDashboard(dashboard).build(); |
| 129 | + |
| 130 | + client.createDashboard(request); |
| 131 | + Assert.fail("No exception raised"); |
| 132 | + } catch (InvalidArgumentException e) { |
| 133 | + // Expected exception |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + @SuppressWarnings("all") |
| 139 | + public void listDashboardsTest() { |
| 140 | + String nextPageToken = ""; |
| 141 | + Dashboard dashboardsElement = Dashboard.newBuilder().build(); |
| 142 | + List<Dashboard> dashboards = Arrays.asList(dashboardsElement); |
| 143 | + ListDashboardsResponse expectedResponse = |
| 144 | + ListDashboardsResponse.newBuilder() |
| 145 | + .setNextPageToken(nextPageToken) |
| 146 | + .addAllDashboards(dashboards) |
| 147 | + .build(); |
| 148 | + mockDashboardsService.addResponse(expectedResponse); |
| 149 | + |
| 150 | + String parent = "parent-995424086"; |
| 151 | + ListDashboardsRequest request = ListDashboardsRequest.newBuilder().setParent(parent).build(); |
| 152 | + |
| 153 | + ListDashboardsPagedResponse pagedListResponse = client.listDashboards(request); |
| 154 | + |
| 155 | + List<Dashboard> resources = Lists.newArrayList(pagedListResponse.iterateAll()); |
| 156 | + Assert.assertEquals(1, resources.size()); |
| 157 | + Assert.assertEquals(expectedResponse.getDashboardsList().get(0), resources.get(0)); |
| 158 | + |
| 159 | + List<AbstractMessage> actualRequests = mockDashboardsService.getRequests(); |
| 160 | + Assert.assertEquals(1, actualRequests.size()); |
| 161 | + ListDashboardsRequest actualRequest = (ListDashboardsRequest) actualRequests.get(0); |
| 162 | + |
| 163 | + Assert.assertEquals(parent, actualRequest.getParent()); |
| 164 | + Assert.assertTrue( |
| 165 | + channelProvider.isHeaderSent( |
| 166 | + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 167 | + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 168 | + } |
| 169 | + |
| 170 | + @Test |
| 171 | + @SuppressWarnings("all") |
| 172 | + public void listDashboardsExceptionTest() throws Exception { |
| 173 | + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 174 | + mockDashboardsService.addException(exception); |
| 175 | + |
| 176 | + try { |
| 177 | + String parent = "parent-995424086"; |
| 178 | + ListDashboardsRequest request = ListDashboardsRequest.newBuilder().setParent(parent).build(); |
| 179 | + |
| 180 | + client.listDashboards(request); |
| 181 | + Assert.fail("No exception raised"); |
| 182 | + } catch (InvalidArgumentException e) { |
| 183 | + // Expected exception |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + @Test |
| 188 | + @SuppressWarnings("all") |
| 189 | + public void getDashboardTest() { |
| 190 | + String name2 = "name2-1052831874"; |
| 191 | + String displayName = "displayName1615086568"; |
| 192 | + String etag = "etag3123477"; |
| 193 | + Dashboard expectedResponse = |
| 194 | + Dashboard.newBuilder().setName(name2).setDisplayName(displayName).setEtag(etag).build(); |
| 195 | + mockDashboardsService.addResponse(expectedResponse); |
| 196 | + |
| 197 | + String name = "name3373707"; |
| 198 | + GetDashboardRequest request = GetDashboardRequest.newBuilder().setName(name).build(); |
| 199 | + |
| 200 | + Dashboard actualResponse = client.getDashboard(request); |
| 201 | + Assert.assertEquals(expectedResponse, actualResponse); |
| 202 | + |
| 203 | + List<AbstractMessage> actualRequests = mockDashboardsService.getRequests(); |
| 204 | + Assert.assertEquals(1, actualRequests.size()); |
| 205 | + GetDashboardRequest actualRequest = (GetDashboardRequest) actualRequests.get(0); |
| 206 | + |
| 207 | + Assert.assertEquals(name, actualRequest.getName()); |
| 208 | + Assert.assertTrue( |
| 209 | + channelProvider.isHeaderSent( |
| 210 | + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 211 | + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 212 | + } |
| 213 | + |
| 214 | + @Test |
| 215 | + @SuppressWarnings("all") |
| 216 | + public void getDashboardExceptionTest() throws Exception { |
| 217 | + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 218 | + mockDashboardsService.addException(exception); |
| 219 | + |
| 220 | + try { |
| 221 | + String name = "name3373707"; |
| 222 | + GetDashboardRequest request = GetDashboardRequest.newBuilder().setName(name).build(); |
| 223 | + |
| 224 | + client.getDashboard(request); |
| 225 | + Assert.fail("No exception raised"); |
| 226 | + } catch (InvalidArgumentException e) { |
| 227 | + // Expected exception |
| 228 | + } |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + @SuppressWarnings("all") |
| 233 | + public void deleteDashboardTest() { |
| 234 | + Empty expectedResponse = Empty.newBuilder().build(); |
| 235 | + mockDashboardsService.addResponse(expectedResponse); |
| 236 | + |
| 237 | + String name = "name3373707"; |
| 238 | + DeleteDashboardRequest request = DeleteDashboardRequest.newBuilder().setName(name).build(); |
| 239 | + |
| 240 | + client.deleteDashboard(request); |
| 241 | + |
| 242 | + List<AbstractMessage> actualRequests = mockDashboardsService.getRequests(); |
| 243 | + Assert.assertEquals(1, actualRequests.size()); |
| 244 | + DeleteDashboardRequest actualRequest = (DeleteDashboardRequest) actualRequests.get(0); |
| 245 | + |
| 246 | + Assert.assertEquals(name, actualRequest.getName()); |
| 247 | + Assert.assertTrue( |
| 248 | + channelProvider.isHeaderSent( |
| 249 | + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 250 | + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 251 | + } |
| 252 | + |
| 253 | + @Test |
| 254 | + @SuppressWarnings("all") |
| 255 | + public void deleteDashboardExceptionTest() throws Exception { |
| 256 | + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 257 | + mockDashboardsService.addException(exception); |
| 258 | + |
| 259 | + try { |
| 260 | + String name = "name3373707"; |
| 261 | + DeleteDashboardRequest request = DeleteDashboardRequest.newBuilder().setName(name).build(); |
| 262 | + |
| 263 | + client.deleteDashboard(request); |
| 264 | + Assert.fail("No exception raised"); |
| 265 | + } catch (InvalidArgumentException e) { |
| 266 | + // Expected exception |
| 267 | + } |
| 268 | + } |
| 269 | + |
| 270 | + @Test |
| 271 | + @SuppressWarnings("all") |
| 272 | + public void updateDashboardTest() { |
| 273 | + String name = "name3373707"; |
| 274 | + String displayName = "displayName1615086568"; |
| 275 | + String etag = "etag3123477"; |
| 276 | + Dashboard expectedResponse = |
| 277 | + Dashboard.newBuilder().setName(name).setDisplayName(displayName).setEtag(etag).build(); |
| 278 | + mockDashboardsService.addResponse(expectedResponse); |
| 279 | + |
| 280 | + Dashboard dashboard = Dashboard.newBuilder().build(); |
| 281 | + UpdateDashboardRequest request = |
| 282 | + UpdateDashboardRequest.newBuilder().setDashboard(dashboard).build(); |
| 283 | + |
| 284 | + Dashboard actualResponse = client.updateDashboard(request); |
| 285 | + Assert.assertEquals(expectedResponse, actualResponse); |
| 286 | + |
| 287 | + List<AbstractMessage> actualRequests = mockDashboardsService.getRequests(); |
| 288 | + Assert.assertEquals(1, actualRequests.size()); |
| 289 | + UpdateDashboardRequest actualRequest = (UpdateDashboardRequest) actualRequests.get(0); |
| 290 | + |
| 291 | + Assert.assertEquals(dashboard, actualRequest.getDashboard()); |
| 292 | + Assert.assertTrue( |
| 293 | + channelProvider.isHeaderSent( |
| 294 | + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 295 | + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 296 | + } |
| 297 | + |
| 298 | + @Test |
| 299 | + @SuppressWarnings("all") |
| 300 | + public void updateDashboardExceptionTest() throws Exception { |
| 301 | + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 302 | + mockDashboardsService.addException(exception); |
| 303 | + |
| 304 | + try { |
| 305 | + Dashboard dashboard = Dashboard.newBuilder().build(); |
| 306 | + UpdateDashboardRequest request = |
| 307 | + UpdateDashboardRequest.newBuilder().setDashboard(dashboard).build(); |
| 308 | + |
| 309 | + client.updateDashboard(request); |
| 310 | + Assert.fail("No exception raised"); |
| 311 | + } catch (InvalidArgumentException e) { |
| 312 | + // Expected exception |
| 313 | + } |
| 314 | + } |
67 | 315 | }
|
0 commit comments