← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16894: Test fix

 

------------------------------------------------------------
revno: 16894
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-10-01 11:03:22 +0200
message:
  Test fix
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserAuthorityGroup.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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-api/src/main/java/org/hisp/dhis/user/UserAuthorityGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserAuthorityGroup.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserAuthorityGroup.java	2014-10-01 09:03:22 +0000
@@ -69,7 +69,7 @@
 
     @Scanned
     private Set<DataSet> dataSets = new HashSet<>();
-
+    
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserAuthorityGroupTest.java	2014-10-01 09:03:22 +0000
@@ -29,6 +29,8 @@
  */
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
@@ -47,37 +49,40 @@
     }
     
     @Test
-    public void testBasicUserAuthorityGroup()
-        throws Exception
-    {
-        String name = "UserAuthorityGroup";
-        String name1 = "UserAuthorityGroup1";
-        String name2 = "UserAuthorityGroup2";
-
-        // Test addUserAuthorityGroup
-        UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
-        userAuthorityGroup.setName( name );
-        userAuthorityGroupStore.save( userAuthorityGroup );
-        assertEquals( userAuthorityGroupStore.get( userAuthorityGroup.getId() ).getName(), name );
-
-        // Test updateUserAuthorityGroup
-        userAuthorityGroup.setName( name1 );
-        userAuthorityGroupStore.update( userAuthorityGroup );
-        assertEquals( userAuthorityGroup.getName(), name1 );
-
-        // Test getUserAuthorityGroup
-        assertEquals( userAuthorityGroupStore.get( userAuthorityGroup.getId() ).getName(), name1 );
-        assertEquals( userAuthorityGroupStore.get( userAuthorityGroup.getId() ).getClass(), userAuthorityGroup
-            .getClass() );
-
-        // Test getAllUserAuthorityGroups
-        UserAuthorityGroup userAuthorityGroup2 = new UserAuthorityGroup();
-        userAuthorityGroup2.setName( name2 );
-        userAuthorityGroupStore.save( userAuthorityGroup2 );
-
-        // Test deleteUserAuthorityGroup
-        assertEquals( userAuthorityGroupStore.getAll().size(), 2 );
-        userAuthorityGroupStore.delete( userAuthorityGroup2 );
-        assertEquals( userAuthorityGroupStore.getAll().size(), 1 );
+    public void testAddGetUserAuthorityGroup()
+    {
+        UserAuthorityGroup roleA = createUserAuthorityGroup( 'A' );
+        UserAuthorityGroup roleB = createUserAuthorityGroup( 'B' );
+        UserAuthorityGroup roleC = createUserAuthorityGroup( 'C' );
+        
+        int idA = userAuthorityGroupStore.save( roleA );
+        int idB = userAuthorityGroupStore.save( roleB );
+        int idC = userAuthorityGroupStore.save( roleC );
+        
+        assertEquals( roleA, userAuthorityGroupStore.get( idA ) );
+        assertEquals( roleB, userAuthorityGroupStore.get( idB ) );
+        assertEquals( roleC, userAuthorityGroupStore.get( idC ) );
+    }
+
+    @Test
+    public void testDeleteUserAuthorityGroup()
+    {
+        UserAuthorityGroup roleA = createUserAuthorityGroup( 'A' );
+        UserAuthorityGroup roleB = createUserAuthorityGroup( 'B' );
+        UserAuthorityGroup roleC = createUserAuthorityGroup( 'C' );
+        
+        int idA = userAuthorityGroupStore.save( roleA );
+        int idB = userAuthorityGroupStore.save( roleB );
+        int idC = userAuthorityGroupStore.save( roleC );
+        
+        assertEquals( roleA, userAuthorityGroupStore.get( idA ) );
+        assertEquals( roleB, userAuthorityGroupStore.get( idB ) );
+        assertEquals( roleC, userAuthorityGroupStore.get( idC ) );
+        
+        userAuthorityGroupStore.delete( roleB );
+        
+        assertNotNull( userAuthorityGroupStore.get( idA ) );
+        assertNull( userAuthorityGroupStore.get( idB ) );
+        assertNotNull( userAuthorityGroupStore.get( idA ) );
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-08-26 10:51:19 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-10-01 09:03:22 +0000
@@ -1159,6 +1159,17 @@
 
         return userGroup;
     }
+    
+    public static UserAuthorityGroup createUserAuthorityGroup( char uniqueCharacter )
+    {
+        UserAuthorityGroup role = new UserAuthorityGroup();
+        role.setAutoFields();
+
+        role.setUid( BASE_UID + uniqueCharacter );
+        role.setName( "UserAuthorityGroup" + uniqueCharacter );
+        
+        return role;
+    }
 
     public static Program createProgram( char uniqueCharacter, List<ProgramStage> programStages,
         OrganisationUnit unit )