2 * Copyright (C) 2012 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.server;
22 import static org.junit.Assert.*;
24 import java.beans.PropertyVetoException;
26 import java.sql.SQLException;
27 import java.util.ArrayList;
28 import java.util.List;
30 import junit.framework.Assert;
32 import org.apache.commons.lang3.StringUtils;
33 import org.glom.web.server.libglom.Document;
34 import org.glom.web.server.libglom.DocumentTest;
35 import org.glom.web.server.libglom.Document.HostingMode;
36 import org.glom.web.shared.DataItem;
37 import org.glom.web.shared.TypedDataItem;
38 import org.glom.web.shared.libglom.layout.LayoutGroup;
39 import org.glom.web.shared.libglom.layout.LayoutItem;
40 import org.glom.web.shared.libglom.layout.LayoutItemNotebook;
41 import org.glom.web.shared.libglom.layout.LayoutItemPortal;
42 import org.glom.web.shared.libglom.layout.TableToViewDetails;
43 import org.junit.AfterClass;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
48 * @author Murray Cumming <murrayc@openismus.com>
51 public class SelfHostConfiguredDocumentTest {
53 private static SelfHoster selfHoster = null;
54 private static ConfiguredDocument configuredDoc;
55 private static Document document;
56 private static String defaultLocale = "";
57 private static String germanLocale = "de";
60 static public void setUp() throws PropertyVetoException, SQLException {
61 URL url = DocumentTest.class.getResource("example_music_collection.glom");
62 assertTrue(url != null);
63 final String testUriMusicCollection = url.toString();
64 assertTrue(!StringUtils.isEmpty(testUriMusicCollection));
66 document = new Document();
67 document.setFileURI(testUriMusicCollection);
68 final boolean retval = document.load();
71 selfHoster = new SelfHoster(document);
72 final boolean hosted = selfHoster.createAndSelfHostFromExample(HostingMode.HOSTING_MODE_POSTGRES_SELF);
75 configuredDoc = new ConfiguredDocument(document);
76 configuredDoc.setUsernameAndPassword(selfHoster.getUsername(), selfHoster.getPassword());
77 assertTrue(configuredDoc.isAuthenticated());
81 static public void tearDown() {
82 if (selfHoster != null) {
89 public void testGetListViewData() {
90 ArrayList<DataItem[]> list = configuredDoc.getListViewData("albums", defaultLocale, 0, 10, false, 0, false);
91 Assert.assertNotNull(list);
92 Assert.assertEquals(5, list.size());
94 DataItem[] data = list.get(2);
95 Assert.assertNotNull(data);
96 Assert.assertEquals(8, data.length);
98 DataItem dataItem = data[0];
99 Assert.assertNotNull(dataItem);
100 Assert.assertEquals("The Wild, the Innocent, & the E-Street Shuffle", dataItem.getText());
103 Assert.assertEquals(1973.0, dataItem.getNumber());
106 Assert.assertEquals(0.0, dataItem.getNumber());
109 Assert.assertEquals("Bruce Springsteen", dataItem.getText());
112 Assert.assertEquals(0.0, dataItem.getNumber());
115 Assert.assertEquals("Sony", dataItem.getText());
118 Assert.assertEquals("", dataItem.getText());
121 Assert.assertEquals(2.0, dataItem.getNumber());
125 public void testGetDetailsData() {
126 final TypedDataItem primaryKeyValue = new TypedDataItem();
127 primaryKeyValue.setNumber(1);
128 final DataItem[] data = configuredDoc.getDetailsData("albums", primaryKeyValue);
129 Assert.assertNotNull(data);
130 Assert.assertEquals(8, data.length);
132 DataItem dataItem = data[0];
133 Assert.assertNotNull(dataItem);
134 Assert.assertEquals(1.0, dataItem.getNumber());
137 Assert.assertEquals("True Blue", dataItem.getText());
140 Assert.assertEquals(1.0, dataItem.getNumber());
143 Assert.assertEquals("Madonna", dataItem.getText());
146 Assert.assertEquals(1.0, dataItem.getNumber());
149 Assert.assertEquals("Warner Bros", dataItem.getText());
152 Assert.assertEquals(1987.0, dataItem.getNumber());
155 Assert.assertEquals("", dataItem.getText());
159 public void testGetRelatedListData() {
160 //TODO: final ArrayList<DataItem[]> list = configuredDoc.getRelatedListData(tableName, portal, foreignKeyValue, start, length, sortColumnIndex, isAscending)
164 public void testGetDetailsLayoutGroup() {;
165 final List<LayoutGroup> list = configuredDoc.getDetailsLayoutGroup("albums", defaultLocale);
166 Assert.assertNotNull(list);
167 Assert.assertEquals(2, list.size());
168 Assert.assertNotNull(list.get(0));
170 LayoutGroup layoutGroup = list.get(1);
171 Assert.assertNotNull(layoutGroup);
172 assertEquals("details", layoutGroup.getName());
173 assertEquals("Details", layoutGroup.getTitle(defaultLocale));
174 //assertEquals("Details", layoutGroup.getTitle(germanLocale));
178 public void testGetRelatedListRowCount() {
179 //final TypedDataItem foreignKeyValue = new TypedDataItem();
180 //foreignKeyValue.setNumber(1);
181 //TODO: configuredDoc.getRelatedListRowCount(tableName, portal, foreignKeyValue);