MarkScaleQueryBuilder extends AbstractQueryBuilder<MarkScale> { @Override protected BaseQueryBuilder build(final MarkScale context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(MARKSCALETYPE_CONDITION, context.getMarkScaleType()) .addAndCondition(ABBRNAME_CONDITION, context.getAbbrName()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(MARKMIN_CONDITION, context.getMarkMin()) .addAndCondition(MARKMAX_CONDITION, context.getMarkMax()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { MarkScale context = new MarkScale(); String expected = "SELECT e FROM MarkScale e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<MarkScale> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraints() throws Exception { unit.setSecurity(false); MarkScale context = new MarkScale(); String expected = "SELECT e FROM MarkScale e WHERE e.status=:status "; MultiplePagedSearch<MarkScale> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); MarkScale context = new MarkScale(); String expected = "SELECT e FROM MarkScale e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<MarkScale> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); MarkScale context = new MarkScale(); String expected = "SELECT e FROM MarkScale e "; MultiplePagedSearch<MarkScale> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { String abbrName = "abbrName"; String name = "name"; Double markMin = 0.0; Double markMax = 10.0; MarkScaleType markScaleType = new MarkScaleType(); markScaleType.setId(1L); MarkScale context = new MarkScale(); context.setAbbrName(abbrName); context.setName(name); context.setMarkMin(markMin); context.setMarkMax(markMax); context.setMarkScaleType(markScaleType); String expected = "SELECT e FROM MarkScale e WHERE ( e.markScaleType = :markScaleType AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') AND e.markMin = :markMin AND e.markMax = :markMax ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<MarkScale> 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 abbrName = "abbrName"; String name = "name"; Double markMin = 0.0; Double markMax = 10.0; MarkScaleType markScaleType = new MarkScaleType(); markScaleType.setId(1L); MarkScale context = new MarkScale(); context.setAbbrName(abbrName); context.setName(name); context.setMarkMin(markMin); context.setMarkMax(markMax); context.setMarkScaleType(markScaleType); String expected = "SELECT e FROM MarkScale e WHERE ( e.markScaleType = :markScaleType AND e.abbrName LIKE CONCAT('%',:abbrName,'%') AND e.name LIKE CONCAT('%',:name,'%') AND e.markMin = :markMin AND e.markMax = :markMax ) "; MultiplePagedSearch<MarkScale> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }