Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis,
5
 *              and the University of New Mexico
6
 *              
7
 *  Purpose: To test the HarvestLog class by using JUnit
8
 *
9
 *   '$Author: costa $'
10
 *     '$Date: 2004-08-26 13:45:59 -0700 (Thu, 26 Aug 2004) $'
11
 * '$Revision: 2254 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

    
28
package edu.ucsb.nceas.metacattest.harvesterClient;
29

    
30
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
31
import java.io.File;
32
import java.sql.Connection;
33
import java.sql.DriverManager;
34
import java.sql.SQLException;
35
import java.sql.SQLWarning;
36
import java.util.Date;
37
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
38
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
39
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
40
import edu.ucsb.nceas.metacat.harvesterClient.HarvestLog;
41
import junit.framework.Test;
42
import junit.framework.TestCase;
43
import junit.framework.TestSuite;
44

    
45
/**
46
 * Test HarvestLog code using JUnit.
47
 *
48
 * @author  costa
49
 */
50
public class HarvestLogTest extends TestCase {
51

    
52
  private Connection conn;
53
  private Harvester harvester;
54
  private HarvestLog harvestLogShallow;
55
  private HarvestLog harvestLogDeep;
56
  private HarvestDocument harvestDocument;
57
  private HarvestSiteSchedule harvestSiteSchedule;
58
  
59

    
60
  public HarvestLogTest(String name) {
61
    super(name);
62
  }
63
  
64
  
65
  protected void setUp() {
66
    String contactEmail = "jdoe@institution.edu";
67
    String dateLastHarvest = "2004-04-01 00:00:00.0";
68
    String dateNextHarvest = "2004-05-01 00:00:00.0";
69
    int detailLogID;
70
    String documentListURL = 
71
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
72
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
73
    String documentURL = 
74
                   "http://www.institution.edu/~jdoe/public_html/document1.xml";
75
    String errorMessage = "JUnit Testing";
76
    HarvestDocument harvestDocument = null;
77
    int harvestLogID;
78
    String harvestOperationCode = "HarvesterStartup";
79
    Date harvestStartTime = new Date();
80
    int identifier = 1;
81
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
82
    String ldapPwd = "secretpassword";
83
    String message = "JUnit Testing";
84
    int revision = 1;
85
    String scope = "docname";
86
    int siteScheduleID = 1;
87
    int status = 0;
88
    boolean test = true;
89
    String unit = "months";
90
    int updateFrequency = 1;
91

    
92
    harvester = new Harvester();
93
    Harvester.loadOptions(test);
94
    conn = harvester.getConnection();  // initializes the database connection
95
    harvester.initLogIDs();
96
    harvestLogID = harvester.getHarvestLogID();
97
    harvestLogShallow = new HarvestLog(harvester, conn, harvestLogID, 
98
                                       harvestStartTime, status, 
99
                                       message, harvestOperationCode, 
100
                                       siteScheduleID);
101

    
102
    harvestLogID = harvester.getHarvestLogID();
103
    detailLogID = harvester.getDetailLogID();
104
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
105
                                                  siteScheduleID,
106
                                                  documentListURL,
107
                                                  ldapDN,
108
                                                  ldapPwd,
109
                                                  dateNextHarvest,
110
                                                  dateLastHarvest,
111
                                                  updateFrequency,
112
                                                  unit,
113
                                                  contactEmail
114
                                                 );
115

    
116
    harvestDocument = new HarvestDocument(harvester,
117
                                          harvestSiteSchedule,
118
                                          scope,
119
                                          identifier,
120
                                          revision,
121
                                          documentType,
122
                                          documentURL
123
                                        );
124
    
125

    
126
    harvestLogDeep = new HarvestLog(harvester, conn, harvestLogID, detailLogID, 
127
                                    harvestStartTime, status, message,
128
                                    harvestOperationCode, siteScheduleID,
129
                                    harvestDocument, errorMessage);    
130
  }
131
  
132
  
133
  protected void tearDown() {
134
    harvester.closeConnection();
135
  }
136
  
137
  
138
  public void testGetCodeLevelValue() {
139
    int lowLevel = harvestLogShallow.getCodeLevelValue("error");
140
    int highLevel = harvestLogShallow.getCodeLevelValue("debug");
141
    
142
    assertTrue(lowLevel < highLevel);
143
  }
144
  
145
  
146
  public void testGetExplanation() {
147
    String harvestOperationCode = "HarvesterStartup";
148
    String explanation;
149

    
150
    explanation = harvestLogShallow.getExplanation(harvestOperationCode);
151
    assertTrue(explanation.equals("Harvester start up"));    
152
  }
153
  
154
  
155
  public void testGetHarvestOperationCodeLevel() {
156
    String harvestOperationCode = "HarvesterStartup";
157
    String harvestOperationCodeLevel;
158

    
159
    harvestOperationCodeLevel = 
160
           harvestLogShallow.getHarvestOperationCodeLevel(harvestOperationCode);
161
    assertTrue(harvestOperationCodeLevel.equalsIgnoreCase("Info"));    
162
  }
163

    
164

    
165
  /**
166
   * Test the construction of HarvestLog object, and a HarvestLog object
167
   * that contains a HarvestDetailLog object.
168
   */
169
  public void testHarvestLogObject() {
170
    assertTrue(harvestLogShallow != null);
171
    assertTrue(harvestLogDeep != null);
172
  }
173
  
174
  
175
  /**
176
   * Tests the printOutput() method when the code level of this operation is
177
   * greater than the maximum level we wish to print. This means that the output
178
   * should not be printed.
179
   */
180
  public void testPrintOutputExceedsMax() {
181
    System.out.println("No output should be printed:");
182
    harvestLogDeep.printOutput(System.out, "Error");
183
  }
184
  
185
  
186
  /**
187
   * Tests the printOutput() method when the code level of this operation is
188
   * less than the maximum level we wish to print. This means that the output
189
   * should be printed.
190
   */
191
  public void testPrintOutputWithinMax() {
192
    System.out.println("The log output should be printed:");
193
    harvestLogDeep.printOutput(System.out, "Debug");
194
  }
195
  
196
  
197
  /**
198
   * Returns the test suite. The test suite consists of all methods in this
199
   * class whose names start with "test".
200
   * 
201
   * @return  a TestSuite object
202
   */
203
  public static Test suite() {
204
    return new TestSuite(HarvestLogTest.class);
205
  }
206
  
207

    
208
  /**
209
   * The main program. Runs the test suite.
210
   * 
211
   * @param args   command line argument array.
212
   */
213
  public static void main(String args[]) {
214
    junit.textui.TestRunner.run(suite());
215
  }
216

    
217
}
(3-3/5)