Search in sources :

Example 11 with LocationName

use of com.google.cloud.speech.v1p1beta1.LocationName in project java-speech by googleapis.

the class AdaptationClientTest method listCustomClassesTest.

@Test
public void listCustomClassesTest() throws Exception {
    CustomClass responsesElement = CustomClass.newBuilder().build();
    ListCustomClassesResponse expectedResponse = ListCustomClassesResponse.newBuilder().setNextPageToken("").addAllCustomClasses(Arrays.asList(responsesElement)).build();
    mockAdaptation.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListCustomClassesPagedResponse pagedListResponse = client.listCustomClasses(parent);
    List<CustomClass> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCustomClassesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAdaptation.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCustomClassesRequest actualRequest = ((ListCustomClassesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListCustomClassesPagedResponse(com.google.cloud.speech.v1p1beta1.AdaptationClient.ListCustomClassesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 12 with LocationName

use of com.google.cloud.speech.v1p1beta1.LocationName in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method listConnectionsTest.

@Test
public void listConnectionsTest() throws Exception {
    Connection responsesElement = Connection.newBuilder().build();
    ListConnectionsResponse expectedResponse = ListConnectionsResponse.newBuilder().setNextPageToken("").addAllConnections(Arrays.asList(responsesElement)).build();
    mockConnectionService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListConnectionsPagedResponse pagedListResponse = client.listConnections(parent);
    List<Connection> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getConnectionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListConnectionsRequest actualRequest = ((ListConnectionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListConnectionsRequest(com.google.cloud.bigquery.connection.v1.ListConnectionsRequest) ListConnectionsResponse(com.google.cloud.bigquery.connection.v1.ListConnectionsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) ListConnectionsPagedResponse(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient.ListConnectionsPagedResponse) LocationName(com.google.cloud.bigquery.connection.v1.LocationName) Test(org.junit.Test)

Example 13 with LocationName

use of com.google.cloud.speech.v1p1beta1.LocationName in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method createConnectionTest.

@Test
public void createConnectionTest() throws Exception {
    Connection expectedResponse = Connection.newBuilder().setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString()).setFriendlyName("friendlyName461933014").setDescription("description-1724546052").setCreationTime(1932333101).setLastModifiedTime(-671513446).setHasCredential(true).build();
    mockConnectionService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    Connection connection = Connection.newBuilder().build();
    String connectionId = "connectionId1923106969";
    Connection actualResponse = client.createConnection(parent, connection, connectionId);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateConnectionRequest actualRequest = ((CreateConnectionRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(connection, actualRequest.getConnection());
    Assert.assertEquals(connectionId, actualRequest.getConnectionId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) ByteString(com.google.protobuf.ByteString) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName) Test(org.junit.Test)

Example 14 with LocationName

use of com.google.cloud.speech.v1p1beta1.LocationName in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method createConnectionExceptionTest.

@Test
public void createConnectionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConnectionService.addException(exception);
    try {
        LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
        Connection connection = Connection.newBuilder().build();
        String connectionId = "connectionId1923106969";
        client.createConnection(parent, connection, connectionId);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Connection(com.google.cloud.bigquery.connection.v1.Connection) ByteString(com.google.protobuf.ByteString) LocationName(com.google.cloud.bigquery.connection.v1.LocationName) Test(org.junit.Test)

Example 15 with LocationName

use of com.google.cloud.speech.v1p1beta1.LocationName in project java-bigqueryconnection by googleapis.

the class CreateConnection method createConnection.

public static void createConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        LocationName parent = LocationName.of(projectId, location);
        CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
        Connection response = client.createConnection(request);
        System.out.println("Connection created successfully :" + response.getName());
    }
}
Also used : ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) Connection(com.google.cloud.bigquery.connection.v1.Connection) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName)

Aggregations

Test (org.junit.Test)34 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 AbstractMessage (com.google.protobuf.AbstractMessage)18 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)16 StatusRuntimeException (io.grpc.StatusRuntimeException)14 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)12 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)12 LocationName (com.google.cloud.automl.v1beta1.LocationName)12 LocationName (com.google.cloud.translate.v3beta1.LocationName)10 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)10 Model (com.google.cloud.automl.v1.Model)8 LocationName (com.google.cloud.bigquery.connection.v1.LocationName)8 Dataset (com.google.cloud.automl.v1.Dataset)7 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 CloudTasksClient (com.google.cloud.tasks.v2.CloudTasksClient)5