@Test(expected = ClassCastException.class) public void testPOJOCombinedSearchWithJacksonHandle() { PojoRepository<Artifact, Long> products = client.newPojoRepository(Artifact.class, Long.class); PojoPage<Artifact> p; this.loadSimplePojos(products); QueryManager queryMgr = client.newQueryManager(); String queryAsString = "{\"search\":{\"query\":{\"and-query\":[" + "{\"word-constraint-query\":{\"constraint-name\":\"pojo-name-field\", \"text\":\"Acme\"}}," + "{\"word-constraint-query\":{\"constraint-name\":\"pojo-name-field\", \"text\":\"special\"}}]}," + "\"options\":{\"constraint\":{\"name\":\"pojo-name-field\", \"word\":{\"json-property\":\"name\"}}}" + "}}"; PojoQueryDefinition qd = (PojoQueryDefinition) queryMgr.newRawCombinedQueryDefinition( new StringHandle(queryAsString).withFormat(Format.JSON)); JacksonHandle results = new JacksonHandle(); p = products.search(qd, 1, results); products.setPageLength(11); assertEquals("total no of pages", 1, p.getTotalPages()); // System.out.println(p.getTotalPages()+results.get().toString()); long pageNo = 1, count = 0; do { count = 0; p = products.search(qd, pageNo, results); while (p.iterator().hasNext()) { Artifact a = p.iterator().next(); validateArtifact(a); count++; assertTrue( "Manufacture name starts with acme", a.getManufacturer().getName().contains("Acme")); assertTrue("Artifact name contains", a.getName().contains("special")); } assertEquals("Page size", count, p.size()); pageNo = pageNo + p.getPageSize(); assertEquals( "Page start from search handls vs page methods", results.get().get("start").asLong(), p.getStart()); assertEquals( "Format in the search handle", "json", results.get().withArray("results").get(1).path("format").asText()); assertTrue( "Uri in search handle contains Artifact", results.get().withArray("results").get(1).path("uri").asText().contains("Artifact")); // System.out.println(results.get().toString()); } while (!p.isLastPage() && pageNo < p.getTotalSize()); assertFalse("search handle has metrics", results.get().has("metrics")); assertEquals("Total from search handle", 11, results.get().get("total").asInt()); assertEquals("page number after the loop", 1, p.getPageNumber()); assertEquals("total no of pages", 1, p.getTotalPages()); }
@Test public void testPOJOSearchWithJacksonHandle() { PojoRepository<Artifact, Long> products = client.newPojoRepository(Artifact.class, Long.class); PojoPage<Artifact> p; this.loadSimplePojos(products); QueryManager queryMgr = client.newQueryManager(); StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("cogs"); JacksonHandle results = new JacksonHandle(); p = products.search(qd, 1, results); products.setPageLength(11); assertEquals("total no of pages", 3, p.getTotalPages()); // System.out.println(p.getTotalPages()+results.get().toString()); long pageNo = 1, count = 0; do { count = 0; p = products.search(qd, pageNo, results); while (p.iterator().hasNext()) { Artifact a = p.iterator().next(); validateArtifact(a); count++; // System.out.println(a.getId()+" "+a.getManufacturer().getName() +" "+count); } assertEquals("Page size", count, p.size()); pageNo = pageNo + p.getPageSize(); assertEquals( "Page start from search handls vs page methods", results.get().get("start").asLong(), p.getStart()); assertEquals( "Format in the search handle", "json", results.get().withArray("results").get(1).path("format").asText()); assertTrue( "Uri in search handle contains Artifact", results.get().withArray("results").get(1).path("uri").asText().contains("Artifact")); // System.out.println(results.get().toString()); } while (!p.isLastPage() && pageNo < p.getTotalSize()); // assertTrue("search handle has metrics",results.get().has("metrics")); assertEquals("Search text is", "cogs", results.get().path("qtext").asText()); assertEquals("Total from search handle", 110, results.get().get("total").asInt()); assertEquals("page number after the loop", 10, p.getPageNumber()); assertEquals("total no of pages", 10, p.getTotalPages()); }
@Test public void test2ExtractionTemplates() { String entityType = "SchemaCompleteEntityType-0.0.2.json"; String schemaName = "SchemaCompleteEntityType"; logger.info("Validating extraction template: " + entityType); JacksonHandle template = new JacksonHandle(); try { template = evalOneResult("tde:get-view( '" + schemaName + "', '" + schemaName + "')", template); } catch (TestEvalException e) { fail("View " + schemaName + " didn't exist"); } JsonNode schemaJson = template.get(); JsonNode body = schemaJson.get("view"); // logger.info("View body :::"+"whole view body ::::"+ body); // logger.info("View name :::"+schemaName+" Result :::"+body.get("name").asText()); // logger.info("View has columns :::"+"Result ::::"+ body.get("columns")); assertEquals("View name", schemaName, body.get("name").asText()); assertTrue("View has columns", body.get("columns").isArray()); }
@Test public void test1ExtractionTemplates() { String entityType = "SchemaCompleteEntityType-0.0.1.json"; String schemaName = "SchemaCompleteEntityType"; logger.info("Validating extraction template: " + entityType); JacksonHandle template = new JacksonHandle(); try { template = evalOneResult("tde:get-view( '" + schemaName + "', '" + schemaName + "')", template); } catch (TestEvalException e) { fail("View " + schemaName + " didn't exist"); } JsonNode schemaJson = template.get(); JsonNode body = schemaJson.get("view"); // logger.info("View body of view-name SchemaCompleteEntityType"+ body); // logger.info("View name :::"+schemaName+" Result :::"+body.get("name").asText()); // logger.info("View has columns :::"+"Result ::::"+ body.get("columns")); assertEquals("View name", schemaName, body.get("name").asText()); assertTrue("View has columns", body.get("columns").isArray()); String schemaName2 = "SchemaCompleteEntityType_arrayreferenceInThisFile"; // logger.info("Validating extraction template: " + entityType); JacksonHandle template2 = new JacksonHandle(); try { template2 = evalOneResult("tde:get-view( '" + schemaName + "', '" + schemaName2 + "')", template2); } catch (TestEvalException e) { fail("View " + schemaName2 + " didn't exist"); } JsonNode schemaJson2 = template2.get(); JsonNode body2 = schemaJson2.get("view"); // logger.info("View body of view-name SchemaCompleteEntityType"+ body2); // logger.info("View name :::"+schemaName2+" Result :::"+body2.get("name").asText()); // logger.info("View has columns :"+ body2.get("columns")); assertEquals("View name", schemaName2, body2.get("name").asText()); assertTrue("View has columns", body2.get("columns").isArray()); String schemaName3 = "SchemaCompleteEntityType_externalArrayReference"; // logger.info("Validating extraction template: " + entityType); JacksonHandle template3 = new JacksonHandle(); try { template3 = evalOneResult("tde:get-view( '" + schemaName + "', '" + schemaName3 + "')", template3); } catch (TestEvalException e) { fail("View " + schemaName3 + " didn't exist"); } JsonNode schemaJson3 = template3.get(); JsonNode body3 = schemaJson3.get("view"); // logger.info("View body of view-name SchemaCompleteEntityType"+ body3); // logger.info("View name :::"+schemaName3+" Result :::"+body3.get("name").asText()); // logger.info("View has columns :"+ body3.get("columns")); assertEquals("View name", schemaName3, body3.get("name").asText()); assertTrue("View has columns", body3.get("columns").isArray()); }
// This test is to verify RAW JSON structured query @Test public void testBulkSearchRawJSONStrucQD() throws Exception { // setAutomaticDirectoryCreation(dbName,"automatic"); setMaintainLastModified(dbName, true); this.loadJSONDocuments(); this.loadXMLDocuments(); GenericDocumentManager docMgr = client.newDocumentManager(); QueryManager queryMgr = client.newQueryManager(); JacksonHandle jh = new JacksonHandle(); ObjectMapper mapper = new ObjectMapper(); // constructing JSON representation of Raw JSON Structured Query ObjectNode txtNode = mapper.createObjectNode(); txtNode.putArray("text").add("woof"); ObjectNode termQNode = mapper.createObjectNode(); termQNode.set("term-query", txtNode); ObjectNode queriesArrayNode = mapper.createObjectNode(); queriesArrayNode.putArray("queries").add(termQNode); ObjectNode txtNode2 = mapper.createObjectNode(); txtNode2.putArray("text").add("bar"); ObjectNode termQNode2 = mapper.createObjectNode(); termQNode2.set("term-query", txtNode2); queriesArrayNode.withArray("queries").add(termQNode2); ObjectNode orQueryNode = mapper.createObjectNode(); orQueryNode.set("or-query", queriesArrayNode); ObjectNode queryArrayNode = mapper.createObjectNode(); queryArrayNode.putArray("queries").add(orQueryNode); ObjectNode mainNode = mapper.createObjectNode(); mainNode.set("query", queryArrayNode); jh.set(mainNode); RawStructuredQueryDefinition qd = queryMgr.newRawStructuredQueryDefinition(jh); System.out.println(jh.get().toString()); docMgr.setNonDocumentFormat(Format.JSON); JacksonHandle results = new JacksonHandle(); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); int count = 1; while (count < 4) { page = docMgr.search(qd, count, results); while (page.hasNext()) { DocumentRecord rec = page.next(); if (rec.getMimetype().contains("xml")) { validateRecord(rec, Format.XML); } else { validateRecord(rec, Format.JSON); } docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertFalse("Record has collections ?", mh.getCollections().isEmpty()); } count++; } System.out.println(results.get().toString()); assertEquals( "Total search results before transaction rollback are ", "204", results.get().get("total").asText()); }
// This test is testing SearchView options and search handle @Test public void testBulkSearchSQDwithJSONResponseFormat() throws Exception { loadJSONDocuments(); JSONDocumentManager docMgr = client.newJSONDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qd = qb.and(qb.term("woof")); docMgr.setNonDocumentFormat(Format.JSON); docMgr.setSearchView(QueryView.FACETS); JacksonHandle jh = new JacksonHandle(); docMgr.search(qd, 1, jh); // System.out.println(jh.get().toString()); assertTrue("Searh response has entry for facets", jh.get().has("facets")); assertFalse( "Searh response has entry for facets", jh.get().has("results")); // Issue 84 is tracking this assertFalse("Searh response has entry for facets", jh.get().has("metrics")); docMgr.setSearchView(QueryView.RESULTS); docMgr.search(qd, 1, jh); assertFalse("Searh response has entry for facets", jh.get().has("facets")); assertTrue("Searh response has entry for facets", jh.get().has("results")); assertFalse( "Searh response has entry for facets", jh.get().has("metrics")); // Issue 84 is tracking this docMgr.setSearchView(QueryView.METADATA); docMgr.search(qd, 1, jh); assertFalse("Searh response has entry for facets", jh.get().has("facets")); assertFalse("Searh response has entry for facets", jh.get().has("results")); assertTrue("Searh response has entry for facets", jh.get().has("metrics")); docMgr.setSearchView(QueryView.ALL); docMgr.search(qd, 1, jh); assertTrue("Searh response has entry for facets", jh.get().has("facets")); assertTrue("Searh response has entry for facets", jh.get().has("results")); assertTrue("Searh response has entry for facets", jh.get().has("metrics")); queryMgr.setView(QueryView.FACETS); queryMgr.search(qd, jh); System.out.println(jh.get().toString()); }