Bump for 3.6-28
[LibreOffice.git] / sw / qa / complex / writer / CheckNamedPropertyValues.java
blobb2541954ce9fdbb2d026239b84e1c3bbaead2568
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package complex.writer;
30 import com.sun.star.beans.PropertyValue;
31 import com.sun.star.container.XNameContainer;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.Type;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.openoffice.test.OfficeConnection;
38 import static org.junit.Assert.*;
40 /**
43 public class CheckNamedPropertyValues {
44 @Test public void checkNamedPropertyValues()
45 throws com.sun.star.uno.Exception
47 XNameContainer xCont = UnoRuntime.queryInterface(
48 XNameContainer.class,
49 (connection.getComponentContext().getServiceManager().
50 createInstanceWithContext(
51 "com.sun.star.document.NamedPropertyValues",
52 connection.getComponentContext())));
54 assertNotNull("XNameContainer was queried but returned null.", xCont);
55 PropertyValue[] prop1 = new PropertyValue[1];
56 prop1[0] = new PropertyValue();
57 prop1[0].Name = "Jupp";
58 prop1[0].Value = "GoodGuy";
60 PropertyValue[] prop2 = new PropertyValue[1];
61 prop2[0] = new PropertyValue();
62 prop2[0].Name = "Horst";
63 prop2[0].Value = "BadGuy";
65 Type t = xCont.getElementType();
66 assertFalse("Initial container is not empty.", xCont.hasElements());
68 xCont.insertByName("prop1", prop1);
69 PropertyValue[]ret = (PropertyValue[])xCont.getByName("prop1");
70 assertEquals(prop1[0].Name, ret[0].Name);
71 assertEquals(prop1[0].Value, ret[0].Value);
72 xCont.replaceByName("prop1", prop2);
73 ret = (PropertyValue[])xCont.getByName("prop1");
74 assertEquals(prop2[0].Name, ret[0].Name);
75 assertEquals(prop2[0].Value, ret[0].Value);
76 xCont.removeByName("prop1");
77 assertFalse("Could not remove PropertyValue.", xCont.hasElements());
78 xCont.insertByName("prop1", prop1);
79 xCont.insertByName("prop2", prop2);
80 assertTrue("Did not insert PropertyValue.", xCont.hasElements());
81 String[] names = xCont.getElementNames();
82 assertEquals("Not all element names were returned.", 2, names.length);
83 for (int i=0; i<names.length; i++) {
84 assertTrue(
85 "Got a wrong element name",
86 names[i].equals("prop1") || names[i].equals("prop2"));
89 try {
90 xCont.insertByName("prop2", prop1);
91 fail("ElementExistException was not thrown.");
93 catch(com.sun.star.container.ElementExistException e) {
96 try {
97 xCont.insertByName("prop3", "Example String");
98 fail("IllegalArgumentException was not thrown.");
100 catch(com.sun.star.lang.IllegalArgumentException e) {
103 try {
104 xCont.removeByName("prop3");
105 fail("NoSuchElementException was not thrown.");
107 catch(com.sun.star.container.NoSuchElementException e) {
111 @BeforeClass public static void setUpConnection() throws Exception {
112 connection.setUp();
115 @AfterClass public static void tearDownConnection()
116 throws InterruptedException, com.sun.star.uno.Exception
118 connection.tearDown();
121 private static final OfficeConnection connection = new OfficeConnection();