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 HarvestDetailLog class by using JUnit
8
 *
9
 *   '$Author: tao $'
10
 *     '$Date: 2007-11-03 21:09:12 -0700 (Sat, 03 Nov 2007) $'
11
 * '$Revision: 3566 $'
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.MetaCatUtil;
31
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
33
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
34
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
35
import edu.ucsb.nceas.utilities.Options;
36

    
37
import java.io.File;
38
import java.sql.Connection;
39
import junit.framework.Test;
40
import junit.framework.TestCase;
41
import junit.framework.TestSuite;
42

    
43
/**
44
 * Tests HarvestDetailLog code using JUnit.
45
 *
46
 * @author  costa
47
 */
48
public class HarvestDetailLogTest extends TestCase {
49

    
50
  private Harvester harvester;
51
  private HarvestDetailLog harvestDetailLog;
52
  private HarvestDocument harvestDocument;
53
  private HarvestSiteSchedule harvestSiteSchedule;
54
  /* Initialize Options*/
55
  static
56
  {
57
	  try
58
	  {
59
		  Options.initialize(new File("build/tests/metacat.properties"));
60
		  MetaCatUtil.pathsForIndexing 
61
		         = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths"));
62
	  }
63
	  catch(Exception e)
64
	  {
65
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
66
	  }
67
  }
68

    
69
  /**
70
   * Constructor for this test.
71
   * 
72
   * @param name     name of the test case
73
   */
74
  public HarvestDetailLogTest(String name) {
75
    super(name);
76
  }
77
  
78

    
79
  /**
80
   * Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
81
   * and HarvestDetailLog objects.
82
   */
83
  protected void setUp() {
84
    Connection conn;
85
    String contactEmail = "jdoe@institution.edu";
86
    String dateLastHarvest = "2004-04-01 00:00:00.0";
87
    String dateNextHarvest = "2004-05-01 00:00:00.0";
88
    int detailLogID;
89
    String documentListURL = 
90
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
91
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
92
    String documentURL = 
93
                   "http://www.institution.edu/~jdoe/public_html/document1.xml";
94
    String errorMessage = "JUnit testing";
95
    int harvestLogID;
96
    int identifier = 1;
97
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
98
    String ldapPwd = "secretpassword";
99
    int revision = 1;
100
    String scope = "docname";
101
    int siteScheduleID = 1;
102
    boolean test = true;
103
    String unit = "months";
104
    int updateFrequency = 1;
105
  
106
    harvester = new Harvester();
107
    Harvester.loadOptions(test);
108
    conn = harvester.getConnection();  // initializes the database connection
109
    harvester.initLogIDs();
110
    harvestLogID = harvester.getHarvestLogID();
111
    detailLogID = harvester.getDetailLogID();
112

    
113
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
114
                                                  siteScheduleID,
115
                                                  documentListURL,
116
                                                  ldapDN,
117
                                                  ldapPwd,
118
                                                  dateNextHarvest,
119
                                                  dateLastHarvest,
120
                                                  updateFrequency,
121
                                                  unit,
122
                                                  contactEmail
123
                                                 );
124

    
125
    harvestDocument = new HarvestDocument(harvester,
126
                                          harvestSiteSchedule,
127
                                          scope,
128
                                          identifier,
129
                                          revision,
130
                                          documentType,
131
                                          documentURL
132
                                        );
133
    
134
    harvestDetailLog = new HarvestDetailLog(harvester, conn, harvestLogID, 
135
                                            detailLogID, harvestDocument, 
136
                                            errorMessage);
137
  }
138
  
139

    
140
  /**
141
   * Closes the database connection when the test completes.
142
   */
143
  protected void tearDown() {
144
    harvester.closeConnection();
145
  }
146

    
147

    
148
  /**
149
   * Tests that the harvestDetailLog object was constructed.
150
   */
151
  public void testHarvestDetailLogObject() {
152
    assertTrue(harvestDetailLog != null);
153
  }
154
  
155
  
156
  /**
157
   * Tests the printOutput() method.
158
   */
159
  public void testPrintOutput() {
160
    harvestDetailLog.printOutput(System.out);
161
  }
162
  
163
  
164
  /**
165
   * Returns the test suite. The test suite consists of all methods in this
166
   * class whose names start with "test".
167
   * 
168
   * @return  a TestSuite object
169
   */
170
  public static Test suite() {
171
    return new TestSuite(HarvestDetailLogTest.class);
172
  }
173
  
174

    
175
  /**
176
   * The main program. Runs the test suite.
177
   * 
178
   * @param args   command line argument array.
179
   */
180
  public static void main(String args[]) {
181
    junit.textui.TestRunner.run(suite());
182
  }
183

    
184
}
(1-1/5)