示例#1
0
  // @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
  public void createGroupJson3() throws Exception {

    Group scimGroup = new Group();
    scimGroup.setDisplayName("name");

    request.setMethod("POST");
    request.setVersion("HTTP/1.0");
    request.setHeader("Authorization", "Basic dXNyOnB3");

    request.setURI("/v1/Groups.json");
    request.setHeader(
        "Content-Length", Integer.toString(scimGroup.getGroup(Group.ENCODING_JSON).length()));
    request.setHeader("Content-Type", "application/x-www-form-urlencoded");
    request.setHeader("Accept", "application/json");
    request.setContent(scimGroup.getGroup(Group.ENCODING_JSON));
    response.parse(tester.getResponses(request.generate()));

    postTesterJson(response);
  }
示例#3
0
  /**
   * 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);
  }
示例#4
0
  /**
   * 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);
  }
示例#5
0
 @BeforeClass
 public static void testInitialise() throws Exception {
   HttpTester out = tester.GETData(TestBase.AUTHS_INIT_PATH, jetty);
   log.info(out.getContent());
 }
示例#6
0
  // @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);
  }
示例#7
0
  /**
   * 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")));
  }
  public void testJavascriptHighlight() throws Exception {
    HttpTester request = new HttpTester();
    HttpTester response = new HttpTester();

    request.setMethod("GET");
    request.setHeader("Host", "tester");
    request.setVersion("HTTP/1.0");

    request.setURI(
        "/access/query/"
            + ServletUtil.encodeURLPath("title:blah")
            + "?callback=test&_hl=true&_hl.requireFieldMatch=true&_hl.fl=*");

    response.parse(servletContainer.getResponses(request.generate()));

    assertEquals(200, response.getStatus());
    assertEquals("application/javascript", response.getContentType());
    assertNotNull(response.getContent());
    assertNotNull(response.getHeader("X-TOTAL-MATCHES"));

    assertEquals("" + 1, response.getHeader("X-TOTAL-MATCHES"));

    // TODO actually parse json...

    assertTrue(response.getContent().contains("context"));
  }
  public void testGET_JSON() throws Exception {
    HttpTester request = new HttpTester();
    HttpTester response = new HttpTester();

    request.setMethod("GET");
    request.setHeader("Host", "tester");
    request.setVersion("HTTP/1.0");

    Collection<DcsDeliverableUnit> dus = dcp.getDeliverableUnits();

    request.setHeader("Accept", "application/javascript");
    request.setURI(
        "/access/query/"
            + ServletUtil.encodeURLPath("entityType:DeliverableUnit AND title:blah")
            + "?callback=js_cb");

    response.parse(servletContainer.getResponses(request.generate()));

    assertEquals(200, response.getStatus());
    assertEquals("application/javascript", response.getContentType());
    assertNotNull(response.getContent());
    assertNotNull(response.getHeader("X-TOTAL-MATCHES"));
    assertTrue(response.getContent().startsWith("js_cb("));

    assertEquals("" + dus.size(), response.getHeader("X-TOTAL-MATCHES"));
  }
  public void testGET_Dcp() throws Exception {
    HttpTester request = new HttpTester();
    HttpTester response = new HttpTester();

    request.setMethod("GET");
    request.setHeader("Host", "tester");
    request.setVersion("HTTP/1.0");

    DcsModelBuilder mb = new DcsXstreamStaxModelBuilder();

    Collection<DcsFile> files = dcp.getFiles();

    request.setURI("/access/query/" + ServletUtil.encodeURLPath("entityType:File"));

    response.parse(servletContainer.getResponses(request.generate()));

    assertEquals(200, response.getStatus());
    assertEquals("application/xml", response.getContentType());
    assertNotNull(response.getContent());
    assertNotNull(response.getHeader("X-TOTAL-MATCHES"));

    assertEquals("" + files.size(), response.getHeader("X-TOTAL-MATCHES"));

    Dcp dcp = mb.buildSip(new ByteArrayInputStream(response.getContent().getBytes()));

    assertEquals(files.size(), dcp.getFiles().size());

    request.setURI("/access/entity/" + ServletUtil.encodeURLPath(":blah:"));
    response.parse(servletContainer.getResponses(request.generate()));
    assertEquals(404, response.getStatus());

    request.setURI(
        "/access/entity/"
            + ServletUtil.encodeURLPath("title:(alksdfasd-axda+!E@!QW@#$!+@!#--~+))"));
    response.parse(servletContainer.getResponses(request.generate()));
    assertEquals(404, response.getStatus());

    request.setURI("/access/entity/" + ServletUtil.encodeURLPath("title:test\\-escape)"));
    response.parse(servletContainer.getResponses(request.generate()));
    assertEquals(404, response.getStatus());

    request.setURI(
        "/access/entity/"
            + "id%3A((%22ARC%5C-11%22)+)+OR+former%3A((%22ARC%5C-11%22)+)creator%3A((%22ARC%5C-11%22)+)+OR+subject%3A((%22ARC%5C-11%22)+)+OR+title%3A((%22ARC%5C-11%22)+)+OR+type%3A((%22ARC%5C-11%22)+)+OR+metadataSearchText%3A((%22ARC%5C-11%22)+)+OR+metadataSchema%3A((%22ARC%5C-11%22)+)fileName%3A((%22ARC%5C-11%22)+)+OR+fileSource%3A((%22ARC%5C-11%22)+)+OR+format%3A((%22ARC%5C-11%22)+)+OR+formatName%3A((%22ARC%5C-11%22)+)+OR+formatSchema%3A((%22ARC%5C-11%22)+)+OR+filePath%3A((%22ARC%5C-11%22)+)+OR+fixityValue%3A((%22ARC%5C-11%22)+)parent%3A((%22ARC%5C-11%22)+)+OR+metadataRef%3A((%22ARC%5C-11%22)+)+OR+formatSchema%3A((%22ARC%5C-11%22)+)+OR+metadataSchema%3A((%22ARC%5C-11%22)+)+OR+collection%3A((%22ARC%5C-11%22)+)+OR+relatedTo%3A((%22ARC%5C-11%22)+)+OR+eventTarget%3A((%22ARC%5C-11%22)+)+OR+deliverableunit%3A((%22ARC%5C-11%22)+)+OR+fileRef%3A((%22ARC%5C-11%22)+)+OR+hasRelationship%3A((%22ARC%5C-11%22)+)?");
    response.parse(servletContainer.getResponses(request.generate()));
    assertEquals(404, response.getStatus());
  }
 private void postTesterXml(HttpTester response) throws Exception {
   Group g = new Group(response.getContent(), User.ENCODING_XML);
   Assert.assertEquals(201, response.getStatus());
   postTester(response, g);
 }