← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12660: more tests for enrollmentService, test that status update works correctly, test that going from c...

 

------------------------------------------------------------
revno: 12660
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-10-15 11:22:18 +0200
message:
  more tests for enrollmentService, test that status update works correctly, test that going from completed/cancelled => active is not allowed
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java	2013-10-15 09:06:28 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java	2013-10-15 09:22:18 +0000
@@ -232,6 +232,78 @@
     }
 
     @Test
+    public void testUpdateCompleted()
+    {
+        Enrollment enrollment = new Enrollment();
+        enrollment.setPerson( maleA.getUid() );
+        enrollment.setProgram( programA.getUid() );
+
+        ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+        assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+        List<Enrollment> enrollments = enrollmentService.getEnrollments( maleA ).getEnrollments();
+
+        assertEquals( 1, enrollments.size() );
+        enrollment = enrollments.get( 0 );
+        enrollment.setStatus( EnrollmentStatus.COMPLETED );
+
+        enrollmentService.updateEnrollment( enrollment );
+        enrollments = enrollmentService.getEnrollments( maleA ).getEnrollments();
+        assertEquals( 1, enrollments.size() );
+        assertEquals( EnrollmentStatus.COMPLETED, enrollments.get( 0 ).getStatus() );
+    }
+
+    @Test
+    public void testUpdateCancelled()
+    {
+        Enrollment enrollment = new Enrollment();
+        enrollment.setPerson( maleA.getUid() );
+        enrollment.setProgram( programA.getUid() );
+
+        ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+        assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+        List<Enrollment> enrollments = enrollmentService.getEnrollments( maleA ).getEnrollments();
+
+        assertEquals( 1, enrollments.size() );
+        enrollment = enrollments.get( 0 );
+        enrollment.setStatus( EnrollmentStatus.CANCELLED );
+
+        enrollmentService.updateEnrollment( enrollment );
+        enrollments = enrollmentService.getEnrollments( maleA ).getEnrollments();
+        assertEquals( 1, enrollments.size() );
+        assertEquals( EnrollmentStatus.CANCELLED, enrollments.get( 0 ).getStatus() );
+    }
+
+    @Test
+    public void testUpdateReEnrollmentShouldFail()
+    {
+        Enrollment enrollment = new Enrollment();
+        enrollment.setPerson( maleA.getUid() );
+        enrollment.setProgram( programA.getUid() );
+
+        ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+        assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+        List<Enrollment> enrollments = enrollmentService.getEnrollments( maleA ).getEnrollments();
+
+        assertEquals( 1, enrollments.size() );
+        enrollment = enrollments.get( 0 );
+        enrollment.setStatus( EnrollmentStatus.CANCELLED );
+
+        importSummary = enrollmentService.updateEnrollment( enrollment );
+        assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+        enrollments = enrollmentService.getEnrollments( maleA ).getEnrollments();
+        assertEquals( 1, enrollments.size() );
+        assertEquals( EnrollmentStatus.CANCELLED, enrollments.get( 0 ).getStatus() );
+
+        enrollment.setStatus( EnrollmentStatus.ACTIVE );
+        importSummary = enrollmentService.updateEnrollment( enrollment );
+        assertEquals( ImportStatus.ERROR, importSummary.getStatus() );
+    }
+
+    @Test
     public void testMultipleEnrollmentsShouldFail()
     {
         Enrollment enrollment = new Enrollment();