Java Code Examples for com.jayway.restassured.response.Response#getHeader()

The following examples show how to use com.jayway.restassured.response.Response#getHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OSDataPrepAPIHelper.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Export the current preparation sample depending the given parameters.
 *
 * @param parameters the export parameters.
 * @return the response.
 */
public Response executeExport(Map<String, String> parameters) throws IOException {
    Response response = given() //
            .contentType(JSON) //
            .when() //
            .queryParameters(parameters) //
            .get("/api/export");

    if (HttpStatus.ACCEPTED.value() == response.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = response.getHeader(HttpHeaders.LOCATION);

        waitForAsyncMethodToFinish(asyncMethodStatusUrl);

        response = given() //
                .contentType(JSON) //
                .when() //
                .queryParameters(parameters) //
                .get("/api/export");
    }
    return response;
}
 
Example 2
Source File: ExportAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void testExport_with_filename() throws Exception {
    // given
    final String preparationId =
            testClient.createPreparationFromFile("export/export_dataset.csv", "testExport", home.getId());

    String fileName = "beerisgoodforyou";

    // when
    final Response export = testClient.exportPreparation(preparationId, "head", ";", fileName);

    // then
    String contentDispositionHeaderValue = export.getHeader("Content-Disposition");
    Assertions.assertThat(contentDispositionHeaderValue).contains("filename*=UTF-8''" + fileName);

}
 
Example 3
Source File: ExportAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void testExport_default_filename() throws Exception {
    // given
    final String preparationId =
            testClient.createPreparationFromFile("export/export_dataset.csv", "testExport", home.getId());

    String fileName = "testExport.csv";

    // when
    final Response export = testClient.exportPreparation(preparationId, "head");

    // then
    String contentDispositionHeaderValue = export.getHeader("Content-Disposition");

    Assertions.assertThat(contentDispositionHeaderValue).contains("filename*=UTF-8''" + fileName);

}
 
Example 4
Source File: APIClientTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
public Response getFailedPreparationWithFilter(String preparationId, String malformedFilter) throws IOException {
    Response transformedResponse = given() //
            .when() //
            .get("/api/preparations/{prepId}/content?version={version}&from={stepId}&filter={filter}",
                    preparationId, "head", "HEAD", malformedFilter);

    if (ACCEPTED.value() == transformedResponse.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");

        AsyncExecution.Status asyncStatus = waitForAsyncMethodToFinish(asyncMethodStatusUrl);
        assertEquals(AsyncExecution.Status.FAILED, asyncStatus);

        return given()
                .expect() //
                .statusCode(200) //
                .log()
                .ifError() //
                .when() //
                .get(asyncMethodStatusUrl);
    }
    return transformedResponse;
}
 
Example 5
Source File: LinkHeaderGenerationTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void linksHeaderShouldBeCorrectlyGenerated(ITestContext ctx) throws Exception {
  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .when()
          .get(SECURE_PATH + "/test/paging/test-path-param?query-param=test-query-param");

  assertEquals(response.getStatusCode(), 200);

  final String headerValue = response.getHeader("Link");
  assertNotNull(headerValue, "Link header is missing in the response");

  final Map<String, String> relToLinkMap = PagingUtil.parseLinkHeader(headerValue);
  final Set<String> expectedRels = new HashSet<>(asList("first", "last", "prev", "next"));
  assertEquals(
      relToLinkMap.keySet(),
      expectedRels,
      "Rels are different " + symmetricDifference(expectedRels, relToLinkMap.keySet()));

  final String expectedUri =
      "http://localhost:"
          + ctx.getAttribute(EverrestJetty.JETTY_PORT)
          + "/rest/private/test/paging/test-path-param";
  for (String link : relToLinkMap.values()) {
    final URI uri = URI.create(link);
    final Map<String, List<String>> params = getQueryParameters(uri.toURL());
    assertEquals(params.size(), 3);
    assertNotNull(params.get("skipCount"));
    assertNotNull(params.get("maxItems"));
    assertEquals(params.get("query-param").get(0), "test-query-param");
    assertEquals(link, expectedUri + '?' + uri.getQuery());
  }
}
 
