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