@Test @SuppressWarnings("all") public void instantiateWorkflowTemplateExceptionTest2() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockWorkflowTemplateService.addException(exception); try { Map<String, String> parameters = new HashMap<>(); client.instantiateWorkflowTemplateAsync(parameters).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
/** * Creates one or more media items in a user's Google Photos library and adds them to an album. * * @param albumId Identifier of the album where the media items are added. The media items are * also added to the user's library. * @param newMediaItems List of media items to be created. * @see #batchCreateMediaItems(String, List, AlbumPosition) */ public final BatchCreateMediaItemsResponse batchCreateMediaItems( String albumId, List<NewMediaItem> newMediaItems) { if (Strings.isNullOrEmpty(albumId)) { throw new InvalidArgumentException( "Request must have an album id.", null /* cause */, GrpcStatusCode.of(Code.INVALID_ARGUMENT), false /* retryable */); } BatchCreateMediaItemsRequest request = BatchCreateMediaItemsRequest.newBuilder() .setAlbumId(albumId) .addAllNewMediaItems(newMediaItems) .build(); return batchCreateMediaItems(request); }
assertThat(((InvalidArgumentException) actualError).isRetryable()).isFalse(); assertThat(((InvalidArgumentException) actualError2).isRetryable()).isTrue();
/** * Creates one or more media items in a user's Google Photos library. * * <p>The items are only added to the library and <b>not</b> to an album. * * @param newMediaItems List of media items to be created. * @see #batchCreateMediaItems(String, List, AlbumPosition) */ public final BatchCreateMediaItemsResponse batchCreateMediaItems( List<NewMediaItem> newMediaItems) { if (newMediaItems == null) { throw new InvalidArgumentException( "Request must have a list of new media items.", null /* cause */, GrpcStatusCode.of(Code.INVALID_ARGUMENT), false /* retryable */); } BatchCreateMediaItemsRequest request = BatchCreateMediaItemsRequest.newBuilder().addAllNewMediaItems(newMediaItems).build(); return batchCreateMediaItems(request); }
@Test @SuppressWarnings("all") public void asyncBatchAnnotateFilesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockImageAnnotator.addException(exception); try { List<AsyncAnnotateFileRequest> requests = new ArrayList<>(); client.asyncBatchAnnotateFilesAsync(requests).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
return new UnknownException(cause, statusCode, retryable); case INVALID_ARGUMENT: return new InvalidArgumentException(cause, statusCode, retryable); case DEADLINE_EXCEEDED: return new DeadlineExceededException(cause, statusCode, retryable);
@Test @SuppressWarnings("all") public void asyncBatchAnnotateFilesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockImageAnnotator.addException(exception); try { List<AsyncAnnotateFileRequest> requests = new ArrayList<>(); client.asyncBatchAnnotateFilesAsync(requests).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
return new UnknownException(cause, statusCode, retryable); case INVALID_ARGUMENT: return new InvalidArgumentException(cause, statusCode, retryable); case DEADLINE_EXCEEDED: return new DeadlineExceededException(cause, statusCode, retryable);
@Test @SuppressWarnings("all") public void annotateVideoExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockVideoIntelligenceService.addException(exception); try { String inputUri = "gs://demomaker/cat.mp4"; Feature featuresElement = Feature.LABEL_DETECTION; List<Feature> features = Arrays.asList(featuresElement); client.annotateVideoAsync(inputUri, features).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
return new UnknownException(message, cause, statusCode, retryable); case INVALID_ARGUMENT: return new InvalidArgumentException(message, cause, statusCode, retryable); case DEADLINE_EXCEEDED: return new DeadlineExceededException(message, cause, statusCode, retryable);
@Test @SuppressWarnings("all") public void asyncBatchAnnotateFilesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockImageAnnotator.addException(exception); try { List<AsyncAnnotateFileRequest> requests = new ArrayList<>(); client.asyncBatchAnnotateFilesAsync(requests).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
return new UnknownException(message, cause, statusCode, retryable); case INVALID_ARGUMENT: return new InvalidArgumentException(message, cause, statusCode, retryable); case DEADLINE_EXCEEDED: return new DeadlineExceededException(message, cause, statusCode, retryable);
@Test @SuppressWarnings("all") public void annotateVideoExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockVideoIntelligenceService.addException(exception); try { String inputUri = "gs://demomaker/cat.mp4"; Feature featuresElement = Feature.LABEL_DETECTION; List<Feature> features = Arrays.asList(featuresElement); client.annotateVideoAsync(inputUri, features).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
@Test @SuppressWarnings("all") public void annotateVideoExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockVideoIntelligenceService.addException(exception); try { String inputUri = "gs://demomaker/cat.mp4"; Feature featuresElement = Feature.LABEL_DETECTION; List<Feature> features = Arrays.asList(featuresElement); client.annotateVideoAsync(inputUri, features).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
@Test @SuppressWarnings("all") public void annotateVideoExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockVideoIntelligenceService.addException(exception); try { String inputUri = "gs://demomaker/cat.mp4"; Feature featuresElement = Feature.LABEL_DETECTION; List<Feature> features = Arrays.asList(featuresElement); client.annotateVideoAsync(inputUri, features).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
@Test @SuppressWarnings("all") public void batchDeleteEntityTypesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockEntityTypes.addException(exception); try { ProjectAgentName parent = ProjectAgentName.of("[PROJECT]"); List<String> entityTypeNames = new ArrayList<>(); client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void batchCreateEntitiesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockEntityTypes.addException(exception); try { EntityTypeName parent = EntityTypeName.of("[PROJECT]", "[ENTITY_TYPE]"); List<EntityType.Entity> entities = new ArrayList<>(); client.batchCreateEntitiesAsync(parent, entities).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void batchUpdateEntitiesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockEntityTypes.addException(exception); try { EntityTypeName parent = EntityTypeName.of("[PROJECT]", "[ENTITY_TYPE]"); List<EntityType.Entity> entities = new ArrayList<>(); client.batchUpdateEntitiesAsync(parent, entities).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void batchCreateEntitiesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockEntityTypes.addException(exception); try { EntityTypeName parent = EntityTypeName.of("[PROJECT]", "[ENTITY_TYPE]"); List<EntityType.Entity> entities = new ArrayList<>(); client.batchCreateEntitiesAsync(parent, entities).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void updateDatabaseDdlExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockDatabaseAdmin.addException(exception); try { DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"); List<String> statements = new ArrayList<>(); client.updateDatabaseDdlAsync(database, statements).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }