use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method missingResourcesTest.
@Test
public void missingResourcesTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
try {
decisionsClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
throw new Exception("RESTTest.missingResourceTest: no exception thrown.");
} catch (UniformInterfaceException e) {
int errorCode = e.getResponse().getStatus();
if (errorCode != 400) {
throw new Exception("RESTTest.missingResourceTest: incorrect error code");
}
String json = e.getResponse().getEntity(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 424) {
throw new Exception("RESTTest.missingResourcesTest() failed, status code not 424");
}
if (jo.optJSONObject("body") != null) {
throw new Exception("RESTTest.missingResourcesTest() failed, body not empty");
}
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method getEntitlementsTest.
@Test
public void getEntitlementsTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME);
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String json = entitlementsClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 200) {
throw new Exception("RESTTest.getEntitlementsTest: failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.getEntitlementsTest: failed, body element is null");
}
JSONArray results = jbody.optJSONArray("results");
if (results == null) {
throw new Exception("RESTTest.getEntitlementsTest: failed, results element is null");
}
if (results.length() < 1) {
throw new Exception("RESTTest.getEntitlementsTest: failed, results array is empty");
}
// dude, there are two entitlements returned.
// the first one is the root resource which is http://www.resttest.com
// and the action value is empty.
// we need to get the second one, which is http://www.resttest.com:80/*
JSONEntitlement ent = new JSONEntitlement(results.getJSONObject(1));
Object resultObj = ent.getActionValue("GET");
if (resultObj != null) {
if (!ent.getActionValue("GET")) {
throw new Exception("RESTTest.getEntitlementsTest: failed, action value is false");
}
} else {
throw new Exception("RESTTest.getEntitlementsTest: failed, action value is null");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method getEntitlementTest.
@Test
public void getEntitlementTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String json = entitlementClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 200) {
throw new Exception("RESTTest.getEntitlementTest() failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.getEntitlementTest() failed, body element is null");
}
JSONEntitlement ent = new JSONEntitlement(jbody);
boolean result = ent.getActionValue("GET");
if (!result) {
throw new Exception("RESTTest.getEntitlementTest() failed");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class ListenerRestTest method testAddDifferentApp.
@Test(dependsOnMethods = { "testAddMoreResources" })
public void testAddDifferentApp() throws Exception {
Form form = new Form();
form.add("application", "sunBank");
form.add("subject", hashedTokenId);
form.add("url", NOTIFICATION_URL);
String result = listenerClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
JSONObject jo = new JSONObject(result);
if (!jo.getString("statusCode").equals(IdRepoErrorCode.ILLEGAL_ARGUMENTS)) {
throw new Exception("ListenerRESTTest.testAddDifferentApp failed to add");
}
Set<EntitlementListener> listeners = ListenerManager.getInstance().getListeners(adminSubject);
if ((listeners == null) || listeners.isEmpty()) {
throw new Exception("ListenerTestTest.testAddDifferentApp: no listeners");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class PrivilegeRestTest method noJSONStringInPut.
private void noJSONStringInPut() throws Exception {
try {
Form form = new Form();
webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).put(String.class, form);
} catch (UniformInterfaceException e) {
validateUniformInterfaceException(e, 9, "noJSONStringInPut");
}
}
Aggregations