BenefitTypeQueryBuilder extends AbstractQueryBuilder<BenefitType> { @Override protected BaseQueryBuilder build(final BenefitType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(PRIORITY_CONDITION, context.getPriority()) .closeBracket(); }    }
@Test public void testConvert() throws Exception { BenefitType context = new BenefitType(); String expected = "SELECT e FROM BenefitType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithOrderBy() throws Exception { BenefitType context = new BenefitType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("priority", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BenefitType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC, e.priority DESC"; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); BenefitType context = new BenefitType(); String expected = "SELECT e FROM BenefitType e WHERE e.status=:status "; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); BenefitType context = new BenefitType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("priority", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BenefitType e WHERE e.status=:status ORDER BY e.name ASC, e.priority DESC"; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledStatusConstraint() throws Exception { unit.setActive(false); BenefitType context = new BenefitType(); String expected = "SELECT e FROM BenefitType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); BenefitType context = new BenefitType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("priority", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BenefitType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC, e.priority DESC"; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); BenefitType context = new BenefitType(); String expected = "SELECT e FROM BenefitType e "; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledDefaultConstraintWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); BenefitType context = new BenefitType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("priority", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BenefitType e ORDER BY e.name ASC, e.priority DESC"; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParameters() throws Exception { String name = "name"; Integer priority = 2; BenefitType context = new BenefitType(); context.setName(name); context.setPriority(priority); String expected = "SELECT e FROM BenefitType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.priority =:priority ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersWithOrderBy() throws Exception { String name = "name"; Integer priority = 2; BenefitType context = new BenefitType(); context.setName(name); context.setPriority(priority); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("priority", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BenefitType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.priority =:priority ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC, e.priority DESC"; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersAndDisabledDeefaultConstaints() throws Exception { unit.setActive(false); unit.setSecurity(false); String name = "name"; Integer priority = 2; BenefitType context = new BenefitType(); context.setName(name); context.setPriority(priority); String expected = "SELECT e FROM BenefitType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.priority =:priority ) "; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersAndDisabledDeefaultConstaintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); String name = "name"; Integer priority = 2; BenefitType context = new BenefitType(); context.setName(name); context.setPriority(priority); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("priority", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BenefitType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.priority =:priority ) ORDER BY e.name ASC, e.priority DESC"; MultiplePagedSearch<BenefitType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }