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()); }
/** * 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"))); }
// @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); }
private void postTesterXml(HttpTester response) throws Exception { Group g = new Group(response.getContent(), User.ENCODING_XML); Assert.assertEquals(201, response.getStatus()); postTester(response, g); }