|
15 | 15 | */
|
16 | 16 | package com.google.cloud.monitoring.dasard.v1;
|
17 | 17 |
|
| 18 | +import static com.google.cloud.monitoring.dasard.v1.DasardsServiceClient.ListDasardsPagedResponse; |
| 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.dasard.v1.CreateDasardRequest; |
| 29 | +import com.google.monitoring.dasard.v1.Dasard; |
| 30 | +import com.google.monitoring.dasard.v1.DeleteDasardRequest; |
| 31 | +import com.google.monitoring.dasard.v1.GetDasardRequest; |
| 32 | +import com.google.monitoring.dasard.v1.ListDasardsRequest; |
| 33 | +import com.google.monitoring.dasard.v1.ListDasardsResponse; |
| 34 | +import com.google.monitoring.dasard.v1.UpdateDasardRequest; |
| 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 DasardsServiceClientTest {
|
@@ -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 createDasardTest() { |
| 91 | +String name = "name3373707"; |
| 92 | +String displayName = "displayName1615086568"; |
| 93 | +String etag = "etag3123477"; |
| 94 | +Dasard expectedResponse = |
| 95 | +Dasard.newBuilder().setName(name).setDisplayName(displayName).setEtag(etag).build(); |
| 96 | +mockDasardsService.addResponse(expectedResponse); |
| 97 | + |
| 98 | +String parent = "parent-995424086"; |
| 99 | +Dasard dasard = Dasard.newBuilder().build(); |
| 100 | +CreateDasardRequest request = |
| 101 | +CreateDasardRequest.newBuilder().setParent(parent).setDasard(dasard).build(); |
| 102 | + |
| 103 | +Dasard actualResponse = client.createDasard(request); |
| 104 | +Assert.assertEquals(expectedResponse, actualResponse); |
| 105 | + |
| 106 | +List<AbstractMessage> actualRequests = mockDasardsService.getRequests(); |
| 107 | +Assert.assertEquals(1, actualRequests.size()); |
| 108 | +CreateDasardRequest actualRequest = (CreateDasardRequest) actualRequests.get(0); |
| 109 | + |
| 110 | +Assert.assertEquals(parent, actualRequest.getParent()); |
| 111 | +Assert.assertEquals(dasard, actualRequest.getDasard()); |
| 112 | +Assert.assertTrue( |
| 113 | +channelProvider.isHeaderSent( |
| 114 | +ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 115 | +GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 116 | +} |
| 117 | + |
| 118 | +@Test |
| 119 | +@SuppressWarnings("all") |
| 120 | +public void createDasardExceptionTest() throws Exception { |
| 121 | +StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 122 | +mockDasardsService.addException(exception); |
| 123 | + |
| 124 | +try { |
| 125 | +String parent = "parent-995424086"; |
| 126 | +Dasard dasard = Dasard.newBuilder().build(); |
| 127 | +CreateDasardRequest request = |
| 128 | +CreateDasardRequest.newBuilder().setParent(parent).setDasard(dasard).build(); |
| 129 | + |
| 130 | +client.createDasard(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 listDasardsTest() { |
| 140 | +String nextPageToken = ""; |
| 141 | +Dasard dasardsElement = Dasard.newBuilder().build(); |
| 142 | +List<Dasard> dasards = Arrays.asList(dasardsElement); |
| 143 | +ListDasardsResponse expectedResponse = |
| 144 | +ListDasardsResponse.newBuilder() |
| 145 | +.setNextPageToken(nextPageToken) |
| 146 | +.addAllDasards(dasards) |
| 147 | +.build(); |
| 148 | +mockDasardsService.addResponse(expectedResponse); |
| 149 | + |
| 150 | +String parent = "parent-995424086"; |
| 151 | +ListDasardsRequest request = ListDasardsRequest.newBuilder().setParent(parent).build(); |
| 152 | + |
| 153 | +ListDasardsPagedResponse pagedListResponse = client.listDasards(request); |
| 154 | + |
| 155 | +List<Dasard> resources = Lists.newArrayList(pagedListResponse.iterateAll()); |
| 156 | +Assert.assertEquals(1, resources.size()); |
| 157 | +Assert.assertEquals(expectedResponse.getDasardsList().get(0), resources.get(0)); |
| 158 | + |
| 159 | +List<AbstractMessage> actualRequests = mockDasardsService.getRequests(); |
| 160 | +Assert.assertEquals(1, actualRequests.size()); |
| 161 | +ListDasardsRequest actualRequest = (ListDasardsRequest) 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 listDasardsExceptionTest() throws Exception { |
| 173 | +StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 174 | +mockDasardsService.addException(exception); |
| 175 | + |
| 176 | +try { |
| 177 | +String parent = "parent-995424086"; |
| 178 | +ListDasardsRequest request = ListDasardsRequest.newBuilder().setParent(parent).build(); |
| 179 | + |
| 180 | +client.listDasards(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 getDasardTest() { |
| 190 | +String name2 = "name2-1052831874"; |
| 191 | +String displayName = "displayName1615086568"; |
| 192 | +String etag = "etag3123477"; |
| 193 | +Dasard expectedResponse = |
| 194 | +Dasard.newBuilder().setName(name2).setDisplayName(displayName).setEtag(etag).build(); |
| 195 | +mockDasardsService.addResponse(expectedResponse); |
| 196 | + |
| 197 | +String name = "name3373707"; |
| 198 | +GetDasardRequest request = GetDasardRequest.newBuilder().setName(name).build(); |
| 199 | + |
| 200 | +Dasard actualResponse = client.getDasard(request); |
| 201 | +Assert.assertEquals(expectedResponse, actualResponse); |
| 202 | + |
| 203 | +List<AbstractMessage> actualRequests = mockDasardsService.getRequests(); |
| 204 | +Assert.assertEquals(1, actualRequests.size()); |
| 205 | +GetDasardRequest actualRequest = (GetDasardRequest) 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 getDasardExceptionTest() throws Exception { |
| 217 | +StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 218 | +mockDasardsService.addException(exception); |
| 219 | + |
| 220 | +try { |
| 221 | +String name = "name3373707"; |
| 222 | +GetDasardRequest request = GetDasardRequest.newBuilder().setName(name).build(); |
| 223 | + |
| 224 | +client.getDasard(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 deleteDasardTest() { |
| 234 | +Empty expectedResponse = Empty.newBuilder().build(); |
| 235 | +mockDasardsService.addResponse(expectedResponse); |
| 236 | + |
| 237 | +String name = "name3373707"; |
| 238 | +DeleteDasardRequest request = DeleteDasardRequest.newBuilder().setName(name).build(); |
| 239 | + |
| 240 | +client.deleteDasard(request); |
| 241 | + |
| 242 | +List<AbstractMessage> actualRequests = mockDasardsService.getRequests(); |
| 243 | +Assert.assertEquals(1, actualRequests.size()); |
| 244 | +DeleteDasardRequest actualRequest = (DeleteDasardRequest) 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 deleteDasardExceptionTest() throws Exception { |
| 256 | +StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 257 | +mockDasardsService.addException(exception); |
| 258 | + |
| 259 | +try { |
| 260 | +String name = "name3373707"; |
| 261 | +DeleteDasardRequest request = DeleteDasardRequest.newBuilder().setName(name).build(); |
| 262 | + |
| 263 | +client.deleteDasard(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 updateDasardTest() { |
| 273 | +String name = "name3373707"; |
| 274 | +String displayName = "displayName1615086568"; |
| 275 | +String etag = "etag3123477"; |
| 276 | +Dasard expectedResponse = |
| 277 | +Dasard.newBuilder().setName(name).setDisplayName(displayName).setEtag(etag).build(); |
| 278 | +mockDasardsService.addResponse(expectedResponse); |
| 279 | + |
| 280 | +Dasard dasard = Dasard.newBuilder().build(); |
| 281 | +UpdateDasardRequest request = |
| 282 | +UpdateDasardRequest.newBuilder().setDasard(dasard).build(); |
| 283 | + |
| 284 | +Dasard actualResponse = client.updateDasard(request); |
| 285 | +Assert.assertEquals(expectedResponse, actualResponse); |
| 286 | + |
| 287 | +List<AbstractMessage> actualRequests = mockDasardsService.getRequests(); |
| 288 | +Assert.assertEquals(1, actualRequests.size()); |
| 289 | +UpdateDasardRequest actualRequest = (UpdateDasardRequest) actualRequests.get(0); |
| 290 | + |
| 291 | +Assert.assertEquals(dasard, actualRequest.getDasard()); |
| 292 | +Assert.assertTrue( |
| 293 | +channelProvider.isHeaderSent( |
| 294 | +ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), |
| 295 | +GaxGrpcProperties.getDefaultApiClientHeaderPattern())); |
| 296 | +} |
| 297 | + |
| 298 | +@Test |
| 299 | +@SuppressWarnings("all") |
| 300 | +public void updateDasardExceptionTest() throws Exception { |
| 301 | +StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); |
| 302 | +mockDasardsService.addException(exception); |
| 303 | + |
| 304 | +try { |
| 305 | +Dasard dasard = Dasard.newBuilder().build(); |
| 306 | +UpdateDasardRequest request = |
| 307 | +UpdateDasardRequest.newBuilder().setDasard(dasard).build(); |
| 308 | + |
| 309 | +client.updateDasard(request); |
| 310 | +Assert.fail("No exception raised"); |
| 311 | +} catch (InvalidArgumentException e) { |
| 312 | +// Expected exception |
| 313 | +} |
| 314 | +} |
67 | 315 | }
|
0 commit comments