Example 6
Source File: AsynchronousTransformerTest.java    From p3-batchrefine with Apache License 2.0 5 votes vote down vote up
private Response doRequest(String input, String transform, String format,
                             MimeType contentType) throws Exception {
      String transformURI = fServers.transformURI(input + "-" + transform + ".json").toString();

      Response response = RestAssured.given()
              .queryParam("refinejson", transformURI)
              .header("Accept", contentType.toString() + ";q=1.0")
              .contentType("text/csv")
              .content(contentsAsBytes("inputs", input, "csv"))
              .when().post();

      Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusCode());

      String location = response.getHeader("location");
      Assert.assertTrue(location != null);

/* Polls until ready. */
      long start = System.currentTimeMillis();
      do {
          response = RestAssured.given()
                  .header("Accept", "text/turtle")
                  .header("Content-Type", "text/turtle")
                  .when().get(location);

          if (System.currentTimeMillis() - start >= ASYNC_TIMEOUT) {
              Assert.fail("Asynchronous call timed out.");
          }

          Thread.sleep(100);

      } while (response.statusCode() == HttpStatus.SC_ACCEPTED);

      return response;
  }
 
Example 7
Source File: OSDataPrepAPIHelper.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * Get preparation content by id and at a given version.
 *
 * @param preparationId the preparation id.
 * @param version version of the preparation
 * @param from Where to get the data from (HEAD if no value)
 * @param tql The TQL filter to apply (pass null if you want the non-filtered preparation content)
 * @return the response.
 */
public Response getPreparationContent(String preparationId, String version, String from, String tql)
        throws IOException {
    RequestSpecification given = given() //
            .queryParam(VERSION, version) //
            .queryParam(FROM, from);
    if (tql != null) {
        given.queryParam("filter", tql);
    }
    Response response = given
            .when() //
            .get("/api/preparations/{preparationId}/content", preparationId);

    if (HttpStatus.ACCEPTED.value() == response.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = response.getHeader(HttpHeaders.LOCATION);

        waitForAsyncMethodToFinish(asyncMethodStatusUrl);

        response = given() //
                .queryParam(VERSION, version) //
                .queryParam(FROM, from) //
                .queryParam("filter", tql) //
                .when() //
                .get("/api/preparations/{preparationId}/content", preparationId);
    }
    return response;
}
 
Example 8
Source File: APIClientTest.java    From data-prep with Apache License 2.0 5 votes vote down vote up
public DataSetMetadata getPrepMetadata(String preparationId) throws IOException {
    DataSetMetadata metadata;

    // when
    Response transformedResponse = given().when().get("/api/preparations/{id}/metadata", preparationId);

    HttpStatus responseStatus = HttpStatus.valueOf(transformedResponse.getStatusCode());
    if (ACCEPTED.equals(responseStatus)) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");

        waitForAsyncMethodToFinishWithSuccess(asyncMethodStatusUrl);

        Response response = given() //
                .when() //
                .expect() //
                .statusCode(200) //
                .log() //
                .ifError() //
                .get("/api/preparations/{id}/metadata", preparationId);
        metadata = mapper.readValue(response.asInputStream(), DataSetMetadata.class);
    } else if (OK.equals(responseStatus)) {
        metadata = mapper.readValue(transformedResponse.asInputStream(), DataSetMetadata.class);
    } else {
        throw new RuntimeException(
                "Could not get preparation metadata. Response was: " + transformedResponse.print());
    }
    return metadata;
}
 
Example 9
Source File: TransformAPITest.java    From data-prep with Apache License 2.0 4 votes vote down vote up
/**
 * Test asynchronous preparation transformation
 */
