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: BridgeFactory_Test.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.comp
.bridgefactory
;
33 import com
.sun
.star
.bridge
.BridgeExistsException
;
34 import com
.sun
.star
.bridge
.XBridge
;
35 import com
.sun
.star
.comp
.connections
.PipedConnection
;
36 import com
.sun
.star
.connection
.XConnection
;
37 import com
.sun
.star
.lang
.XComponent
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import complexlib
.ComplexTestCase
;
41 public final class BridgeFactory_Test
extends ComplexTestCase
{
42 public String
getTestObjectName() {
43 return getClass().getName();
46 public String
[] getTestMethodNames() {
47 return new String
[] { "test" };
50 public void test() throws Exception
{
51 PipedConnection rightSide
= new PipedConnection(new Object
[0]);
52 PipedConnection leftSide
= new PipedConnection(new Object
[]{rightSide
});
54 BridgeFactory bridgeFactory
= new BridgeFactory(); // create the needed bridgeFactory
57 XBridge xBridge
= bridgeFactory
.createBridge("testbridge", "urp", (XConnection
)leftSide
, null);
59 // test that we get the same bridge
60 assure("", UnoRuntime
.areSame(xBridge
,
61 bridgeFactory
.getBridge("testbridge")));
63 // test that we can not create another bridge with same name
65 XBridge dummy
= bridgeFactory
.createBridge("testbridge", "urp", (XConnection
)leftSide
, null);
69 catch(BridgeExistsException bridgeExistsException
) {
73 // test getExistingBridges
74 XBridge xBridges
[] = bridgeFactory
.getExistingBridges();
75 assure("", UnoRuntime
.areSame(xBridge
, xBridges
[0]));
78 XComponent xComponent
= UnoRuntime
.queryInterface(XComponent
.class, xBridge
);
82 // test that the bridge has been removed
83 assure("", bridgeFactory
.getBridge("testbridge") == null);
87 rightSide
= new PipedConnection(new Object
[0]);
88 leftSide
= new PipedConnection(new Object
[]{rightSide
});
91 // test that we really get a new bridge
92 XBridge xBridge_new
= bridgeFactory
.createBridge("testbridge", "urp", (XConnection
)leftSide
, null);
93 assure("", !UnoRuntime
.areSame(xBridge
, xBridge_new
));
95 for(int i
= 0; i
<10000; ++ i
) {
96 Object x
[] = new Object
[100];
99 // test getExistingBridges
100 xBridges
= bridgeFactory
.getExistingBridges();
103 && UnoRuntime
.areSame(xBridge_new
, xBridges
[0]));
105 // dispose the new bridge
106 XComponent xComponent_new
= UnoRuntime
.queryInterface(XComponent
.class, xBridge_new
);
107 xComponent_new
.dispose();