@AfterClass @Override protected void destroy() { try { //first stop cache managers, then clear the index super.destroy(); } finally { //delete the index otherwise it will mess up the index for next tests Util.recursiveFileRemove(indexDirectory); } } }
public void testIndexPresence() { SearchIntegrator searchIntegrator = Search.getSearchManager((Cache) getCacheForQuery()).unwrap(SearchIntegrator.class); verifyClassIsIndexed(searchIntegrator, getModelFactory().getUserImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getAccountImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getTransactionImplClass()); verifyClassIsNotIndexed(searchIntegrator, getModelFactory().getAddressImplClass()); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014823: maxResults must be greater than 0") public void testPagination1() { QueryFactory qf = getQueryFactory(); qf.from(getModelFactory().getUserImplClass()) .maxResults(0); }
public void testBetween1() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")) .build(); List<Transaction> list = q.list(); assertEquals(4, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) <= 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) >= 0); } }
User user1 = getModelFactory().makeUser(); user1.setId(1); user1.setName("John"); Address address1 = getModelFactory().makeAddress(); address1.setStreet("Main Street"); address1.setPostCode("X1234"); User user2 = getModelFactory().makeUser(); user2.setId(2); user2.setName("Spider"); Address address2 = getModelFactory().makeAddress(); address2.setStreet("Old Street"); address2.setPostCode("Y12"); address2.setNumber(-12); Address address3 = getModelFactory().makeAddress(); address3.setStreet("Bond Street"); address3.setPostCode("ZZ"); User user3 = getModelFactory().makeUser(); user3.setId(3); user3.setName("Spider"); user3.setCreationDate(Instant.parse("2011-12-03T10:15:30Z")); user3.setPasswordExpirationDate(Instant.parse("2011-12-03T10:15:30Z")); if (!testNullCollections()) { user3.setAddresses(new ArrayList<>());
public void testIsNull3() { if (testNullCollections()) { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .having("addresses").isNull() .build(); List<User> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).getId()); } }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028521: Full-text queries cannot be applied to property 'longDescription' in type org.infinispan.query.dsl.embedded.testdomain.hsearch.TransactionHS unless the property is indexed and analyzed.") @Override public void testFullTextTerm() { super.testFullTextTerm(); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028521: Full-text queries cannot be applied to property 'longDescription' in type org.infinispan.query.dsl.embedded.testdomain.hsearch.TransactionHS unless the property is indexed and analyzed.") @Override public void testFullTextPhrase() { super.testFullTextPhrase(); } }
@Test(expectedExceptions = IllegalStateException.class) public void testWrongQueryBuilding1() { QueryFactory qf = getQueryFactory(); qf.not().having("name").eq("John").build(); }
public void testSampleDomainQuery8() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")) .build(); List<Transaction> list = q.list(); assertEquals(4, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) <= 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) >= 0); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIn3() { QueryFactory qf = getQueryFactory(); qf.from(getModelFactory().getUserImplClass()).having("id").in(Collections.emptySet()); }
public void testBetween3() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")).includeLower(false) .build(); List<Transaction> list = q.list(); assertEquals(3, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) <= 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) > 0); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIn4() { QueryFactory qf = getQueryFactory(); qf.from(getModelFactory().getUserImplClass()).having("id").in((Collection) null); }
public void testBetween2() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")).includeUpper(false) .build(); List<Transaction> list = q.list(); assertEquals(3, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) < 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) >= 0); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIn6() { QueryFactory qf = getQueryFactory(); Object[] array = new Object[0]; qf.from(getModelFactory().getUserImplClass()).having("id").in(array); }
public void testDateGrouping1() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("date") .having("date").between(makeDate("2013-02-15"), makeDate("2013-03-15")) .groupBy("date") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(makeDate("2013-02-27"), list.get(0)[0]); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIn5() { QueryFactory qf = getQueryFactory(); qf.from(getModelFactory().getUserImplClass()).having("id").in((Object[]) null); }
public void testDateFilteringWithGroupBy() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("date") .having("date").between(makeDate("2013-02-15"), makeDate("2013-03-15")) .groupBy("date") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(java.util.Date.class, list.get(0)[0].getClass()); assertEquals(makeDate("2013-02-27"), list.get(0)[0]); }
public void testFullTextPhrase() { QueryFactory qf = getQueryFactory(); Query q = qf.create("from " + getModelFactory().getTransactionTypeName() + " where longDescription:'expensive shoes'"); List<Transaction> list = q.list(); assertEquals(50, list.size()); }