1
package org.hisp.dhis.dataelement;
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;
31
import java.util.HashSet;
34
import org.hisp.dhis.DhisConvenienceTest;
37
* @author Lars Helge Overland
40
public class DataElementCategoryStoreTest
41
extends DhisConvenienceTest
43
private DataElementCategoryStore categoryStore;
45
private DataElementCategoryOption categoryOptionA;
46
private DataElementCategoryOption categoryOptionB;
47
private DataElementCategoryOption categoryOptionC;
49
private DataElementCategory categoryA;
50
private DataElementCategory categoryB;
51
private DataElementCategory categoryC;
53
private Set<DataElementCategoryOption> categoryOptions;
55
// -------------------------------------------------------------------------
57
// -------------------------------------------------------------------------
60
public void setUpTest()
62
categoryOptionService = (DataElementCategoryOptionService) getBean( DataElementCategoryOptionService.ID );
64
categoryStore = (DataElementCategoryStore) getBean( DataElementCategoryStore.ID );
66
categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );
67
categoryOptionB = new DataElementCategoryOption( "CategoryOptionB" );
68
categoryOptionC = new DataElementCategoryOption( "CategoryOptionC" );
70
categoryOptionService.addDataElementCategoryOption( categoryOptionA );
71
categoryOptionService.addDataElementCategoryOption( categoryOptionB );
72
categoryOptionService.addDataElementCategoryOption( categoryOptionC );
74
categoryOptions = new HashSet<DataElementCategoryOption>();
76
categoryOptions.add( categoryOptionA );
77
categoryOptions.add( categoryOptionB );
78
categoryOptions.add( categoryOptionC );
81
// -------------------------------------------------------------------------
83
// -------------------------------------------------------------------------
85
public void testAddGet()
87
categoryA = new DataElementCategory( "CategoryA", categoryOptions );
88
categoryB = new DataElementCategory( "CategoryB", categoryOptions );
89
categoryC = new DataElementCategory( "CategoryC", categoryOptions );
91
int idA = categoryStore.addDataElementCategory( categoryA );
92
int idB = categoryStore.addDataElementCategory( categoryB );
93
int idC = categoryStore.addDataElementCategory( categoryC );
95
assertEquals( categoryA, categoryStore.getDataElementCategory( idA ) );
96
assertEquals( categoryB, categoryStore.getDataElementCategory( idB ) );
97
assertEquals( categoryC, categoryStore.getDataElementCategory( idC ) );
99
assertEquals( categoryOptions, categoryStore.getDataElementCategory( idA ).getCategoryOptions() );
100
assertEquals( categoryOptions, categoryStore.getDataElementCategory( idB ).getCategoryOptions() );
101
assertEquals( categoryOptions, categoryStore.getDataElementCategory( idC ).getCategoryOptions() );
104
public void testDelete()
106
categoryA = new DataElementCategory( "CategoryA", categoryOptions );
107
categoryB = new DataElementCategory( "CategoryB", categoryOptions );
108
categoryC = new DataElementCategory( "CategoryC", categoryOptions );
110
int idA = categoryStore.addDataElementCategory( categoryA );
111
int idB = categoryStore.addDataElementCategory( categoryB );
112
int idC = categoryStore.addDataElementCategory( categoryC );
114
assertNotNull( categoryStore.getDataElementCategory( idA ) );
115
assertNotNull( categoryStore.getDataElementCategory( idB ) );
116
assertNotNull( categoryStore.getDataElementCategory( idC ) );
118
categoryStore.deleteDataElementCategory( categoryA );
120
assertNull( categoryStore.getDataElementCategory( idA ) );
121
assertNotNull( categoryStore.getDataElementCategory( idB ) );
122
assertNotNull( categoryStore.getDataElementCategory( idC ) );
124
categoryStore.deleteDataElementCategory( categoryB );
126
assertNull( categoryStore.getDataElementCategory( idA ) );
127
assertNull( categoryStore.getDataElementCategory( idB ) );
128
assertNotNull( categoryStore.getDataElementCategory( idC ) );
131
public void testGetAll()
133
categoryA = new DataElementCategory( "CategoryA", categoryOptions );
134
categoryB = new DataElementCategory( "CategoryB", categoryOptions );
135
categoryC = new DataElementCategory( "CategoryC", categoryOptions );
137
categoryStore.addDataElementCategory( categoryA );
138
categoryStore.addDataElementCategory( categoryB );
139
categoryStore.addDataElementCategory( categoryC );
141
Collection<DataElementCategory> categories = categoryStore.getAllDataElementCategories();
143
assertEquals( 4, categories.size() ); // Including default
144
assertTrue( categories.contains( categoryA ) );
145
assertTrue( categories.contains( categoryB ) );
146
assertTrue( categories.contains( categoryC ) );