Search in sources :

Example 21 with EventBusMessage

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

the class TenantAmqpEndpoint method processRequest.

@Override
public final void processRequest(final Message msg, final ResourceIdentifier targetAddress, final HonoUser clientPrincipal) {
    final EventBusMessage request = EventBusMessage.forOperation(msg).setReplyToAddress(msg).setAppCorrelationId(msg).setCorrelationId(msg).setTenant(msg).setJsonPayload(msg);
    vertx.eventBus().send(TenantConstants.EVENT_BUS_ADDRESS_TENANT_IN, request.toJson());
}
Also used : EventBusMessage(org.eclipse.hono.util.EventBusMessage)

Example 22 with EventBusMessage

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

the class BaseCredentialsServiceTest method testAddSucceedsForMinimalData.

/**
 * Verifies that the base service accepts a request for adding
 * credentials that contains the minimum required properties.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddSucceedsForMinimalData(final TestContext ctx) {
    final JsonObject testData = createValidCredentialsObject();
    final EventBusMessage msg = createRequestForPayload(CredentialsConstants.CredentialsAction.add, testData);
    service.processRequest(msg).setHandler(ctx.asyncAssertSuccess(response -> {
        ctx.assertEquals(HttpURLConnection.HTTP_CREATED, response.getStatus());
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) BeforeClass(org.junit.BeforeClass) CredentialsResult(org.eclipse.hono.util.CredentialsResult) 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) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) CredentialsObject(org.eclipse.hono.util.CredentialsObject) EventBusMessage(org.eclipse.hono.util.EventBusMessage) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 23 with EventBusMessage

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

the class BaseCredentialsServiceTest method testGetFailsForMissingAuthId.

/**
 * Verifies that the base service fails a request for getting credentials
 * with a 400 error code if the authentication identifier is missing.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testGetFailsForMissingAuthId(final TestContext ctx) {
    // GIVEN a request for getting credentials that does not specify an auth ID
    final CredentialsObject malformedPayload = new CredentialsObject().setType("my-type").addSecret(CredentialsObject.emptySecret(null, null));
    final EventBusMessage request = createRequestForPayload(CredentialsConstants.CredentialsAction.get, JsonObject.mapFrom(malformedPayload));
    // WHEN processing the request
    service.processRequest(request).setHandler(ctx.asyncAssertFailure(t -> {
        // THEN the response contains a 400 error code
        ctx.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, ((ServiceInvocationException) t).getErrorCode());
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) BeforeClass(org.junit.BeforeClass) CredentialsResult(org.eclipse.hono.util.CredentialsResult) 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) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) CredentialsObject(org.eclipse.hono.util.CredentialsObject) EventBusMessage(org.eclipse.hono.util.EventBusMessage) CredentialsObject(org.eclipse.hono.util.CredentialsObject) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.Test)

Example 24 with EventBusMessage

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

the class BaseCredentialsServiceTest method testAddFailsForShortTimestamp.

/**
 * Verifies that the base service rejects a request for adding
 * credentials that contains a secret with a time stamp that does
 * not include an offset.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddFailsForShortTimestamp(final TestContext ctx) {
    final JsonObject secret = new JsonObject().put(CredentialsConstants.FIELD_SECRETS_NOT_BEFORE, "2007-04-05T14:30");
    final JsonObject testData = createValidCredentialsObject(secret);
    final EventBusMessage msg = createRequestForPayload(CredentialsConstants.CredentialsAction.add, testData);
    service.processRequest(msg).setHandler(ctx.asyncAssertFailure(t -> {
        ctx.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, ((ServiceInvocationException) t).getErrorCode());
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) BeforeClass(org.junit.BeforeClass) CredentialsResult(org.eclipse.hono.util.CredentialsResult) 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) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) CredentialsObject(org.eclipse.hono.util.CredentialsObject) EventBusMessage(org.eclipse.hono.util.EventBusMessage) JsonObject(io.vertx.core.json.JsonObject) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.Test)

Example 25 with EventBusMessage

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

the class BaseCredentialsServiceTest method testAddFailsForMalformedTimestamp.

/**
 * Verifies that the base service rejects a request for adding
 * credentials that contain a secret with a malformed time stamp.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddFailsForMalformedTimestamp(final TestContext ctx) {
    final JsonObject secret = new JsonObject().put(CredentialsConstants.FIELD_SECRETS_NOT_BEFORE, "no-timestamp");
    final JsonObject testData = createValidCredentialsObject(secret);
    final EventBusMessage msg = createRequestForPayload(CredentialsConstants.CredentialsAction.add, testData);
    service.processRequest(msg).setHandler(ctx.asyncAssertFailure(t -> {
        ctx.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, ((ServiceInvocationException) t).getErrorCode());
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) BeforeClass(org.junit.BeforeClass) CredentialsResult(org.eclipse.hono.util.CredentialsResult) 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) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) CredentialsObject(org.eclipse.hono.util.CredentialsObject) EventBusMessage(org.eclipse.hono.util.EventBusMessage) JsonObject(io.vertx.core.json.JsonObject) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.Test)

Aggregations

EventBusMessage (org.eclipse.hono.util.EventBusMessage)29 Future (io.vertx.core.Future)26 JsonObject (io.vertx.core.json.JsonObject)26 HttpURLConnection (java.net.HttpURLConnection)26 Handler (io.vertx.core.Handler)24 AsyncResult (io.vertx.core.AsyncResult)21 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)18 TestContext (io.vertx.ext.unit.TestContext)16 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)16 Test (org.junit.Test)16 Timeout (org.junit.rules.Timeout)16 RunWith (org.junit.runner.RunWith)16 ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)14 CredentialsConstants (org.eclipse.hono.util.CredentialsConstants)13 CredentialsObject (org.eclipse.hono.util.CredentialsObject)13 CredentialsResult (org.eclipse.hono.util.CredentialsResult)13 BeforeClass (org.junit.BeforeClass)13 TenantConstants (org.eclipse.hono.util.TenantConstants)11 Objects (java.util.Objects)10 ClientErrorException (org.eclipse.hono.client.ClientErrorException)8