use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationFailsForDisabledDevice.
/**
* Verifies that the registry fails to assert a disabled device's registration status with a 404 error code.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForDisabledDevice(final VertxTestContext ctx) {
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final Device device = new Device();
device.setEnabled(false);
getHelper().registry.registerDevice(tenantId, deviceId, device).compose(ok -> getClient().assertRegistration(tenantId, deviceId, null, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
ctx.verify(() -> assertErrorCode(t, HttpURLConnection.HTTP_NOT_FOUND));
ctx.completeNow();
}));
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationSucceedsForDevice.
/**
* Verifies that the registry succeeds a request to assert a device's registration status.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationSucceedsForDevice(final VertxTestContext ctx) {
final JsonObject defaults = new JsonObject().put(MessageHelper.SYS_PROPERTY_CONTENT_TYPE, "application/vnd.acme+json");
final Device device = new Device();
device.setDefaults(defaults.getMap());
final String deviceId = getHelper().getRandomDeviceId(tenantId);
getHelper().registry.registerDevice(tenantId, deviceId, device).compose(r -> getClient().assertRegistration(tenantId, deviceId, null, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(resp -> {
ctx.verify(() -> {
assertThat(resp.getDeviceId()).isEqualTo(deviceId);
assertThat(resp.getDefaults()).containsExactlyEntriesIn(defaults.getMap());
});
ctx.completeNow();
}));
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class DeviceRegistrationApiTests method testAssertRegistrationFailsForUnauthorizedGateway.
/**
* Verifies that the registry fails a gateway's request to assert a device's registration status for which it is not
* authorized with a 403 error code.
*
* @param ctx The vert.x test context.
*/
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForUnauthorizedGateway(final VertxTestContext ctx) {
// Prepare the identities to insert
final String deviceId = getHelper().getRandomDeviceId(tenantId);
final String authorizedGateway = getHelper().getRandomDeviceId(tenantId);
final String unauthorizedGateway = getHelper().getRandomDeviceId(tenantId);
final Device device = new Device();
device.setVia(Collections.singletonList(authorizedGateway));
getHelper().registry.registerDevice(tenantId, authorizedGateway).compose(ok -> getHelper().registry.registerDevice(tenantId, unauthorizedGateway)).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(ok -> getClient().assertRegistration(tenantId, deviceId, unauthorizedGateway, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
assertErrorCode(t, HttpURLConnection.HTTP_FORBIDDEN);
ctx.completeNow();
}));
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project vertx-web by vert-x3.
the class RouterBuilderIntegrationTest method testIssue1876.
@Timeout(10000)
@Test
public void testIssue1876(Vertx vertx, VertxTestContext testContext) {
Checkpoint checkpoint = testContext.checkpoint(2);
loadBuilderAndStartServer(vertx, "specs/repro_1876.yaml", testContext, routerBuilder -> {
routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false).setMountNotImplementedHandler(true));
routerBuilder.operation("createAccount").handler(routingContext -> routingContext.response().setStatusCode(200).end());
routerBuilder.operation("createAccountMember").handler(routingContext -> routingContext.response().setStatusCode(200).end());
}).onComplete(h -> {
testRequest(client, HttpMethod.POST, "/accounts").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("id", 123).put("type", "account-registration").put("attributes", new JsonObject().put("ownerEmail", "test@gmail.com"))), testContext, checkpoint);
testRequest(client, HttpMethod.POST, "/members").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("type", "account-member-registration").put("attributes", new JsonObject().put("email", "test@gmail.com"))), testContext, checkpoint);
});
}
use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.
the class RequestResponseClientTest method testCreateAndSendRequestReturnsCorrespondingResponseMessage.
/**
* Verifies that the client returns the service's response message that correlates with the request.
*
* @param ctx The vert.x test context.
*/
@Test
public void testCreateAndSendRequestReturnsCorrespondingResponseMessage(final VertxTestContext ctx) {
// WHEN sending a request message to the peer
client.compose(c -> c.createAndSendRequest("request", null, Buffer.buffer("hello"), "text/plain", SimpleRequestResponseResult::from, span)).onComplete(ctx.succeeding(s -> {
ctx.verify(() -> {
// THEN the response is passed to the handler registered with the request
assertEquals(200, s.getStatus());
assertEquals("payload", s.getPayload().toString());
verify(sample).completed(isA(Accepted.class));
// and a timer has been set to time out the request
final ArgumentCaptor<Handler<Long>> timeoutHandlerCaptor = VertxMockSupport.argumentCaptorHandler();
verify(vertx).setTimer(eq(clientConfig.getRequestTimeout()), timeoutHandlerCaptor.capture());
// triggering the timer now that the request has been handled should not invoke the sampler timeout method
timeoutHandlerCaptor.getValue().handle(1L);
verify(sample, never()).timeout();
});
ctx.completeNow();
}));
// WHEN a response is received for the request
final Message request = verifySenderSendAndUpdateDelivery(new Accepted());
final ProtonMessageHandler responseHandler = verifyResponseHandlerSet();
final Message response = ProtonHelper.message("payload");
response.setCorrelationId(request.getMessageId());
MessageHelper.addProperty(response, MessageHelper.APP_PROPERTY_STATUS, 200);
final ProtonDelivery delivery = mock(ProtonDelivery.class);
responseHandler.handle(delivery, response);
}
Aggregations