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: daigle $'
10
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
11
 * '$Revision: 4080 $'
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
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
32
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
33
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
34
import edu.ucsb.nceas.metacat.service.PropertyService;
35
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
36
import edu.ucsb.nceas.utilities.Options;
37

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

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

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

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

    
80
  /**
81
   * Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
82
   * and HarvestDetailLog objects.
83
   */
84
  protected void setUp() {
85
    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
    boolean test = true;
104
    String unit = "months";
105
    int updateFrequency = 1;
106
  
107
    harvester = new Harvester();
108
    Harvester.loadOptions(test);
109
    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
  }
139
  
140

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

    
148

    
149
  /**
150
   * Tests that the harvestDetailLog object was constructed.
151
   */
152
  public void testHarvestDetailLogObject() {
153
    assertTrue(harvestDetailLog != null);
154
  }
155
  
156
  
157
  /**
158
   * Tests the printOutput() method.
159
   */
160
  public void testPrintOutput() {
161
    harvestDetailLog.printOutput(System.out);
162
  }
163
  
164
  
165
  /**
166
   * 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
}
(1-1/5)