DataItemTest: Test the date type too, and improve the asserts.
[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 org.apache.commons.lang3.StringUtils;
27 import org.glom.web.server.libglom.Document;
28 import org.glom.web.server.libglom.DocumentTest;
29 import org.glom.web.shared.DocumentInfo;
30 import org.glom.web.shared.Reports;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34
35 /**
36  * @author Murray Cumming <murrayc@openismus.com>
37  *
38  */
39 public class ConfiguredDocumentTest {
40
41         private static ConfiguredDocument configuredDoc;
42         private static Document document;
43         private static String defaultLocale = "";
44         private static String germanLocale = "de";
45         
46         @BeforeClass
47         static public void setUp() throws PropertyVetoException {
48                 URL url = DocumentTest.class.getResource("example_music_collection.glom");
49                 assertNotNull(url);
50                 final String testUriMusicCollection = url.toString();
51                 assertTrue(!StringUtils.isEmpty(testUriMusicCollection));
52
53                 document = new Document();
54                 document.setFileURI(testUriMusicCollection);
55                 final boolean retval = document.load();
56                 assertTrue(retval);
57                 
58                 configuredDoc = new ConfiguredDocument(document);
59         }
60
61         @AfterClass
62         static public void tearDown() {
63         }
64
65         /**
66          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocument()}.
67          */
68         @Test
69         public void testGetDocument() {
70                 assertNotNull(configuredDoc.getDocument());
71         }
72
73         /**
74          * Test method for {@link org.glom.web.server.ConfiguredDocument#isAuthenticated()}.
75          */
76         @Test
77         public void testIsAuthenticated() {
78                 assertFalse(configuredDoc.isAuthenticated());
79         }
80
81         /**
82          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentID()}.
83          */
84         @Test
85         public void testGetDocumentID() {
86                 //This is a simple setter/getter:
87                 final String docID = "somethingOrOther";
88                 configuredDoc.setDocumentID(docID);
89                 assertEquals(docID, configuredDoc.getDocumentID());
90         }
91
92         /**
93          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDefaultLocaleID()}.
94          */
95         @Test
96         public void testGetDefaultLocaleID() {
97                 assertEquals("", configuredDoc.getDefaultLocaleID());
98         }
99
100         /**
101          * Test method for {@link org.glom.web.server.ConfiguredDocument#getDocumentInfo(java.lang.String)}.
102          */
103         @Test
104         public void testGetDocumentInfo() {
105                 //Default locale:
106                 DocumentInfo docInfo = configuredDoc.getDocumentInfo(defaultLocale);
107                 assertNotNull(docInfo);
108                 assertEquals(docInfo.getTitle(), "Music Collection");
109                 
110                 //Other locale:
111                 docInfo = configuredDoc.getDocumentInfo(germanLocale);
112                 assertNotNull(docInfo);
113                 assertEquals(docInfo.getTitle(), "Musiksammlung");
114                 
115                 //Invalid locale, which should use the default one:
116                 docInfo = configuredDoc.getDocumentInfo("someinvalidlocale");
117                 assertNotNull(docInfo);
118                 assertEquals(docInfo.getTitle(), "Music Collection");
119         }
120
121         /**
122          * 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)}.
123          */
124         @Test
125         public void testGetSuitableRecordToViewDetails() {
126                 //TODO: final NavigationRecord navRecord = configuredDoc.getSuitableRecordToViewDetails(tableName, portal, primaryKeyValue);
127         }
128
129         /**
130          * Test method for {@link org.glom.web.server.ConfiguredDocument#getReports(java.lang.String, java.lang.String)}.
131          */
132         @Test
133         public void testGetReports() {
134                 final Reports reports = configuredDoc.getReports("albums", defaultLocale);
135                 assertNotNull(reports);
136                 //TODO: test more details.
137         }
138
139 }