Project

General

Profile

1
<!--
2
  * sitemaps.html
3
  *
4
  *      Authors: Michael Daigle
5
  *    Copyright: 2008 Regents of the University of California and the
6
  *               National Center for Ecological Analysis and Synthesis
7
  *  For Details: http://www.nceas.ucsb.edu/
8
  *      Created: 2008 November 4
9
  *      Version: 
10
  *    File Info: '$ '
11
  * 
12
  * 
13
-->
14
<HTML>
15
<HEAD>
16
<TITLE>Testing Metacat</TITLE>
17
<!-- unfortunately, we have to look for the common css file in the 
18
     user docs directory.  This is because the user docs deploy to 
19
     the top level of the metacat docs on the knb web server -->
20
<link rel="stylesheet" type="text/css" href="../user/common.css">
21
<link rel="stylesheet" type="text/css" href="./default.css">
22
</HEAD> 
23
<BODY>
24
  <table width="100%">
25
    <tr>
26
      <td class="tablehead" colspan="2"><p class="label">Testing Metacat</p></td>
27
      <td class="tablehead" colspan="2" align="right">
28
        <a href="./metacat-eclipse-project.html">Back</a> | <a href="./index.html">Home</a> | 
29
        <!--a href="add next file here when one exists" -->Next<!-- /a -->
30
      </td>
31
    </tr>
32
  </table>
33
      
34
  <div class="header1">Table of Contents</div>
35
  <div class="toc">
36
    <div class="toc1"><a href="#Intro">About Metacat Testing</a></div>
37
      <div class="toc2"><a href="#Overview">Overview</a></div>
38
      <div class="toc2"><a href="#MetacatImplementation">JUnit Implementation in Metacat</a></div>
39
    <div class="toc1"><a href="#WritingTestCase">Writing a Test Case</a></div>
40
      <div class="toc2"><a href="#Basics">Basics</a></div>
41
      <div class="toc2"><a href="#MCTestCase">MCTestCase Base Class</a></div>           
42
      <div class="toc2"><a href="#BestPractices">Best Practices</a></div>
43
    <div class="toc1"><a href="#RunTests">Running Test Cases</a></div>
44
      <div class="toc2"><a href="#AntTask">Ant task</a></div>
45
      <div class="toc2"><a href="#ConfigureMetacat">Configure Metacat For Testing</a></div>
46
      <div class="toc2"><a href="#RunAllTests">Run All Tests</a></div>
47
      <div class="toc2"><a href="#RunOneTest">Run One Test</a></div>
48
      <div class="toc2"><a href="#ViewingOutput">Viewing Test Output</a></div>
49
    <div class="toc1"><a href="#TestDbVersions">Testing Different Database Schema Versions</a></div>
50
      <div class="toc2"><a href="#scripts">Scripts to Run</a></div>
51
      <div class="toc2"><a href="#checkoutScripts">Get Scripts Via Checkout</a></div>
52
      <div class="toc2"><a href="#scriptRepo">Script Repository</a></div>
53
  </div>  
54
  
55
  <a name="Intro"></a><div class="header1">About Metacat Testing</div>
56
  <a name="Overview"></a><div class="header2">Overview</div>
57
  <p>Metacat uses JUnit tests to test its core functionality.  These tests are
58
  good for testing the internal workings of an application, but don't test the 
59
  layout and appearance.  JUnit tests are meant to be one tool in the developer's 
60
  test arsinal. If you are not familiar with JUnit, you should search out some 
61
  tutorial documentation online.  One such tutorial is at 
62
  <a href="http://clarkware.com/articles/JUnitPrimer.html"> The Clarkware JUnit primer</a></p>
63
  
64
  <p>Metacat test cases will need to be run on the same server as the Metacat
65
  instance that you want to test.  Since Metacat and its test cases share the same
66
  configuration files, there is no way to run the tests remotely.</p>
67

    
68
  <a name="MetacatImplementation"></a><div class="header2">JUnit Implementation in Metacat</div>
69
  <p>Metacat test cases are located in the code at:
70
  <div class="code">&lt;workspace&gt;/metacat/test/edu/ucsb/nceas/metacat*/</div>  
71
  There you will find several java files that define JUnit tests.</p>
72
  
73
  <p> Test cases are run via an ant task, and output from the tests appears in 
74
  a build directory.  More on this to follow.</p>
75

    
76
  <a name="WritingTestCase"></a><div class="header1">Writing a Test Case</div>
77
  <a name="Basics"></a><div class="header2">Basics</div>
78
  <p>All you need to do to get your JUnit test included into the Metacat test 
79
  suite is to create it in one of the &lt;workspace&gt;/test/edu/ucsb/nceas/metacat*/
80
  directories.  The ant test tasks will know that it should be run. </p>
81
  
82
  <p> The following methods are required in a test case class:
83
  <ul>
84
    <li>public &lt;Constructor&gt;(String name) - The constructor for the test class. </li>
85
	<li>public void setUp() - Set up any dependencies for the tests.  This is run before each test case.</li> 
86
	<li>public void tearDown() - Release an resources used by the test.</li> 
87
	<li>public static Test suite() - define the test methods that need to be run.</li>
88
	<li>public void initialize() - define any global initializations that need to be done.</li>
89
  </ul>
90
  
91
  You will test for failure using the many assertion methods available.</p>
92
  
93
  <a name="MCTestCase"></a><div class="header2">MCTestCase Base Class</div>
94
  <p>Metacat test cases extend the MCTestCase base class, which holds common 
95
  methods and variables.  Some of these include:
96
  <ul>
97
    <li>SUCCESS/FALURE - boolean variables holding the values for success and failure. </li>
98
	<li>metacatUrl, username, password - connection variables used for LDAP connectivity</li> 
99
	<li>readDocumentIdWhichEqualsDoc() - method to read a document from Metacat server.</li> 
100
	<li>debug() - method to display debug output to standard error.</li>
101
  </ul>
102
  These are just a few examples to give you an idea of what is in MCTestCase.
103
  </p>
104
  
105
  <a name="BestPractices"></a><div class="header2">Best Practices</div>
106
  <p>The following are a few best practices when writing test cases:
107
  <ul>
108
    <li>Extend MCTestCase - Although strictly speaking, it is possible to bypass MCTestCase
109
    and just extend the JUnit TestCase class, you should not do so.   You should always
110
    extend the MCTestCase class.</li>
111
    <li>Extend Multiple Test Methods - Try to strike a balance between the number of test 
112
    methods and the size of each test.  If a test method starts to get huge, you might see
113
    if you can break it down into mulitple tests based on functionality.  If the number of
114
    tests in the test suite starts to get large, you might see if it makes sense to 
115
    separate them out into different test classes.</li>
116
	<li>Use assertion message - Most assertion methods have an alternate implementation that 
117
	includes a message parameter.  This message will be shown if the assertion fails.  You
118
	should use this version of the assertion method.</li> 
119
	<li>debug() - You should use the debug() method available in the MCTestCase class to
120
	display debug output as opposed to System.err.println().  The test configuration will
121
	allow you to turn off debug output when you use the debug() method.</li>
122
  </ul>
123

    
124
  <a name="RunTests"></a><div class="header1">Running Test Cases</div>
125
  <a name="AntTask"></a><div class="header2">Ant task</div>
126
  <p>As we discussed earlier, the test cases run from within ant tasks.  There is a 
127
  task to run all tests and a task to run individual tests. </p>
128
  <p>You will need to have ant installed on your system.  For downloads and instructions,
129
  visit the <a href="http://ant.apache.org/">Apache Ant site</a>.
130
  </p>
131
  <a name="ConfigureMetacat"></a><div class="header2">Configure Metacat For Testing</div>
132
  <p>The test cases will look at the server's metacat properties file for configuration, 
133
  so there are two places that need to be configured.</p>
134
  <p>First, you need to edit the configuration file at:
135
  <div class="code">&lt;workspace&gt;/metacat/test/test.properties</div>
136
  This should only hold one property: metacat.contextDir.  This should point to 
137
  the context directory for the metacat server you are testing.  For example:
138
  <div class="code">metacat.contextDir=/usr/share/tomcat5.5/webapps/knb</div>
139
  The test classes will use this to determine where to look for the server
140
  metacat.properties file.</p>
141
  
142
  <p>the remainder of the configuration needs to happen in the actual server's 
143
  metacat.properties file located at:
144
  <div class="code">&lt;workspace&gt;/metacat/lib/metacat.properties</div>
145
  You will need to verify that all test.* properties are set correctly:
146
  <ul>
147
    <li>test.printdebug - true if you want debug output, false otherwise </li>
