AddressTypeQueryBuilder extends AbstractQueryBuilder<AddressType> { @Override protected BaseQueryBuilder build(final AddressType 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 { AddressType context = new AddressType(); String expectedQuery = "SELECT e FROM AddressType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { AddressType context = new AddressType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM AddressType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC, e.abbrName DESC"; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); AddressType context = new AddressType(); String expectedQuery = "SELECT e FROM AddressType e "; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraintWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); AddressType context = new AddressType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy2 = new OrderBy("abbrName", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM AddressType e ORDER BY e.name DESC, e.abbrName ASC"; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityCondition() throws Exception { unit.setSecurity(false); AddressType context = new AddressType(); String expectedQuery = "SELECT e FROM AddressType e WHERE e.status=:status "; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConditionWithOrderBy() throws Exception { unit.setSecurity(false); AddressType context = new AddressType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM AddressType e WHERE e.status=:status ORDER BY e.name DESC"; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusCondition() throws Exception { unit.setActive(false); AddressType context = new AddressType(); String expectedQuery = "SELECT e FROM AddressType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConditionWithOrderBy() throws Exception { unit.setActive(false); AddressType context = new AddressType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM AddressType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC"; MultiplePagedSearch<AddressType> 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 = "name"; AddressType context = new AddressType(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM AddressType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<AddressType> 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 = "name"; AddressType context = new AddressType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM AddressType 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"; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "AN"; String name = "name"; AddressType context = new AddressType(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM AddressType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "AN"; String name = "name"; AddressType context = new AddressType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM AddressType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) ORDER BY e.abbrName DESC"; MultiplePagedSearch<AddressType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }