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