← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17794: User unit tests

 

------------------------------------------------------------
revno: 17794
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-12-25 11:43:54 +0100
message:
  User unit tests
added:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.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/UserGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java	2014-12-22 09:30:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java	2014-12-25 10:43:54 +0000
@@ -46,6 +46,9 @@
 import java.util.HashSet;
 import java.util.Set;
 
+/**
+ * @author Lars Helge Overland
+ */
 @JacksonXmlRootElement( localName = "userGroup", namespace = DxfNamespaces.DXF_2_0 )
 public class UserGroup
     extends BaseIdentifiableObject

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java	2014-12-24 14:44:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserGroupService.java	2014-12-25 10:43:54 +0000
@@ -35,6 +35,9 @@
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.springframework.transaction.annotation.Transactional;
 
+/**
+ * @author Lars Helge Overland
+ */
 @Transactional
 public class DefaultUserGroupService
     implements UserGroupService

=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java	2014-12-25 10:43:54 +0000
@@ -0,0 +1,149 @@
+package org.hisp.dhis.user;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class UserServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private UserCredentialsStore userCredentialsStore;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    private OrganisationUnit unit1;
+    private OrganisationUnit unit2;
+
+    @Override
+    public void setUpTest()
+        throws Exception
+    { 
+        unit1 = createOrganisationUnit( 'A' );
+        unit2 = createOrganisationUnit( 'B' );
+
+        organisationUnitService.addOrganisationUnit( unit1 );
+        organisationUnitService.addOrganisationUnit( unit2 );        
+    }
+
+    @Test
+    public void testAddGetUser()
+    {        
+        Set<OrganisationUnit> units = new HashSet<>();
+        
+        units.add( unit1 );
+        units.add( unit2 );
+
+        User userA = createUser( 'A' );
+        User userB = createUser( 'B' );
+        
+        userA.setOrganisationUnits( units );
+        userB.setOrganisationUnits( units );
+
+        int idA = userService.addUser( userA );
+        int idB = userService.addUser( userB );
+        
+        assertEquals( userA, userService.getUser( idA ) );
+        assertEquals( userB, userService.getUser( idB ) );
+        
+        assertEquals( units, userService.getUser( idA ).getOrganisationUnits() );
+        assertEquals( units, userService.getUser( idB ).getOrganisationUnits() );
+    }
+
+    @Test
+    public void testUpdateUser()
+    {
+        User userA = createUser( 'A' );
+        User userB = createUser( 'B' );
+
+        int idA = userService.addUser( userA );
+        int idB = userService.addUser( userB );
+
+        assertEquals( userA, userService.getUser( idA ) );
+        assertEquals( userB, userService.getUser( idB ) );
+        
+        userA.setSurname( "UpdatedSurnameA" );
+        
+        userService.updateUser( userA );
+        
+        assertEquals( userService.getUser( idA ).getSurname(), "UpdatedSurnameA" );
+    }
+    
+    @Test
+    public void testDeleteUser()
+    {
+        User userA = createUser( 'A' );
+        User userB = createUser( 'B' );
+
+        int idA = userService.addUser( userA );
+        int idB = userService.addUser( userB );
+
+        assertEquals( userA, userService.getUser( idA ) );
+        assertEquals( userB, userService.getUser( idB ) );
+        
+        userService.deleteUser( userA );
+        
+        assertNull( userService.getUser( idA ) );
+        assertNotNull( userService.getUser( idB ) );
+    }
+
+    @Test
+    public void testAddGetUserCredentials()
+    {
+        User userA = createUser( 'A' );
+        User userB = createUser( 'B' );
+        
+        UserCredentials credentialsA = createUserCredentials( 'A', userA );
+        UserCredentials credentialsB = createUserCredentials( 'B', userB );
+        
+        int idA = userCredentialsStore.addUserCredentials( credentialsA );
+        int idB = userCredentialsStore.addUserCredentials( credentialsB );
+        
+        assertEquals( credentialsA, userCredentialsStore.getUserCredentials( idA ) );
+        assertEquals( credentialsB, userCredentialsStore.getUserCredentials( idB ) );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java	2014-12-25 10:43:54 +0000
@@ -43,7 +43,6 @@
 
 /**
  * @author Nguyen Hong Duc
- * @version $Id: UserStoreTest.java 5724 2008-09-18 14:37:01Z larshelg $
  */
 public class UserStoreTest
     extends DhisSpringTest

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-12-12 17:48:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-12-25 10:43:54 +0000
@@ -158,6 +158,8 @@
             Iterator<String> iterator = filters.iterator();
             String name = null;
 
+            // Use database query for name filter
+
             if ( schema.getProperty( "name" ) != null && schema.getProperty( "name" ).isPersisted() )
             {
                 while ( iterator.hasNext() )
@@ -192,7 +194,8 @@
             }
             else
             {
-                // get full list if we are using filters
+                // Get full list when using filters other than name
+                
                 if ( !filters.isEmpty() )
                 {
                     if ( options.hasPaging() )