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 .
18 package com
.sun
.star
.comp
.helper
;
20 import java
.util
.HashMap
;
21 import java
.util
.logging
.Level
;
22 import java
.util
.logging
.Logger
;
24 import com
.sun
.star
.lang
.XComponent
;
25 import com
.sun
.star
.lang
.XMultiComponentFactory
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XComponentContext
;
29 import static org
.junit
.Assert
.assertEquals
;
30 import static org
.junit
.Assert
.assertNotNull
;
31 import org
.junit
.Test
;
33 public class ComponentContext_Test
{
35 private static final Logger logger
= Logger
.getLogger(ComponentContext_Test
.class.getName());
37 @Test public void test() throws Exception
{
38 logger
.log(Level
.INFO
, "Testing ComponentContext");
39 HashMap
<String
, Object
> table
= new HashMap
<String
, Object
>();
40 table
.put("bla1", new ComponentContextEntry(null, Integer
.valueOf(1)));
41 XComponentContext xInitialContext
= Bootstrap
.createInitialComponentContext(table
);
43 table
= new HashMap
<String
, Object
>();
44 table
.put("bla2", new ComponentContextEntry(Integer
.valueOf(2)));
45 table
.put("bla3", Integer
.valueOf(3));
46 XComponentContext xContext
= new ComponentContext(table
, xInitialContext
);
48 XMultiComponentFactory xSMgr
= xContext
.getServiceManager();
50 assertNotNull(xSMgr
.createInstanceWithContext("com.sun.star.loader.Java", xContext
));
51 assertNotNull(xSMgr
.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", xContext
));
52 assertNotNull(xSMgr
.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xContext
));
53 assertNotNull(xSMgr
.createInstanceWithContext("com.sun.star.connection.Connector", xContext
));
54 assertNotNull(xSMgr
.createInstanceWithContext("com.sun.star.connection.Acceptor", xContext
));
55 // assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.lang.ServiceManager", xContext));
57 assertNotNull(xContext
.getValueByName("bla1"));
58 assertNotNull(xContext
.getValueByName("bla2"));
59 assertNotNull(xContext
.getValueByName("bla3"));
60 assertNotNull(xInitialContext
.getValueByName("bla2"));
61 assertNotNull(xInitialContext
.getValueByName("bla3"));
63 assertEquals(((Integer
) xContext
.getValueByName("bla1")).intValue(), 1);
64 assertEquals(((Integer
) xContext
.getValueByName("bla2")).intValue(), 2);
65 assertEquals(((Integer
) xContext
.getValueByName("bla3")).intValue(), 3);
66 assertEquals(((Integer
) xInitialContext
.getValueByName("bla1")).intValue(), 1);
68 XComponent xComp
= UnoRuntime
.queryInterface(
69 XComponent
.class, xInitialContext
);