148
    <li>test.metacatUrl - the url for the metacat servlet (i.e. http://localhost:8080/knb/metacat)</li>
149
    <li>test.contextUrl - the url for the metacat web service (i.e. http://localhost:8080/knb)</li>
150
    <li>test.metacatDeployDir - the directory where metacat is physically deployed (i.e. /usr/local/tomcat/webapps/knb)</li>
151
    <li>test.mcUser - the first metacat test user ("uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org" should be fine)</li>
152
    <li>test.mcPassword - the first metacat test password ("kepler" should be fine)</li>
153
    <li>test.mcAnotherUser - the second metacat test user.  This user must be a member of the knb-usr 
154
        group in ldap. ("uid=test,o=NCEAS,dc=ecoinformatics,dc=org" should be fine)</li>
155
    <li>test.mcAnotherPassword - the second metacat test password ("test" should be fine)</li>
156
    <li>test.piscoUser - the pisco test user ("uid=piscotest,o=PISCO,dc=ecoinformatics,dc=org" should be fine)</li>
157
    <li>test.piscoPassword - the pisco test password ("testPW" should be fine)</li>
158
    <li>test.lterUser - the lter test user ("uid=tmonkey,o=LTER,dc=ecoinformatics,dc=org" should be fine)</li>
159
    <li>test.lterPassword - the lter test password ("T3$tusr" should be fine)</li>
160
    <li>test.testProperty - a property to verify that we can read properties (leave as "testing")</li>
161
  </ul>
162
  </p>
163
  
164
  <p>Note that none of the test users should also be administrative users.  This will mess up 
165
  the access tests since some document modifications will succeed when we expect them to fail.</p>
166
  
167
  <p>Once this is done, you will need to rebuild and redeploy the Metacat server.  Note that
168
  changing these properties does nothing to change the way the Metacat server runs.  Rebuilding
169
  and redeploying merely makes the test properties available to the JUnit tests.</p>
170
  
171
  <a name="RunAllTests"></a><div class="header2">Run All Tests</div>
172
  <p>To run all tests, go to the &lt;workspace&gt;/metacat directory and type</p>
173
  <div class="code">ant clean test</div>
174
  You will see a line to standard output summarizing each test result.
175
  </p>
176
  
177
  <a name="RunOneTest"></a><div class="header2">Run One Test</div>
178
  <p>To run one test, go to the &lt;workspace&gt;/metacat directory and type</p>
179
  <div class="code">ant clean runonetest -Dtesttorun=&lt;test_name&gt;</div>
180
  Where &lt;test_name&gt; is the name of the JUnit test class (without .java on 
181
  the end).  You will see debug information print to standard error.
182
  </p>
183
  
184
  <a name="ViewingOutput"></a><div class="header2">Viewing Test Output</div>
185
  <p>Regardless of whether you ran one test or all tests, you will see output in
186
  the Metacat build directory in your code at:
187
  <div class="code">&lt;workspace&gt;/metacat/build</div>
188
  There will be one output file for each test class.  The files will look like 
189
  <div class="code">TEST-edu.ucsb.nceas.&lt;test_dir&gt;.&lt;test_name&gt;.txt</div>
190
  where &lt;test_dir&gt; is the metacat* directory where the test lives and 
191
  &lt;test_name&gt; is the name of the JUnit test class. These output files will have
192
  all standard error and standard out output as well as information on assertion 
193
  failures in the event of a failed test.
194
  </p>
195
  
196
  <a name="TestDbVersions"></a><div class="header1">Testing Different Database Schema Versions</div>
197
  <p>Now and again it is necessary to restore your test database to an older schema version
198
  either because you need to test upgrade functionality, or you need to test backwords 
199
  compatibility of code.  This section describes how to get your db schema to an older 
200
  version.
201
  
202
  <a name="scripts"></a><div class="header2">Scripts to Run</div>
203
  <p>It is assumed that you have an empty metacat database up and running with a 
204
  metacat user.
205
  <p>There are two types of scripts that need to be run in order to create a Metacat
206
  schema:</p>
207
  <ul>
208
  <li>xmltables-&lt;dbtype&gt;.sql - where &lt;dbtype&gt; is either oracle or postgres
209
  depending on what type of database you are running against.  This script creates the
210
  necessary tables for Metacat.</li>
211
  <li>loaddtdschema-&lt;dbtype&gt;.sql - where &lt;dbtype&gt; is either oracle or postgres
212
  depending on what type of database you are running against.  This script creates the
213
  necessary seed data for Metacat.</li>
214
  </ul> 
215
  
216
  <a name="checkoutScripts"></a><div class="header2">Get Scripts Via Checkout</div>
217
  <p>One way to get the scripts you need is to check out the release tag for the version
218
  of metacat that you want to install.  You can then run the two scripts shown above to
219
  create your database.</p>
220
  
221
  <a name="scriptRepo"></a><div class="header2">Script Repository</div>
222
  <p>For convenience, the scripts to create each version have been extracted and 
223
  checked into:</p>
224
    <div class="code">&lt;metacat_code&gt;/src/scripts/metacat-db-versions</div>
225
  <p>The files look like:</p>
226
  <ul>
227
  <li>&lt;version&gt;_xmltables-&lt;dbtype&gt;.sql - where &lt;version&gt; is the version
228
  of the schema that you want to create and &lt;dbtype&gt; is either oracle or postgres
229
  depending on what type of database you are running against.  This script creates the
230
  necessary tables for Metacat.</li>
231
  <li>&lt;version&gt;_loaddtdschema-&lt;dbtype&gt;.sql - where &lt;version&gt; is the version
232
  of the schema that you want to create and &lt;dbtype&gt; is either oracle or postgres
233
  depending on what type of database you are running against.  This script creates the
234
  necessary seed data for Metacat.</li>
235
  <li>&lt;version&gt;_cleanall-&lt;dbtype&gt;.sql - where &lt;version&gt; is the version
236
  of the schema that you want to create and &lt;dbtype&gt; is either oracle or postgres
237
  depending on what type of database you are running against. This is a convenience script
238
  to clean out the changes for that version.</li>
239
  </ul>
240
  
241
  <a name="scriptRepo"></a><div class="header2">Manually Run Scripts</div>
242
  <p>For instructions on running database scripts manually, please refer to:
243
  <a href="../user/run-db-scripts.html">how to run database scripts</a></p>
244
    
245
  <br>
246
  <a href="./metacat-eclipse-project.html">Back</a> | <a href="./index.html">Home</a> | 
247
  <!--a href="add next file here when one exists" -->Next<!-- /a -->
248

    
249
</BODY>
250
</HTML>
(31-31/31)