ContactTypeQueryBuilder extends AbstractQueryBuilder<ContactType> { @Override protected BaseQueryBuilder build(final ContactType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBR_NAME_CONDITION, context.getAbbrName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { ContactType context = new ContactType(); String expectedQuery = "SELECT e FROM ContactType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { ContactType context = new ContactType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM ContactType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstaints() throws Exception { unit.setSecurity(false); ContactType context = new ContactType(); String expectedQuery = "SELECT e FROM ContactType e WHERE e.status=:status "; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstaintsWithOrderBy() throws Exception { unit.setSecurity(false); ContactType context = new ContactType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM ContactType e WHERE e.status=:status ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWihDisabledStatusConstaint() throws Exception { unit.setActive(false); ContactType context = new ContactType(); String expectedQuery = "SELECT e FROM ContactType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWihDisabledStatusConstaintWithOrderBy() throws Exception { unit.setActive(false); ContactType context = new ContactType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM ContactType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultCOnstaints() throws Exception { unit.setActive(false); unit.setSecurity(false); ContactType context = new ContactType(); String expectedQuery = "SELECT e FROM ContactType e "; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultCOnstaintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); ContactType context = new ContactType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM ContactType e ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String abbrName = "AN"; String name = "fsdfds"; ContactType context = new ContactType(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM ContactType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { String abbrName = "AN"; String name = "fsdfds"; ContactType context = new ContactType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM ContactType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultCOnstaints() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "AN"; String name = "fsdfds"; ContactType context = new ContactType(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM ContactType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultCOnstaintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "AN"; String name = "fsdfds"; ContactType context = new ContactType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM ContactType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<ContactType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }