Search in sources :

Example 36 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project joynr by bmwcarit.

the class SingleControlledBounceProxyTest method testSimpleChannelSetupAndDeletion.

@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")));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project joynr by bmwcarit.

the class ChannelServiceResponseMatchers method containsChannel.

public static Matcher<JsonPath> containsChannel(final String channelId) {
    return new BaseMatcher<JsonPath>() {

        @Override
        public boolean matches(Object item) {
            JsonPath jsonPath = (JsonPath) item;
            List<String> channelIds = jsonPath.getList("name");
            for (String c : channelIds) {
                if (c.equals(channelId)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public void describeMismatch(Object item, Description description) {
            JsonPath jsonPath = (JsonPath) item;
            description.appendText(jsonPath.prettyPrint());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("contains channel ID '" + channelId + "'");
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) JsonPath(com.jayway.restassured.path.json.JsonPath)

Example 38 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project dataverse by IQSS.

the class BuiltinUsersIT method testUserId.

@Test
public void testUserId() {
    String email = null;
    Response createUserResponse = createUser(getRandomUsername(), "firstName", "lastName", email);
    createUserResponse.prettyPrint();
    assertEquals(200, createUserResponse.getStatusCode());
    JsonPath createdUser = JsonPath.from(createUserResponse.body().asString());
    int builtInUserIdFromJsonCreateResponse = createdUser.getInt("data.user." + idKey);
    int authenticatedUserIdFromJsonCreateResponse = createdUser.getInt("data.authenticatedUser." + idKey);
    String username = createdUser.getString("data.user." + usernameKey);
    Response getUserResponse = getUserFromDatabase(username);
    getUserResponse.prettyPrint();
    assertEquals(200, getUserResponse.getStatusCode());
    JsonPath getUserJson = JsonPath.from(getUserResponse.body().asString());
    int userIdFromDatabase = getUserJson.getInt("data.id");
    Response deleteUserResponse = deleteUser(username);
    assertEquals(200, deleteUserResponse.getStatusCode());
    deleteUserResponse.prettyPrint();
    System.out.println(userIdFromDatabase + " was the id from the database");
    System.out.println(builtInUserIdFromJsonCreateResponse + " was the id of the BuiltinUser from JSON response on create");
    System.out.println(authenticatedUserIdFromJsonCreateResponse + " was the id of the AuthenticatedUser from JSON response on create");
    assertEquals(userIdFromDatabase, authenticatedUserIdFromJsonCreateResponse);
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 39 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project dataverse by IQSS.

the class BuiltinUsersIT method testLogin.

@Test
public void testLogin() {
    String usernameToCreate = getRandomUsername();
    String email = null;
    Response createUserResponse = createUser(usernameToCreate, "firstName", "lastName", email);
    createUserResponse.prettyPrint();
    assertEquals(200, createUserResponse.getStatusCode());
    JsonPath createdUser = JsonPath.from(createUserResponse.body().asString());
    String createdUsername = createdUser.getString("data.user." + usernameKey);
    assertEquals(usernameToCreate, createdUsername);
    String createdToken = createdUser.getString("data.apiToken");
    logger.info(createdToken);
    Response getApiTokenShouldFail = UtilIT.getApiTokenUsingUsername(usernameToCreate, usernameToCreate);
    getApiTokenShouldFail.then().assertThat().body("message", equalTo("This API endpoint has been disabled.")).statusCode(FORBIDDEN.getStatusCode());
    Response setAllowApiTokenLookupViaApi = UtilIT.setSetting(SettingsServiceBean.Key.AllowApiTokenLookupViaApi, "true");
    setAllowApiTokenLookupViaApi.then().assertThat().statusCode(OK.getStatusCode());
    Response getApiTokenUsingUsername = UtilIT.getApiTokenUsingUsername(usernameToCreate, usernameToCreate);
    getApiTokenUsingUsername.prettyPrint();
    assertEquals(200, getApiTokenUsingUsername.getStatusCode());
    String retrievedTokenUsingUsername = JsonPath.from(getApiTokenUsingUsername.asString()).getString("data.message");
    assertEquals(createdToken, retrievedTokenUsingUsername);
    Response failExpected = UtilIT.getApiTokenUsingUsername("junk", "junk");
    failExpected.prettyPrint();
    assertEquals(400, failExpected.getStatusCode());
    if (BuiltinUsers.retrievingApiTokenViaEmailEnabled) {
        Response getApiTokenUsingEmail = getApiTokenUsingEmail(usernameToCreate + "@mailinator.com", usernameToCreate);
        getApiTokenUsingEmail.prettyPrint();
        assertEquals(200, getApiTokenUsingEmail.getStatusCode());
        String retrievedTokenUsingEmail = JsonPath.from(getApiTokenUsingEmail.asString()).getString("data.message");
        assertEquals(createdToken, retrievedTokenUsingEmail);
    }
    Response removeAllowApiTokenLookupViaApi = UtilIT.deleteSetting(SettingsServiceBean.Key.AllowApiTokenLookupViaApi);
    removeAllowApiTokenLookupViaApi.then().assertThat().statusCode(200);
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 40 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project dataverse by IQSS.

the class UtilIT method getDatasetIdFromResponse.

static Integer getDatasetIdFromResponse(Response createDatasetResponse) {
    JsonPath createdDataset = JsonPath.from(createDatasetResponse.body().asString());
    int datasetId = createdDataset.getInt("data.id");
    logger.info("Id found in create dataset response: " + datasetId);
    return datasetId;
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath)

Aggregations

JsonPath (com.jayway.restassured.path.json.JsonPath)83 Test (org.junit.Test)56 Response (com.jayway.restassured.response.Response)25 BaseRestTest (integration.BaseRestTest)11 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)10 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)9 Matchers.anyString (org.mockito.Matchers.anyString)8 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Ignore (org.junit.Ignore)5 MongoDbSeed (integration.MongoDbSeed)4 HashMap (java.util.HashMap)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)2 Application (org.talend.dataprep.transformation.Application)2