SpecialtyQueryBuilder extends AbstractQueryBuilder<Specialty> { @Override protected BaseQueryBuilder build(final Specialty context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(SPECIALTYTYPE_CONDITION, context.getSpecialtyType()) .addAndCondition(ABBRNAME_CONDITION, context.getAbbrName()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(CIPHER_CONDITION, context.getCipher()) .addAndCondition(BEGDATE_CONDITION, context.getBegDate()) .addAndCondition(ENDDATE_CONDITION, context.getEndDate()) .closeBracket(); }    }
@Test public void testBuildWithParameters() throws Exception { String cipher = "fsdfsd"; Specialty context = new Specialty(); String abbrName = "fsdsd"; String name = "fsdsd"; Date endDate = new Date(); context.setCipher(cipher); context.setBegDate(new Date()); context.setAbbrName(abbrName); context.setName(name); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM Specialty e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') AND e.cipher LIKE CONCAT('%',:cipher,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Specialty> 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 cipher = "fsdfsd"; Specialty context = new Specialty(); String abbrName = "fsdsd"; String name = "fsdsd"; Date endDate = new Date(); context.setCipher(cipher); context.setBegDate(new Date()); context.setAbbrName(abbrName); context.setName(name); context.setEndDate(endDate); String expectedQuery = "SELECT e FROM Specialty e WHERE ( e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') AND e.cipher LIKE CONCAT('%',:cipher,'%') AND e.begDate <= :begDate AND e.endDate >= :endDate ) "; MultiplePagedSearch<Specialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuild() throws Exception { Specialty context = new Specialty(); String expectedQuery = "SELECT e FROM Specialty e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Specialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); Specialty context = new Specialty(); String expectedQuery = "SELECT e FROM Specialty e WHERE e.status=:status "; MultiplePagedSearch<Specialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); Specialty context = new Specialty(); String expectedQuery = "SELECT e FROM Specialty e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Specialty> 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); Specialty context = new Specialty(); String expectedQuery = "SELECT e FROM Specialty e "; MultiplePagedSearch<Specialty> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }