EnrolmentForeignTypeQueryBuilder extends AbstractQueryBuilder<EnrolmentForeignType> { @Override protected BaseQueryBuilder build(final EnrolmentForeignType 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 { EnrolmentForeignType context = new EnrolmentForeignType(); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { EnrolmentForeignType context = new EnrolmentForeignType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<EnrolmentForeignType> 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); EnrolmentForeignType context = new EnrolmentForeignType(); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE e.status=:status "; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); EnrolmentForeignType context = new EnrolmentForeignType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE e.status=:status ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<EnrolmentForeignType> 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); EnrolmentForeignType context = new EnrolmentForeignType(); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); EnrolmentForeignType context = new EnrolmentForeignType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultCOnstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentForeignType context = new EnrolmentForeignType(); String expectedQuery = "SELECT e FROM EnrolmentForeignType e "; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultCOnstraintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); EnrolmentForeignType context = new EnrolmentForeignType(); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM EnrolmentForeignType e ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String abbrName = "abbrName"; String name = "name"; EnrolmentForeignType context = new EnrolmentForeignType(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { String abbrName = "abbrName"; String name = "name"; EnrolmentForeignType context = new EnrolmentForeignType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<EnrolmentForeignType> 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); String abbrName = "abbrName"; String name = "name"; EnrolmentForeignType context = new EnrolmentForeignType(); context.setAbbrName(abbrName); context.setName(name); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<EnrolmentForeignType> 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); String abbrName = "abbrName"; String name = "name"; EnrolmentForeignType context = new EnrolmentForeignType(); context.setAbbrName(abbrName); context.setName(name); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expectedQuery = "SELECT e FROM EnrolmentForeignType e WHERE ( e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) ORDER BY e.abbrName ASC, e.name DESC"; MultiplePagedSearch<EnrolmentForeignType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }