DegreeQueryBuilder extends AbstractQueryBuilder<Degree> { @Override protected BaseQueryBuilder build(final Degree context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(DEGREE_CONDITION, context.getDegreeType()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Degree context = new Degree(); String expectedQuery = "SELECT e FROM Degree e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { Degree context = new Degree(); OrderBy orderBy1 = new OrderBy("person", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("degreeType", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM Degree e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.person ASC, e.degreeType DESC"; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); Degree context = new Degree(); String expectedQuery = "SELECT e FROM Degree e WHERE e.status=:status "; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); Degree context = new Degree(); OrderBy orderBy1 = new OrderBy("person", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("degreeType", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM Degree e WHERE e.status=:status ORDER BY e.person ASC, e.degreeType DESC"; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); Degree context = new Degree(); String expectedQuery = "SELECT e FROM Degree e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); Degree context = new Degree(); OrderBy orderBy1 = new OrderBy("person", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("degreeType", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM Degree e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.person ASC, e.degreeType DESC"; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraints() throws Exception { unit.setSecurity(false); unit.setActive(false); Degree context = new Degree(); String expectedQuery = "SELECT e FROM Degree e "; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraintsWithOrderBy() throws Exception { unit.setSecurity(false); unit.setActive(false); Degree context = new Degree(); OrderBy orderBy1 = new OrderBy("person", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("degreeType", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM Degree e ORDER BY e.person ASC, e.degreeType DESC"; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { DegreeType degreeType = new DegreeType(); Person person = new Person(); Degree context = new Degree(); context.setPerson(person); context.setDegreeType(degreeType); String expectedQuery = "SELECT e FROM Degree e WHERE ( e.person=:person AND e.degreeType=:degreeType ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { DegreeType degreeType = new DegreeType(); Person person = new Person(); Degree context = new Degree(); context.setPerson(person); context.setDegreeType(degreeType); OrderBy orderBy1 = new OrderBy("person", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("degreeType", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM Degree e WHERE ( e.person=:person AND e.degreeType=:degreeType ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.person ASC, e.degreeType DESC"; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDEfaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); DegreeType degreeType = new DegreeType(); Person person = new Person(); Degree context = new Degree(); context.setPerson(person); context.setDegreeType(degreeType); String expectedQuery = "SELECT e FROM Degree e WHERE ( e.person=:person AND e.degreeType=:degreeType ) "; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDEfaultConstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); DegreeType degreeType = new DegreeType(); Person person = new Person(); Degree context = new Degree(); context.setPerson(person); context.setDegreeType(degreeType); OrderBy orderBy1 = new OrderBy("person", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("degreeType", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM Degree e WHERE ( e.person=:person AND e.degreeType=:degreeType ) ORDER BY e.person ASC, e.degreeType DESC"; MultiplePagedSearch<Degree> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }