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

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/importobject/ImportObjectServiceTest.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.importexport.importobject;
 
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
 
 
32
import org.hisp.dhis.DhisConvenienceTest;
 
33
import org.hisp.dhis.importexport.GroupMemberAssociation;
 
34
import org.hisp.dhis.dataelement.DataElement;
 
35
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 
36
import org.hisp.dhis.dataelement.DataElementCategoryComboService;
 
37
import org.hisp.dhis.dataelement.DataElementGroup;
 
38
import org.hisp.dhis.dataelement.DataElementService;
 
39
import org.hisp.dhis.dataset.DataSet;
 
40
import org.hisp.dhis.importexport.GroupMemberType;
 
41
import org.hisp.dhis.importexport.ImportObject;
 
42
import org.hisp.dhis.importexport.ImportObjectService;
 
43
import org.hisp.dhis.importexport.ImportObjectStatus;
 
44
import org.hisp.dhis.indicator.Indicator;
 
45
import org.hisp.dhis.indicator.IndicatorGroup;
 
46
import org.hisp.dhis.indicator.IndicatorService;
 
47
import org.hisp.dhis.indicator.IndicatorType;
 
48
import org.hisp.dhis.period.MonthlyPeriodType;
 
49
 
 
50
import static org.hisp.dhis.expression.Expression.SEPARATOR;
 
51
 
 
52
/**
 
53
 * @author Lars Helge Overland
 
54
 * @version $Id$
 
55
 */
 
56
public class ImportObjectServiceTest
 
57
    extends DhisConvenienceTest
 
58
{
 
59
    private ImportObjectService importObjectService;
 
60
    
 
61
    private DataElement dataElementA;    
 
62
    private DataElement dataElementB;    
 
63
    private DataElement dataElementC;
 
64
    
 
65
    private DataElementCategoryCombo categoryComboA;
 
66
    
 
67
    private DataElementGroup dataElementGroupA;    
 
68
    private DataElementGroup dataElementGroupB;
 
69
    private DataElementGroup dataElementGroupC;
 
70
    
 
71
    private GroupMemberAssociation associationA; 
 
72
    private GroupMemberAssociation associationB; 
 
73
    private GroupMemberAssociation associationC;
 
74
    private GroupMemberAssociation associationD; 
 
75
    private GroupMemberAssociation associationE; 
 
76
    private GroupMemberAssociation associationF;
 
77
    
 
78
    private DataSet dataSetA;
 
79
    
 
80
    private GroupMemberAssociation associationG;
 
81
    private GroupMemberAssociation associationH;
 
82
    private GroupMemberAssociation associationI;    
 
83
    
 
84
    private IndicatorType indicatorTypeA;
 
85
    
 
86
    private Indicator indicatorA;    
 
87
    private Indicator indicatorB;    
 
88
    private Indicator indicatorC;
 
89
    
 
90
    private IndicatorGroup indicatorGroupA;
 
91
    private IndicatorGroup indicatorGroupB;
 
92
 
 
93
    private int idA;
 
94
    private int idB;
 
95
    private int idC;
 
96
    private int idD;
 
97
    private int idE;
 
98
    private int idF;
 
99
    private int idG;
 
100
    private int idH;
 
101
    private int idI;
 
102
    
 
103
    // -------------------------------------------------------------------------
 
104
    // Fixture
 
105
    // -------------------------------------------------------------------------
 
106
 
 
107
    public void setUpTest()
 
108
    {
 
109
        importObjectService = (ImportObjectService) getBean( ImportObjectService.ID );
 
110
        
 
111
        categoryComboService = (DataElementCategoryComboService) getBean( DataElementCategoryComboService.ID );
 
112
        
 
113
        dataElementService = (DataElementService) getBean( DataElementService.ID );
 
114
 
 
115
        indicatorService = (IndicatorService) getBean( IndicatorService.ID );
 
116
 
 
117
        categoryComboA = new DataElementCategoryCombo( "CategoryComboA" );
 
118
        
 
119
        categoryComboA.setId( 'A' );
 
120
        
 
121
        dataElementA = createDataElement( 'A', categoryComboA );        
 
122
        dataElementB = createDataElement( 'B', categoryComboA );        
 
123
        dataElementC = createDataElement( 'C', categoryComboA );
 
124
        
 
125
        dataElementA.setId( 'A' );
 
126
        dataElementB.setId( 'B' );
 
127
        dataElementC.setId( 'C' );
 
128
        
 
129
        dataElementGroupA = createDataElementGroup( 'A' );
 
130
        dataElementGroupB = createDataElementGroup( 'B' );
 
131
        dataElementGroupC = createDataElementGroup( 'C' );
 
132
        
 
133
        dataElementGroupA.setId( 'A' );
 
134
        dataElementGroupB.setId( 'B' );
 
135
        dataElementGroupB.setId( 'C' );
 
136
 
 
137
        associationA = new GroupMemberAssociation( 'A', 'A' );
 
138
        associationB = new GroupMemberAssociation( 'A', 'B' );        
 
139
        associationC = new GroupMemberAssociation( 'A', 'C' );
 
140
        associationD = new GroupMemberAssociation( 'B', 'A' );        
 
141
        associationE = new GroupMemberAssociation( 'B', 'B' );        
 
142
        associationF = new GroupMemberAssociation( 'B', 'C' );
 
143
        
 
144
        dataSetA = createDataSet( 'A', new MonthlyPeriodType() );
 
145
        
 
146
        dataSetA.setId( 'A' );
 
147
        
 
148
        associationG = new GroupMemberAssociation( 'A', 'A' );
 
149
        associationH = new GroupMemberAssociation( 'A', 'B' );
 
150
        associationI = new GroupMemberAssociation( 'A', 'C' );
 
151
                
 
152
        indicatorTypeA = createIndicatorType( 'A' );
 
153
        
 
154
        indicatorTypeA.setId( 'A' );
 
155
        
 
156
        indicatorA = createIndicator( 'A', indicatorTypeA );        
 
157
        indicatorB = createIndicator( 'B', indicatorTypeA );        
 
158
        indicatorC = createIndicator( 'C', indicatorTypeA );
 
159
        
 
160
        indicatorA.setId( 'A' );
 
161
        indicatorB.setId( 'B' );
 
162
        indicatorC.setId( 'C' );
 
163
        
 
164
        indicatorGroupA = createIndicatorGroup( 'A' );
 
165
        indicatorGroupB = createIndicatorGroup( 'B' );
 
166
        
 
167
        indicatorGroupA.setId( 'A' );
 
168
        indicatorGroupB.setId( 'B' );
 
169
 
 
170
        idA = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, dataElementA );
 
171
        idB = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, dataElementB );
 
