use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.
the class TestAccount method testAccountSearch.
// XXX this test needs work
// @Test
public void testAccountSearch() {
Storage ss;
try {
ss = makeServicesStorage();
/*
* arggg how do I get it to do an exact match */
JSONObject data = ss.getPathsJSON("users/", new JSONObject("{\"email\":\"bob@indigo-e.co.uk\"}"));
String[] paths = (String[]) data.get("listItems");
if (paths.length >= 1) {
for (int i = 0; i < paths.length; i++) {
// log.info(paths[i] +" : "+ i +" of "+ paths.length);
}
}
} catch (CSPDependencyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExistException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnimplementedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnderlyingStorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.
the class TestAccount method testAccountCreate.
@Test
public void testAccountCreate() throws Exception {
Storage ss = makeServicesStorage();
/* delete user so we can create it later - will return 404 if user doesn't exist */
JSONObject data = ss.getPathsJSON("users/", new JSONObject("{\"userId\":\"test31@collectionspace.org\"}"));
String[] paths = (String[]) data.get("listItems");
if (paths.length > 0)
ss.deleteJSON("users/" + paths[0]);
JSONObject u1 = getJSON("user1.json");
/* create the user based on json */
/* will give a hidden 500 error if userid is not unique (useful eh?) */
String path = ss.autocreateJSON("users/", u1, null);
assertNotNull(path);
JSONObject u2 = getJSON("user1.json");
ss.updateJSON("users/" + path, u2, new JSONObject());
JSONObject u3 = ss.retrieveJSON("users/" + path, new JSONObject());
assertNotNull(u3);
// Check output
assertEquals("Test Mccollectionspace.org", u3.getString("screenName"));
assertEquals("test31@collectionspace.org", u3.getString("userId"));
assertEquals("test31@collectionspace.org", u3.getString("email"));
assertEquals("active", u3.getString("status"));
// Check the method we're about to use to check if login works works
creds.setCredential(ServicesStorageGenerator.CRED_USERID, "test31@collectionspace.org");
creds.setCredential(ServicesStorageGenerator.CRED_PASSWORD, "blahblah");
cache.reset();
ReturnedDocument out = conn.getXMLDocument(RequestMethod.GET, "collectionobjects", null, creds, cache);
assertFalse(out.getStatus() == 200);
// Check login works
creds.setCredential(ServicesStorageGenerator.CRED_USERID, "test31@collectionspace.org");
creds.setCredential(ServicesStorageGenerator.CRED_PASSWORD, "testtestt");
cache.reset();
out = conn.getXMLDocument(RequestMethod.GET, "collectionobjects", null, creds, cache);
log.debug("Status", out.getStatus());
// assertTrue(out.getStatus()==200);
//
ss.deleteJSON("users/" + path);
/* tidy up and delete user */
}
use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.
the class TestDummyData method testDataCreation.
@Test
public void testDataCreation() {
Storage ss;
try {
ss = makeServicesStorage();
// create objects/procedures/
String objectUrl = create("collectionobjects/", "collectionobjects_common", "dummydata-object1.xml", "collection-object");
String acquisitionUrl = create("acquisitions/", "acquisitions_common", "dummydata-acquisition.xml", "acquisition");
String intakeUrl = create("intakes/", "intakes_common", "dummydata-intake.xml", "intake");
String loaninUrl = create("loansin/", "loansin_common", "dummydata-loanin.xml", "loanin");
String loanoutUrl = create("loansout/", "loansout_common", "dummydata-loanout.xml", "loanout");
String objectexitUrl = create("objectexit/", "objectexit_common", "dummydata-objectexit.xml", "objectexit");
// String groupUrl = create("group/", "group_common", "dummydata-group.xml","group");
// make relationships
relate2way(ss, objectUrl, acquisitionUrl);
relate2way(ss, objectUrl, intakeUrl);
relate2way(ss, objectUrl, loaninUrl);
relate2way(ss, objectUrl, loanoutUrl);
relate2way(ss, objectUrl, objectexitUrl);
testRelations(ss, objectUrl, acquisitionUrl, "affects");
testRelations(ss, objectUrl, intakeUrl, "affects");
testRelations(ss, objectUrl, loaninUrl, "affects");
testRelations(ss, objectUrl, loanoutUrl, "affects");
testRelations(ss, objectUrl, objectexitUrl, "affects");
// testRelations(ss,objectUrl,groupUrl,"affects");
} catch (CSPDependencyException e) {
fail(e.getMessage());
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.
the class TestPermissions method testPermissions.
@Test
public void testPermissions() throws Exception {
// create role
JSONObject roledata = createRole("role.json");
String role = roledata.getString("roleId");
log.info(roledata.toString());
assertFalse(roledata == null);
// list permissions for role
// cspace-services/authorization/roles/{csid}/permroles/xxx
Storage ss;
ss = makeServicesStorage();
JSONObject data = ss.getPathsJSON("roles/" + role + "/permrole", null);
String[] roleperms = (String[]) data.get("listItems");
log.info(data.toString());
if (roleperms.length > 0) {
log.info("has permissions already");
}
// add a permission
// get acquisition crudl
// /cspace-services/authorization/permissions?res=acquisition&actGrp=CRUDL
String resourceName = "acquisition";
JSONObject permrestrictions = new JSONObject();
permrestrictions.put("keywords", resourceName);
permrestrictions.put("queryString", "CRUDL");
permrestrictions.put("queryTerm", "actGrp");
JSONObject pdata = ss.getPathsJSON("permission", permrestrictions);
String[] perms = (String[]) pdata.get("listItems");
String permID = "";
if (perms.length > 0) {
permID = perms[0];
} else {
// need to create this permission type
fail("missing permission type Acquisition CRUDL " + permrestrictions.toString());
}
JSONObject permdata = new JSONObject();
permdata.put("permissionId", permID);
permdata.put("resourceName", resourceName);
JSONArray permarray = new JSONArray();
permarray.put(permdata);
JSONObject addperm = new JSONObject();
addperm.put("permission", permarray);
addperm.put("role", roledata);
log.info(addperm.toString());
// add permissions to role
String path = ss.autocreateJSON("permrole", addperm, null);
log.info(path);
assertNotNull(path);
// test permissions is in role
// delete role
ss.deleteJSON("role/" + role);
try {
ss.retrieveJSON("role/" + role, new JSONObject());
// XXX use JUnit exception annotation
assertFalse(true);
} catch (UnderlyingStorageException e) {
// XXX use JUnit exception annotation
assertTrue(true);
}
}
use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.
the class TestPermissions method createRole.
private JSONObject createRole(String jsonFile) {
Storage ss;
try {
// delete this role if exist
JSONObject u1 = getJSON(jsonFile);
String roleName = u1.getString("roleName");
JSONObject test = new JSONObject();
test.put("keywords", roleName);
ss = makeServicesStorage();
/* delete role if already exists */
JSONObject data = ss.getPathsJSON("role/", test);
String[] paths = (String[]) data.get("listItems");
log.info(data.toString());
if (paths.length > 0) {
ss.deleteJSON("role/" + paths[0]);
}
// create role
String path = ss.autocreateJSON("role/", u1, null);
assertNotNull(path);
JSONObject u3 = ss.retrieveJSON("role/" + path, new JSONObject());
assertNotNull(u3);
// return role path
JSONObject roledata = new JSONObject();
roledata.put("roleName", roleName);
roledata.put("roleId", path);
return roledata;
} catch (CSPDependencyException e) {
fail("CSPDependencyException:" + e.getMessage());
} catch (JSONException e) {
fail("JSONException:" + e.getMessage());
} catch (ExistException e) {
fail("ExistException:" + e.getMessage());
} catch (UnimplementedException e) {
fail("UnimplementedException:" + e.getMessage());
} catch (UnderlyingStorageException e) {
fail("UnderlyingStorageException:" + e.getMessage());
} catch (IOException e) {
fail("IOException:" + e.getMessage());
}
return null;
}
Aggregations