1   /*
2    * Copyright 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.goetz.domino.log4j;
18  
19  import java.util.Vector;
20  
21  import junit.framework.TestCase;
22  import lotus.domino.Database;
23  import lotus.domino.Document;
24  import lotus.domino.DocumentCollection;
25  import lotus.domino.NotesFactory;
26  import lotus.domino.NotesThread;
27  import lotus.domino.Session;
28  
29  import org.apache.log4j.helpers.LogLog;
30  
31  /***
32   * Verify field sizes of all log documents.
33   * 
34   * @author Bernd Götz
35   */
36  public class VerifyFieldSizeTest extends TestCase {
37  	
38  	public void testGetLastDocument() throws Exception {
39  
40  		NotesThread.sinitThread();
41  		
42  		Session session = NotesFactory.createSession();
43  
44  		String databaseName = "DOMAPP/applog00.nsf";
45  		String serverName = "dominotest";
46  		Database db = session.getDatabase(serverName, databaseName);
47  		if (!db.isOpen()) {
48  			LogLog.debug("Log databaseName is closed. Trying to open it.");
49  			db.open();
50  		}
51  		
52  		// now search:
53  		String f = "Form = \"frmEvents\" & " +
54  		"AppName = \"RemoteTestServlet1\"";
55  		
56  //        DateTime t = session.createDateTime("Yesterday");
57  //        System.out.println("today: " + t.toString());
58  	
59  		DocumentCollection dc = db.search(f);
60  		
61  		System.out.println("No of docs: " + dc.getCount());
62  		
63  		Document d = dc.getFirstDocument();
64  		int j = 1;
65  		int maxbytes = 0;
66  		while (d != null) {
67  			Vector ve = d.getItemValue("Events");
68  //			System.out.print(j + " - id: " + d.getNoteID());
69  //			System.out.print(", lines: " + ve.size());
70  			int len = 0;
71  			for (int i = 0; i < ve.size(); i++) {
72  				String l = (String)ve.elementAt(i);
73  				len += l.length();
74  			}
75  //			System.out.println(", bytes: " + len);
76  			if (len > maxbytes) {
77  				maxbytes = len;
78  			}
79  			d = dc.getNextDocument();
80  			j++;
81  		}
82  		System.out.println("maxbytes: " + maxbytes);
83  		
84  		db.recycle();
85  		session.recycle();
86  		NotesThread.stermThread();
87  		
88  	}
89  
90  }