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