Document: Load title translations and test them.
[online-glom:gwt-glom.git] / src / test / java / org / glom / web / server / ConfiguredDocumentTest.java
1 /*
2  * Copyright (C) 2012 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
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.
10  *
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
14  * for more details.
15  *
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/>.
18  */
19
20 package org.glom.web.server;
21
22 import static org.junit.Assert.*;
23
24 import java.beans.PropertyVetoException;
25 import java.net.URL;
26 import junit.framework.Assert;
27
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;
37
38 /**
39  * @author Ben Konrath <ben@bagu.org>
40  *
41  */
42 public class ConfiguredDocumentTest {
43
44         private static ConfiguredDocument configuredDoc;
45         private static Document document;
46         
47         @BeforeClass
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));
53
54                 document = new Document();
55                 document.setFileURI(testUriMusicCollection);
56                 final boolean retval = document.load();
57                 assertTrue(retval);
58                 
59                 configuredDoc = new ConfiguredDocument(document);
60         }
61
62         @AfterClass
63         static public void tearDown() {
64         }
65
66         /**
67          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocument()}.
68          */
69         @Test
70         public void testGetDocument() {
71                 Assert.assertNotNull(configuredDoc.getDocument());
72         }
73
74         /**
75          * Test method for {@link org.glom.web.server.ConfiguredDocument#isAuthenticated()}.
76          */
77         @Test
78         public void testIsAuthenticated() {
79                 Assert.assertFalse(configuredDoc.isAuthenticated());
80         }
81
82         /**
83          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentID()}.
84          */
85         @Test
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());
91         }
92
93         /**
94          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDefaultLocaleID()}.
95          */
96         @Test
97         public void testGetDefaultLocaleID() {
98                 Assert.assertEquals("", configuredDoc.getDefaultLocaleID());
99         }
100
101         /**
102          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentInfo(java.lang.String)}.
103          */
104         @Test
105         public void testGetDocumentInfo() {
106                 //Default locale:
107                 DocumentInfo docInfo = configuredDoc.getDocumentInfo("");
108                 Assert.assertNotNull(docInfo);
109                 Assert.assertEquals(docInfo.getTitle(), "Music Collection");
110                 
111                 //Other locale:
112                 docInfo = configuredDoc.getDocumentInfo("de");
113                 Assert.assertNotNull(docInfo);
114                 Assert.assertEquals(docInfo.getTitle(), "Musiksammlung");
115                 
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");
120         }
121
122         /* This requires a database connection:
123         @Test
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.
130         }
131         */
132
133         /* This requires a database connection:
134         @Test
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.
142         }
143         */
144
145         /* This requires a database connection:
146         @Test
147         public void testGetRelatedListData() {
148                 //TODO: final ArrayList<DataItem[]> list = configuredDoc.getRelatedListData(tableName, portal, foreignKeyValue, start, length, sortColumnIndex, isAscending)
149         }
150         */
151
152         /* This requires a database connection (to update the portals details):
153         @Test
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.
159         }
160         */
161
162         /* This requires a database connection:
163         @Test
164         public void testGetRelatedListRowCount() {
165                 final TypedDataItem foreignKeyValue = new TypedDataItem();
166                 primaryKeyValue.setNumber(1);
167                 configuredDoc.getRelatedListRowCount(tableName, portal, foreignKeyValue);
168         }
169         */
170
171         /**
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)}.
173          */
174         @Test
175         public void testGetSuitableRecordToViewDetails() {
176                 //TODO: final NavigationRecord navRecord = configuredDoc.getSuitableRecordToViewDetails(tableName, portal, primaryKeyValue);
177         }
178
179         /**
180          * Test method for {@link org.glom.web.server.ConfiguredDocument#getListViewLayoutGroup(java.lang.String, java.lang.String)}.
181          */
182         @Test
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.
189         }
190
191         /**
192          * Test method for {@link org.glom.web.server.ConfiguredDocument#getReports(java.lang.String, java.lang.String)}.
193          */
194         @Test
195         public void testGetReports() {
196                 final Reports reports = configuredDoc.getReports("albums", "");
197                 Assert.assertNotNull(reports);
198                 //TODO: test more details.
199         }
200
201 }