@@ -213,8 +213,10 @@ class LdapImportUsersCmdSpec extends spock.lang.Specification {
213213
214214 def accountService = Mock (AccountService )
215215 1 * accountService. getActiveAccountByName(' ACCOUNT' , 0 ) >> Mock (AccountVO )
216+
216217 1 * accountService
. createUser(
' rmurphy' , _ ,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
' ACCOUNT' ,
0 , _)
>> Mock (
UserVO )
217218 0 * accountService
. createUserAccount(
' rmurphy' , _,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
' ACCOUNT' ,
2 ,
0 ,
' DOMAIN' ,
null , _, _)
219+ 0 * accountService
. updateUser(_,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
null ,
null ,
null ,
null );
218220
219221 def ldapImportUsersCmd = new LdapImportUsersCmd (ldapManager, domainService, accountService)
220222 ldapImportUsersCmd. accountName = " ACCOUNT"
@@ -226,6 +228,36 @@ class LdapImportUsersCmdSpec extends spock.lang.Specification {
226228 then : " expect 1 call on accountService createUser and 0 on account service create user account"
227229 }
228230
231+
232+ def " Test create ldap import account for an already existing cloudstack user" () {
233+ given : " We have an LdapManager, DomainService, two users and a LdapImportUsersCmd"
234+ def ldapManager = Mock (LdapManager )
235+ List<LdapUser > users = new ArrayList ()
236+ users
. add(
new LdapUser (
" rmurphy" ,
" [email protected] " ,
" Ryan" ,
" Murphy" ,
" cn=rmurphy,ou=engineering,dc=cloudstack,dc=org" ,
" engineering" ))
237+ ldapManager. getUsers() >> users
238+ LdapUserResponse response1
= new LdapUserResponse (
" rmurphy" ,
" [email protected] " ,
" Ryan" ,
" Murphy" ,
" cn=rmurphy,ou=engineering,dc=cloudstack,dc=org" ,
" engineering" )
239+ ldapManager. createLdapUserResponse(_) >>> response1
240+
241+ def domainService = Mock (DomainService )
242+ 1 * domainService. getDomain(1L ) >> new DomainVO (" DOMAIN" , 1L , 1L , " DOMAIN" , UUID . randomUUID(). toString());;
243+
244+ def accountService = Mock (AccountService )
245+ 1 * accountService. getActiveAccountByName(' ACCOUNT' , 0 ) >> Mock (AccountVO )
246+ 1 * accountService. getActiveUserAccount(' rmurphy' ,0 ) >> Mock (UserAccountVO )
247+ 0 * accountService
. createUser(
' rmurphy' , _ ,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
' ACCOUNT' ,
0 , _)
>> Mock (
UserVO )
248+ 0 * accountService
. createUserAccount(
' rmurphy' , _,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
' ACCOUNT' ,
2 ,
0 ,
' DOMAIN' ,
null , _, _)
249+ 1 * accountService
. updateUser(_,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
null ,
null ,
null ,
null );
250+
251+ def ldapImportUsersCmd = new LdapImportUsersCmd (ldapManager, domainService, accountService)
252+ ldapImportUsersCmd. accountName = " ACCOUNT"
253+ ldapImportUsersCmd. accountType = 2 ;
254+ ldapImportUsersCmd. domainId = 1L ;
255+
256+ when : " create account is called"
257+ ldapImportUsersCmd. execute()
258+ then : " expect 1 call on accountService updateUser and 0 on account service create user and create user account"
259+ }
260+
229261 def " Test create ldap import account for a new cloudstack account" () {
230262 given : " We have an LdapManager, DomainService, two users and a LdapImportUsersCmd"
231263 def ldapManager = Mock (LdapManager )
@@ -242,6 +274,7 @@ class LdapImportUsersCmdSpec extends spock.lang.Specification {
242274 1 * accountService. getActiveAccountByName(' ACCOUNT' , 0 ) >> null
243275 0 * accountService
. createUser(
' rmurphy' , _ ,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
' ACCOUNT' ,
0 , _)
244276 1 * accountService
. createUserAccount(
' rmurphy' , _,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
' ACCOUNT' ,
2 ,
0 ,
' DOMAIN' ,
null , _, _)
277+ 0 * accountService
. updateUser(_,
' Ryan' ,
' Murphy' ,
' [email protected] ' ,
null ,
null ,
null ,
null ,
null );
245278
246279 def ldapImportUsersCmd = new LdapImportUsersCmd (ldapManager, domainService, accountService)
247280 ldapImportUsersCmd. accountName = " ACCOUNT"
0 commit comments