BroadcastingQueryBuilder extends AbstractQueryBuilder<BroadcastingMessage> { @Override protected BaseQueryBuilder build(final BroadcastingMessage context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(TOPIC_CONDITION, context.getTopic()) .closeBracket(); }    }
@Test public void testConvert() throws Exception { BroadcastingMessage context = new BroadcastingMessage(); String expected = "SELECT e FROM BroadcastingMessage e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithOrderBy() throws Exception { BroadcastingMessage context = new BroadcastingMessage(); OrderBy orderBy1 = new OrderBy("content", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("topic", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BroadcastingMessage e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.content ASC, e.topic DESC"; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); BroadcastingMessage context = new BroadcastingMessage(); String expected = "SELECT e FROM BroadcastingMessage e WHERE e.status=:status "; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledSecurityConstraintWithOrderBy() throws Exception { unit.setSecurity(false); BroadcastingMessage context = new BroadcastingMessage(); OrderBy orderBy1 = new OrderBy("content", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("topic", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BroadcastingMessage e WHERE e.status=:status ORDER BY e.content ASC, e.topic DESC"; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledStatusConstraint() throws Exception { unit.setActive(false); BroadcastingMessage context = new BroadcastingMessage(); String expected = "SELECT e FROM BroadcastingMessage e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledStatusConstraintWithOrderBy() throws Exception { unit.setActive(false); BroadcastingMessage context = new BroadcastingMessage(); OrderBy orderBy1 = new OrderBy("content", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("topic", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BroadcastingMessage e WHERE e.crtUserGroup IN (:userGroups) ORDER BY e.content ASC, e.topic DESC"; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); BroadcastingMessage context = new BroadcastingMessage(); String expected = "SELECT e FROM BroadcastingMessage e "; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithDisabledDefaultConstraintWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); BroadcastingMessage context = new BroadcastingMessage(); OrderBy orderBy1 = new OrderBy("content", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("topic", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BroadcastingMessage e ORDER BY e.content ASC, e.topic DESC"; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParameters() throws Exception { String topic = "topic"; String content = "content"; BroadcastingMessage context = new BroadcastingMessage(); context.setTopic(topic); context.setContent(content); String expected = "SELECT e FROM BroadcastingMessage e WHERE ( e.topic LIKE CONCAT('%',:topic,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersWithOrderBy() throws Exception { String topic = "topic"; String content = "content"; BroadcastingMessage context = new BroadcastingMessage(); context.setTopic(topic); context.setContent(content); OrderBy orderBy1 = new OrderBy("content", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("topic", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BroadcastingMessage e WHERE ( e.topic LIKE CONCAT('%',:topic,'%') ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) ORDER BY e.content ASC, e.topic DESC"; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersAndDisabledDeefaultConstaints() throws Exception { unit.setActive(false); unit.setSecurity(false); String topic = "topic"; String content = "content"; BroadcastingMessage context = new BroadcastingMessage(); context.setTopic(topic); context.setContent(content); String expected = "SELECT e FROM BroadcastingMessage e WHERE ( e.topic LIKE CONCAT('%',:topic,'%') ) "; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testConvertWithParametersAndDisabledDeefaultConstaintsWithOrderBy() throws Exception { unit.setActive(false); unit.setSecurity(false); String topic = "topic"; String content = "content"; BroadcastingMessage context = new BroadcastingMessage(); context.setTopic(topic); context.setContent(content); OrderBy orderBy1 = new OrderBy("content", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("topic", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); String expected = "SELECT e FROM BroadcastingMessage e WHERE ( e.topic LIKE CONCAT('%',:topic,'%') ) ORDER BY e.content ASC, e.topic DESC"; MultiplePagedSearch<BroadcastingMessage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); pagedSearch.setOrders(orders); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }