Search in sources :

Example 26 with EventBusMessage

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

the class BaseCredentialsServiceTest method testCredentialsAddWithEmptySecret.

/**
 * Verifies that the base service accepts a request for adding
 * credentials that contain an empty secret.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testCredentialsAddWithEmptySecret(final TestContext ctx) {
    final JsonObject testData = createValidCredentialsObject(new JsonObject());
    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 27 with EventBusMessage

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

the class BaseCredentialsServiceTest method testAddSucceedsForLongTimestamp.

/**
 * Verifies that the base service accepts a request for adding
 * credentials that contains a secret with a time stamp including
 * an offset.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddSucceedsForLongTimestamp(final TestContext ctx) {
    final JsonObject secret = new JsonObject().put(CredentialsConstants.FIELD_SECRETS_NOT_BEFORE, "2007-04-05T12:30-02:00");
    final JsonObject testData = createValidCredentialsObject(secret);
    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 28 with EventBusMessage

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

the class BaseCredentialsServiceTest method testAddFailsForEmptySecrets.

/**
 * Verifies that the base service rejects a request for adding
 * credentials containing an empty <em>secrets</em> array.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddFailsForEmptySecrets(final TestContext ctx) {
    final JsonObject testData = createValidCredentialsObject(null);
    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 29 with EventBusMessage

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

the class BaseCredentialsServiceTest method testAddFailsForMissingSecrets.

/**
 * Verifies that the base service rejects a request for adding
 * credentials that do not contain a <em>secrets</em> array at all.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testAddFailsForMissingSecrets(final TestContext ctx) {
    final JsonObject testData = createValidCredentialsObject();
    testData.remove(CredentialsConstants.FIELD_SECRETS);
    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