GenderTypeQueryBuilder extends AbstractQueryBuilder<GenderType> { @Override protected BaseQueryBuilder build(final GenderType 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 { GenderType context = new GenderType(); String expectedQuery = "SELECT e FROM GenderType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<GenderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityCOnstraint() throws Exception { unit.setSecurity(false); GenderType context = new GenderType(); String expectedQuery = "SELECT e FROM GenderType e WHERE e.status=:status "; MultiplePagedSearch<GenderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusCosntraint() throws Exception { unit.setActive(false); GenderType context = new GenderType(); String expectedQuery = "SELECT e FROM GenderType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<GenderType> 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); GenderType context = new GenderType(); String expectedQuery = "SELECT e FROM GenderType e "; MultiplePagedSearch<GenderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String abbrName = "abbrname"; GenderType context = new GenderType(); context.setAbbrName(abbrName); String expectedQuery = "SELECT e FROM GenderType e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<GenderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); String abbrName = "abbrname"; GenderType context = new GenderType(); context.setAbbrName(abbrName); String expectedQuery = "SELECT e FROM GenderType e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<GenderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }