Exemplo n.º 1
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")));
  }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
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);
  }
Exemplo n.º 4
0
 @BeforeClass
 public static void testInitialise() throws Exception {
   HttpTester out = tester.GETData(TestBase.AUTHS_INIT_PATH, jetty);
   log.info(out.getContent());
 }