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