SpecOfferTypeQueryBuilder extends AbstractQueryBuilder<SpecOfferType> { @Override protected BaseQueryBuilder build(final SpecOfferType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBR_NAME_CONDITION, context.getAbbrName()) .addAndCondition(TIME_PERIOD_CONDITION, context.getTimePeriod()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { SpecOfferType context = new SpecOfferType(); String expectedQuery = "SELECT e FROM SpecOfferType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); SpecOfferType context = new SpecOfferType(); String expectedQuery = "SELECT e FROM SpecOfferType e WHERE e.status=:status "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); SpecOfferType context = new SpecOfferType(); String expectedQuery = "SELECT e FROM SpecOfferType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); SpecOfferType context = new SpecOfferType(); String expectedQuery = "SELECT e FROM SpecOfferType e "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOneParameter() throws Exception { String abbrName = "abbrName"; SpecOfferType context = new SpecOfferType(); context.setAbbrName(abbrName); String expectedQuery = "SELECT e FROM SpecOfferType e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildEmptyParameters() throws Exception { TimePeriod timePeriod = new TimePeriod(); String abbrName = "abbrName"; SpecOfferType context = new SpecOfferType(); context.setAbbrName(abbrName); context.setTimePeriod(timePeriod); String expectedQuery = "SELECT e FROM SpecOfferType e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.timePeriod = :timePeriod) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildEmptyParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); TimePeriod timePeriod = new TimePeriod(); String abbrName = "abbrName"; SpecOfferType context = new SpecOfferType(); context.setAbbrName(abbrName); context.setTimePeriod(timePeriod); String expectedQuery = "SELECT e FROM SpecOfferType e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.timePeriod = :timePeriod) "; MultiplePagedSearch<SpecOfferType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }