EducationFormTypeQueryBuilder extends AbstractQueryBuilder<EducationFormType> { @Override protected BaseQueryBuilder build(final EducationFormType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(NAME_CONDITION, context.getName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { EducationFormType context = new EducationFormType(); String expectedQuery = "SELECT e FROM EducationFormType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EducationFormType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { EducationFormType context = new EducationFormType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM EducationFormType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC"; MultiplePagedSearch<EducationFormType> 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); EducationFormType context = new EducationFormType(); String expectedQuery = "SELECT e FROM EducationFormType e WHERE e.status=:status "; MultiplePagedSearch<EducationFormType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); EducationFormType context = new EducationFormType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM EducationFormType e WHERE e.status=:status ORDER BY e.name ASC"; MultiplePagedSearch<EducationFormType> 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); EducationFormType context = new EducationFormType(); String expectedQuery = "SELECT e FROM EducationFormType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EducationFormType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusCOnstraintWithOrderBy() throws Exception { unit.setActive(false); EducationFormType context = new EducationFormType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM EducationFormType e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC"; MultiplePagedSearch<EducationFormType> 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); EducationFormType context = new EducationFormType(); String expectedQuery = "SELECT e FROM EducationFormType e "; MultiplePagedSearch<EducationFormType> 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); EducationFormType context = new EducationFormType(); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM EducationFormType e ORDER BY e.name ASC"; MultiplePagedSearch<EducationFormType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String name = "name"; EducationFormType context = new EducationFormType(); context.setName(name); String expectedQuery = "SELECT e FROM EducationFormType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EducationFormType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { String name = "name"; EducationFormType context = new EducationFormType(); context.setName(name); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM EducationFormType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.name ASC"; MultiplePagedSearch<EducationFormType> 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 name = "name"; EducationFormType context = new EducationFormType(); context.setName(name); String expectedQuery = "SELECT e FROM EducationFormType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) "; MultiplePagedSearch<EducationFormType> 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 name = "name"; EducationFormType context = new EducationFormType(); context.setName(name); OrderBy orderBy1 = new OrderBy("name", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1); String expectedQuery = "SELECT e FROM EducationFormType e WHERE ( e.name LIKE CONCAT('%',:name,'%') ) ORDER BY e.name ASC"; MultiplePagedSearch<EducationFormType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }