1
package org.hisp.dhis.jdbc.batchhandler;
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.jdbc.BatchHandler;
34
import org.hisp.dhis.jdbc.BatchHandlerFactory;
35
import org.hisp.dhis.indicator.IndicatorService;
36
import org.hisp.dhis.indicator.IndicatorType;
39
* @author Lars Helge Overland
40
* @version $Id: IndicatorTypeBatchHandlerTest.java 4949 2008-04-21 07:59:54Z larshelg $
42
public class IndicatorTypeBatchHandlerTest
43
extends DhisConvenienceTest
45
private BatchHandlerFactory batchHandlerFactory;
47
private BatchHandler batchHandler;
49
private IndicatorType indicatorTypeA;
50
private IndicatorType indicatorTypeB;
51
private IndicatorType indicatorTypeC;
53
// -------------------------------------------------------------------------
55
// -------------------------------------------------------------------------
57
public void setUpTest()
59
indicatorService = (IndicatorService) getBean( IndicatorService.ID );
61
batchHandlerFactory = (BatchHandlerFactory) getBean( BatchHandlerFactory.ID );
63
batchHandler = batchHandlerFactory.createBatchHandler( IndicatorTypeBatchHandler.class );
67
indicatorTypeA = createIndicatorType( 'A' );
68
indicatorTypeB = createIndicatorType( 'B' );
69
indicatorTypeC = createIndicatorType( 'C' );
72
public void tearDownTest()
77
// -------------------------------------------------------------------------
79
// -------------------------------------------------------------------------
81
public void testAddObject()
83
batchHandler.addObject( indicatorTypeA );
84
batchHandler.addObject( indicatorTypeB );
85
batchHandler.addObject( indicatorTypeC );
89
Collection<IndicatorType> indicatorTypes = indicatorService.getAllIndicatorTypes();
91
assertTrue( indicatorTypes.contains( indicatorTypeA ) );
92
assertTrue( indicatorTypes.contains( indicatorTypeB ) );
93
assertTrue( indicatorTypes.contains( indicatorTypeC ) );
96
public void testInsertObject()
98
int idA = batchHandler.insertObject( indicatorTypeA, true );
99
int idB = batchHandler.insertObject( indicatorTypeB, true );
100
int idC = batchHandler.insertObject( indicatorTypeC, true );
102
assertNotNull( indicatorService.getIndicatorType( idA ) );
103
assertNotNull( indicatorService.getIndicatorType( idB ) );
104
assertNotNull( indicatorService.getIndicatorType( idC ) );
107
public void testUpdateObject()
109
int id = indicatorService.addIndicatorType( indicatorTypeA );
111
indicatorTypeA.setName( "UpdatedName" );
113
batchHandler.updateObject( indicatorTypeA );
115
assertEquals( indicatorService.getIndicatorType( id ).getName(), "UpdatedName" );
118
public void testGetObjectIdentifier()
120
int referenceId = indicatorService.addIndicatorType( indicatorTypeA );
122
int retrievedId = batchHandler.getObjectIdentifier( "IndicatorTypeA" );
124
assertEquals( referenceId, retrievedId );
127
public void testObjectExists()
129
indicatorService.addIndicatorType( indicatorTypeA );
131
assertTrue( batchHandler.objectExists( indicatorTypeA ) );
133
assertFalse( batchHandler.objectExists( indicatorTypeB ) );