use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.
the class ManagerIT method testCreateDeleteRsaDevice.
@Test
public void testCreateDeleteRsaDevice() 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.getDeviceStates(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
String got = bout.toString();
Assert.assertTrue(got.contains("Created 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 testPatchRsa.
@Test
public void testPatchRsa() throws Exception {
final String deviceName = "patchme-device-rsa";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
try {
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithNoAuth(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.patchRsa256ForAuth(deviceName, RSA_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
String got = bout.toString();
Assert.assertTrue(got.contains("Created device: {"));
} finally {
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 testMqttDeviceConfig.
// MQTT device tests
@Test
public void testMqttDeviceConfig() throws Exception {
final String deviceName = "rsa-device-mqtt-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.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=events", "-num_messages=1", "-algorithm=RS256" };
com.example.cloud.iot.examples.MqttExample.main(testArgs);
// End device test.
// Assertions
String got = bout.toString();
System.out.println(got);
Assert.assertTrue(got.contains("Payload :"));
// 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 testPatchEs.
@Test
public void testPatchEs() throws Exception {
final String deviceName = "patchme-device-es";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
try {
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithNoAuth(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
DeviceRegistryExample.patchEs256ForAuth(deviceName, ES_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
String got = bout.toString();
Assert.assertTrue(got.contains("Created device: {"));
} finally {
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 testCreateDeleteUnauthDevice.
@Test
public void testCreateDeleteUnauthDevice() throws Exception {
final String deviceName = "noauth-device";
topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
DeviceRegistryExample.createDeviceWithNoAuth(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
String got = bout.toString();
Assert.assertTrue(got.contains("Created 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());
}
}
Aggregations