172
        idC = importObjectService.addImportObject( ImportObjectStatus.UPDATE, GroupMemberType.NONE, dataElementC );
 
173
        idD = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, dataElementGroupA );
 
174
        idE = importObjectService.addImportObject( ImportObjectStatus.UPDATE, GroupMemberType.NONE, dataElementGroupB );
 
175
        idF = importObjectService.addImportObject( ImportObjectStatus.UPDATE, GroupMemberType.NONE, dataElementGroupC );
 
176
        idG = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationA );
 
177
        idH = importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.DATAELEMENTGROUP, associationB );
 
178
        idI = importObjectService.addImportObject( ImportObjectStatus.MATCH, GroupMemberType.DATAELEMENTGROUP, associationC );
 
179
    }
 
180
 
 
181
    // -------------------------------------------------------------------------
 
182
    // Supportive methods
 
183
    // -------------------------------------------------------------------------
 
184
 
 
185
    private void assertEquals( ImportObject importObject, ImportObjectStatus status, Class<?> clazz, GroupMemberType type, Object object, Object compareObject )
 
186
    {
 
187
        assertEquals( importObject.getStatus(), status );
 
188
        assertEquals( importObject.getClassName(), clazz.getName() );
 
189
        assertEquals( importObject.getGroupMemberType(), type );
 
190
        assertEquals( importObject.getObject(), object );
 
191
        assertEquals( importObject.getCompareObject(), compareObject );
 
192
    }
 
193
    
 
194
    private void assertNulls( Integer... identifiers )
 
195
    {
 
196
        for ( Integer id : identifiers )
 
197
        {
 
198
            assertNull( String.valueOf( id ), importObjectService.getImportObject( id ) );
 
199
        }
 
200
    }
 
201
    
 
202
    private void assertNotNulls( Integer... identifiers )
 
203
    {
 
204
        for ( Integer id : identifiers )
 
205
        {
 
206
            assertNotNull( String.valueOf( id ), importObjectService.getImportObject( id ) );
 
207
        }
 
208
    }
 
209
    
 
210
    // -------------------------------------------------------------------------
 
211
    // ImportObject
 
212
    // -------------------------------------------------------------------------
 
213
    
 
214
    public void testAddGetImportObject()
 
