Search in sources :

Example 16 with ServiceInvocationException

use of org.eclipse.hono.client.ServiceInvocationException 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 17 with ServiceInvocationException

use of org.eclipse.hono.client.ServiceInvocationException 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)

Example 18 with ServiceInvocationException

use of org.eclipse.hono.client.ServiceInvocationException 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 19 with ServiceInvocationException

use of org.eclipse.hono.client.ServiceInvocationException 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

ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)19 Future (io.vertx.core.Future)17 JsonObject (io.vertx.core.json.JsonObject)17 HttpURLConnection (java.net.HttpURLConnection)15 TestContext (io.vertx.ext.unit.TestContext)11 EventBusMessage (org.eclipse.hono.util.EventBusMessage)11 BeforeClass (org.junit.BeforeClass)11 Test (org.junit.Test)11 Timeout (org.junit.rules.Timeout)11 AsyncResult (io.vertx.core.AsyncResult)10 Handler (io.vertx.core.Handler)10 ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)10 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)9 RunWith (org.junit.runner.RunWith)9 Vertx (io.vertx.core.Vertx)7 CredentialsConstants (org.eclipse.hono.util.CredentialsConstants)7 CredentialsObject (org.eclipse.hono.util.CredentialsObject)7 Buffer (io.vertx.core.buffer.Buffer)6 Objects (java.util.Objects)6 Optional (java.util.Optional)6