WaveTypeQueryBuilder extends AbstractQueryBuilder<WaveType> { @Override protected BaseQueryBuilder build(final WaveType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { WaveType context = new WaveType(); String expected = "SELECT e FROM WaveType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { WaveType context = new WaveType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expected = "SELECT e FROM WaveType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC"; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); WaveType context = new WaveType(); String expected = "SELECT e FROM WaveType e WHERE e.status=:status "; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); WaveType context = new WaveType(); String expected = "SELECT e FROM WaveType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); WaveType context = new WaveType(); String expected = "SELECT e FROM WaveType e "; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraintsAndOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); WaveType context = new WaveType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expected = "SELECT e FROM WaveType e ORDER BY e.name ASC"; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String name = "name"; WaveType context = new WaveType(); context.setName(name); String expected = "SELECT e FROM WaveType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ";; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersWithDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); String name = "name"; WaveType context = new WaveType(); context.setName(name); String expected = "SELECT e FROM WaveType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) ";; MultiplePagedSearch<WaveType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }