OrderTypeQueryBuilder extends AbstractQueryBuilder<OrderType> { @Override protected BaseQueryBuilder build(final OrderType context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(NAME_CONDITION, context.getName()) .addAndCondition(ABBR_NAME_CONDITION, context.getAbbrName()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { OrderType context = new OrderType(); String expected = "SELECT e FROM OrderType e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<OrderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithSecurityCOnstraint() throws Exception { unit.setSecurity(false); OrderType context = new OrderType(); String expected = "SELECT e FROM OrderType e WHERE e.status=:status "; MultiplePagedSearch<OrderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); OrderType context = new OrderType(); String expected = "SELECT e FROM OrderType e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<OrderType> 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); OrderType context = new OrderType(); String expected = "SELECT e FROM OrderType e "; MultiplePagedSearch<OrderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Long parentId = 1L; String abbrName = "abbr name"; String name = "name"; OrderType parent = new OrderType(); parent.setId(parentId); OrderType context = new OrderType(); context.setAbbrName(abbrName); context.setName(name); context.setParent(parent); String expected = "SELECT e FROM OrderType e WHERE ( e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<OrderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersAndDIsabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); Long parentId = 1L; String abbrName = "abbr name"; String name = "name"; OrderType parent = new OrderType(); parent.setId(parentId); OrderType context = new OrderType(); context.setAbbrName(abbrName); context.setName(name); context.setParent(parent); String expected = "SELECT e FROM OrderType e WHERE ( e.parent = :parent AND e.name LIKE CONCAT('%',:name,'%') AND e.abbrName LIKE CONCAT('%',:abbrName,'%') ) "; MultiplePagedSearch<OrderType> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }