@Test
  public void testTransaction() throws InterruptedException {
    // Assertions
    deletedEndpoint.expectedMessageCount(8);
    deletedEndpoint.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 204);

    transactedEndpoint.expectedMessageCount(1);

    verifiedEndpoint.expectedMessageCount(3);

    midtransactionEndpoint.expectedMessageCount(3);
    midtransactionEndpoint.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 201);

    notfoundEndpoint.expectedMessageCount(6);
    notfoundEndpoint.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 404);

    // Start the transaction
    final Map<String, Object> headers = new HashMap<>();
    headers.put(Exchange.HTTP_METHOD, "POST");
    headers.put(Exchange.CONTENT_TYPE, "text/turtle");

    // Create the object
    final String fullPath =
        template.requestBodyAndHeaders(
            "direct:create", FcrepoTestUtils.getTurtleDocument(), headers, String.class);

    assertNotNull(fullPath);

    final String identifier = fullPath.replaceAll(FcrepoTestUtils.getFcrepoBaseUrl(), "");

    // Test the creation of several objects
    template.sendBodyAndHeader("direct:transact", null, "TestIdentifierBase", identifier);

    // Test the object
    template.sendBodyAndHeader(
        "direct:verify", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/one");
    template.sendBodyAndHeader(
        "direct:verify", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/two");
    template.sendBodyAndHeader(
        "direct:verify", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/three");

    // Teardown
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/one");
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/two");
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/three");
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier);

    // Confirm assertions
    verifiedEndpoint.assertIsSatisfied();
    deletedEndpoint.assertIsSatisfied();
    transactedEndpoint.assertIsSatisfied();
    notfoundEndpoint.assertIsSatisfied();
    midtransactionEndpoint.assertIsSatisfied();
  }
Ejemplo n.º 2
0
 public Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers)
     throws Exception {
   ProducerTemplate template = context.createProducerTemplate();
   Object answer = null;
   try {
     answer = template.requestBodyAndHeaders(endpointUri, body, headers);
   } finally {
     template.stop();
   }
   return answer;
 }