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")));
}
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 + "'");
}
};
}
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);
}
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);
}
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;
}
Aggregations