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 junit.framework.Assert;
28 import org.apache.commons.lang3.StringUtils;
29 import org.glom.web.server.libglom.Document;
30 import org.glom.web.server.libglom.DocumentTest;
31 import org.glom.web.shared.DocumentInfo;
32 import org.glom.web.shared.Reports;
33 import org.glom.web.shared.libglom.layout.LayoutGroup;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
39 * @author Ben Konrath <ben@bagu.org>
42 public class ConfiguredDocumentTest {
44 private static ConfiguredDocument configuredDoc;
45 private static Document document;
48 static public void setUp() throws PropertyVetoException {
49 URL url = DocumentTest.class.getResource("example_music_collection.glom");
50 assertTrue(url != null);
51 final String testUriMusicCollection = url.toString();
52 assertTrue(!StringUtils.isEmpty(testUriMusicCollection));
54 document = new Document();
55 document.setFileURI(testUriMusicCollection);
56 final boolean retval = document.load();
59 configuredDoc = new ConfiguredDocument(document);
63 static public void tearDown() {
67 * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocument()}.
70 public void testGetDocument() {
71 Assert.assertNotNull(configuredDoc.getDocument());
75 * Test method for {@link org.glom.web.server.ConfiguredDocument#isAuthenticated()}.
78 public void testIsAuthenticated() {
79 Assert.assertFalse(configuredDoc.isAuthenticated());
83 * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentID()}.
86 public void testGetDocumentID() {
87 //This is a simple setter/getter:
88 final String docID = "somethingOrOther";
89 configuredDoc.setDocumentID(docID);
90 Assert.assertEquals(docID, configuredDoc.getDocumentID());
94 * Test method for {@link org.glom.web.server.ConfiguredDocument#getDefaultLocaleID()}.
97 public void testGetDefaultLocaleID() {
98 Assert.assertEquals("", configuredDoc.getDefaultLocaleID());
102 * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentInfo(java.lang.String)}.
105 public void testGetDocumentInfo() {
107 DocumentInfo docInfo = configuredDoc.getDocumentInfo("");
108 Assert.assertNotNull(docInfo);
109 Assert.assertEquals(docInfo.getTitle(), "Music Collection");
112 docInfo = configuredDoc.getDocumentInfo("de");
113 Assert.assertNotNull(docInfo);
114 Assert.assertEquals(docInfo.getTitle(), "Musiksammlung");
116 //Invalid locale, which should use the default one:
117 docInfo = configuredDoc.getDocumentInfo("someinvalidlocale");
118 Assert.assertNotNull(docInfo);
119 Assert.assertEquals(docInfo.getTitle(), "Music Collection");
122 /* This requires a database connection:
124 public void testGetListViewData() {
125 final ArrayList<DataItem[]> list = configuredDoc.getListViewData("albums", "", 0, 10, false, 0, false);
126 Assert.assertNotNull(list);
127 Assert.assertEquals(10, list.size());
128 Assert.assertNotNull(list.get(0));
129 //TODO: test more details.
133 /* This requires a database connection:
135 public void testGetDetailsData() {
136 final TypedDataItem primaryKeyValue = new TypedDataItem();
137 primaryKeyValue.setNumber(1);
138 final DataItem[] data = configuredDoc.getDetailsData("albums", primaryKeyValue);
139 Assert.assertNotNull(data);
140 Assert.assertNotNull(data[0]);
141 //TODO: test more details.
145 /* This requires a database connection:
147 public void testGetRelatedListData() {
148 //TODO: final ArrayList<DataItem[]> list = configuredDoc.getRelatedListData(tableName, portal, foreignKeyValue, start, length, sortColumnIndex, isAscending)
152 /* This requires a database connection (to update the portals details):
154 public void testGetDetailsLayoutGroup() {;
155 final List<LayoutGroup> list = configuredDoc.getDetailsLayoutGroup("albums", "");
156 Assert.assertNotNull(list);
157 Assert.assertNotNull(list.get(0));
158 //TODO: test more details.
162 /* This requires a database connection:
164 public void testGetRelatedListRowCount() {
165 final TypedDataItem foreignKeyValue = new TypedDataItem();
166 primaryKeyValue.setNumber(1);
167 configuredDoc.getRelatedListRowCount(tableName, portal, foreignKeyValue);
172 * Test method for {@link org.glom.web.server.ConfiguredDocument#getSuitableRecordToViewDetails(java.lang.String, org.glom.web.shared.libglom.layout.LayoutItemPortal, org.glom.web.shared.TypedDataItem)}.
175 public void testGetSuitableRecordToViewDetails() {
176 //TODO: final NavigationRecord navRecord = configuredDoc.getSuitableRecordToViewDetails(tableName, portal, primaryKeyValue);
180 * Test method for {@link org.glom.web.server.ConfiguredDocument#getListViewLayoutGroup(java.lang.String, java.lang.String)}.
183 public void testGetListViewLayoutGroup() {
184 final LayoutGroup group = configuredDoc.getListViewLayoutGroup("albums", "");
185 Assert.assertNotNull(group);
186 Assert.assertNotNull(group.getItems());
187 Assert.assertEquals(8, group.getItems().size());
188 //TODO: test more details.
192 * Test method for {@link org.glom.web.server.ConfiguredDocument#getReports(java.lang.String, java.lang.String)}.
195 public void testGetReports() {
196 final Reports reports = configuredDoc.getReports("albums", "");
197 Assert.assertNotNull(reports);
198 //TODO: test more details.