1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Test03.java,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 package complex
.passwordcontainer
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.task
.UrlRecord
;
36 import com
.sun
.star
.task
.UserRecord
;
37 import com
.sun
.star
.task
.XPasswordContainer
;
38 import com
.sun
.star
.task
.XMasterPasswordHandling
;
39 import com
.sun
.star
.task
.XInteractionHandler
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import share
.LogWriter
;
45 public class Test03
implements PasswordContainerTest
{
46 XMultiServiceFactory m_xMSF
= null;
47 XPasswordContainer m_xPasswordContainer
= null;
48 TestHelper m_aTestHelper
= null;
50 public Test03 ( XMultiServiceFactory xMSF
, LogWriter aLogWriter
)
53 m_aTestHelper
= new TestHelper (aLogWriter
, "Test03: ");
56 public boolean test() {
57 final String sURL
= "http://www.openoffice.org";
58 final String sUserPre
= "OOoUser";
59 final String sPwdPre
= "Password";
60 final int iPersistentUserNum
= 10;
61 final int iRuntimeUserNum
= 5;
63 UserRecord aInputUserList
[] = new UserRecord
[iPersistentUserNum
+iRuntimeUserNum
];
64 for(int i
= 0; i
< iPersistentUserNum
; i
++) {
65 String sTemp
[] = {sPwdPre
+ "_1_" + i
}; // currently one password for one user
66 aInputUserList
[i
] = new UserRecord(sUserPre
+ "_1_" + i
, sTemp
);
68 for(int i
= 0; i
< iRuntimeUserNum
; i
++) {
69 String sTemp
[] = {sPwdPre
+ "_2_" + i
};
70 aInputUserList
[i
+iPersistentUserNum
] = new UserRecord(sUserPre
+ "_2_" + i
, sTemp
);
74 Object oPasswordContainer
= m_xMSF
.createInstance("com.sun.star.task.PasswordContainer");
75 XPasswordContainer xContainer
= (XPasswordContainer
)UnoRuntime
.queryInterface(XPasswordContainer
.class, oPasswordContainer
);
76 Object oHandler
= m_xMSF
.createInstance("com.sun.star.task.InteractionHandler");
77 XInteractionHandler xHandler
= (XInteractionHandler
)UnoRuntime
.queryInterface(XInteractionHandler
.class, oHandler
);
78 MasterPasswdHandler aMHandler
= new MasterPasswdHandler(xHandler
);
79 XMasterPasswordHandling xMHandling
= (XMasterPasswordHandling
)UnoRuntime
.queryInterface(XMasterPasswordHandling
.class, oPasswordContainer
);
81 // allow the storing of the passwords
82 xMHandling
.allowPersistentStoring(true);
84 // add a set of users and passwords for the same URL persistently
85 for(int i
= 0; i
< iPersistentUserNum
; i
++) {
86 xContainer
.addPersistent(sURL
, aInputUserList
[i
].UserName
, aInputUserList
[i
].Passwords
, aMHandler
);
89 // add a set of users and passwords for the same URL for runtime
90 for(int i
= 0; i
< iRuntimeUserNum
; i
++) {
91 xContainer
.add(sURL
, aInputUserList
[i
+iPersistentUserNum
].UserName
, aInputUserList
[i
+iPersistentUserNum
].Passwords
, aMHandler
);
94 // get the result for the URL and check that it contains persistent and runtime passwords
95 UrlRecord aRecord
= xContainer
.find(sURL
, aMHandler
);
96 if(!aRecord
.Url
.equals(sURL
)) {
97 m_aTestHelper
.Error("URL mismatch. Got " + aRecord
.Url
+ "; should be " + sURL
);
100 if(!m_aTestHelper
.sameLists(aRecord
.UserList
, aInputUserList
)) {
101 m_aTestHelper
.Error("User list is not the expected");
105 // remove all the persistent passwords
106 xContainer
.removeAllPersistent();
108 // remove the runtime passwords
109 aRecord
= xContainer
.find(sURL
, aMHandler
);
110 for(int i
= 0; i
< aRecord
.UserList
.length
; i
++) {
111 xContainer
.remove(sURL
, aRecord
.UserList
[i
].UserName
);
114 // disallow the storing of the passwords
115 xMHandling
.allowPersistentStoring(false);
117 m_aTestHelper
.Error("Exception: " + e
);