dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #07121
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2009: Fixed test error. Impl method ValidationRuleService.getValidationRulesByDataElements( Collection).
------------------------------------------------------------
revno: 2009
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-08-30 15:04:39 +0200
message:
Fixed test error. Impl method ValidationRuleService.getValidationRulesByDataElements( Collection).
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java 2010-08-30 11:31:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java 2010-08-30 13:04:39 +0000
@@ -115,7 +115,7 @@
Collection<DataSet> getDataSetsBySource( Source source );
- Collection<DataSet> getDataSetsBySources( Collection<Source> sources );
+ Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources );
// -------------------------------------------------------------------------
// FrequencyOverrideAssociation
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2010-05-28 19:17:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2010-08-30 13:04:39 +0000
@@ -30,6 +30,7 @@
import java.util.Collection;
import java.util.Date;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.source.Source;
@@ -143,6 +144,8 @@
*/
ValidationRule getValidationRuleByName( String name );
+ Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements );
+
// -------------------------------------------------------------------------
// ValidationRuleGroup
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java 2010-05-28 19:17:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java 2010-08-30 13:04:39 +0000
@@ -27,7 +27,10 @@
package org.hisp.dhis.validation;
+import java.util.Collection;
+
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.dataelement.DataElement;
/**
* @author Chau Thu Tran
@@ -57,4 +60,6 @@
* @return the generated unique identifier for the ValidationRule.
*/
void updateValidationRule( ValidationRule validationRule );
+
+ Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java 2010-08-30 11:31:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java 2010-08-30 13:04:39 +0000
@@ -155,7 +155,7 @@
public Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources )
{
- return getDataSetsBySources( sources );
+ return i18n( i18nService, dataSetStore.getDataSetsBySources( sources ) );
}
public int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<? extends Source> sources )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-08-30 11:31:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-08-30 13:04:39 +0000
@@ -167,7 +167,7 @@
}
@SuppressWarnings( "unchecked" )
- public Collection<DataSet> getDataSetsBySources( Collection<Source> sources )
+ public Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources )
{
String hql = "select distinct d from DataSet d join d.sources s where s.id in (:ids)";
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2010-08-30 07:50:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2010-08-30 13:04:39 +0000
@@ -350,6 +350,11 @@
{
return validationRuleStore.getByName( name );
}
+
+ public Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements )
+ {
+ return validationRuleStore.getValidationRulesByDataElements( dataElements );
+ }
// -------------------------------------------------------------------------
// ValidationRuleGroup CRUD operations
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java 2010-05-28 19:17:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java 2010-08-30 13:04:39 +0000
@@ -27,10 +27,16 @@
package org.hisp.dhis.validation.hibernate;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
import org.hibernate.Session;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.period.PeriodStore;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.ConversionUtils;
import org.hisp.dhis.validation.ValidationRule;
import org.hisp.dhis.validation.ValidationRuleStore;
@@ -81,4 +87,23 @@
session.update( validationRule );
}
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements )
+ {
+ Set<ValidationRule> validationRules = new HashSet<ValidationRule>();
+
+ Collection<Integer> ids = ConversionUtils.getIdentifiers( DataElement.class, dataElements );
+
+ String hql = "select distinct v from ValidationRule v join v.leftSide ls join ls.dataElementsInExpression lsd where lsd.id in (:ids)";
+
+ validationRules.addAll( sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ids ).list() );
+
+ hql = "select distinct v from ValidationRule v join v.rightSide rs join rs.dataElementsInExpression rsd where rsd.id in (:ids)";
+
+ validationRules.addAll( sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ids ).list() );
+
+ return validationRules;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java 2010-08-30 13:04:39 +0000
@@ -36,14 +36,10 @@
import java.util.HashSet;
import org.hisp.dhis.DhisSpringTest;
-import org.hisp.dhis.mock.MockSource;
-import org.hisp.dhis.period.MonthlyPeriodType;
-import org.hisp.dhis.period.PeriodStore;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.period.WeeklyPeriodType;
-import org.hisp.dhis.period.YearlyPeriodType;
import org.hisp.dhis.source.Source;
-import org.hisp.dhis.source.SourceStore;
import org.junit.Test;
/**
@@ -53,12 +49,8 @@
public class DataSetServiceTest
extends DhisSpringTest
{
- private PeriodStore periodStore;
-
private DataSetService dataSetService;
- private SourceStore sourceStore;
-
private PeriodType periodType;
@Override
@@ -67,9 +59,7 @@
{
dataSetService = (DataSetService) getBean( DataSetService.ID );
- periodStore = (PeriodStore) getBean( PeriodStore.ID );
-
- sourceStore = (SourceStore) getBean( SourceStore.ID );
+ organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
@@ -200,13 +190,13 @@
@Test
public void testGetDataSetsBySource()
{
- Source sourceA = new MockSource( "A" );
- Source sourceB = new MockSource( "B" );
- Source sourceC = new MockSource( "C" );
+ OrganisationUnit sourceA = createOrganisationUnit( 'A' );
+ OrganisationUnit sourceB = createOrganisationUnit( 'B' );
+ OrganisationUnit sourceC = createOrganisationUnit( 'C' );
- sourceStore.addSource( sourceA );
- sourceStore.addSource( sourceB );
- sourceStore.addSource( sourceC );
+ organisationUnitService.addOrganisationUnit( sourceA );
+ organisationUnitService.addOrganisationUnit( sourceB );
+ organisationUnitService.addOrganisationUnit( sourceC );
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
@@ -247,30 +237,21 @@
@Test
public void testGetDataSetsBySources()
{
- Source sourceA = new MockSource( "A" );
- Source sourceB = new MockSource( "B" );
- Source sourceC = new MockSource( "C" );
- Source sourceD = new MockSource( "D" );
-
- sourceStore.addSource( sourceA );
- sourceStore.addSource( sourceB );
- sourceStore.addSource( sourceC );
- sourceStore.addSource( sourceD );
-
+ OrganisationUnit unitA = createOrganisationUnit( 'A' );
+ OrganisationUnit unitB = createOrganisationUnit( 'B' );
+ OrganisationUnit unitC = createOrganisationUnit( 'C' );
+ organisationUnitService.addOrganisationUnit( unitA );
+ organisationUnitService.addOrganisationUnit( unitB );
+ organisationUnitService.addOrganisationUnit( unitC );
+
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
DataSet dataSetC = createDataSet( 'C', periodType );
DataSet dataSetD = createDataSet( 'D', periodType );
-
- dataSetA.getSources().add( sourceA );
- dataSetA.getSources().add( sourceB );
-
- dataSetB.getSources().add( sourceB );
- dataSetB.getSources().add( sourceC );
-
- dataSetC.getSources().add( sourceC );
-
- dataSetD.getSources().add( sourceD );
+ dataSetA.getSources().add( unitA );
+ dataSetA.getSources().add( unitB );
+ dataSetB.getSources().add( unitA );
+ dataSetC.getSources().add( unitB );
dataSetService.addDataSet( dataSetA );
dataSetService.addDataSet( dataSetB );
@@ -278,45 +259,42 @@
dataSetService.addDataSet( dataSetD );
Collection<Source> sources = new HashSet<Source>();
-
- sources.add( sourceA );
- sources.add( sourceD );
+ sources.add( unitA );
+ sources.add( unitB );
Collection<DataSet> dataSets = dataSetService.getDataSetsBySources( sources );
-
- assertEquals( 2, dataSets.size() );
+
+ assertEquals( 3, dataSets.size() );
assertTrue( dataSets.contains( dataSetA ) );
- assertTrue( dataSets.contains( dataSetD ) );
-
- sources.clear();
-
- sources.add( sourceB );
- sources.add( sourceC );
+ assertTrue( dataSets.contains( dataSetB ) );
+ assertTrue( dataSets.contains( dataSetC ) );
+ sources = new HashSet<Source>();
+ sources.add( unitA );
+
dataSets = dataSetService.getDataSetsBySources( sources );
- assertEquals( 3, dataSets.size() );
+ assertEquals( 2, dataSets.size() );
assertTrue( dataSets.contains( dataSetA ) );
assertTrue( dataSets.contains( dataSetB ) );
- assertTrue( dataSets.contains( dataSetC ) );
}
-
+
@Test
public void testGetSourcesAssociatedWithDataSet()
{
- Source sourceA = new MockSource( "A" );
- Source sourceB = new MockSource( "B" );
- Source sourceC = new MockSource( "C" );
- Source sourceD = new MockSource( "D" );
- Source sourceE = new MockSource( "E" );
- Source sourceF = new MockSource( "F" );
+ OrganisationUnit sourceA = createOrganisationUnit( 'A' );
+ OrganisationUnit sourceB = createOrganisationUnit( 'B' );
+ OrganisationUnit sourceC = createOrganisationUnit( 'C' );
+ OrganisationUnit sourceD = createOrganisationUnit( 'D' );
+ OrganisationUnit sourceE = createOrganisationUnit( 'E' );
+ OrganisationUnit sourceF = createOrganisationUnit( 'F' );
- sourceStore.addSource( sourceA );
- sourceStore.addSource( sourceB );
- sourceStore.addSource( sourceC );
- sourceStore.addSource( sourceD );
- sourceStore.addSource( sourceE );
- sourceStore.addSource( sourceF );
+ organisationUnitService.addOrganisationUnit( sourceA );
+ organisationUnitService.addOrganisationUnit( sourceB );
+ organisationUnitService.addOrganisationUnit( sourceC );
+ organisationUnitService.addOrganisationUnit( sourceD );
+ organisationUnitService.addOrganisationUnit( sourceE );
+ organisationUnitService.addOrganisationUnit( sourceF );
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
@@ -342,54 +320,4 @@
assertEquals( 2, dataSetService.getSourcesAssociatedWithDataSet( dataSetA, sources ) );
assertEquals( 2, dataSetService.getSourcesAssociatedWithDataSet( dataSetB, sources ) );
}
-
- // -------------------------------------------------------------------------
- // FrequencyOverrideAssociation
- // -------------------------------------------------------------------------
-
- @Test
- public void testFrequencyOverrideAssociation()
- throws Exception
- {
- PeriodType periodType1 = periodStore.getPeriodType( YearlyPeriodType.class );
- PeriodType periodType2 = periodStore.getPeriodType( MonthlyPeriodType.class );
- PeriodType periodType3 = periodStore.getPeriodType( WeeklyPeriodType.class );
-
- DataSet dataSet1 = new DataSet( "name1", periodType1 );
- DataSet dataSet2 = new DataSet( "name2", periodType2 );
-
- dataSetService.addDataSet( dataSet1 );
- dataSetService.addDataSet( dataSet2 );
-
- Source source1 = new MockSource( "Source1" );
- Source source2 = new MockSource( "Source2" );
- sourceStore.addSource( source1 );
- sourceStore.addSource( source2 );
-
- FrequencyOverrideAssociation association = new FrequencyOverrideAssociation( dataSet1, source1, periodType3 );
-
- dataSetService.addFrequencyOverrideAssociation( association );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet1 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source1 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet2 ).size(), 0 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source2 ).size(), 0 );
-
- dataSetService.addFrequencyOverrideAssociation( new FrequencyOverrideAssociation( dataSet1, source2, periodType3 ) );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet1 ).size(), 2 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source1 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet2 ).size(), 0 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source2 ).size(), 1 );
-
- dataSetService.addFrequencyOverrideAssociation( new FrequencyOverrideAssociation( dataSet2, source1, periodType3 ) );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet1 ).size(), 2 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source1 ).size(), 2 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet2 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source2 ).size(), 1 );
-
- dataSetService.deleteFrequencyOverrideAssociation( association );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet1 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source1 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsByDataSet( dataSet2 ).size(), 1 );
- assertEquals( dataSetService.getFrequencyOverrideAssociationsBySource( source2 ).size(), 1 );
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java 2010-07-01 10:08:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java 2010-08-30 13:04:39 +0000
@@ -37,14 +37,11 @@
import java.util.Set;
import org.hisp.dhis.DhisTest;
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.expression.Expression;
import org.hisp.dhis.expression.ExpressionService;
-
import org.hisp.dhis.period.PeriodType;
-
import org.junit.Test;
/**
@@ -52,11 +49,10 @@
* @version $Id: ValidationRuleStoreTest.java 3679 2007-10-22 18:25:18Z larshelg
* $
*/
-@SuppressWarnings( "unchecked" )
public class ValidationRuleStoreTest
extends DhisTest
{
- private GenericIdentifiableObjectStore<ValidationRule> validationRuleStore;
+ private ValidationRuleStore validationRuleStore;
private ExpressionService expressionService;
@@ -84,7 +80,7 @@
public void setUpTest()
throws Exception
{
- validationRuleStore = (GenericIdentifiableObjectStore<ValidationRule>) getBean( "org.hisp.dhis.validation.ValidationRuleStore" );
+ validationRuleStore = (ValidationRuleStore) getBean( ValidationRuleStore.ID );
dataElementService = (DataElementService) getBean( DataElementService.ID );
@@ -132,7 +128,7 @@
ValidationRule validationRule = createValidationRule( 'A', ValidationRule.OPERATOR_EQUAL, expressionA,
expressionB, periodType );
- int id = validationRuleStore.save( validationRule );
+ int id = validationRuleStore.saveValidationRule( validationRule );
validationRule = validationRuleStore.get( id );
@@ -151,7 +147,7 @@
ValidationRule validationRule = createValidationRule( 'A', ValidationRule.OPERATOR_EQUAL, expressionA,
expressionB, periodType );
- int id = validationRuleStore.save( validationRule );
+ int id = validationRuleStore.saveValidationRule( validationRule );
validationRule = validationRuleStore.get( id );
@@ -165,7 +161,7 @@
validationRule.setType( ValidationRule.TYPE_STATISTICAL );
validationRule.setOperator( ValidationRule.OPERATOR_GREATER );
- validationRuleStore.update( validationRule );
+ validationRuleStore.updateValidationRule( validationRule );
validationRule = validationRuleStore.get( id );
@@ -183,8 +179,8 @@
ValidationRule validationRuleB = createValidationRule( 'B', ValidationRule.OPERATOR_EQUAL, expressionA,
expressionB, periodType );
- int idA = validationRuleStore.save( validationRuleA );
- int idB = validationRuleStore.save( validationRuleB );
+ int idA = validationRuleStore.saveValidationRule( validationRuleA );
+ int idB = validationRuleStore.saveValidationRule( validationRuleB );
assertNotNull( validationRuleStore.get( idA ) );
assertNotNull( validationRuleStore.get( idB ) );
@@ -212,8 +208,8 @@
ValidationRule validationRuleB = createValidationRule( 'B', ValidationRule.OPERATOR_EQUAL, expressionA,
expressionB, periodType );
- validationRuleStore.save( validationRuleA );
- validationRuleStore.save( validationRuleB );
+ validationRuleStore.saveValidationRule( validationRuleA );
+ validationRuleStore.saveValidationRule( validationRuleB );
Collection<ValidationRule> rules = validationRuleStore.getAll();
@@ -230,12 +226,65 @@
ValidationRule validationRuleB = createValidationRule( 'B', ValidationRule.OPERATOR_EQUAL, expressionA,
expressionB, periodType );
- int id = validationRuleStore.save( validationRuleA );
- validationRuleStore.save( validationRuleB );
+ int id = validationRuleStore.saveValidationRule( validationRuleA );
+ validationRuleStore.saveValidationRule( validationRuleB );
ValidationRule rule = validationRuleStore.getByName( "ValidationRuleA" );
assertEquals( rule.getId(), id );
assertEquals( rule.getName(), "ValidationRuleA" );
}
+
+ @Test
+ public void testGetValidationRulesByDataElements()
+ {
+ Set<DataElement> dataElementsA = new HashSet<DataElement>();
+ dataElementsA.add( dataElementA );
+ dataElementsA.add( dataElementB );
+
+ Set<DataElement> dataElementsB = new HashSet<DataElement>();
+ dataElementsB.add( dataElementC );
+ dataElementsB.add( dataElementD );
+
+ Set<DataElement> dataElementsC = new HashSet<DataElement>();
+
+ Set<DataElement> dataElementsD = new HashSet<DataElement>();
+ dataElementsD.addAll( dataElementsA );
+ dataElementsD.addAll( dataElementsB );
+
+ Expression expression1 = new Expression( "Expression1", "Expression1", dataElementsA );
+ Expression expression2 = new Expression( "Expression2", "Expression2", dataElementsB );
+ Expression expression3 = new Expression( "Expression3", "Expression3", dataElementsC );
+
+ expressionService.addExpression( expression1 );
+ expressionService.addExpression( expression2 );
+ expressionService.addExpression( expression3 );
+
+ ValidationRule ruleA = createValidationRule( 'A', ValidationRule.OPERATOR_EQUAL, expression1, expression3, periodType );
+ ValidationRule ruleB = createValidationRule( 'B', ValidationRule.OPERATOR_EQUAL, expression2, expression3, periodType );
+ ValidationRule ruleC = createValidationRule( 'C', ValidationRule.OPERATOR_EQUAL, expression3, expression3, periodType );
+
+ validationRuleStore.saveValidationRule( ruleA );
+ validationRuleStore.saveValidationRule( ruleB );
+ validationRuleStore.saveValidationRule( ruleC );
+
+ Collection<ValidationRule> rules = validationRuleStore.getValidationRulesByDataElements( dataElementsA );
+
+ assertNotNull( rules );
+ assertEquals( 1, rules.size() );
+ assertTrue( rules.contains( ruleA ) );
+
+ rules = validationRuleStore.getValidationRulesByDataElements( dataElementsB );
+
+ assertNotNull( rules );
+ assertEquals( 1, rules.size() );
+ assertTrue( rules.contains( ruleB ) );
+
+ rules = validationRuleStore.getValidationRulesByDataElements( dataElementsD );
+
+ assertNotNull( rules );
+ assertEquals( 2, rules.size() );
+ assertTrue( rules.contains( ruleA ) );
+ assertTrue( rules.contains( ruleB ) );
+ }
}