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