1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package complex.passwordcontainer; 29 30 import com.sun.star.lang.XMultiServiceFactory; 31 import com.sun.star.task.XInteractionHandler; 32 import com.sun.star.task.XPasswordContainer; 33 import com.sun.star.task.UrlRecord; 34 import com.sun.star.task.UserRecord; 35 import com.sun.star.task.XMasterPasswordHandling; 36 37 import com.sun.star.uno.UnoRuntime; 38 39 // import share.LogWriter; 40 41 public class Test01 implements PasswordContainerTest { 42 XMultiServiceFactory m_xMSF = null; 43 XPasswordContainer m_xPasswordContainer = null; 44 TestHelper m_aTestHelper = null; 45 46 public Test01 ( XMultiServiceFactory xMSF ) 47 { 48 m_xMSF = xMSF; 49 m_aTestHelper = new TestHelper ( "Test01: "); 50 } 51 52 public boolean test() { 53 final String sURL = "http://www.openoffice.org"; 54 final String sUserPre = "OOoUser"; 55 final String sPwdPre = "Password"; 56 final int iUserNum1 = 10; 57 final int iUserNum2 = 5; 58 59 UserRecord aInputUserList1[] = new UserRecord[iUserNum1]; 60 for(int i = 0; i < iUserNum1; i++) { 61 String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user 62 aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp); 63 } 64 UserRecord aInputUserList2[] = new UserRecord[iUserNum2]; 65 for(int i = 0; i < iUserNum2; i++) { 66 String sTemp[] = {sPwdPre + "_2_" + i}; 67 aInputUserList2[i] = new UserRecord(sUserPre + "_2_" + i, sTemp); 68 } 69 try { 70 Object oPasswordContainer = m_xMSF.createInstance( "com.sun.star.task.PasswordContainer" ); 71 XPasswordContainer xContainer = UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); 72 Object oHandler = m_xMSF.createInstance( "com.sun.star.task.InteractionHandler" ); 73 XInteractionHandler xHandler = UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); 74 MasterPasswdHandler aMHandler = new MasterPasswdHandler( xHandler ); 75 76 // add a set of users and passwords for the same URL for runtime 77 for(int i = 0; i < iUserNum1; i++) { 78 xContainer.add(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler); 79 } 80 for (int i = 0; i < iUserNum2; i++) { 81 xContainer.add(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler); 82 } 83 84 // remove some of the passwords 85 for (int i = 0; i < iUserNum1; i++) { 86 xContainer.remove(sURL, aInputUserList1[i].UserName); 87 } 88 89 // get the result and check it with the expected one 90 UrlRecord aRecord = xContainer.find(sURL, aMHandler); 91 if(!aRecord.Url.equals(sURL)) { 92 m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL); 93 return false; 94 } 95 if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) { 96 m_aTestHelper.Error("User list is not the expected"); 97 return false; 98 } 99 100 // remove the runtime passwords 101 aRecord = xContainer.find(sURL, aMHandler); 102 for(int i = 0; i < aRecord.UserList.length; i++) { 103 xContainer.remove(sURL, aRecord.UserList[i].UserName); 104 } 105 } catch(Exception e) { 106 m_aTestHelper.Error("Exception: " + e); 107 return false; 108 } 109 return true; 110 } 111 } 112