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 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_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());
  }