SpecOfferBenefitQueryBuilder extends AbstractQueryBuilder<SpecOfferBenefit> { @Override protected BaseQueryBuilder build(final SpecOfferBenefit context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(SPECOFFER_CONDITION, context.getSpecOffer()) .addAndCondition(BENEFIT_CONDITION, context.getBenefit()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { SpecOfferBenefit context = new SpecOfferBenefit(); String expectedQuery = "SELECT e FROM SpecOfferBenefit e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { SpecOfferBenefit context = new SpecOfferBenefit(); OrderBy orderBy1 = new OrderBy("benefit", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM SpecOfferBenefit e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.benefit ASC"; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); SpecOfferBenefit context = new SpecOfferBenefit(); String expectedQuery = "SELECT e FROM SpecOfferBenefit e WHERE e.status=:status "; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); SpecOfferBenefit context = new SpecOfferBenefit(); String expectedQuery = "SELECT e FROM SpecOfferBenefit e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); SpecOfferBenefit context = new SpecOfferBenefit(); String expectedQuery = "SELECT e FROM SpecOfferBenefit e "; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithAllParameters() throws Exception { Benefit benefit = new Benefit(); SpecOffer specOffer = new SpecOffer(); SpecOfferBenefit context = new SpecOfferBenefit(); context.setSpecOffer(specOffer); context.setBenefit(benefit); String expectedQuery = "SELECT e FROM SpecOfferBenefit e WHERE ( e.specOffer = :specOffer AND e.benefit = :benefit ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithAllParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); Benefit benefit = new Benefit(); SpecOffer specOffer = new SpecOffer(); SpecOfferBenefit context = new SpecOfferBenefit(); context.setSpecOffer(specOffer); context.setBenefit(benefit); String expectedQuery = "SELECT e FROM SpecOfferBenefit e WHERE ( e.specOffer = :specOffer AND e.benefit = :benefit ) "; MultiplePagedSearch<SpecOfferBenefit> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }