1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH München (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo;
24  
25  import java.util.ArrayList;
26  import java.util.Calendar;
27  import java.util.GregorianCalendar;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  /***
32   * @author MarcusT
33   */
34  public final class ViewEntryProxyTest extends BaseProxyTest {
35  
36      private DDatabase newDB;
37      private DView newView;
38      private Calendar correctNow;
39  
40      /***
41       * Creates a instance for all ViewEntryProxyTests.
42       *
43       * @param name the tests name
44       */
45      public ViewEntryProxyTest(String name) {
46          super(name);
47      }
48  
49      /***
50       * Sets up the proper test environment for every method again.
51       */
52      public void setUp() {
53          baseSetUp();
54      }
55  
56      /***
57       * Tests the method getColumnValues.
58       */
59      public void testGetColumnValues() {
60          System.out.println("-> testGetColumnValues");
61          createNewDBAndView(System.currentTimeMillis() + "testGetColumnValues.nsf");
62  
63          List list = new ArrayList();
64          list.add("somePath");
65          list.add(correctNow);
66          list.add("ObjStoreName");
67          list.add("DbName1");
68  
69          Iterator it = newView.getAllEntriesByKey(list, true);
70          DViewEntry entry = (DViewEntry) it.next();
71          List colVals = entry.getColumnValues();
72          assertEquals("First ColumnValue does not match.", "somePath", colVals.get(0));
73          assertEquals("Second ColumnValue does not match.", correctNow, colVals.get(1));
74          assertEquals("Third ColumnValue does not match.", "ObjStoreName", colVals.get(2));
75          assertEquals("Fourth ColumnValue does not match.", "DbName1", colVals.get(3));
76          assertEquals("Fifth ColumnValue does not match.", "DbTitle", colVals.get(4));
77  
78          newDB.remove();
79      }
80  
81      /***
82       * Tests the method getDocument.
83       */
84      public void testGetDocument() {
85          createNewDBAndView(System.currentTimeMillis() + "testGetColumnValues.nsf");
86  
87          List list = new ArrayList();
88          list.add("somePath");
89          list.add(correctNow);
90          list.add("ObjStoreName");
91          list.add("DbName1");
92  
93          Iterator it = newView.getAllEntriesByKey(list, true);
94          DViewEntry entry = (DViewEntry) it.next();
95          DDocument doc = entry.getDocument();
96          assertNotNull("There should be a document.", doc);
97          assertNotNull("The document also should have a UniId.", doc.getUniversalID());
98  
99          newDB.remove();
100     }
101 
102     /***
103      * Tests the method isDocument.
104      */
105     public void testIsDocument() {
106         createNewDBAndView(System.currentTimeMillis() + "testGetColumnValues.nsf");
107 
108         List list = new ArrayList();
109         list.add("somePath");
110         list.add(correctNow);
111         list.add("ObjStoreName");
112         list.add("DbName1");
113 
114         Iterator it = newView.getAllEntriesByKey(list, true);
115         DViewEntry entry = (DViewEntry) it.next();
116         assertTrue("The ViewEntry should represent a document.", entry.isDocument());
117 
118         newDB.remove();
119     }
120 
121     /***
122      * todo isCategory (but wait for ViewNavigator, or something alike).
123      */
124     public void testIsCategory() {
125 
126     }
127 
128     /***
129      * todo isTotal (but wait for ViewNavigator, or something alike).
130      */
131     public void testIsTotal() {
132 
133     }
134 
135     /***
136      * Excluded part of setUp, because not in every test, a new DB is necessary.
137      * If this method were executed before every testMethod, each such
138      * testMethod would have to call <code>newDB.remove()</code>, but this way,
139      * only callers of this method need to call it.
140      *
141      * @param name the databases localhost filePath
142      */
143     private void createNewDBAndView(String name) {
144         String dbName = System.currentTimeMillis() + name;
145 
146         correctNow = new GregorianCalendar();
147         correctNow.clear(Calendar.HOUR);
148         correctNow.clear(Calendar.MINUTE);
149         correctNow.clear(Calendar.SECOND);
150         correctNow.clear(Calendar.MILLISECOND);
151 
152         DDatabase db = null;
153         try {
154             db = getSession().getDatabase(getServerName(), "log.ntf");
155         } catch (DNotesException e1) {
156             e1.printStackTrace();
157             fail("Cannot open database log.ntf");
158         }
159         try {
160             newDB = db.createDatabaseFromTemplate(getServerName(), dbName, true);
161         } catch (DNotesException e) {
162             assertTrue("Could not create DB from template.", false);
163         }
164 
165         DDocument doc1 = newDB.createDocument();
166         doc1.replaceItemValue("Form", "ObjStoreUsageForm");
167         doc1.replaceItemValue("ObjStoreName", "ObjStoreName");
168         doc1.replaceItemValue("DbName", "DbName1");
169         doc1.replaceItemValue("DbTitle", "DbTitle");
170         doc1.replaceItemValue("DocCount", 2);
171         doc1.replaceItemValue("Server", "somePath");
172         doc1.replaceItemValue("StartTime", correctNow);
173         doc1.save();
174         DDocument doc2 = newDB.createDocument();
175         doc2.replaceItemValue("Form", "ObjStoreUsageForm");
176         doc2.replaceItemValue("ObjStoreName", "ObjStoreName");
177         doc2.replaceItemValue("DbName", "DbName1");
178         doc2.replaceItemValue("DbTitle", "DbTitle");
179         doc2.replaceItemValue("DocCount", 2);
180         doc2.replaceItemValue("Server", "somePath");
181         doc2.replaceItemValue("StartTime", correctNow);
182         doc2.save();
183         DDocument doc3 = newDB.createDocument();
184         doc3.replaceItemValue("Form", "ObjStoreUsageForm");
185         doc3.replaceItemValue("ObjStoreName", "ObjStoreName");
186         doc3.replaceItemValue("DbName", "DbName2");
187         doc3.replaceItemValue("DbTitle", "DbTitle");
188         doc3.replaceItemValue("DocCount", 2);
189         doc3.replaceItemValue("Server", "somePath");
190         doc3.replaceItemValue("StartTime", correctNow);
191         doc3.save();
192         DDocument doc4 = newDB.createDocument();
193         doc4.replaceItemValue("Form", "ObjStoreUsageForm");
194         doc4.replaceItemValue("ObjStoreName", "ObjStoreName");
195         doc4.replaceItemValue("DbName", "DbName2");
196         doc4.replaceItemValue("DbTitle", "DbTitle");
197         doc4.replaceItemValue("DocCount", 2);
198         doc4.replaceItemValue("Server", "somePath");
199         doc4.replaceItemValue("StartTime", correctNow);
200         doc4.save();
201         newView = newDB.getView("Object Store Usage");
202     }
203 }