@Test
public void first_transformation_should_be_async() throws Exception {
    // given
    final String preparationId =
            testClient.createPreparationFromFile("dataset/dataset_TDP-402.csv", "testDataset", home.getId());
    testClient.applyAction(preparationId,
            IOUtils.toString(this.getClass().getResourceAsStream("transformation/TDP-402.json"), UTF_8));

    // when
    Response transformedResponse = given()
            .when() //
            .expect()
            .statusCode(202)
            .log()
            .ifError() //
            .get("/api/preparations/{id}/content?version=head", preparationId);

    // first time we have a 202 with a Location to see asynchronous method status
    Assert.assertEquals(HttpStatus.ACCEPTED.value(), transformedResponse.getStatusCode());
    final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");

    Assert.assertNotNull(asyncMethodStatusUrl);

    boolean isAsyncMethodRunning = true;
    int nbLoop = 0;

    while (isAsyncMethodRunning && nbLoop < 100) {

        String statusAsyncMethod = given()
                .when() //
                .expect()
                .statusCode(200)
                .log()
                .ifError() //
                .get(asyncMethodStatusUrl)
                .asString();

        AsyncExecutionMessage asyncExecutionMessage =
                mapper.readerFor(AsyncExecutionMessage.class).readValue(statusAsyncMethod);

        isAsyncMethodRunning = asyncExecutionMessage.getStatus().equals(AsyncExecution.Status.RUNNING);

        Thread.sleep(50);
        nbLoop++;
    }

    // second time should be a 200
    transformedResponse = given()
            .when() //
            .expect()
            .statusCode(200)
            .log()
            .ifError() //
            .get("/api/preparations/{id}/content?version=head", preparationId);

    Assert.assertEquals(HttpStatus.OK.value(), transformedResponse.getStatusCode());

}
 
Example 10
Source File: APIClientTest.java    From data-prep with Apache License 2.0 4 votes vote down vote up
/**
 * Method handling 202/200 status to get the transformation content
 *
 * @param preparationId is of the preparation
 * @param version version of the preparation
 * @param stepId like HEAD or FILTER, etc.
 * @param filter TQL filter to filter the preparation content
 * @return the content of a preparation
 * @throws IOException
 */
public Response getPreparation(String preparationId, String version, String stepId, String filter)
        throws IOException {
    // when
    Response transformedResponse;
    RequestSpecification initialRequest = given().when();
    if (filter.isEmpty()) {
        transformedResponse = initialRequest //
                .get("/api/preparations/{prepId}/content?version={version}&from={stepId}", preparationId, version,
                        stepId);
    } else {
        transformedResponse = initialRequest //
                .get("/api/preparations/{prepId}/content?version={version}&from={stepId}&filter={filter}",
                        preparationId, version, stepId, filter);
    }

    if (ACCEPTED.value() == transformedResponse.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");

        waitForAsyncMethodToFinishWithSuccess(asyncMethodStatusUrl);

        ResponseSpecification contentRequest = given() //
                .when() //
                .expect() //
                .statusCode(200) //
                .log() //
                .ifError();
        if (filter.isEmpty()) {
            transformedResponse = contentRequest //
                    .get("/api/preparations/{prepId}/content?version={version}&from={stepId}", preparationId,
                            version, stepId);
        } else {
            transformedResponse = contentRequest //
                    .get("/api/preparations/{prepId}/content?version={version}&from={stepId}&filter={filter}",
                            preparationId, version, stepId, filter);
        }
    }

    return transformedResponse;
}
 
Example 11
Source File: ControlledBounceProxyServerTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 40000)
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithoutMessagesPending() throws Exception {

    final String channelId = "channel_testNormalMessagingWithoutMessagesPending";
    final String trackingId = "trackingId_testNormalMessagingWithoutMessagesPending";

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                            .post("channels?ccid=" + channelId);
    /* @formatter:on */

    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));
    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);

    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);

    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));

    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);
    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);

    // open long polling channel
    /* @formatter:off */
    Response responseOpenChannel = given().when()
                                          .contentType(ContentType.BINARY)
                                          .header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                          .get(SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(200 /* OK */, responseOpenChannel.getStatusCode());

    // long poll should return without messages after a while
    // body doesn't actually contain proper json, but each message
    // serialized as json attached. We have to split them first.
    String body = responseOpenChannel.getBody().asString();
    List<String> messages = Utilities.splitJson(body);
    assertEquals(0, messages.size());
}
 