215
    {
 
216
        assertEquals( importObjectService.getImportObject( idA ), ImportObjectStatus.NEW, DataElement.class, GroupMemberType.NONE, dataElementA, null );        
 
217
        assertEquals( importObjectService.getImportObject( idC ), ImportObjectStatus.UPDATE, DataElement.class, GroupMemberType.NONE, dataElementC, null );
 
218
        assertEquals( importObjectService.getImportObject( idH ), ImportObjectStatus.MATCH, GroupMemberAssociation.class, GroupMemberType.DATAELEMENTGROUP, associationB, null );
 
219
    }
 
220
    
 
221
    public void testAddGetImportObjectWithCompareObject()
 
222
    {
 
223
        int importObjectIdA = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementA, dataElementB );
 
224
        int importObjectIdB = importObjectService.addImportObject( ImportObjectStatus.UPDATE, dataElementB, dataElementC );
 
225
        int importObjectIdC = importObjectService.addImportObject( ImportObjectStatus.MATCH, dataElementC, dataElementA );
 
226
        
 
227
        assertEquals( importObjectService.getImportObject( importObjectIdA ), ImportObjectStatus.NEW, DataElement.class, GroupMemberType.NONE, dataElementA, dataElementB );
 
228
        assertEquals( importObjectService.getImportObject( importObjectIdB ), ImportObjectStatus.UPDATE, DataElement.class, GroupMemberType.NONE, dataElementB, dataElementC );
 
229
        assertEquals( importObjectService.getImportObject( importObjectIdC ), ImportObjectStatus.MATCH, DataElement.class, GroupMemberType.NONE, dataElementC, dataElementA );
 
230
    }
 
231
 
 
232
    public void testGetImportObjectsByClass()
 
233
    {
 
234
        Collection<ImportObject> importObjects = importObjectService.getImportObjects( DataElement.class );
 
235
        
 
236
        assertEquals( importObjects.size(), 3 );
 
237
        
 
238
        assertTrue( importObjects.contains( importObjectService.getImportObject( idA ) ) );
 
239
        assertTrue( importObjects.contains( importObjectService.getImportObject( idB ) ) );
 
240
        assertTrue( importObjects.contains( importObjectService.getImportObject( idC ) ) );
 
241
        
 
242
        importObjects = importObjectService.getImportObjects( GroupMemberAssociation.class );
 
243
 
 
244
        assertEquals( importObjects.size(), 3 );
 
245
        
 
246
        assertTrue( importObjects.contains( importObjectService.getImportObject( idG ) ) );
 
247
        assertTrue( importObjects.contains( importObjectService.getImportObject( idH ) ) );
 
248
        assertTrue( importObjects.contains( importObjectService.getImportObject( idI ) ) );        
 
249
    }
 
250
 
 
251
    public void testGetImportObjectsByStatusClass()
 
252
    {
 
253
        Collection<ImportObject> importObjects = importObjectService.getImportObjects( ImportObjectStatus.NEW, DataElement.class );
 
254
        
 
255
        assertEquals( importObjects.size(), 2 );
 
256
        
 
257
        assertTrue( importObjects.contains( importObjectService.getImportObject( idA ) ) );
 
258
        assertTrue( importObjects.contains( importObjectService.getImportObject( idB ) ) );
 
259
        
 
260
        importObjects = importObjectService.getImportObjects( ImportObjectStatus.MATCH, GroupMemberAssociation.class );
 
261
 
 
262
        assertEquals( importObjects.size(), 2 );
 
263
        
 
264
        assertTrue( importObjects.contains( importObjectService.getImportObject( idH )  ) );
 
265
        assertTrue( importObjects.contains( importObjectService.getImportObject( idI )  ) );        
 
266
    }
 
267
 
 
268
    public void testGetImportObjectsByGroupMemberType()
 
269
    {
 
270
        Collection<ImportObject> importObjects = importObjectService.getImportObjects( GroupMemberType.NONE );
 
271
        
 
272
        assertEquals( importObjects.size(), 6 );
 
273
        
 
274
        assertTrue( importObjects.contains( importObjectService.getImportObject( idA ) ) );
 
275
        assertTrue( importObjects.contains( importObjectService.getImportObject( idB ) ) );
 
276
        assertTrue( importObjects.contains( importObjectService.getImportObject( idC ) ) );
 
277
        assertTrue( importObjects.contains( importObjectService.getImportObject( idD ) ) );
 
278
        assertTrue( importObjects.contains( importObjectService.getImportObject( idE ) ) );
 
279
        assertTrue( importObjects.contains( importObjectService.getImportObject( idF ) ) );
 
280
        
 
281
        importObjects = importObjectService.getImportObjects( GroupMemberType.DATAELEMENTGROUP );
 
282
 
 
283
        assertEquals( importObjects.size(), 3 );
 
284
        
 
285
        assertTrue( importObjects.contains( importObjectService.getImportObject( idG ) ) );
 
286
        assertTrue( importObjects.contains( importObjectService.getImportObject( idH ) ) );
 
287
        assertTrue( importObjects.contains( importObjectService.getImportObject( idI ) ) );        
 
288
    }
 
