/** * Verifies that service returns 404 if a client provides wrong client context. * * @param ctx The vert.x test context. */ @Test public void testGetCredentialsFailsForWrongClientContext(final TestContext ctx) { final JsonObject clientContext = new JsonObject() .put("client-id", "gateway-one"); register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", clientContext, new JsonArray(), ctx); final JsonObject testContext = new JsonObject() .put("client-id", "gateway-two"); final Async get = ctx.async(); getCompleteCredentialsService().get("tenant", "myType", "myId", testContext, ctx.asyncAssertSuccess(s -> { assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND)); get.complete(); })); get.await(2000); }
protected static void assertRegistered( final CompleteCredentialsService svc, final String tenant, final String authId, final String type, final TestContext ctx) { final Async registration = ctx.async(); svc.get(tenant, type, authId, ctx.asyncAssertSuccess(t -> { assertThat(t.getStatus(), is(HttpURLConnection.HTTP_OK)); registration.complete(); })); registration.await(); }
/** * Verifies that service returns existing credentials for proper client context. * * @param ctx The vert.x test context. */ @Test public void testGetCredentialsSucceedsForProperClientContext(final TestContext ctx) { final JsonObject clientContext = new JsonObject() .put("client-id", "gateway-one"); register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", clientContext, new JsonArray(), ctx); final Async get = ctx.async(); getCompleteCredentialsService().get("tenant", "myType", "myId", clientContext, ctx.asyncAssertSuccess(s -> { assertThat(s.getStatus(), is(HttpURLConnection.HTTP_OK)); assertThat(s.getPayload().getString(CredentialsConstants.FIELD_AUTH_ID), is("myId")); assertThat(s.getPayload().getString(CredentialsConstants.FIELD_TYPE), is("myType")); get.complete(); })); get.await(2000); }
protected static void assertNotRegistered( final CompleteCredentialsService svc, final String tenant, final String authId, final String type, final TestContext ctx) { final Async registration = ctx.async(); svc.get(tenant, type, authId, ctx.asyncAssertSuccess(t -> { assertThat(t.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND)); registration.complete(); })); registration.await(); }
/** * Verifies that the service returns existing credentials. * * @param ctx The vert.x test context. */ @Test public void testGetCredentialsSucceedsForExistingCredentials(final TestContext ctx) { register(getCompleteCredentialsService(), "tenant", "device", "myId", "myType", ctx); final Async get = ctx.async(); getCompleteCredentialsService().get("tenant", "myType", "myId", ctx.asyncAssertSuccess(s -> { assertThat(s.getStatus(), is(HttpURLConnection.HTTP_OK)); assertThat(s.getPayload().getString(CredentialsConstants.FIELD_AUTH_ID), is("myId")); assertThat(s.getPayload().getString(CredentialsConstants.FIELD_TYPE), is("myType")); get.complete(); })); get.await(); }
/** * Verifies that the service returns 404 if a client wants to retrieve non-existing credentials. * * @param ctx The vert.x test context. */ @Test public void testGetCredentialsFailsForNonExistingCredentials(final TestContext ctx) { final Async get = ctx.async(); getCompleteCredentialsService().get("tenant", "myType", "non-existing", ctx.asyncAssertSuccess(s -> { assertThat(s.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND)); get.complete(); })); get.await(); }