use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class ManagerIT method testSetIam.
@Test
public void testSetIam() throws Exception {
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.setIamPermissions(PROJECT_ID, CLOUD_REGION, REGISTRY_ID, MEMBER, ROLE);
DeviceRegistryExample.getIamPermissions(PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
String got = bout.toString();
Assert.assertTrue(got.contains("ETAG"));
DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.deleteTopic(topic.getNameAsTopicName());
}
}
use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class ManagerIT method testCreateConfigureDevice.
@Test
public void testCreateConfigureDevice() throws Exception {
final String deviceName = "rsa-device-config";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithRs256(deviceName, RSA_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.setDeviceConfiguration(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID, "some-test-data", 0L);
String got = bout.toString();
Assert.assertTrue(got.contains("Updated: 2"));
DeviceRegistryExample.deleteDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.deleteTopic(topic.getNameAsTopicName());
}
}
use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class ManagerIT method testMqttDeviceState.
@Test
public void testMqttDeviceState() throws Exception {
final String deviceName = "rsa-device-mqtt-state";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithRs256(deviceName, RSA_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.listDevices(PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
// Device bootstrapped, time to connect and run.
String[] testArgs = { "-project_id=" + PROJECT_ID, "-registry_id=" + REGISTRY_ID, "-device_id=" + deviceName, "-private_key_file=" + PKCS_PATH, "-message_type=state", "-algorithm=RS256" };
com.example.cloud.iot.examples.MqttExample.main(testArgs);
// End device test.
// Assertions
String got = bout.toString();
Assert.assertTrue(got.contains("Publishing state message 1"));
Assert.assertTrue(got.contains("Finished loop successfully. Goodbye!"));
// Clean up
DeviceRegistryExample.deleteDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.deleteTopic(topic.getNameAsTopicName());
}
}
use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class ManagerIT method testCreateGetDevice.
@Test
public void testCreateGetDevice() throws Exception {
final String deviceName = "rsa-device";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithRs256(deviceName, RSA_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.getDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
String got = bout.toString();
Assert.assertTrue(got.contains("Created device: {"));
Assert.assertTrue(got.contains("Retrieving device"));
DeviceRegistryExample.deleteDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.deleteTopic(topic.getNameAsTopicName());
}
}
use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class ManagerIT method testHttpDeviceConfig.
@Test
public void testHttpDeviceConfig() throws Exception {
final String deviceName = "rsa-device-http-state";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithRs256(deviceName, RSA_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.listDevices(PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
// Device bootstrapped, time to connect and run.
String[] testArgs = { "-project_id=" + PROJECT_ID, "-registry_id=" + REGISTRY_ID, "-device_id=" + deviceName, "-private_key_file=" + PKCS_PATH, "-num_messages=1", "-message_type=event", "-algorithm=RS256" };
com.example.cloud.iot.examples.HttpExample.main(testArgs);
// End device test.
// Assertions
String got = bout.toString();
Assert.assertTrue(got.contains("200"));
Assert.assertTrue(got.contains("OK"));
Assert.assertTrue(got.contains("\"binaryData\": \"\""));
// Clean up
DeviceRegistryExample.deleteDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
topicAdminClient.deleteTopic(topic.getNameAsTopicName());
}
}
Aggregations