Project

General

Profile

1 2134 costa
/**
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 HarvestDetailLog class by using JUnit
8
 *
9
 *   '$Author$'
10
 *     '$Date$'
11
 * '$Revision$'
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 4385 daigle
import edu.ucsb.nceas.MCTestCase;
31 2134 costa
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32 2143 costa
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
33
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
34
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
35 4080 daigle
import edu.ucsb.nceas.metacat.service.PropertyService;
36 4701 daigle
import edu.ucsb.nceas.metacat.util.MetacatUtil;
37 3566 tao
38 2143 costa
import java.sql.Connection;
39 2134 costa
import junit.framework.Test;
40
import junit.framework.TestSuite;
41
42
/**
43 2255 costa
 * Tests HarvestDetailLog code using JUnit.
44 2134 costa
 *
45
 * @author  costa
46
 */
47 4385 daigle
public class HarvestDetailLogTest extends MCTestCase {
48 2134 costa
49
  private Harvester harvester;
50 2143 costa
  private HarvestDetailLog harvestDetailLog;
51
  private HarvestDocument harvestDocument;
52
  private HarvestSiteSchedule harvestSiteSchedule;
53 4127 daigle
  /* Initialize Properties*/
54 3566 tao
  static
55
  {
56
	  try
57
	  {
58 4816 daigle
		  PropertyService.getInstance();
59 3566 tao
	  }
60
	  catch(Exception e)
61
	  {
62
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
63
	  }
64
  }
65 2134 costa
66 2255 costa
  /**
67
   * Constructor for this test.
68
   *
69
   * @param name     name of the test case
70
   */
71 2134 costa
  public HarvestDetailLogTest(String name) {
72
    super(name);
73
  }
74
75 2255 costa
76
  /**
77
   * Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
78
   * and HarvestDetailLog objects.
79
   */
80 2134 costa
  protected void setUp() {
81 2143 costa
    Connection conn;
82
    String contactEmail = "jdoe@institution.edu";
83
    String dateLastHarvest = "2004-04-01 00:00:00.0";
84
    String dateNextHarvest = "2004-05-01 00:00:00.0";
85
    int detailLogID;
86
    String documentListURL =
87
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
88
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
89
    String documentURL =
90
                   "http://www.institution.edu/~jdoe/public_html/document1.xml";
91
    String errorMessage = "JUnit testing";
92
    int harvestLogID;
93
    int identifier = 1;
94
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
95
    String ldapPwd = "secretpassword";
96
    int revision = 1;
97
    String scope = "docname";
98
    int siteScheduleID = 1;
99 2158 costa
    boolean test = true;
100 2143 costa
    String unit = "months";
101
    int updateFrequency = 1;
102
103 2134 costa
    harvester = new Harvester();
104 4127 daigle
    Harvester.loadProperties(test);
105 2143 costa
    conn = harvester.getConnection();  // initializes the database connection
106
    harvester.initLogIDs();
107
    harvestLogID = harvester.getHarvestLogID();
108
    detailLogID = harvester.getDetailLogID();
109
110
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
111
                                                  siteScheduleID,
112
                                                  documentListURL,
113
                                                  ldapDN,
114
                                                  ldapPwd,
115
                                                  dateNextHarvest,
116
                                                  dateLastHarvest,
117
                                                  updateFrequency,
118
                                                  unit,
119
                                                  contactEmail
120
                                                 );
121
122
    harvestDocument = new HarvestDocument(harvester,
123
                                          harvestSiteSchedule,
124
                                          scope,
125
                                          identifier,
126
                                          revision,
127
                                          documentType,
128
                                          documentURL
129
                                        );
130
131
    harvestDetailLog = new HarvestDetailLog(harvester, conn, harvestLogID,
132
                                            detailLogID, harvestDocument,
133
                                            errorMessage);
134 2134 costa
  }
135
136 2255 costa
137
  /**
138
   * Closes the database connection when the test completes.
139
   */
140 2134 costa
  protected void tearDown() {
141 2143 costa
    harvester.closeConnection();
142 2134 costa
  }
143
144
145
  /**
146 2143 costa
   * Tests that the harvestDetailLog object was constructed.
147 2134 costa
   */
148 2143 costa
  public void testHarvestDetailLogObject() {
149
    assertTrue(harvestDetailLog != null);
150 2134 costa
  }
151
152
153
  /**
154 2143 costa
   * Tests the printOutput() method.
155
   */
156
  public void testPrintOutput() {
157
    harvestDetailLog.printOutput(System.out);
158
  }
159
160
161
  /**
162 2134 costa
   * Returns the test suite. The test suite consists of all methods in this
163
   * class whose names start with "test".
164
   *
165
   * @return  a TestSuite object
166
   */
167
  public static Test suite() {
168
    return new TestSuite(HarvestDetailLogTest.class);
169
  }
170
171
172
  /**
173
   * The main program. Runs the test suite.
174
   *
175
   * @param args   command line argument array.
176
   */
177
  public static void main(String args[]) {
178
    junit.textui.TestRunner.run(suite());
179
  }
180
181
}