PaperTypeQueryBuilder extends AbstractQueryBuilder<PaperType> { @Override protected BaseQueryBuilder build(final PaperType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBR_NAME_CONDITION, context.getAbbrName()) .addAndCondition(PAPERUSAGE_CONDITION, context.getPaperUsage()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PaperType context = new PaperType(); String expectedQuery = "SELECT e FROM PaperType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PaperType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PaperType context = new PaperType(); String expectedQuery = "SELECT e FROM PaperType e WHERE e.status=:status "; MultiplePagedSearch<PaperType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PaperType context = new PaperType(); String expectedQuery = "SELECT e FROM PaperType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PaperType> 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); PaperType context = new PaperType(); String expectedQuery = "SELECT e FROM PaperType e "; MultiplePagedSearch<PaperType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String abbrName = "abbrname"; String name = "fdsfds"; PaperUsage paperUsage = new PaperUsage(); PaperType context = new PaperType(); context.setAbbrName(abbrName); context.setName(name); context.setPaperUsage(paperUsage); String expectedQuery = "SELECT e FROM PaperType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.paperUsage = :paperUsage ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PaperType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "abbrname"; String name = "fdsfds"; PaperUsage paperUsage = new PaperUsage(); PaperType context = new PaperType(); context.setAbbrName(abbrName); context.setName(name); context.setPaperUsage(paperUsage); String expectedQuery = "SELECT e FROM PaperType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.paperUsage = :paperUsage ) "; MultiplePagedSearch<PaperType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }