Search in sources :

Example 1 with CredentialsConstants

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

the class CredentialsHttpIT method testGetCredentialsForDeviceRegardlessOfType.

/**
 * Verifies that the service returns all credentials registered for a given device regardless of type.
 * <p>
 * The returned JsonObject must consist of the total number of entries and contain all previously added credentials
 * in the provided JsonArray that is found under the key of the endpoint {@link CredentialsConstants#CREDENTIALS_ENDPOINT}.
 *
 * @param context The vert.x test context.
 * @throws InterruptedException if registration of credentials is interrupted.
 */
@Test
public void testGetCredentialsForDeviceRegardlessOfType(final TestContext context) throws InterruptedException {
    final String pskAuthId = getRandomAuthId(TEST_AUTH_ID);
    final List<JsonObject> credentialsToAdd = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        final JsonObject requestBody = newPskCredentials(deviceId, pskAuthId);
        requestBody.put(CredentialsConstants.FIELD_TYPE, "type" + i);
        credentialsToAdd.add(requestBody);
    }
    addMultipleCredentials(credentialsToAdd).compose(ar -> registry.getCredentials(TENANT, deviceId)).setHandler(context.asyncAssertSuccess(b -> {
        assertResponseBodyContainsAllCredentials(context, b.toJsonObject(), credentialsToAdd);
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Constants(org.eclipse.hono.util.Constants) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) After(org.junit.After) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) StandardCharsets(java.nio.charset.StandardCharsets) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Rule(org.junit.Rule) DeviceRegistryHttpClient(org.eclipse.hono.tests.DeviceRegistryHttpClient) CredentialsObject(org.eclipse.hono.util.CredentialsObject) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

CompositeFuture (io.vertx.core.CompositeFuture)1 Future (io.vertx.core.Future)1 Vertx (io.vertx.core.Vertx)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 HttpURLConnection (java.net.HttpURLConnection)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 DeviceRegistryHttpClient (org.eclipse.hono.tests.DeviceRegistryHttpClient)1 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)1 Constants (org.eclipse.hono.util.Constants)1 CredentialsConstants (org.eclipse.hono.util.CredentialsConstants)1 CredentialsObject (org.eclipse.hono.util.CredentialsObject)1 After (org.junit.After)1 AfterClass (org.junit.AfterClass)1