289
    
 
290
    public void testDeleteImportObject()
 
291
    {
 
292
        assertNotNulls( idA, idB, idC );
 
293
 
 
294
        importObjectService.deleteImportObject( idA );
 
295
 
 
296
        assertNulls( idA );
 
297
        assertNotNulls( idB, idC );
 
298
 
 
299
        importObjectService.deleteImportObject( idB );
 
300
 
 
301
        assertNulls( idA, idB );
 
302
        assertNotNulls( idC );
 
303
 
 
304
        importObjectService.deleteImportObject( idC );
 
305
 
 
306
        assertNulls( idA, idB, idC );
 
307
    }
 
308
    
 
309
    public void testDeleteImportObjectsByClass()
 
310
    {
 
311
        assertNotNulls( idA, idB, idC, idD, idE, idF, idG, idH, idI );
 
312
        
 
313
        importObjectService.deleteImportObjects( DataElement.class );
 
314
 
 
315
        assertNotNulls( idD, idE, idF, idG, idH, idI );
 
316
        assertNulls( idA, idB, idC );
 
317
 
 
318
        importObjectService.deleteImportObjects( DataElementGroup.class );
 
319
 
 
320
        assertNotNulls( idG, idH, idI );
 
321
        assertNulls( idA, idB, idC, idD, idE, idF );
 
322
    }
 
323
    
 
324
    public void testCascadeDeleteImportObject()
 
325
    {
 
326
        int idJ = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationD );
 
327
        int idK = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationE );
 
328
        int idL = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationF );
 
329
        
 
330
        int idM = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, dataSetA );
 
331
        
 
332
        int idN = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATASET, associationG );
 
333
        int idO = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATASET, associationH );
 
334
        int idP = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATASET, associationI );
 
335
        
 
336
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 3 );
 
337
        assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 3 );
 
338
        assertEquals( importObjectService.getImportObjects( DataSet.class ).size(), 1 );
 
339
        assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 9 );
 
340
        
 
341
        assertNotNulls( idJ, idK, idL, idM, idN, idO, idP );
 
342
        
 
343
        importObjectService.cascadeDeleteImportObject( idA );
 
344
 
 
345
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 2 );
 
346
        assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 3 );
 
347
        assertEquals( importObjectService.getImportObjects( DataSet.class ).size(), 1 );
 
348
        assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 6 );
 
349
 
 
350
        assertNulls( idA, idG, idJ, idN );
 
351
        
 
352
        importObjectService.cascadeDeleteImportObject( idD );
 
353
 
 
354
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 2 );
 
355
        assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 2 );
 
356
        assertEquals( importObjectService.getImportObjects( DataSet.class ).size(), 1 );
 
357
        assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 4 );
 
358
        
 
359
        assertNulls( idD, idH, idI );
 
360
        
 
361
        importObjectService.cascadeDeleteImportObject( idM );
 
362
 
 
363
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 2 );
 
364
        assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 2 );
 
365
        assertEquals( importObjectService.getImportObjects( DataSet.class ).size(), 0 );
 
366
        assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 2 );
 
367
        
 
368
        assertNulls( idM, idO, idP );
 
369
    }
 
370
    
 
371
    public void testCascadeDeleteIndicatorsContainingDataElement()
 
372
    {
 
373
        String suffix = SEPARATOR + categoryComboA.getId();
 
374
        
 
375
        indicatorA.setNumerator( "[" + Integer.valueOf( 'A' ) + suffix + "]+[" + Integer.valueOf( 'B' ) + suffix + "]-[" + Integer.valueOf( 'C' ) + suffix + "]" );
 
376
        indicatorA.setDenominator( "[" + Integer.valueOf( 'A' ) + suffix + "]" );
 
377
 
 
378
        indicatorB.setNumerator( "[" + Integer.valueOf( 'B' ) + suffix + "]+[" + Integer.valueOf( 'C' ) + suffix + "]" );
 
379
        indicatorB.setDenominator( "[" + Integer.valueOf( 'B' ) + suffix + "]" );
 
380
        
 
381
        indicatorC.setNumerator( "[" + Integer.valueOf( 'A' ) + suffix + "]" );
 
382
        indicatorC.setDenominator( "[" + Integer.valueOf( 'A' ) + suffix + "]" );
 
383
        
 
384
        importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, indicatorA );
 