Example 12
Source File: ControlledBounceProxyServerTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened() throws Exception {

    final String channelId = "channel-testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened";
    final String trackingId = "trackingId-testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened";

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                            .post("channels?ccid=" + channelId);
    /* @formatter:on */

    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));

    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);

    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);

    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));

    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);

    // post messages to long polling channel before opening channel
    byte[] expectedPayload = "message-123".getBytes(StandardCharsets.UTF_8);
    byte[] serializedMessage = bpMock.createImmutableMessage(100000l, expectedPayload).getSerializedMessage();

    /* @formatter:off */
    Response responsePostMessage = given().when()
                                          .contentType(ContentType.BINARY)
                                          .body(serializedMessage)
                                          .post("message" + SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(201 /* Created */, responsePostMessage.getStatusCode());
    assertThat(responsePostMessage.getHeader(HEADER_LOCATION),
               isMessageUrlwithJsessionId(bpUrl, "message-123", sessionId, SESSIONID_NAME));
    assertEquals("message-123", responsePostMessage.getHeader(HEADER_MSG_ID));

    // open long polling channel
    /* @formatter:off */
    Response responseOpenChannel = given().when()
                                          .contentType(ContentType.BINARY)
                                          .header("X-Atmosphere-tracking-id", trackingId)
                                          .get(SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(200 /* OK */, responseOpenChannel.getStatusCode());

    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
    assertEquals(1, messages.size());
    assertEquals(expectedPayload, messages.get(0).getUnencryptedBody());
}
 
Example 13
Source File: ControlledBounceProxyServerTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 30000)
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened() throws Exception {

    final String channelId = "channel-testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened";
    final String trackingId = "trackingId-testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened";

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                            .post("channels?ccid=" + channelId);
    /* @formatter:on */

    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));
    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);

    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);
    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));

    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);

    // post messages to long polling channel before opening channel
    String msgIds[] = { "message-123", "message-456", "message-789" };
    for (String msgId : msgIds) {
        byte[] serializedMessage = bpMock.createImmutableMessage(100000l, msgId.getBytes(StandardCharsets.UTF_8))
                                         .getSerializedMessage();

        /* @formatter:off */
        Response responsePostMessage = given().when()
                                              .log()
                                              .all()
                                              .contentType(ContentType.BINARY)
                                              .body(serializedMessage)
                                              .post("message/" + SESSIONID_APPENDIX + sessionId);
        /* @formatter:on */
        assertEquals(201 /* Created */, responsePostMessage.getStatusCode());
        assertThat(responsePostMessage.getHeader(HEADER_LOCATION),
                   isMessageUrlwithJsessionId(bpUrl, msgId, sessionId, SESSIONID_NAME));
        assertEquals(msgId, responsePostMessage.getHeader(HEADER_MSG_ID));
    }

    // open long polling channel
    /* @formatter:off */
    Response responseOpenChannel = given().when()
                                          .contentType(ContentType.BINARY)
                                          .header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                          .get(SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(200 /* OK */, responseOpenChannel.getStatusCode());

    // body doesn't actually contain proper json, but each message
    // serialized as json attached. We have to split them first.
    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
    assertEquals(3, messages.size());

    assertThat(messages, containsPayload("message-123"));
    assertThat(messages, containsPayload("message-456"));
    assertThat(messages, containsPayload("message-789"));
}
 
