~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.dataelement;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
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.
 
17
 *
 
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.
 
28
 */
 
29
 
 
30
import java.util.Collection;
 
31
import java.util.HashSet;
 
32
import java.util.Set;
 
33
 
 
34
import org.hisp.dhis.DhisConvenienceTest;
 
35
 
 
36
/**
 
37
 * @author Lars Helge Overland
 
38
 * @version $Id$
 
39
 */
 
40
public class DataElementCategoryComboServiceTest
 
41
    extends DhisConvenienceTest
 
42
{
 
43
    private DataElementCategoryCombo categoryComboA;
 
44
    private DataElementCategoryCombo categoryComboB;
 
45
    private DataElementCategoryCombo categoryComboC;
 
46
    
 
47
    private DataElementCategory categoryA;
 
48
    private DataElementCategory categoryB;
 
49
    private DataElementCategory categoryC;
 
50
    
 
51
    private Set<DataElementCategory> categories;
 
52
 
 
53
    // -------------------------------------------------------------------------
 
54
    // Fixture
 
55
    // -------------------------------------------------------------------------
 
56
 
 
57
    @Override
 
58
    public void setUpTest()
 
59
    {
 
60
        categoryComboService = (DataElementCategoryComboService) getBean( DataElementCategoryComboService.ID );
 
61
        
 
62
        categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
 
63
        
 
64
        categories = new HashSet<DataElementCategory>();
 
65
        
 
66
        categoryA = new DataElementCategory( "CategoryA" );
 
67
        categoryB = new DataElementCategory( "CategoryB" );
 
68
        categoryC = new DataElementCategory( "CategoryC" );
 
69
        
 
70
        categoryService.addDataElementCategory( categoryA );
 
71
        categoryService.addDataElementCategory( categoryB );
 
72
        categoryService.addDataElementCategory( categoryC );
 
73
        
 
74
        categories.add( categoryA );
 
75
        categories.add( categoryB );
 
76
        categories.add( categoryC );        
 
77
    }
 
78
 
 
79
    // -------------------------------------------------------------------------
 
80
    // Tests
 
81
    // -------------------------------------------------------------------------
 
82
 
 
83
    public void testAddGet()
 
84
    {
 
85
        categoryComboA = new DataElementCategoryCombo( "CategoryComboA", categories );
 
86
        categoryComboB = new DataElementCategoryCombo( "CategoryComboB", categories );
 
87
        categoryComboC = new DataElementCategoryCombo( "CategoryComboC", categories );
 
88
        
 
89
        int idA = categoryComboService.addDataElementCategoryCombo( categoryComboA );
 
90
        int idB = categoryComboService.addDataElementCategoryCombo( categoryComboB );
 
91
        int idC = categoryComboService.addDataElementCategoryCombo( categoryComboC );
 
92
        
 
93
        assertEquals( categoryComboA, categoryComboService.getDataElementCategoryCombo( idA ) );
 
94
        assertEquals( categoryComboB, categoryComboService.getDataElementCategoryCombo( idB ) );
 
95
        assertEquals( categoryComboC, categoryComboService.getDataElementCategoryCombo( idC ) );
 
96
        
 
97
        assertEquals( categories, categoryComboService.getDataElementCategoryCombo( idA ).getCategories() );
 
98
        assertEquals( categories, categoryComboService.getDataElementCategoryCombo( idB ).getCategories() );
 
99
        assertEquals( categories, categoryComboService.getDataElementCategoryCombo( idC ).getCategories() );        
 
100
    }
 
101
    
 
102
    public void testDelete()
 
103
    {
 
104
        categoryComboA = new DataElementCategoryCombo( "CategoryComboA", categories );
 
105
        categoryComboB = new DataElementCategoryCombo( "CategoryComboB", categories );
 
106
        categoryComboC = new DataElementCategoryCombo( "CategoryComboC", categories );
 
107
        
 
108
        int idA = categoryComboService.addDataElementCategoryCombo( categoryComboA );
 
109
        int idB = categoryComboService.addDataElementCategoryCombo( categoryComboB );
 
110
        int idC = categoryComboService.addDataElementCategoryCombo( categoryComboC );
 
111
        
 
112
        assertNotNull( categoryComboService.getDataElementCategoryCombo( idA ) );
 
113
        assertNotNull( categoryComboService.getDataElementCategoryCombo( idB ) );
 
114
        assertNotNull( categoryComboService.getDataElementCategoryCombo( idC ) );
 
115
        
 
116
        categoryComboService.deleteDataElementCategoryCombo( categoryComboA );
 
117
 
 
118
        assertNull( categoryComboService.getDataElementCategoryCombo( idA ) );
 
119
        assertNotNull( categoryComboService.getDataElementCategoryCombo( idB ) );
 
120
        assertNotNull( categoryComboService.getDataElementCategoryCombo( idC ) );
 
121
        
 
122
        categoryComboService.deleteDataElementCategoryCombo( categoryComboB );
 
123
 
 
124
        assertNull( categoryComboService.getDataElementCategoryCombo( idA ) );
 
125
        assertNull( categoryComboService.getDataElementCategoryCombo( idB ) );
 
126
        assertNotNull( categoryComboService.getDataElementCategoryCombo( idC ) );        
 
127
    }
 
128
    
 
129
    public void testGetAll()
 
130
    {
 
131
        categoryComboA = new DataElementCategoryCombo( "CategoryComboA", categories );
 
132
        categoryComboB = new DataElementCategoryCombo( "CategoryComboB", categories );
 
133
        categoryComboC = new DataElementCategoryCombo( "CategoryComboC", categories );
 
134
        
 
135
        categoryComboService.addDataElementCategoryCombo( categoryComboA );
 
136
        categoryComboService.addDataElementCategoryCombo( categoryComboB );
 
137
        categoryComboService.addDataElementCategoryCombo( categoryComboC );
 
138
        
 
139
        Collection<DataElementCategoryCombo> categoryCombos = categoryComboService.getAllDataElementCategoryCombos();
 
140
        
 
141
        assertEquals( 4, categoryCombos.size() ); // Including default
 
142
        assertTrue( categoryCombos.contains( categoryComboA ) );
 
143
        assertTrue( categoryCombos.contains( categoryComboB ) );
 
144
        assertTrue( categoryCombos.contains( categoryComboC ) );        
 
145
    }
 
146
}