/** * Verifies that the registry returns 404 when getting an unknown device. * * @param ctx The vert.x test context. */ @Test public void testGetUnknownDeviceReturnsNotFound(final TestContext ctx) { getCompleteRegistrationService() .getDevice(TENANT, DEVICE, ctx.asyncAssertSuccess(response -> { ctx.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getStatus()); })); }
/** * Verifies that the registry returns 404 when unregistering an unknown device. * * @param ctx The vert.x test context. */ @Test public void testDeregisterUnknownDeviceReturnsNotFound(final TestContext ctx) { getCompleteRegistrationService() .removeDevice(TENANT, DEVICE, ctx.asyncAssertSuccess(response -> { ctx.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getStatus()); })); }
/** * Verifies that the registry returns 409 when trying to register a device twice. * * @param ctx The vert.x test context. */ @Test public void testDuplicateRegistrationFails(final TestContext ctx) { final Future<RegistrationResult> result = Future.future(); getCompleteRegistrationService().addDevice(TENANT, DEVICE, new JsonObject(), result.completer()); result.map(response -> { ctx.assertEquals(HttpURLConnection.HTTP_CREATED, response.getStatus()); return response; }).compose(ok -> { final Future<RegistrationResult> addResult = Future.future(); getCompleteRegistrationService().addDevice(TENANT, DEVICE, new JsonObject(), addResult.completer()); return addResult; }).setHandler( ctx.asyncAssertSuccess(response -> { ctx.assertEquals(HttpURLConnection.HTTP_CONFLICT, response.getStatus()); })); }
/** * Verifies that the registry returns 404 when getting an unregistered device. * * @param ctx The vert.x test context. */ @Test public void testGetFailsForDeregisteredDevice(final TestContext ctx) { final Future<RegistrationResult> result = Future.future(); getCompleteRegistrationService().addDevice(TENANT, DEVICE, new JsonObject(), result.completer()); result.compose(response -> { ctx.assertEquals(HttpURLConnection.HTTP_CREATED, response.getStatus()); final Future<RegistrationResult> deregisterResult = Future.future(); getCompleteRegistrationService().removeDevice(TENANT, DEVICE, deregisterResult.completer()); return deregisterResult; }).compose(response -> { ctx.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, response.getStatus()); final Future<RegistrationResult> getResult = Future.future(); getCompleteRegistrationService().getDevice(TENANT, DEVICE, getResult.completer()); return getResult; }).setHandler(ctx.asyncAssertSuccess(response -> { ctx.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getStatus()); })); } }
/** * Verifies that the registry returns 200 when getting an existing device. * * @param ctx The vert.x test context. */ @Test public void testGetSucceedsForRegisteredDevice(final TestContext ctx) { final Future<RegistrationResult> result = Future.future(); getCompleteRegistrationService().addDevice(TENANT, DEVICE, new JsonObject(), result.completer()); result.compose(response -> { ctx.assertEquals(HttpURLConnection.HTTP_CREATED, response.getStatus()); final Future<RegistrationResult> addResult = Future.future(); getCompleteRegistrationService().getDevice(TENANT, DEVICE, addResult.completer()); return addResult; }).setHandler( ctx.asyncAssertSuccess(s -> { ctx.assertEquals(HttpURLConnection.HTTP_OK, s.getStatus()); ctx.assertNotNull(s.getPayload()); } )); }