PersonLanguageQueryBuilder extends AbstractQueryBuilder<PersonLanguage> { @Override protected BaseQueryBuilder build(final PersonLanguage context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(PERSON_CONDITION, context.getPerson()) .addAndCondition(LANGUAGE_CONDITION, context.getLanguage()) .addAndCondition(LANGUAGELEVEL_CONDITION, context.getLanguageLevel()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { PersonLanguage context = new PersonLanguage(); String expectedQuery = "SELECT e FROM PersonLanguage e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonLanguage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledSecurityConstraint() throws Exception { unit.setSecurity(false); PersonLanguage context = new PersonLanguage(); String expectedQuery = "SELECT e FROM PersonLanguage e WHERE e.status=:status "; MultiplePagedSearch<PersonLanguage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); PersonLanguage context = new PersonLanguage(); String expectedQuery = "SELECT e FROM PersonLanguage e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonLanguage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); PersonLanguage context = new PersonLanguage(); String expectedQuery = "SELECT e FROM PersonLanguage e "; MultiplePagedSearch<PersonLanguage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { Person person = new Person(); Language language = new Language(); LanguageLevel languageLevel = new LanguageLevel(); PersonLanguage context = new PersonLanguage(); context.setPerson(person); context.setLanguage(language); context.setLanguageLevel(languageLevel); String expectedQuery = "SELECT e FROM PersonLanguage e WHERE ( e.person = :person AND e.language = :language AND e.languageLevel = :languageLevel ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<PersonLanguage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Person person = new Person(); Language language = new Language(); LanguageLevel languageLevel = new LanguageLevel(); PersonLanguage context = new PersonLanguage(); context.setPerson(person); context.setLanguage(language); context.setLanguageLevel(languageLevel); String expectedQuery = "SELECT e FROM PersonLanguage e WHERE ( e.person = :person AND e.language = :language AND e.languageLevel = :languageLevel ) "; MultiplePagedSearch<PersonLanguage> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expectedQuery, actualQuery); }