@Test
  public void testPOJOSearchWithoutSearchHandle() {
    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("Widgets");

    products.setPageLength(11);
    p = products.search(qd, 1);
    assertEquals("total no of pages", 5, p.getTotalPages());
    System.out.println(p.getTotalPages());
    long pageNo = 1, count = 0;
    do {
      count = 0;

      p = products.search(qd, pageNo);

      while (p.iterator().hasNext()) {
        Artifact a = p.iterator().next();
        validateArtifact(a);
        assertTrue("Artifact Id is odd", a.getId() % 2 != 0);
        assertTrue(
            "Company name contains widgets", a.getManufacturer().getName().contains("Widgets"));
        count++;
        //				System.out.println(a.getId()+" "+a.getManufacturer().getName() +"  "+count);
      }
      assertEquals("Page size", count, p.size());
      pageNo = pageNo + p.getPageSize();
    } while (!p.isLastPage() && pageNo < p.getTotalSize());
    assertEquals("page number after the loop", 5, p.getPageNumber());
    assertEquals("total no of pages", 5, p.getTotalPages());
  }
  @Test(expected = ClassCastException.class)
  public void testPOJOqbeSearchWithSearchHandle() {
    PojoRepository<Artifact, Long> products = client.newPojoRepository(Artifact.class, Long.class);
    PojoPage<Artifact> p;
    this.loadSimplePojos(products);

    QueryManager queryMgr = client.newQueryManager();
    String queryAsString =
        "{\"$query\":{"
            + "\"$and\":[{\"inventory\":{\"$gt\":1010}},{\"inventory\":{\"$le\":1110}}]"
            + ",\"$filtered\": true}}";
    System.out.println(queryAsString);
    PojoQueryDefinition qd =
        (PojoQueryDefinition)
            queryMgr.newRawQueryByExampleDefinition(
                new StringHandle(queryAsString).withFormat(Format.JSON));
    qd.setCollections("even");
    SearchHandle results = new SearchHandle();
    products.setPageLength(10);
    p = products.search(qd, 1, results);
    assertEquals("total no of pages", 5, p.getTotalPages());
    System.out.println(p.getTotalPages());
    //		System.out.println(results.getMetrics().getQueryResolutionTime());
    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);
        assertTrue(
            "Enventory lies between 1010 to 1110",
            a.getInventory() > 1010 && a.getInventory() <= 1110);
        assertTrue("Artifact Id is even", a.getId() % 2 == 0);
        assertTrue("Company name contains Acme", a.getManufacturer().getName().contains("Acme"));
        count++;
        //				System.out.println(a.getId()+" "+a.getManufacturer().getName() +"  "+count);
      }
      assertEquals("Page size", count, p.size());
      pageNo = pageNo + p.getPageSize();
      MatchDocumentSummary[] mds = results.getMatchResults();
      assertEquals("Size of the results summary", 10, mds.length);
      for (MatchDocumentSummary md : mds) {
        assertTrue("every uri should contain the class name", md.getUri().contains("Artifact"));
      }
      String[] facetNames = results.getFacetNames();
      for (String fname : facetNames) {
        System.out.println(fname);
      }
      //			assertEquals("Total results from search handle ",50,results.getTotalResults());
      //			assertTrue("Search Handle metric results ",results.getMetrics().getTotalTime()>0);
    } while (!p.isLastPage() && pageNo < p.getTotalSize());
    assertEquals("Page start check", 41, p.getStart());
    assertEquals("page number after the loop", 5, p.getPageNumber());
    assertEquals("total no of pages", 5, p.getTotalPages());
  }
  @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 testPOJOSearchWithSearchHandle() {
    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("Acme");
    SearchHandle results = new SearchHandle();
    products.setPageLength(11);
    p = products.search(qd, 1, results);
    assertEquals("total no of pages", 5, p.getTotalPages());
    System.out.println(p.getTotalPages());
    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);
        assertTrue("Artifact Id is even", a.getId() % 2 == 0);
        assertTrue("Company name contains Acme", a.getManufacturer().getName().contains("Acme"));
        count++;
        //				System.out.println(a.getId()+" "+a.getManufacturer().getName() +"  "+count);
      }
      assertEquals("Page size", count, p.size());
      pageNo = pageNo + p.getPageSize();
      MatchDocumentSummary[] mds = results.getMatchResults();
      assertEquals("Size of the results summary", 11, mds.length);
      for (MatchDocumentSummary md : mds) {
        assertTrue("every uri should contain the class name", md.getUri().contains("Artifact"));
      }
      String[] facetNames = results.getFacetNames();
      for (String fname : facetNames) {
        System.out.println(fname);
      }
      assertEquals("Total resulr from search handle ", 55, results.getTotalResults());
      //			assertTrue("Search Handle metric results ",results.getMetrics().getTotalTime()>0);
    } while (!p.isLastPage() && pageNo < p.getTotalSize());
    assertEquals("Page start check", 45, p.getStart());
    assertEquals("page number after the loop", 5, p.getPageNumber());
    assertEquals("total no of pages", 5, p.getTotalPages());
  }
Example #5
0
  @Test
  public static void test() throws Exception {
    AutoTestCase.testName = "PlaceOrder";
    AutoTestCase.tester = "Subha Srinivasan";

    WebDriver driver = GeneralMethods.startDriver();

    BufferedWriter artifact =
        Artifact.OpenArtifact(GeneralMethods.getArtifactName(), testName + "  ", timeStamp);

    // Objects used
    OrderPage lp = new OrderPage(driver, "orderpage");
    AccountPage ap = new AccountPage(driver, "accountpage");

    Actions actions = new Actions(driver);
    System.out.println("* * * * * Start of " + testName + " test * * * * *");
    int localStressLoop = AutomationSettings.getLocalStressLoopIterations();

    // Test case infrastructure
    String currStepResult = null;
    String prevStepResult = null;
    String iterationStamp = "";
    String preReq = null;
    AutoTestCase.testData =
        "site=" + deployment + "  browser=" + AutomationSettings.getTestDataItem("ChromeVersion");
    lp.launchApplication();

    //  System.out.println("* * * * * *  Local stress loop iteration # " +iterationStamp);
    // Validate the purchase price

    currStepResult = lp.searchProduct("Apple iphone 4s") ? "Pass" : "Fail";
    Artifact.VerifyWriteToArtifactS(
        artifact, "Check the product link is displayed ", currStepResult);
    String totalpurchaseprice = lp.getPurchasePrice(lp.totalPrice);
    System.out.println(" the total purchase Price" + totalpurchaseprice);
    Assert.assertEquals("$282.00", totalpurchaseprice);
    Artifact.VerifyWriteToArtifactS(artifact, "Validate the purchase price ", currStepResult);

    driver.quit();
    driver = null;

    Artifact.CloseArtifact(artifact);
  }
  @Test(expected = ClassCastException.class)
  public void testPOJOqbeSearchWithoutSearchHandle() {
    PojoRepository<Artifact, Long> products = client.newPojoRepository(Artifact.class, Long.class);
    PojoPage<Artifact> p;
    this.loadSimplePojos(products);
    QueryManager queryMgr = client.newQueryManager();
    String queryAsString =
        "{\"$query\":{"
            + "\"$and\":[{\"name\":{\"$word\":\"cogs\",\"$exact\": false}}]"
            + ",\"$not\":[{\"name\":{\"$word\":\"special\",\"$exact\": false}}]"
            + "}}";

    PojoQueryDefinition qd =
        (PojoQueryDefinition)
            queryMgr.newRawQueryByExampleDefinition(
                new StringHandle(queryAsString).withFormat(Format.JSON));
    qd.setCollections("odd");
    products.setPageLength(11);
    p = products.search(qd, 1);
    assertEquals("total no of pages", 4, p.getTotalPages());
    //		System.out.println(p.getTotalPages());
    long pageNo = 1, count = 0;
    do {
      count = 0;

      p = products.search(qd, pageNo);

      while (p.iterator().hasNext()) {
        Artifact a = p.iterator().next();
        validateArtifact(a);
        assertFalse("Verifying document with special is not there", a.getId() % 5 == 0);
        assertTrue("Artifact Id is odd", a.getId() % 2 != 0);
        assertTrue(
            "Company name contains widgets", a.getManufacturer().getName().contains("Widgets"));
        count++;
        //				System.out.println(a.getId()+" "+a.getManufacturer().getName() +"  "+count);
      }
      assertEquals("Page size", count, p.size());
      pageNo = pageNo + p.getPageSize();
    } while (!p.isLastPage() && pageNo < p.getTotalSize());
    assertEquals("page number after the loop", 4, p.getPageNumber());
    assertEquals("total no of pages", 4, p.getTotalPages());
  }
  public Artifact getArtifact(int counter) {

    Artifact cogs = new Artifact();
    cogs.setId(counter);
    if (counter % 5 == 0) {
      cogs.setName("Cogs special");
      if (counter % 2 == 0) {
        Company acme = new Company();
        acme.setName("Acme special, Inc.");
        acme.setWebsite("http://www.acme special.com");
        acme.setLatitude(41.998 + counter);
        acme.setLongitude(-87.966 + counter);
        cogs.setManufacturer(acme);

      } else {
        Company widgets = new Company();
        widgets.setName("Widgets counter Inc.");
        widgets.setWebsite("http://www.widgets counter.com");
        widgets.setLatitude(41.998 + counter);
        widgets.setLongitude(-87.966 + counter);
        cogs.setManufacturer(widgets);
      }
    } else {
      cogs.setName("Cogs " + counter);
      if (counter % 2 == 0) {
        Company acme = new Company();
        acme.setName("Acme " + counter + ", Inc.");
        acme.setWebsite("http://www.acme" + counter + ".com");
        acme.setLatitude(41.998 + counter);
        acme.setLongitude(-87.966 + counter);
        cogs.setManufacturer(acme);

      } else {
        Company widgets = new Company();
        widgets.setName("Widgets " + counter + ", Inc.");
        widgets.setWebsite("http://www.widgets" + counter + ".com");
        widgets.setLatitude(41.998 + counter);
        widgets.setLongitude(-87.966 + counter);
        cogs.setManufacturer(widgets);
      }
    }
    cogs.setInventory(1000 + counter);
    return cogs;
  }
 public void validateArtifact(Artifact art) {
   assertNotNull("Artifact object should never be Null", art);
   assertNotNull("Id should never be Null", art.id);
   assertTrue("Inventry is always greater than 1000", art.getInventory() > 1000);
 }