use of com.google.cloud.dialogflow.v2.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()));
}
use of com.google.cloud.dialogflow.v2.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.
}
}
use of com.google.cloud.dialogflow.v2.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());
}
}
use of com.google.cloud.dialogflow.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.
the class CreateKeyRing method createKeyRing.
// Create a new key ring.
public void createKeyRing(String projectId, String locationId, String id) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the parent name from the project and location.
LocationName locationName = LocationName.of(projectId, locationId);
// Build the key ring to create.
KeyRing keyRing = KeyRing.newBuilder().build();
// Create the key ring.
KeyRing createdKeyRing = client.createKeyRing(locationName, id, keyRing);
System.out.printf("Created key ring %s%n", createdKeyRing.getName());
}
}
use of com.google.cloud.dialogflow.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method quickstart.
public void quickstart(String projectId, String locationId) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the parent from the project and location.
LocationName parent = LocationName.of(projectId, locationId);
// Call the API.
ListKeyRingsPagedResponse response = client.listKeyRings(parent);
// Iterate over each key ring and print its name.
System.out.println("key rings:");
for (KeyRing keyRing : response.iterateAll()) {
System.out.printf("%s%n", keyRing.getName());
}
}
}
Aggregations