use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class DictionaryRestApiTest method testGetAssociationDef.
public void testGetAssociationDef() throws Exception {
GetRequest req = new GetRequest(URL_SITES + "/cm_person/association/cm_avatar");
Response response = sendRequest(req, 200);
JSONObject result = new JSONObject(response.getContentAsString());
assertEquals(200, response.getStatus());
validateAssociationDef(result);
// wrong data
response = sendRequest(new GetRequest(URL_SITES + "/cm_personalbe/association/cms_avatarsara"), 404);
assertEquals(404, response.getStatus());
// ask for an invalid association, which returns a null array
response = sendRequest(new GetRequest(URL_SITES + "/cm_person/association/cm_atari"), 200);
// change to return 404
result = new JSONObject(response.getContentAsString());
assertEquals(0, result.length());
assertEquals(200, response.getStatus());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class DictionaryRestApiTest method validatePropertiesConformity.
private void validatePropertiesConformity(JSONArray classDefs) throws Exception {
final int itemsToTest = 10;
for (int i = 0; (i < itemsToTest) && (i < classDefs.length()); ++i) {
JSONObject classDef1 = classDefs.getJSONObject(i);
JSONArray propertyNames1 = classDef1.getJSONObject("properties").names();
// properties of class obtained by api/classes
List<String> propertyValues1 = Collections.emptyList();
if (propertyNames1 != null) {
propertyValues1 = new ArrayList<String>(propertyNames1.length());
for (int j = 0; j < propertyNames1.length(); j++) {
propertyValues1.add(propertyNames1.getString(j));
}
}
String classUrl = classDef1.getString("url");
assertTrue(classUrl.contains(URL_SITES));
Response responseFromGetClassDef = sendRequest(new GetRequest(classUrl), 200);
JSONObject classDef2 = new JSONObject(responseFromGetClassDef.getContentAsString());
assertTrue(classDef2.length() > 0);
assertEquals(200, responseFromGetClassDef.getStatus());
assertEquals(classDef1.getString("name"), classDef2.getString("name"));
JSONArray propertyNames2 = classDef2.getJSONObject("properties").names();
// properties of class obtained by api/classes/class
List<String> propertyValues2 = Collections.emptyList();
if (propertyNames2 != null) {
propertyValues2 = new ArrayList<String>(propertyNames2.length());
for (int j = 0; j < propertyNames2.length(); j++) {
propertyValues2.add(propertyNames2.getString(j));
}
}
Response responseFromGetPropertiesDef = sendRequest(new GetRequest(classUrl + "/properties"), 200);
JSONArray propertiesDefs = new JSONArray(responseFromGetPropertiesDef.getContentAsString());
assertEquals(200, responseFromGetClassDef.getStatus());
// properties of class obtained by api/classes/class/properties
List<String> propertyValues3 = new ArrayList<String>(propertiesDefs.length());
for (int j = 0; j < propertiesDefs.length(); j++) {
propertyValues3.add(propertiesDefs.getJSONObject(j).getString("name"));
}
assertEquivalenceProperties(propertyValues1, propertyValues2);
assertEquivalenceProperties(propertyValues2, propertyValues3);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class DictionaryRestApiTest method testGetClassDetail.
public void testGetClassDetail() throws Exception {
GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed");
Response response = sendRequest(req, 200);
JSONObject result = new JSONObject(response.getContentAsString());
assertEquals(result.length() > 0, true);
assertEquals(200, response.getStatus());
validateAspectClass(result);
req = new GetRequest(URL_SITES + "/cm_cmobject");
response = sendRequest(req, 200);
result = new JSONObject(response.getContentAsString());
assertEquals(result.length() > 0, true);
assertEquals(200, response.getStatus());
validateTypeClass(result);
response = sendRequest(new GetRequest("/api/classes/cm_hi"), 404);
assertEquals(404, response.getStatus());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class DictionaryRestApiTest method testSubClassDetails.
public void testSubClassDetails() throws Exception {
GetRequest req = new GetRequest(URL_SITES + "/sys_base/subclasses");
Map<String, String> arguments = new HashMap<String, String>();
arguments.put("r", "true");
req.setArgs(arguments);
Response response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
response = sendRequest(req, 200);
JSONArray result = new JSONArray(response.getContentAsString());
assertEquals(result.length() > 0, true);
for (int i = 0; i < result.length(); i++) {
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200, response.getStatus());
arguments.clear();
arguments.put("r", "false");
req.setArgs(arguments);
response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(result.length() > 0, true);
for (int i = 0; i < result.length(); i++) {
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200, response.getStatus());
assertEquals(200, response.getStatus());
arguments.clear();
arguments.put("r", "false");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
result = new JSONArray(response.getContentAsString());
assertEquals(result.length() > 0, true);
for (int i = 0; i < result.length(); i++) {
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200, response.getStatus());
arguments.clear();
arguments.put("r", "true");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
result = new JSONArray(response.getContentAsString());
assertEquals(result.length() > 0, true);
for (int i = 0; i < result.length(); i++) {
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200, response.getStatus());
// data with only name along
arguments.clear();
arguments.put("r", "true");
arguments.put("n", "cmobject");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404, response.getStatus());
// invalid name and namespaceprefix
arguments.clear();
arguments.put("r", "true");
// name and namespaceprefix are valid one , but its not present in sys_base as a sub-class
arguments.put("n", "dublincore");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404, response.getStatus());
// invalid name and a valid namespaceprefix
arguments.clear();
arguments.put("r", "true");
// name and namespaceprefix are invalid one
arguments.put("n", "dublincoresara");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404, response.getStatus());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class DictionaryRestApiTest method testGetPropertyDefs.
public void testGetPropertyDefs() throws Exception {
// validate for a particular property cm_created in the class cm_auditable
GetRequest req = new GetRequest(URL_SITES + "/cm_auditable/properties");
Map<String, String> arguments = new HashMap<String, String>();
arguments.put("nsp", "cm");
req.setArgs(arguments);
Response response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
JSONArray result = new JSONArray(response.getContentAsString());
assertEquals(200, response.getStatus());
assertEquals(5, result.length());
// validate with no parameter => returns an array of property definitions
arguments.clear();
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(200, response.getStatus());
assertEquals(result.length() > 0, true);
for (int i = 0; i < result.length(); i++) {
if (result.getJSONObject(i).get("name").equals("cm:created")) {
validatePropertyDef(result.getJSONObject(i));
}
}
// test /api/properties
req = new GetRequest(URL_PROPERTIES);
response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
result = new JSONArray(response.getContentAsString());
assertEquals(result.length() > 0, true);
for (int i = 0; i < result.length(); i++) {
if (result.getJSONObject(i).get("name").equals("cm:created")) {
validatePropertyDef(result.getJSONObject(i));
}
@SuppressWarnings("unused") String title = "";
if (result.getJSONObject(i).has("title") == true) {
title = result.getJSONObject(i).getString("title");
}
}
// test /api/properties?name=cm:name&name=cm:title&name=cm:description
req = new GetRequest(URL_PROPERTIES + "?name=cm:name&name=cm:title&name=cm:description");
response = sendRequest(req, 200);
assertEquals(200, response.getStatus());
result = new JSONArray(response.getContentAsString());
assertEquals(3, result.length());
}
Aggregations