use of io.vertx.ext.web.client.HttpResponse in project hono by eclipse.
the class DeviceRegistryHttpClient method addDeviceForTenant.
/**
* Creates a tenant and adds a device to it with a given password.
* <p>
* The password will be added as a hashed password using the device identifier as the authentication identifier.
*
* @param tenantId The ID of the tenant to create.
* @param tenant The tenant payload as specified by the Tenant management API.
* @param deviceId The identifier of the device to add.
* @param device The data to register for the device.
* @param password The password to use for the device's credentials.
* @return A future indicating the outcome of the operation.
* @throws NullPointerException if tenant is {@code null}.
*/
public Future<HttpResponse<Buffer>> addDeviceForTenant(final String tenantId, final Tenant tenant, final String deviceId, final Device device, final String password) {
Objects.requireNonNull(tenant);
final PasswordCredential secret = IntegrationTestSupport.createPasswordCredential(deviceId, password);
return addTenant(tenantId, tenant).compose(ok -> registerDevice(tenantId, deviceId, device)).compose(ok -> addCredentials(tenantId, deviceId, Collections.singleton(secret)));
}
use of io.vertx.ext.web.client.HttpResponse in project hono by eclipse.
the class DeviceRegistryHttpClient method addPskDeviceForTenant.
/**
* Creates a tenant and adds a device to it with a given Pre-Shared Key.
* <p>
* The device will be registered with a set of <em>psk</em> credentials using the device identifier as the
* authentication identifier and PSK identity.
*
* @param tenantId The identifier of the tenant to add the secret to.
* @param tenant The tenant payload as specified by the Tenant management API.
* @param deviceId The identifier of the device to add to the tenant.
* @param deviceData Additional data to register for the device.
* @param key The shared key.
* @return A future indicating the outcome of the operation.
* @throws NullPointerException if any of the parameters are are {@code null}.
*/
public Future<HttpResponse<Buffer>> addPskDeviceForTenant(final String tenantId, final Tenant tenant, final String deviceId, final Device deviceData, final String key) {
Objects.requireNonNull(tenant);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(deviceData);
Objects.requireNonNull(key);
final PskCredential credential = IntegrationTestSupport.createPskCredentials(deviceId, key);
return addTenant(tenantId, tenant).compose(ok -> registerDevice(tenantId, deviceId, deviceData)).compose(ok -> addCredentials(tenantId, deviceId, Collections.singleton(credential)));
}
use of io.vertx.ext.web.client.HttpResponse in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathLabelExplodeArray.
/**
* Test: path_label_explode_array
* Expected parameters sent:
* color: .blue.black.brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testPathLabelExplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_label_explode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isArray());
res.put("color", new JsonArray(color_path.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
startServer();
apiClient.pathLabelExplodeArray(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.ext.web.client.HttpResponse in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testPathSimpleNoexplodeArray.
/**
* Test: path_simple_noexplode_array
* Expected parameters sent:
* color: blue,black,brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testPathSimpleNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("path_simple_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_path = params.pathParameter("color");
assertNotNull(color_path);
assertTrue(color_path.isArray());
res.put("color", new JsonArray(color_path.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_path;
color_path = new ArrayList<>();
color_path.add("blue");
color_path.add("black");
color_path.add("brown");
startServer();
apiClient.pathSimpleNoexplodeArray(color_path, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
use of io.vertx.ext.web.client.HttpResponse in project vertx-web by vert-x3.
the class OpenAPI3ParametersUnitTest method testQuerySpaceDelimitedNoexplodeArray.
/**
* Test: query_spaceDelimited_noexplode_array
* Expected parameters sent:
* color: blue%20black%20brown
* Expected response: {"color":["blue","black","brown"]}
* @throws Exception
*/
@Test
public void testQuerySpaceDelimitedNoexplodeArray() throws Exception {
routerFactory.addHandlerByOperationId("query_spaceDelimited_noexplode_array", routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
JsonObject res = new JsonObject();
RequestParameter color_query = params.queryParameter("color");
assertNotNull(color_query);
assertTrue(color_query.isArray());
res.put("color", new JsonArray(color_query.getArray().stream().map(param -> param.getString()).collect(Collectors.toList())));
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json; charset=utf-8").end(res.encode());
});
CountDownLatch latch = new CountDownLatch(1);
List<Object> color_query;
color_query = new ArrayList<>();
color_query.add("blue");
color_query.add("black");
color_query.add("brown");
startServer();
apiClient.querySpaceDelimitedNoexplodeArray(color_query, (AsyncResult<HttpResponse> ar) -> {
if (ar.succeeded()) {
assertEquals(200, ar.result().statusCode());
assertTrue("Expected: " + new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").encode() + " Actual: " + ar.result().bodyAsJsonObject().encode(), new JsonObject("{\"color\":[\"blue\",\"black\",\"brown\"]}").equals(ar.result().bodyAsJsonObject()));
} else {
assertTrue(ar.cause().getMessage(), false);
}
latch.countDown();
});
awaitLatch(latch);
}
Aggregations