2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex
.passwordcontainer
;
21 import com
.sun
.star
.lang
.XMultiServiceFactory
;
22 import com
.sun
.star
.task
.XInteractionHandler
;
23 import com
.sun
.star
.task
.XPasswordContainer
;
24 import com
.sun
.star
.task
.UrlRecord
;
25 import com
.sun
.star
.task
.UserRecord
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
29 public class Test01
implements PasswordContainerTest
{
30 private XMultiServiceFactory m_xMSF
= null;
31 private TestHelper m_aTestHelper
= null;
33 public Test01 ( XMultiServiceFactory xMSF
)
36 m_aTestHelper
= new TestHelper ( "Test01: ");
39 public boolean test() {
40 final String sURL
= "http://www.openoffice.org";
41 final String sUserPre
= "OOoUser";
42 final String sPwdPre
= "Password";
43 final int iUserNum1
= 10;
44 final int iUserNum2
= 5;
46 UserRecord aInputUserList1
[] = new UserRecord
[iUserNum1
];
47 for(int i
= 0; i
< iUserNum1
; i
++) {
48 String sTemp
[] = {sPwdPre
+ "_1_" + i
}; // currently one password for one user
49 aInputUserList1
[i
] = new UserRecord(sUserPre
+ "_1_" + i
, sTemp
);
51 UserRecord aInputUserList2
[] = new UserRecord
[iUserNum2
];
52 for(int i
= 0; i
< iUserNum2
; i
++) {
53 String sTemp
[] = {sPwdPre
+ "_2_" + i
};
54 aInputUserList2
[i
] = new UserRecord(sUserPre
+ "_2_" + i
, sTemp
);
57 Object oPasswordContainer
= m_xMSF
.createInstance( "com.sun.star.task.PasswordContainer" );
58 XPasswordContainer xContainer
= UnoRuntime
.queryInterface(XPasswordContainer
.class, oPasswordContainer
);
59 Object oHandler
= m_xMSF
.createInstance( "com.sun.star.task.InteractionHandler" );
60 XInteractionHandler xHandler
= UnoRuntime
.queryInterface(XInteractionHandler
.class, oHandler
);
61 MasterPasswdHandler aMHandler
= new MasterPasswdHandler( xHandler
);
63 // add a set of users and passwords for the same URL for runtime
64 for(int i
= 0; i
< iUserNum1
; i
++) {
65 xContainer
.add(sURL
, aInputUserList1
[i
].UserName
, aInputUserList1
[i
].Passwords
, aMHandler
);
67 for (int i
= 0; i
< iUserNum2
; i
++) {
68 xContainer
.add(sURL
, aInputUserList2
[i
].UserName
, aInputUserList2
[i
].Passwords
, aMHandler
);
71 // remove some of the passwords
72 for (int i
= 0; i
< iUserNum1
; i
++) {
73 xContainer
.remove(sURL
, aInputUserList1
[i
].UserName
);
76 // get the result and check it with the expected one
77 UrlRecord aRecord
= xContainer
.find(sURL
, aMHandler
);
78 if(!aRecord
.Url
.equals(sURL
)) {
79 m_aTestHelper
.Error("URL mismatch. Got " + aRecord
.Url
+ "; should be " + sURL
);
82 if(!m_aTestHelper
.sameLists(aRecord
.UserList
, aInputUserList2
)) {
83 m_aTestHelper
.Error("User list is not the expected");
87 // remove the runtime passwords
88 aRecord
= xContainer
.find(sURL
, aMHandler
);
89 for(int i
= 0; i
< aRecord
.UserList
.length
; i
++) {
90 xContainer
.remove(sURL
, aRecord
.UserList
[i
].UserName
);
92 } catch(Exception e
) {
93 m_aTestHelper
.Error("Exception: " + e
);