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.junit.AfterClass;
40 import org.junit.BeforeClass;
41 import org.junit.Test;
44 * @author Murray Cumming <murrayc@openismus.com>
47 public class SelfHostConfiguredDocumentTest {
49 private static SelfHoster selfHoster = null;
50 private static ConfiguredDocument configuredDoc;
51 private static Document document;
52 private static String defaultLocale = "";
53 private static String germanLocale = "de";
56 static public void setUp() throws PropertyVetoException, SQLException {
57 URL url = DocumentTest.class.getResource("example_music_collection.glom");
58 assertTrue(url != null);
59 final String testUriMusicCollection = url.toString();
60 assertTrue(!StringUtils.isEmpty(testUriMusicCollection));
62 document = new Document();
63 document.setFileURI(testUriMusicCollection);
64 final boolean retval = document.load();
67 selfHoster = new SelfHoster(document);
68 final boolean hosted = selfHoster.createAndSelfHostFromExample(HostingMode.HOSTING_MODE_POSTGRES_SELF);
71 configuredDoc = new ConfiguredDocument(document);
72 configuredDoc.setUsernameAndPassword(selfHoster.getUsername(), selfHoster.getPassword());
73 assertTrue(configuredDoc.isAuthenticated());
77 static public void tearDown() {
78 if (selfHoster != null) {
85 public void testGetListViewData() {
86 ArrayList<DataItem[]> list = configuredDoc.getListViewData("albums", defaultLocale, 0, 10, false, 0, false);
87 Assert.assertNotNull(list);
88 Assert.assertEquals(5, list.size());
90 DataItem[] data = list.get(2);
91 Assert.assertNotNull(data);
92 Assert.assertEquals(8, data.length);
94 DataItem dataItem = data[0];
95 Assert.assertNotNull(dataItem);
96 Assert.assertEquals("The Wild, the Innocent, & the E-Street Shuffle", dataItem.getText());
99 Assert.assertEquals(1973.0, dataItem.getNumber());
102 Assert.assertEquals(0.0, dataItem.getNumber());
105 Assert.assertEquals("Bruce Springsteen", dataItem.getText());
108 Assert.assertEquals(0.0, dataItem.getNumber());
111 Assert.assertEquals("Sony", dataItem.getText());
114 Assert.assertEquals("", dataItem.getText());
117 Assert.assertEquals(2.0, dataItem.getNumber());
121 public void testGetDetailsData() {
122 final TypedDataItem primaryKeyValue = new TypedDataItem();
123 primaryKeyValue.setNumber(1);
124 final DataItem[] data = configuredDoc.getDetailsData("albums", primaryKeyValue);
125 Assert.assertNotNull(data);
126 Assert.assertEquals(8, data.length);
128 DataItem dataItem = data[0];
129 Assert.assertNotNull(dataItem);
130 Assert.assertEquals(1.0, dataItem.getNumber());
133 Assert.assertEquals("True Blue", dataItem.getText());
136 Assert.assertEquals(1.0, dataItem.getNumber());
139 Assert.assertEquals("Madonna", dataItem.getText());
142 Assert.assertEquals(1.0, dataItem.getNumber());
145 Assert.assertEquals("Warner Bros", dataItem.getText());
148 Assert.assertEquals(1987.0, dataItem.getNumber());
151 Assert.assertEquals("", dataItem.getText());
155 public void testGetRelatedListData() {
156 //TODO: final ArrayList<DataItem[]> list = configuredDoc.getRelatedListData(tableName, portal, foreignKeyValue, start, length, sortColumnIndex, isAscending)
159 public void testGetDetailsLayoutGroup(final String locale, final String detailsTitle) {;
160 final List<LayoutGroup> list = configuredDoc.getDetailsLayoutGroup("albums", locale);
161 Assert.assertNotNull(list);
162 Assert.assertEquals(2, list.size());
163 Assert.assertNotNull(list.get(0));
165 LayoutGroup layoutGroup = list.get(1);
166 Assert.assertNotNull(layoutGroup);
167 assertEquals("details", layoutGroup.getName());
168 assertEquals("Details", layoutGroup.getTitle()); //We don't need to specify locale again.
169 //assertEquals("Details", layoutGroup.getTitle(germanLocale));
173 public void testGetDetailsLayoutGroup() {;
174 testGetDetailsLayoutGroup(defaultLocale, "Details");
175 testGetDetailsLayoutGroup(germanLocale, "Details");
179 public void testGetRelatedListRowCount() {
180 //final TypedDataItem foreignKeyValue = new TypedDataItem();
181 //foreignKeyValue.setNumber(1);
182 //TODO: configuredDoc.getRelatedListRowCount(tableName, portal, foreignKeyValue);