Example 14
Source File: ControlledBounceProxyServerTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened() throws Exception {

    final String channelId = "channel-testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened";
    final String trackingId = "trackingId-testNormalMessagingWithMultipleMessagePostsAfterChannelWasOpened";

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                            .post("channels?ccid=" + channelId);
    /* @formatter:on */

    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));
    final String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);

    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);
    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));

    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);

    // open long polling channel first in separate thread
    Future<?> longPollingChannelFuture = Executors.newSingleThreadExecutor().submit(new Callable<Response>() {

        @Override
        public Response call() throws Exception {

            /* @formatter:off */
            return given().when()
                          .contentType(ContentType.BINARY)
                          .header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                          .get("");
            /* @formatter:on */
        }
    });

    // post messages to long polling channel after opening channel
    String msgIds[] = { "message-123", "message-456", "message-789" };
    for (String msgId : msgIds) {
        byte[] serializedMessage = bpMock.createImmutableMessage(100000l, msgId.getBytes(StandardCharsets.UTF_8))
                                         .getSerializedMessage();

        /* @formatter:off */
        Response responsePostMessage = given().when()
                                              .contentType(ContentType.BINARY)
                                              .body(serializedMessage)
                                              .post("message/" + SESSIONID_APPENDIX + sessionId);
        /* @formatter:on */
        assertEquals(201 /* Created */, responsePostMessage.getStatusCode());
        String messageUrl = responsePostMessage.getHeader(HEADER_LOCATION);
        assertThat(messageUrl, isMessageUrlwithJsessionId(bpUrl, msgId, sessionId, SESSIONID_NAME));
        assertEquals(msgId, responsePostMessage.getHeader(HEADER_MSG_ID));
    }

    Response responseOpenChannel = (Response) longPollingChannelFuture.get(10, TimeUnit.SECONDS);
    assertEquals(200 /* OK */, responseOpenChannel.getStatusCode());

    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
    assertEquals(1, messages.size());
    assertThat(messages, containsPayload("message-123"));
}
 
Example 15
Source File: SingleControlledBounceProxyTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
@Ignore("Ignore until servers are started in a separate JVM. Guice static problem")
public void testSimpleChannelSetupAndDeletion() throws Exception {

    String bpUrl = configuration.getBounceProxyUrl(SingleControlledBounceProxy.ID);

    // get bounce proxies list
    JsonPath listBps = given().get("bounceproxies").body().jsonPath();
    assertThat(listBps,
               anyOf(containsBounceProxy(SingleControlledBounceProxy.ID, "ALIVE"),
                     containsBounceProxy(SingleControlledBounceProxy.ID, "ACTIVE")));

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = //
            given().header(X_ATMOSPHERE_TRACKING_ID, "test-trackingId").post("channels?ccid=test-channel");
    /* @formatter:on */
    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertEquals(SingleControlledBounceProxy.ID, responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));

    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);
    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, "test-channel", SESSIONID_NAME));
    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);

    // list channels
    JsonPath listChannels = given().get("channels").getBody().jsonPath();
    // TODO uncomment as soon as channel deletion is implemented
    // assertThat(listChannels, is(numberOfChannels(1)));
    assertThat(listChannels, containsChannel("test-channel"));

    RestAssured.baseURI = bpUrl;

    JsonPath listBpChannels = given().get("channels" + SESSIONID_APPENDIX + sessionId).getBody().jsonPath();
    // TODO uncomment as soon as channel deletion is implemented
    // assertThat(listBpChannels, is(numberOfChannels(2)));
    assertThat(listBpChannels, containsChannel("test-channel"));
    assertThat(listBpChannels, containsChannel("/*"));

    assertEquals(200 /* OK */,
                 given().delete("channels/test-channel" + SESSIONID_APPENDIX + sessionId + "/")
                        .thenReturn()
                        .statusCode());
    JsonPath listBpChannelsAfterDelete = given().get("channels" + SESSIONID_APPENDIX + sessionId)
                                                .getBody()
                                                .jsonPath();
    // TODO uncomment as soon as channel deletion is implemented
    // assertThat(listBpChannelsAfterDelete, is(numberOfChannels(1)));
    assertThat(listBpChannelsAfterDelete, not(containsChannel("test-channel")));
}
 
Example 16
Source File: AttachmentTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test
public void testSendAndDownload() throws Exception {
    String channelId = "AttachmentTest_" + createUuidString();

    bpMock.createChannel(channelId);

    Response senMsgResponse = sendAttachmentMessage(channelId).get();

    String msgId = senMsgResponse.getHeader("msgId");

    Future<Response> response = bpMock.longPollInOwnThread(channelId, 1000000, 200);
    Response longPoll = response.get();

    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(longPoll);

    assertEquals(1, messages.size());

    ImmutableMessage message = messages.get(0);
    assertTrue(message.getUnencryptedBody() != null);

    Response attachment = getAttachment(channelId, msgId);
    logger.debug("Received attachment: ", convertStreamToString(attachment.getBody().asInputStream()));
}