Search in sources :

Example 11 with Storage

use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.

the class TestPermissions method createUser.

private JSONObject createUser(String jsonFile) {
    Storage ss;
    try {
        JSONObject u1 = getJSON(jsonFile);
        String screenName = u1.getString("screenName");
        String userId = u1.getString("userId");
        JSONObject test = new JSONObject();
        test.put("userId", userId);
        ss = makeServicesStorage();
        /* delete user if already exists */
        JSONObject data = ss.getPathsJSON("users/", test);
        String[] paths = (String[]) data.get("listItems");
        if (paths.length > 0)
            ss.deleteJSON("users/" + paths[0]);
        /* 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(jsonFile);
        ss.updateJSON("users/" + path, u2, new JSONObject());
        JSONObject u3 = ss.retrieveJSON("users/" + path, new JSONObject());
        assertNotNull(u3);
        JSONObject userdata = new JSONObject();
        userdata.put("screenName", screenName);
        // csid
        userdata.put("accountId", path);
        // really email
        userdata.put("userId", userId);
        return userdata;
    } 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;
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) JSONException(org.json.JSONException) IOException(java.io.IOException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 12 with Storage

use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.

the class TestServiceThroughAPI method testObjectsList.

// XXX use autocreate not create when create dies
@Test
public void testObjectsList() throws Exception {
    Storage ss = makeServicesStorage();
    String p1 = ss.autocreateJSON("collection-object/", getJSON("obj3.json"), null);
    String p2 = ss.autocreateJSON("collection-object/", getJSON("obj4.json"), null);
    String p3 = ss.autocreateJSON("collection-object/", getJSON("obj4.json"), null);
    int num = 0;
    Boolean keeptrying = true;
    String[] names = null;
    String tester = "";
    JSONObject rest = new JSONObject();
    while (keeptrying) {
        rest.put("pageNum", num);
        JSONObject data = ss.getPathsJSON("collection-object", rest);
        String[] names_temp = (String[]) data.get("listItems");
        if (names_temp.length > 0) {
            if (tester.equals(names_temp[0])) {
                keeptrying = false;
            } else {
                tester = names_temp[0];
                if (names == null) {
                    names = names_temp;
                } else {
                    names = concat(names, names_temp);
                }
            }
        } else {
            keeptrying = false;
        }
        num++;
    }
    assertArrayContainsString(names, p1);
    assertArrayContainsString(names, p2);
    assertArrayContainsString(names, p3);
    ss.deleteJSON("collection-object/" + p1);
    try {
        ss.retrieveJSON("collection-object/" + p1, new JSONObject());
        // XXX use JUnit exception annotation
        assertFalse(true);
    } catch (Exception e) {
        // XXX use JUnit exception annotation
        assertTrue(true);
    }
    ss.deleteJSON("collection-object/" + p2);
    try {
        ss.retrieveJSON("collection-object/" + p2, new JSONObject());
        // XXX use JUnit exception annotation
        assertFalse(true);
    } catch (Exception e) {
        // XXX use JUnit exception annotation
        assertTrue(true);
    }
    ss.deleteJSON("collection-object/" + p3);
    try {
        ss.retrieveJSON("collection-object/" + p3, new JSONObject());
        // XXX use JUnit exception annotation
        assertFalse(true);
    } catch (Exception e) {
        // XXX use JUnit exception annotation
        assertTrue(true);
    }
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) ExistException(org.collectionspace.csp.api.persistence.ExistException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException) Test(org.junit.Test)

Example 13 with Storage

use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.

the class TestServiceThroughAPI method getPostDelete.

private void getPostDelete(String objtype, JSONObject jsoncreate, JSONObject jsonupdate, String testfield, Boolean testDelete) throws Exception {
    Storage ss = makeServicesStorage();
    // create
    String path = doCreate(ss, objtype, jsoncreate);
    // GET and test
    JSONObject jsc = doRetrieve(ss, objtype, path);
    assertEquals(jsc.get(testfield), jsoncreate.get(testfield));
    // UPDATE & Test
    ss.updateJSON(objtype + path, jsonupdate, new JSONObject());
    JSONObject js = ss.retrieveJSON(objtype + path, new JSONObject());
    assertEquals(js.get(testfield), jsonupdate.get(testfield));
    if (testDelete) {
        doDelete(ss, objtype, path);
    }
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject)

Example 14 with Storage

use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.

the class TestServiceThroughAPI method testSearch.

@Test
public void testSearch() throws Exception {
    Storage ss = makeServicesStorage();
    String p1 = ss.autocreateJSON("collection-object/", getJSON("obj3.json"), null);
    String p2 = ss.autocreateJSON("collection-object/", getJSON("obj-search.json"), null);
    JSONObject restriction = new JSONObject();
    restriction.put("keywords", "aardvark");
    JSONObject data = ss.getPathsJSON("collection-object", restriction);
    String[] names = (String[]) data.get("listItems");
    // XXX add pagination support CSPACE-1836
    assertArrayContainsString(names, p2);
    assertArrayDoesNotContainString(names, p1);
    ss.deleteJSON("collection-object/" + p1);
    ss.deleteJSON("collection-object/" + p2);
    try {
        ss.retrieveJSON("collection-object/" + p2, new JSONObject());
        // XXX use JUnit exception annotation
        assertFalse(true);
    } catch (Exception e) {
        // XXX use JUnit exception annotation
        assertTrue(true);
    }
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) ExistException(org.collectionspace.csp.api.persistence.ExistException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException) Test(org.junit.Test)

Example 15 with Storage

use of org.collectionspace.csp.api.persistence.Storage in project application by collectionspace.

the class TestVocab method testAuthorities.

@Test
public void testAuthorities() throws Exception {
    log.info("testAuthorities_start");
    Storage ss = makeServicesStorage();
    log.info("testAuthorities:person");
    // XXX disable until soft delete works better everywhere
    // testAllAuthorities(ss,"/person/defaultPersonAuthority","displayName");
    log.info("testAuthorities:vocab");
    // testAllAuthorities(ss,"/vocab/xxx","displayName");
    log.info("testAuthorities:organization");
    // XXX disable until soft delete works better everywhere
    // testAllAuthorities(ss,"/organization/organization","displayName");
    // testAllAuthorities(ss,"/place/place","displayName");
    log.info("testAuthorities:work");
    // testAllAuthorities(ss,"/work/work","displayName");
    log.info("testAuthorities:concept");
    // testAllAuthorities(ss,"/concept/concept","displayName");
    // testAllAuthorities(ss,"/citation/citation","displayName");
    log.info("testAuthorities_finish");
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) Test(org.junit.Test)

Aggregations

Storage (org.collectionspace.csp.api.persistence.Storage)15 JSONObject (org.json.JSONObject)13 Test (org.junit.Test)10 ExistException (org.collectionspace.csp.api.persistence.ExistException)8 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)7 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)5 JSONException (org.json.JSONException)5 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)4 CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)4 IOException (java.io.IOException)2 JSONArray (org.json.JSONArray)2 HttpSession (javax.servlet.http.HttpSession)1 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)1 UIException (org.collectionspace.csp.api.ui.UIException)1 UIRequest (org.collectionspace.csp.api.ui.UIRequest)1 UISession (org.collectionspace.csp.api.ui.UISession)1