Update ooo320-m1
[ooovba.git] / svtools / qa / complex / passwordcontainer / Test01.java
blob02e1ec087f0fbfb8069e1fb458b743a800a9b4e3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Test01.java,v $
11 * $Revision: 1.2 $
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.XInteractionHandler;
36 import com.sun.star.task.XPasswordContainer;
37 import com.sun.star.task.UrlRecord;
38 import com.sun.star.task.UserRecord;
39 import com.sun.star.task.XMasterPasswordHandling;
41 import com.sun.star.uno.UnoRuntime;
43 import share.LogWriter;
45 public class Test01 implements PasswordContainerTest {
46 XMultiServiceFactory m_xMSF = null;
47 XPasswordContainer m_xPasswordContainer = null;
48 TestHelper m_aTestHelper = null;
50 public Test01 ( XMultiServiceFactory xMSF, LogWriter aLogWriter )
52 m_xMSF = xMSF;
53 m_aTestHelper = new TestHelper (aLogWriter, "Test01: ");
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 iUserNum1 = 10;
61 final int iUserNum2 = 5;
63 UserRecord aInputUserList1[] = new UserRecord[iUserNum1];
64 for(int i = 0; i < iUserNum1; i++) {
65 String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user
66 aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp);
68 UserRecord aInputUserList2[] = new UserRecord[iUserNum2];
69 for(int i = 0; i < iUserNum2; i++) {
70 String sTemp[] = {sPwdPre + "_2_" + i};
71 aInputUserList2[i] = new UserRecord(sUserPre + "_2_" + i, sTemp);
73 try {
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 );
80 // add a set of users and passwords for the same URL for runtime
81 for(int i = 0; i < iUserNum1; i++) {
82 xContainer.add(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler);
84 for (int i = 0; i < iUserNum2; i++) {
85 xContainer.add(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler);
88 // remove some of the passwords
89 for (int i = 0; i < iUserNum1; i++) {
90 xContainer.remove(sURL, aInputUserList1[i].UserName);
93 // get the result and check it with the expected one
94 UrlRecord aRecord = xContainer.find(sURL, aMHandler);
95 if(!aRecord.Url.equals(sURL)) {
96 m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
97 return false;
99 if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) {
100 m_aTestHelper.Error("User list is not the expected");
101 return false;
104 // remove the runtime passwords
105 aRecord = xContainer.find(sURL, aMHandler);
106 for(int i = 0; i < aRecord.UserList.length; i++) {
107 xContainer.remove(sURL, aRecord.UserList[i].UserName);
109 } catch(Exception e) {
110 m_aTestHelper.Error("Exception: " + e);
111 return false;
113 return true;