Search in sources :

Example 1 with TenantConstants

use of org.eclipse.hono.util.TenantConstants in project hono by eclipse.

the class BaseTenantServiceTest method testAddFailsForAdapterConfigWithoutType.

/**
 * Verifies that the base service fails for a payload that defines an adapter entry, but does not provide the
 * mandatory field {@link TenantConstants#FIELD_ADAPTERS_TYPE}.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddFailsForAdapterConfigWithoutType(final TestContext ctx) {
    final JsonObject testPayload = createValidTenantPayload();
    final JsonArray adapterArray = new JsonArray();
    // no type specified (which is a violation of the API)
    adapterArray.add(new JsonObject());
    testPayload.put(TenantConstants.FIELD_ADAPTERS, adapterArray);
    final EventBusMessage msg = createRequest(TenantConstants.TenantAction.add, testPayload);
    tenantService.processRequest(msg).setHandler(ctx.asyncAssertFailure(t -> {
        ctx.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, ((ServiceInvocationException) t).getErrorCode());
    }));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) TenantResult(org.eclipse.hono.util.TenantResult) BeforeClass(org.junit.BeforeClass) TenantConstants(org.eclipse.hono.util.TenantConstants) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) EventBusMessage(org.eclipse.hono.util.EventBusMessage) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Future(io.vertx.core.Future) JsonArray(io.vertx.core.json.JsonArray) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) EventBusMessage(org.eclipse.hono.util.EventBusMessage) JsonObject(io.vertx.core.json.JsonObject) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.Test)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 HttpURLConnection (java.net.HttpURLConnection)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)1 EventBusMessage (org.eclipse.hono.util.EventBusMessage)1 TenantConstants (org.eclipse.hono.util.TenantConstants)1 TenantResult (org.eclipse.hono.util.TenantResult)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 Timeout (org.junit.rules.Timeout)1 RunWith (org.junit.runner.RunWith)1