static { try { jetty = tester.setupJetty(); } catch (Exception ex) { log.error("TestGeneral: Could not set up jetty! " + ex.getLocalizedMessage()); } }
/** * Writes a series of Objects then does a Read using a trailing slash and checks each object is * found */ @Test public void testTrailingSlashOkayOnList() throws Exception { // clear (avoid paging) JSONArray items = null; HttpTester out1 = tester.POSTData("/cataloging", tester.makeSimpleRequest(testStr2), jetty); HttpTester out2 = tester.POSTData("/cataloging", tester.makeSimpleRequest(testStr2), jetty); HttpTester out3 = tester.POSTData("/cataloging", tester.makeSimpleRequest(testStr2), jetty); // Read with a trailing slash HttpTester out = tester.GETData("/cataloging/", jetty); // Build up a list of items returned JSONObject result = new JSONObject(out.getContent()); items = result.getJSONArray("items"); Set<String> files = new HashSet<String>(); int pgSz = 100; int pgNum = 0; String objtype = "cataloging"; String itemmarker = "items"; boolean exists = false; boolean end = false; // Page through do { out = tester.GETData("/" + objtype + "/?pageNum=" + pgNum + "&pageSize=" + pgSz, jetty); assertEquals(200, out.getStatus()); /* create list of files */ JSONObject result1 = new JSONObject(out.getContent()); JSONArray items1 = result1.getJSONArray(itemmarker); if (items1.length() > 0) { for (int i = 0; i < items1.length(); i++) { files.add("/" + objtype + "/" + items1.getJSONObject(i).getString("csid")); } } else { end = true; } exists = files.contains(out1.getHeader("Location")) && files.contains(out2.getHeader("Location")) && files.contains(out3.getHeader("Location")); pgNum++; } while (!end && !exists); /* clean up */ tester.DELETEData(out1.getHeader("Location"), jetty); tester.DELETEData(out2.getHeader("Location"), jetty); tester.DELETEData(out3.getHeader("Location"), jetty); // Check each object is in the list assertTrue(files.contains(out1.getHeader("Location"))); assertTrue(files.contains(out2.getHeader("Location"))); assertTrue(files.contains(out3.getHeader("Location"))); }
/** * Tests the extracted part of the URN is as expected * * @throws Exception */ @Test public void testDeURNedField() throws Exception { // create person authority to use String personStr = "{\"shortIdentifier\":\"mytestperson\",\"personTermGroup\":[{\"termDisplayName\":\"TEST my test person\"}]}"; HttpTester out = tester.POSTData( TestBase.MAIN_PERSON_INSTANCE_PATH + "/", tester.makeSimpleRequest(personStr), jetty); String person_url = out.getHeader("Location"); JSONObject persondata = new JSONObject(out.getContent()); String urn = persondata.getString("urn"); // assign person authority JSONObject testdata = new JSONObject(urnTestJoe); testdata.getJSONObject("fields").put("fieldCollectionPlace", urn); // create object out = tester.POSTData("/cataloging/", testdata, jetty); assertEquals(out.getMethod(), null); String id = out.getHeader("Location"); // read and check out = tester.GETData(id, jetty); JSONObject one = new JSONObject(tester.getFields(out.getContent())); log.info(one.toString()); assertEquals(one.get("fieldCollectionPlace"), urn); // assertEquals(one.get("de-urned-fieldCollectionPlace"), "TEST my test person"); // clean up tester.DELETEData(id, jetty); tester.DELETEData("/vocabularies/" + person_url, jetty); }
// @Test public void test2() throws Exception { JSONObject user = new JSONObject(); user.put("userid", "*****@*****.**"); user.put("password", "Administrator"); // ServletTester jetty=setupJetty("testsci", user); // ServletTester jetty=setupJetty(false,"tenant2.xml"); // http://nightly.collectionspace.org/collectionspace/tenant/core/invokereport/88b3bdb5-a7fd-4e39-aaa1 // String csid = "/reporting/search?doctype=Acquisition"; // uispec(jetty,"/generator?quantity=10&maxrelationships=10&startvalue=0&extraprefix=Related","acquisition.uispec"); // String csid = "/generator?quantity=10&maxrelationships=10&startvalue=0&extraprefix=Related"; // String csid = "/cataloging/termList/dateEarliestSingleEra"; // String csid = "/role/08a84ce3-9236-468b-b8c2-66d07706b273"; String csid = TestBase.MAIN_PERSON_INSTANCE_PATH; // http://nightly.collectionspace.org/collectionspace/chain/vocabularies/location/source-vocab/relatedTerm // String test = // "{\"fields\":{\"lenderGroup\":[{\"_primary\":true}],\"loanPurposes\":[{\"loanPurpose\":\"\",\"_primary\":true}],\"updatedBys\":[{\"_primary\":true}],\"loanInNumbers\":[{\"_primary\":true}],\"updatedAtStart\":\"2011-09-05\"},\"operation\":\"or\"}"; String test = "{\"termsUsed\":[],\"relations\":[],\"csid\":\"\",\"refobjs\":[],\"namespace\":\"person\"," + "\"fields\":{\"surName\":\"\",\"birthPlace\":\"\",\"deathDate\":\"\",\"updatedBy\":\"[email protected]\"," + "\"nationalities\":[{\"_primary\":true,\"nationality\":\"\"}],\"shortIdentifier\":\"bobclampett\"," + "\"schoolsOrStyles\":[{\"_primary\":true,\"schoolOrStyle\":\"\"}],\"title\":\"\",\"initials\":\"\"," + "\"createdAt\":\"2011-10-10T13:46:44Z\",\"nameNote\":\"save something\",\"termStatus\":\"\",\"gender\":\"\",\"birthDate\":\"\",\"foreName\":\"\"," + "\"groups\":[{\"_primary\":true,\"group\":\"\"}],\"recordtype\":\"person\",\"nameAdditions\":\"\"," + "\"occupations\":[{\"occupation\":\"\",\"_primary\":true}],\"middleName\":\"\",\"bioNote\":\"\"," + "\"csid\":\"79a356bd-17ab-47cf-8174\",\"deathPlace\":\"\",\"updatedAt\":\"2011-10-10T14:20:28Z\"," + "\"createdBy\":\"[email protected]\",\"equivalentContexts\":[],\"authorityid\":\"34d85e61-7d0f-4b37-a6c4\"," + "\"displayName\":\"Bob Clampett\",\"salutation\":\"\"," + "\"refid\":\"urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(bobclampett)'Bob Clampett'\"," + "\"telephoneNumberGroup\":[{\"_primary\":true,\"telephoneNumberType\":\"\"}],\"emailGroup\":[{\"emailType\":\"\",\"_primary\":true}]," + "\"faxNumberGroup\":[{\"_primary\":true,\"faxNumberType\":\"\"}],\"webAddressGroup\":[{\"_primary\":true,\"webAddressType\":\"\"}]," + "\"addressGroup\":[{\"_primary\":true,\"addressType\":\"\"}]," + "\"narrowerContexts\":[{\"_primary\":true,\"narrowerContext\":\"urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(tommix)'Tom Mix'\"}]," + "\"relatedTerms\":[{\"_primary\":true}]," + "\"broaderContext\":\"urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(georgebancroft)'George Bancroft'\"}}"; HttpTester out; // loanedObjectStatus // out = jettyDo(jetty, "GET", "/tenant/testsci/authorities/vocab/initialize", null); // out = jettyDo(jetty, "GET", "/tenant/testsci/cataloging/uispec", null); // out = GETData(csid, jetty); out = tester.POSTData(csid, test, jetty); // DELETEData("/users/c990a163-ef62-4f06-95ae-c362d3fac9ff",jetty); // JSONObject fields=new JSONObject(out.getContent()).getJSONObject("fields"); // cspace-services/personauthorities/5c642112-f75a-43b4-aff8/items/0e07e795-fb9d-4f39-a848/ // HttpTester out2=jettyDo(jetty,"POST","/chain/upload",null); // log.info(out.getContent()); }
// @Test - no guarentee that the service layer created this report and put it where I could find // it public void testReports() throws Exception { String uipath = "/acquisition/"; String data = tester.acquisitionCreate(); HttpTester out; // Create out = tester.POSTData(uipath, tester.makeSimpleRequest(data), jetty); String id = out.getHeader("Location"); // Retrieve out = tester.jettyDo(jetty, "GET", "/tenant/core" + id, null); HttpTester out3 = tester.jettyDo(jetty, "GET", "/tenant/core/reporting/search/acquisition", null); log.info(out3.getContent()); JSONObject one = new JSONObject(out.getContent()); JSONObject list = new JSONObject(out3.getContent()); String reportcsid = list.getJSONArray("reportlist").getString(0); String path = one.getString("csid"); JSONObject report = new JSONObject(); report.put("docType", "acquisition"); report.put("singleCSID", path); report.put("mode", "single"); JSONObject fields = new JSONObject(); fields.put("fields", report); String url = "/invokereport/" + reportcsid; HttpTester out2 = tester.POSTData(url, fields.toString(), jetty, "GET"); log.info(out2.getContent()); assertEquals(200, out2.getStatus()); log.info(Integer.toString(out2.getStatus())); assertEquals("application/pdf", out2.getHeader("Content-Type")); log.info(out2.getHeader("Content-Type")); // Delete tester.DELETEData(id, jetty); }
/** * Checks a vocabulary (here a person) can be linked to an object * * @throws Exception */ @Test public void testTermsUsedVocab() throws Exception { // create person authority to use String personStr = "{\"personTermGroup\":[{\"termDisplayName\":\"TEST my test person\"}]}"; HttpTester out = tester.POSTData( TestBase.MAIN_PERSON_INSTANCE_PATH + "/", tester.makeSimpleRequest(personStr), jetty); String person_url = out.getHeader("Location"); JSONObject persondata = new JSONObject(out.getContent()); String urn = persondata.getString("urn"); // assign person authority JSONObject testdata = new JSONObject(urnTestJoe); testdata.getJSONObject("fields").put("contentPeople", urn); // create object out = tester.POSTData("/cataloging/", testdata, jetty); String id = out.getHeader("Location"); out = tester.GETData(id, jetty); // I believe the items below where copied from test above and are not needed // JSONObject one = new JSONObject(getFields(out.getContent())); // assertEquals(one.get("contentPeople"), urn); // assertEquals(one.get("de-urned-contentPeople"), "TEST my test person2"); // get the cataloging linked to the vocab item out = tester.GETData("/vocabularies" + person_url, jetty); // clean up tester.DELETEData(id, jetty); tester.DELETEData("/vocabularies/" + person_url, jetty); }
@AfterClass public static void testStop() throws Exception { tester.stopJetty(jetty); }
@BeforeClass public static void testInitialise() throws Exception { HttpTester out = tester.GETData(TestBase.AUTHS_INIT_PATH, jetty); log.info(out.getContent()); }