@Override protected void createCacheManagers() throws Throwable { Util.recursiveFileRemove(indexDirectory); boolean created = new File(indexDirectory).mkdirs(); assertTrue(created); ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "filesystem") .addProperty("default.indexBase", indexDirectory) .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); }
private void checkIndexPresence(Cache cache) { SearchIntegrator searchIntegrator = Search.getSearchManager(cache).unwrap(SearchIntegrator.class); verifyClassIsIndexed(searchIntegrator, getModelFactory().getUserImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getAccountImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getTransactionImplClass()); verifyClassIsNotIndexed(searchIntegrator, getModelFactory().getAddressImplClass()); }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028526: Invalid query.*") public void testFullTextRegexpFuzzyNotAllowed() { Query q = createQueryFromString("from " + getModelFactory().getTransactionTypeName() + " t where t.longDescription : /[R|r]ent/~2"); q.list(); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014823: maxResults must be greater than 0") public void testPagination2() { QueryFactory qf = getQueryFactory(); qf.from(getModelFactory().getUserImplClass()) .maxResults(-4); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014802: 'from' must be an instance of java.lang.Comparable") public void testBetweenArgsAreComparable() { QueryFactory qf = getQueryFactory(); qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(new Object(), new Object()) .build(); }
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"); Account account1 = getModelFactory().makeAccount(); account1.setId(1); account1.setDescription("John Doe's first bank account"); account1.setCreationDate(makeDate("2013-01-03"));
@BeforeClass(alwaysRun = true) protected void populateCache() throws Exception { 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"); Transaction transaction0 = getModelFactory().makeTransaction(); transaction0.setId(0); transaction0.setDescription("Birthday present");
public void testGlobalCount() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .select(count("creationDate")) .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(3L, list.get(0)[0]); }
public void testSampleDomainQuery17() { QueryFactory qf = getQueryFactory(); // all accounts for a user. first get the user by id and then get his account. Query q1 = qf.from(getModelFactory().getUserImplClass()) .having("id").eq(1).build(); List<User> users = q1.list(); Query q2 = qf.from(getModelFactory().getAccountImplClass()) .orderBy("description", SortOrder.ASC) .having("id").in(users.get(0).getAccountIds()).build(); List<Account> list = q2.list(); assertEquals(2, list.size()); assertEquals("John Doe's first bank account", list.get(0).getDescription()); assertEquals("John Doe's second bank account", list.get(1).getDescription()); }
public void testInsertAndIterateInTx() throws Exception { final User newUser = getModelFactory().makeUser(); newUser.setId(15); newUser.setName("Test"); newUser.setSurname("User"); newUser.setGender(User.Gender.MALE); newUser.setAge(20); List results = withTx(tm(0), (Callable<List>) () -> { Query q = getQueryFactory().from(getModelFactory().getUserImplClass()) .not().having("age").eq(20) .build(); cache(0).put("new_user_" + newUser.getId(), newUser); return q.list(); }); cache(0).remove("new_user_" + newUser.getId()); assertEquals(3, results.size()); }
public void testInstant1() { Query q = createQueryFromString("from " + getModelFactory().getUserTypeName() + " u where u.creationDate = '2011-12-03T10:15:30Z'"); List<User> list = q.list(); assertEquals(3, list.size()); }
public void testSampleDomainQuery19() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .having("addresses.postCode").in("ZZ", "X1234").build(); List<User> list = q.list(); assertEquals(2, list.size()); assertTrue(Arrays.asList(1, 2).contains(list.get(0).getId())); assertTrue(Arrays.asList(1, 2).contains(list.get(1).getId())); }
public void testGlobalSum() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select(sum("amount")) .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(9693d, (Double) list.get(0)[0], 0.0001d); }
public void testSortByDate() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("creationDate", SortOrder.DESC) .build(); List<Account> list = q.list(); assertEquals(3, list.size()); assertEquals(3, list.get(0).getId()); assertEquals(2, list.get(1).getId()); assertEquals(1, list.get(2).getId()); }
public void testInstant2() { Query q = createQueryFromString("from " + getModelFactory().getUserTypeName() + " u where u.passwordExpirationDate = '2011-12-03T10:15:30Z'"); List<User> list = q.list(); assertEquals(3, list.size()); }
@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); }
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 = ParsingException.class, expectedExceptionsMessageRegExp = "ISPN028522: .*property is analyzed.*") public void testExactMatchOnAnalyzedFieldNotAllowed() { Query q = createQueryFromString("from " + getModelFactory().getTransactionTypeName() + " where longDescription = 'Birthday present'"); q.list(); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "ISPN014806: No parameters named '\\[param2\\]' were found") public void testUnknownParamWithParameterMap() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getUserImplClass()) .having("name").eq(param("param1")) .build(); Map<String, Object> parameterMap = new HashMap<>(1); parameterMap.put("param2", User.Gender.MALE); q.setParameters(parameterMap); }
public void testGlobalMinDouble() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select(min("amount")) .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(5d, list.get(0)[0]); }