tests: ConfiguredDocumentTest: Make this pass.
[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 java.util.ArrayList;
27 import java.util.List;
28
29 import junit.framework.Assert;
30
31 import org.apache.commons.lang3.StringUtils;
32 import org.glom.web.server.libglom.Document;
33 import org.glom.web.server.libglom.DocumentTest;
34 import org.glom.web.shared.DataItem;
35 import org.glom.web.shared.DocumentInfo;
36 import org.glom.web.shared.Reports;
37 import org.glom.web.shared.libglom.layout.LayoutGroup;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41
42 /**
43  * @author Ben Konrath <ben@bagu.org>
44  *
45  */
46 public class ConfiguredDocumentTest {
47
48         private static ConfiguredDocument configuredDoc;
49         private static Document document;
50         
51         @BeforeClass
52         static public void setUp() throws PropertyVetoException {
53                 URL url = DocumentTest.class.getResource("example_music_collection.glom");
54                 assertTrue(url != null);
55                 final String testUriMusicCollection = url.toString();
56                 assertTrue(!StringUtils.isEmpty(testUriMusicCollection));
57
58                 document = new Document();
59                 document.setFileURI(testUriMusicCollection);
60                 final boolean retval = document.load();
61                 assertTrue(retval);
62                 
63                 configuredDoc = new ConfiguredDocument(document);
64         }
65
66         @AfterClass
67         static public void tearDown() {
68         }
69
70         /**
71          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocument()}.
72          */
73         @Test
74         public void testGetDocument() {
75                 Assert.assertNotNull(configuredDoc.getDocument());
76         }
77
78         /**
79          * Test method for {@link org.glom.web.server.ConfiguredDocument#isAuthenticated()}.
80          */
81         @Test
82         public void testIsAuthenticated() {
83                 Assert.assertFalse(configuredDoc.isAuthenticated());
84         }
85
86         /**
87          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentID()}.
88          */
89         @Test
90         public void testGetDocumentID() {
91                 //This is a simple setter/getter:
92                 final String docID = "somethingOrOther";
93                 configuredDoc.setDocumentID(docID);
94                 Assert.assertEquals(docID, configuredDoc.getDocumentID());
95         }
96
97         /**
98          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDefaultLocaleID()}.
99          */
100         @Test
101         public void testGetDefaultLocaleID() {
102                 Assert.assertEquals("", configuredDoc.getDefaultLocaleID());
103         }
104
105         /**
106          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentInfo(java.lang.String)}.
107          */
108         @Test
109         public void testGetDocumentInfo() {
110                 final DocumentInfo docInfo = configuredDoc.getDocumentInfo("");
111                 Assert.assertNotNull(docInfo);
112         }
113
114         /* This requires a database connection:
115         @Test
116         public void testGetListViewData() {
117                 final ArrayList<DataItem[]> list = configuredDoc.getListViewData("albums", "", 0, 10, false, 0, false);
118                 Assert.assertNotNull(list);
119                 Assert.assertEquals(10, list.size());
120                 Assert.assertNotNull(list.get(0));
121                 //TODO: test more details.
122         }
123         */
124
125         /* This requires a database connection:
126         @Test
127         public void testGetDetailsData() {
128                 final TypedDataItem primaryKeyValue = new TypedDataItem();
129                 primaryKeyValue.setNumber(1);
130                 final DataItem[] data = configuredDoc.getDetailsData("albums", primaryKeyValue);
131                 Assert.assertNotNull(data);
132                 Assert.assertNotNull(data[0]);
133                 //TODO: test more details.
134         }
135         */
136
137         /* This requires a database connection:
138         @Test
139         public void testGetRelatedListData() {
140                 //TODO: final ArrayList<DataItem[]> list = configuredDoc.getRelatedListData(tableName, portal, foreignKeyValue, start, length, sortColumnIndex, isAscending)
141         }
142         */
143
144         /* This requires a database connection (to update the portals details):
145         @Test
146         public void testGetDetailsLayoutGroup() {;
147                 final List<LayoutGroup> list = configuredDoc.getDetailsLayoutGroup("albums", "");
148                 Assert.assertNotNull(list);
149                 Assert.assertNotNull(list.get(0));
150                 //TODO: test more details.
151         }
152         */
153
154         /* This requires a database connection:
155         @Test
156         public void testGetRelatedListRowCount() {
157                 final TypedDataItem foreignKeyValue = new TypedDataItem();
158                 primaryKeyValue.setNumber(1);
159                 configuredDoc.getRelatedListRowCount(tableName, portal, foreignKeyValue);
160         }
161         */
162
163         /**
164          * 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)}.
165          */
166         @Test
167         public void testGetSuitableRecordToViewDetails() {
168                 //TODO: final NavigationRecord navRecord = configuredDoc.getSuitableRecordToViewDetails(tableName, portal, primaryKeyValue);
169         }
170
171         /**
172          * Test method for {@link org.glom.web.server.ConfiguredDocument#getListViewLayoutGroup(java.lang.String, java.lang.String)}.
173          */
174         @Test
175         public void testGetListViewLayoutGroup() {
176                 final LayoutGroup group = configuredDoc.getListViewLayoutGroup("albums", "");
177                 Assert.assertNotNull(group);
178                 Assert.assertNotNull(group.getItems());
179                 Assert.assertEquals(8, group.getItems().size());
180                 //TODO: test more details.
181         }
182
183         /**
184          * Test method for {@link org.glom.web.server.ConfiguredDocument#getReports(java.lang.String, java.lang.String)}.
185          */
186         @Test
187         public void testGetReports() {
188                 final Reports reports = configuredDoc.getReports("albums", "");
189                 Assert.assertNotNull(reports);
190                 //TODO: test more details.
191         }
192
193 }