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: costa $'
10
 *     '$Date: 2009-07-27 14:47:44 -0700 (Mon, 27 Jul 2009) $'
11
 * '$Revision: 4999 $'
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
    boolean commandLineMode = true;
83
    String contactEmail = "jdoe@institution.edu";
84
    String dateLastHarvest = "2004-04-01 00:00:00.0";
85
    String dateNextHarvest = "2004-05-01 00:00:00.0";
86
    int detailLogID;
87
    String documentListURL = 
88
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
89
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
90
    String documentURL = 
91
                   "http://www.institution.edu/~jdoe/public_html/document1.xml";
92
    String errorMessage = "JUnit testing";
93
    int harvestLogID;
94
    int identifier = 1;
95
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
96
    String ldapPwd = "secretpassword";
97
    int revision = 1;
98
    String scope = "docname";
99
    int siteScheduleID = 1;
100
    boolean test = true;
101
    String unit = "months";
102
    int updateFrequency = 1;
103
  
104
    harvester = new Harvester();
105
    Harvester.loadProperties(commandLineMode, test);
106
    conn = harvester.getConnection();  // initializes the database connection
107
    harvester.initLogIDs();
108
    harvestLogID = harvester.getHarvestLogID();
109
    detailLogID = harvester.getDetailLogID();
110

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

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

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

    
145

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

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

    
182
}
(1-1/5)