385
        importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, indicatorB );
 
386
        importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, indicatorC );
 
387
        
 
388
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 3 );
 
389
        assertEquals( importObjectService.getImportObjects( Indicator.class ).size(), 3 );
 
390
        
 
391
        importObjectService.cascadeDeleteImportObject( idA );
 
392
 
 
393
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 2 );
 
394
        assertEquals( importObjectService.getImportObjects( Indicator.class ).size(), 1 );
 
395
 
 
396
        importObjectService.cascadeDeleteImportObject( idC );
 
397
 
 
398
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 1 );
 
399
        assertEquals( importObjectService.getImportObjects( Indicator.class ).size(), 0 );
 
400
    }
 
401
    
 
402
    public void testCascadeDeleteImportObjects()
 
403
    {
 
404
        int idJ = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationD );
 
405
        int idK = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationE );
 
406
        int idL = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.DATAELEMENTGROUP, associationF );
 
407
        
 
408
        int idM = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, dataSetA );
 
409
        
 
410
        int idN = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, indicatorA );
 
411
        int idO = importObjectService.addImportObject( ImportObjectStatus.NEW, GroupMemberType.NONE, indicatorB );
 
412
        
 
413
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 3 );
 
414
        assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 3 );
 
415
        assertEquals( importObjectService.getImportObjects( Indicator.class ).size(), 2 );
 
416
        assertEquals( importObjectService.getImportObjects( DataSet.class ).size(), 1 );
 
417
        assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 6 );
 
418
 
 
419
        assertNotNulls( idJ, idK, idL, idM, idN, idO );
 
420
        
 
421
        importObjectService.cascadeDeleteImportObjects( DataElement.class );
 
422
 
 
423
        assertEquals( importObjectService.getImportObjects( DataElement.class ).size(), 0 );
 
424
        assertEquals( importObjectService.getImportObjects( DataElementGroup.class ).size(), 3 );
 
425
        assertEquals( importObjectService.getImportObjects( Indicator.class ).size(), 0 );
 
426
        assertEquals( importObjectService.getImportObjects( DataSet.class ).size(), 0 );
 
427
        assertEquals( importObjectService.getImportObjects( GroupMemberAssociation.class ).size(), 0 );
 
428
 
 
429
        assertNulls( idA, idB, idC, idG, idH, idI, idJ, idK, idL, idN, idO );
 
430
    }
 
431
 
 
432
    // -------------------------------------------------------------------------
 
433
    // Object
 
434
    // -------------------------------------------------------------------------
 
435
    
 
436
    public void testMatchObject()
 
437
    {
 
438
        indicatorService.addIndicatorType( indicatorTypeA );
 
439
        
 
440
        categoryComboService.addDataElementCategoryCombo( categoryComboA );
 
441
        
 
442
        int existingObjectIdA = dataElementService.addDataElement( dataElementA );
 
443
        int existingObjectIdB = indicatorService.addIndicator( indicatorA );
 
444
        
 
445
        int importObjectIdA = importObjectService.addImportObject( ImportObjectStatus.NEW, dataElementB, null );
 
446
        int importObjectIdB = importObjectService.addImportObject( ImportObjectStatus.UPDATE, indicatorB, indicatorA );
 
447
        
 
448
        importObjectService.matchObject( importObjectIdA, existingObjectIdA );
 
449
        importObjectService.matchObject( importObjectIdB, existingObjectIdB );
 
450
        
 
451
        ImportObject importObjectA = importObjectService.getImportObject( importObjectIdA );
 
452
        ImportObject importObjectB = importObjectService.getImportObject( importObjectIdB );
 
453
        
 
454
        DataElement existingObjectA = (DataElement) importObjectA.getObject();
 
455
        Indicator existingObjectB = (Indicator) importObjectB.getObject();
 
456
        
 
457
        assertEquals( existingObjectA.getId(), 'B' );
 
458
        assertEquals( existingObjectA.getName(), "DataElementA" );
 
459
        assertEquals( importObjectA.getStatus(), ImportObjectStatus.MATCH );
 
460
 
 
461
        assertEquals( existingObjectB.getId(), 'B' );
 
462
        assertEquals( existingObjectB.getName(), "IndicatorA" );
 
463
        assertEquals( importObjectB.getStatus(), ImportObjectStatus.MATCH );
 
464
    }
 
465
}