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: 2009-02-23 11:29:07 -0800 (Mon, 23 Feb 2009) $'
11
 * '$Revision: 4816 $'
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.MCTestCase;
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.metacat.service.PropertyService;
36
import edu.ucsb.nceas.metacat.util.MetacatUtil;
37

    
38
import java.sql.Connection;
39
import junit.framework.Test;
40
import junit.framework.TestSuite;
41

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

    
49
  private Harvester harvester;
50
  private HarvestDetailLog harvestDetailLog;
51
  private HarvestDocument harvestDocument;
52
  private HarvestSiteSchedule harvestSiteSchedule;
53
  /* Initialize Properties*/
54
  static
55
  {
56
	  try
57
	  {
58
		  PropertyService.getInstance();
59
	  }
60
	  catch(Exception e)
61
	  {
62
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
63
	  }
64
  }
65

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

    
76
  /**
77
   * Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
78
   * and HarvestDetailLog objects.
79
   */
80
  protected void setUp() {
81
    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
    boolean test = true;
100
    String unit = "months";
101
    int updateFrequency = 1;
102
  
103
    harvester = new Harvester();
104
    Harvester.loadProperties(test);
105
    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
  }
135
  
136

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

    
144

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