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