EnrolmentStatusQueryBuilder extends AbstractQueryBuilder<EnrolmentStatus> { @Override protected BaseQueryBuilder build(final EnrolmentStatus context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(ENROLMENT_CONDITION, context.getEnrolment()) .addAndCondition(SPECOFFERWAVE_CONDITION, context.getSpecOfferWave()) .addAndCondition(ENROLMENTSTATUSTYPE_CONDITION, context.getEnrolmentStatusType()) .addAndCondition(ISCONTRACT_CONDITION, context.getIsContract()) .addAndCondition(ISSTATE_CONDITION, context.getIsState()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { EnrolmentStatus context = new EnrolmentStatus(); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithOrderBy() throws Exception { EnrolmentStatus context = new EnrolmentStatus(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specOfferWave", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentStatusType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.enrolment ASC, e.specOfferWave DESC, e.enrolmentStatusType ASC"; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraitns() throws Exception { unit.setSecurity(false); EnrolmentStatus context = new EnrolmentStatus(); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE e.status=:status "; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraitnsWithOrderBy() throws Exception { unit.setSecurity(false); EnrolmentStatus context = new EnrolmentStatus(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specOfferWave", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentStatusType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE e.status=:status ORDER BY e.enrolment ASC, e.specOfferWave DESC, e.enrolmentStatusType ASC"; MultiplePagedSearch<EnrolmentStatus> 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); EnrolmentStatus context = new EnrolmentStatus(); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); EnrolmentStatus context = new EnrolmentStatus(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specOfferWave", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentStatusType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.enrolment ASC, e.specOfferWave DESC, e.enrolmentStatusType ASC"; MultiplePagedSearch<EnrolmentStatus> 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); EnrolmentStatus context = new EnrolmentStatus(); String expectedQuery = "SELECT e FROM EnrolmentStatus e "; MultiplePagedSearch<EnrolmentStatus> 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); EnrolmentStatus context = new EnrolmentStatus(); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specOfferWave", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentStatusType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentStatus e ORDER BY e.enrolment ASC, e.specOfferWave DESC, e.enrolmentStatusType ASC"; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Integer isState = 1; Integer isContract = 0; Enrolment enrolment = new Enrolment(); SpecOfferWave specOfferWave = new SpecOfferWave(); EnrolmentStatusType enrolmentStatusType = new EnrolmentStatusType(); EnrolmentStatus context = new EnrolmentStatus(); context.setEnrolment(enrolment); context.setSpecOfferWave(specOfferWave); context.setEnrolmentStatusType(enrolmentStatusType); context.setIsContract(isContract); context.setIsState(isState); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE ( e.enrolment = :enrolment AND e.specOfferWave =:specOfferWave AND e.enrolmentStatusType =:enrolmentStatusType AND e.isContract =:isContract AND e.isState =:isState ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersWithOrderBy() throws Exception { Enrolment enrolment = new Enrolment(); SpecOfferWave specOfferWave = new SpecOfferWave(); EnrolmentStatusType enrolmentStatusType = new EnrolmentStatusType(); EnrolmentStatus context = new EnrolmentStatus(); context.setEnrolment(enrolment); context.setSpecOfferWave(specOfferWave); context.setEnrolmentStatusType(enrolmentStatusType); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specOfferWave", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentStatusType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE ( e.enrolment = :enrolment AND e.specOfferWave =:specOfferWave AND e.enrolmentStatusType =:enrolmentStatusType ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.enrolment ASC, e.specOfferWave DESC, e.enrolmentStatusType ASC"; MultiplePagedSearch<EnrolmentStatus> 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); Enrolment enrolment = new Enrolment(); SpecOfferWave specOfferWave = new SpecOfferWave(); EnrolmentStatusType enrolmentStatusType = new EnrolmentStatusType(); EnrolmentStatus context = new EnrolmentStatus(); context.setEnrolment(enrolment); context.setSpecOfferWave(specOfferWave); context.setEnrolmentStatusType(enrolmentStatusType); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE ( e.enrolment = :enrolment AND e.specOfferWave =:specOfferWave AND e.enrolmentStatusType =:enrolmentStatusType ) "; MultiplePagedSearch<EnrolmentStatus> 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); Enrolment enrolment = new Enrolment(); SpecOfferWave specOfferWave = new SpecOfferWave(); EnrolmentStatusType enrolmentStatusType = new EnrolmentStatusType(); EnrolmentStatus context = new EnrolmentStatus(); context.setEnrolment(enrolment); context.setSpecOfferWave(specOfferWave); context.setEnrolmentStatusType(enrolmentStatusType); OrderBy orderBy1 = new OrderBy("enrolment", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("specOfferWave", OrderByType.DESC); OrderBy orderBy3 = new OrderBy("enrolmentStatusType", OrderByType.ASC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2, orderBy3); String expectedQuery = "SELECT e FROM EnrolmentStatus e WHERE ( e.enrolment = :enrolment AND e.specOfferWave =:specOfferWave AND e.enrolmentStatusType =:enrolmentStatusType ) ORDER BY e.enrolment ASC, e.specOfferWave DESC, e.enrolmentStatusType ASC"; MultiplePagedSearch<EnrolmentStatus> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }