1
package org.hisp.dhis.datadictionary;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.Collection;
32
import org.hisp.dhis.DhisConvenienceTest;
33
import org.hisp.dhis.dataelement.DataElement;
34
import org.hisp.dhis.dataelement.DataElementService;
35
import org.hisp.dhis.indicator.Indicator;
36
import org.hisp.dhis.indicator.IndicatorService;
37
import org.hisp.dhis.indicator.IndicatorType;
40
* @author Lars Helge Overland
43
public class DataDictionaryServiceTest
44
extends DhisConvenienceTest
46
private DataDictionaryService dataDictionaryService;
48
private DataDictionary dataDictionaryA;
49
private DataDictionary dataDictionaryB;
51
private DataElement dataElementA;
52
private DataElement dataElementB;
54
private IndicatorType indicatorType;
56
private Indicator indicatorA;
57
private Indicator indicatorB;
59
// -------------------------------------------------------------------------
61
// -------------------------------------------------------------------------
63
public void setUpTest()
66
dataDictionaryService = (DataDictionaryService) getBean( DataDictionaryService.ID );
68
dataElementService = (DataElementService) getBean( DataElementService.ID );
70
indicatorService = (IndicatorService) getBean( IndicatorService.ID );
72
dataDictionaryA = createDataDictionary( 'A' );
73
dataDictionaryB = createDataDictionary( 'B' );
75
dataElementA = createDataElement( 'A' );
76
dataElementB = createDataElement( 'B' );
78
indicatorType = createIndicatorType( 'A' );
80
indicatorService.addIndicatorType( indicatorType );
82
indicatorA = createIndicator( 'A', indicatorType );
83
indicatorB = createIndicator( 'B', indicatorType );
86
// -------------------------------------------------------------------------
87
// DataDictionary tests
88
// -------------------------------------------------------------------------
90
public void testSaveGetDataDictionary()
92
dataElementService.addDataElement( dataElementA );
93
dataElementService.addDataElement( dataElementB );
95
indicatorService.addIndicator( indicatorA );
96
indicatorService.addIndicator( indicatorB );
98
dataDictionaryA.getDataElements().add( dataElementA );
99
dataDictionaryA.getDataElements().add( dataElementB );
101
dataDictionaryA.getIndicators().add( indicatorA );
102
dataDictionaryA.getIndicators().add( indicatorB );
104
int id = dataDictionaryService.saveDataDictionary( dataDictionaryA );
106
dataDictionaryA = dataDictionaryService.getDataDictionary( id );
108
assertEquals( dataDictionaryA.getName(), "DataDictionaryA" );
109
assertEquals( dataDictionaryA.getDescription(), "DescriptionA" );
110
assertEquals( dataDictionaryA.getRegion(), "RegionA" );
111
assertEquals( dataDictionaryA.getDataElements().size(), 2 );
113
assertTrue( dataDictionaryA.getDataElements().contains( dataElementA ) );
114
assertTrue( dataDictionaryA.getDataElements().contains( dataElementB ) );
116
assertTrue( dataDictionaryA.getIndicators().contains( indicatorA ) );
117
assertTrue( dataDictionaryA.getIndicators().contains( indicatorB ) );
119
dataDictionaryA.setName( "DataDictionaryB" );
120
dataDictionaryA.setDescription( "DescriptionB" );
121
dataDictionaryA.setRegion( "RegionB" );
123
dataDictionaryService.saveDataDictionary( dataDictionaryA );
125
dataDictionaryA = dataDictionaryService.getDataDictionary( id );
127
assertEquals( dataDictionaryA.getName(), "DataDictionaryB" );
128
assertEquals( dataDictionaryA.getDescription(), "DescriptionB" );
129
assertEquals( dataDictionaryA.getRegion(), "RegionB" );
132
public void testGetDataDictionaryByName()
134
dataDictionaryService.saveDataDictionary( dataDictionaryA );
135
dataDictionaryService.saveDataDictionary( dataDictionaryB );
137
dataDictionaryA = dataDictionaryService.getDataDictionaryByName( "DataDictionaryA" );
139
assertNotNull( dataDictionaryA );
140
assertEquals( dataDictionaryA.getName(), "DataDictionaryA" );
141
assertEquals( dataDictionaryA.getDescription(), "DescriptionA" );
144
public void testDeleteDataDictionary()
146
int idA = dataDictionaryService.saveDataDictionary( dataDictionaryA );
147
int idB = dataDictionaryService.saveDataDictionary( dataDictionaryB );
149
assertNotNull( dataDictionaryService.getDataDictionary( idA ) );
150
assertNotNull( dataDictionaryService.getDataDictionary( idB ) );
152
dataDictionaryService.deleteDataDictionary( dataDictionaryA );
154
assertNull( dataDictionaryService.getDataDictionary( idA ) );
155
assertNotNull( dataDictionaryService.getDataDictionary( idB ) );
157
dataDictionaryService.deleteDataDictionary( dataDictionaryB );
159
assertNull( dataDictionaryService.getDataDictionary( idA ) );
160
assertNull( dataDictionaryService.getDataDictionary( idB ) );
163
public void testGetAllDataDictionaries()
165
dataDictionaryService.saveDataDictionary( dataDictionaryA );
166
dataDictionaryService.saveDataDictionary( dataDictionaryB );
168
Collection<DataDictionary> dictionaries = dataDictionaryService.getAllDataDictionaries();
170
assertTrue( dictionaries.size() == 2 );
171
assertTrue( dictionaries.contains( dataDictionaryA ) );
172
assertTrue( dictionaries.contains( dataDictionaryB ) );