BenefitQueryBuilder extends AbstractQueryBuilder<Benefit> { @Override protected BaseQueryBuilder build(final Benefit context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(BENEFITTYPE_CONDITION, context.getBenefitType()) .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBRNAME_CONDITION, context.getAbbrName()) .addAndCondition(DESCRIPTION_CONDITION, context.getDescription()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Benefit context = new Benefit(); String expected = "SELECT e FROM Benefit e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { Benefit context = new Benefit(); OrderBy orderBy1 = new OrderBy("benefitType", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("parent", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy5 = new OrderBy("begdate", OrderByType.ASC); OrderBy orderBy6 = new OrderBy("enddate", OrderByType.DESC); OrderBy orderBy7 = new OrderBy("description", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4, orderBy5, orderBy6, orderBy7); String expected = "SELECT e FROM Benefit e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.benefitType ASC, e.parent DESC, e.abbrName ASC, e.name DESC, e.begdate ASC, e.enddate DESC, e.description ASC"; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); Benefit context = new Benefit(); String expected = "SELECT e FROM Benefit e WHERE e.status=:status "; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); Benefit context = new Benefit(); OrderBy orderBy1 = new OrderBy("benefitType", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("parent", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy5 = new OrderBy("begdate", OrderByType.ASC); OrderBy orderBy6 = new OrderBy("enddate", OrderByType.DESC); OrderBy orderBy7 = new OrderBy("description", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4, orderBy5, orderBy6, orderBy7); String expected = "SELECT e FROM Benefit e WHERE e.status=:status ORDER BY e.benefitType ASC, e.parent DESC, e.abbrName ASC, e.name DESC, e.begdate ASC, e.enddate DESC, e.description ASC"; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); Benefit context = new Benefit(); String expected = "SELECT e FROM Benefit e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); Benefit context = new Benefit(); OrderBy orderBy1 = new OrderBy("benefitType", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("parent", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy5 = new OrderBy("begdate", OrderByType.ASC); OrderBy orderBy6 = new OrderBy("enddate", OrderByType.DESC); OrderBy orderBy7 = new OrderBy("description", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4, orderBy5, orderBy6, orderBy7); String expected = "SELECT e FROM Benefit e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.benefitType ASC, e.parent DESC, e.abbrName ASC, e.name DESC, e.begdate ASC, e.enddate DESC, e.description ASC"; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDEfaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); Benefit context = new Benefit(); String expected = "SELECT e FROM Benefit e "; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDEfaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); Benefit context = new Benefit(); OrderBy orderBy1 = new OrderBy("benefitType", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("parent", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy5 = new OrderBy("begdate", OrderByType.ASC); OrderBy orderBy6 = new OrderBy("enddate", OrderByType.DESC); OrderBy orderBy7 = new OrderBy("description", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4, orderBy5, orderBy6, orderBy7); String expected = "SELECT e FROM Benefit e ORDER BY e.benefitType ASC, e.parent DESC, e.abbrName ASC, e.name DESC, e.begdate ASC, e.enddate DESC, e.description ASC"; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParameters() throws Exception { BenefitType benefitType = new BenefitType(); Benefit parent = new Benefit(); String abbrName = "fsdsfds"; String name = "name1"; Date begDate = new Date(); Date endDate = new Date(); String description = "dsafds"; Benefit context = new Benefit(); context.setBenefitType(benefitType); context.setParent(parent); context.setAbbrName(abbrName); context.setName(name); context.setBegDate(begDate); context.setEndDate(endDate); context.setDescription(description); String expected = "SELECT e FROM Benefit e WHERE ( e.benefitType = :benefitType AND e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.description LIKE CONCAT('%',:description,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersWithOrderBy() throws Exception { BenefitType benefitType = new BenefitType(); Benefit parent = new Benefit(); String abbrName = "fsdsfds"; String name = "name1"; Date begDate = new Date(); Date endDate = new Date(); String description = "dsafds"; Benefit context = new Benefit(); context.setBenefitType(benefitType); context.setParent(parent); context.setAbbrName(abbrName); context.setName(name); context.setBegDate(begDate); context.setEndDate(endDate); context.setDescription(description); OrderBy orderBy1 = new OrderBy("benefitType", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("parent", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy5 = new OrderBy("begdate", OrderByType.ASC); OrderBy orderBy6 = new OrderBy("enddate", OrderByType.DESC); OrderBy orderBy7 = new OrderBy("description", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4, orderBy5, orderBy6, orderBy7); String expected = "SELECT e FROM Benefit e WHERE ( e.benefitType = :benefitType AND e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.description LIKE CONCAT('%',:description,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.benefitType ASC, e.parent DESC, e.abbrName ASC, e.name DESC, e.begdate ASC, e.enddate DESC, e.description ASC"; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); BenefitType benefitType = new BenefitType(); Benefit parent = new Benefit(); String abbrName = "fsdsfds"; String name = "name1"; Date begDate = new Date(); Date endDate = new Date(); String description = "dsafds"; Benefit context = new Benefit(); context.setBenefitType(benefitType); context.setParent(parent); context.setAbbrName(abbrName); context.setName(name); context.setBegDate(begDate); context.setEndDate(endDate); context.setDescription(description); String expected = "SELECT e FROM Benefit e WHERE ( e.benefitType = :benefitType AND e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.description LIKE CONCAT('%',:description,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate ) "; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersAndDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); BenefitType benefitType = new BenefitType(); Benefit parent = new Benefit(); String abbrName = "fsdsfds"; String name = "name1"; Date begDate = new Date(); Date endDate = new Date(); String description = "dsafds"; Benefit context = new Benefit(); context.setBenefitType(benefitType); context.setParent(parent); context.setAbbrName(abbrName); context.setName(name); context.setBegDate(begDate); context.setEndDate(endDate); context.setDescription(description); OrderBy orderBy1 = new OrderBy("benefitType", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("parent", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy4 = new OrderBy("name", OrderByType.DESC); OrderBy orderBy5 = new OrderBy("begdate", OrderByType.ASC); OrderBy orderBy6 = new OrderBy("enddate", OrderByType.DESC); OrderBy orderBy7 = new OrderBy("description", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3, orderBy4, orderBy5, orderBy6, orderBy7); String expected = "SELECT e FROM Benefit e WHERE ( e.benefitType = :benefitType AND e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.description LIKE CONCAT('%',:description,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate ) ORDER BY e.benefitType ASC, e.parent DESC, e.abbrName ASC, e.name DESC, e.begdate ASC, e.enddate DESC, e.description ASC"; MultiplePagedSearch<Benefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }