Project

General

Profile

« Previous | Next » 

Revision 5335

Added by berkley almost 14 years ago

added a test for CrudService and added tests for IdentifierManager for each method

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2010 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *  Purpose: To test the Access Controls in metacat by JUnit
6
 *
7
 *   '$Author: berkley $'
8
 *     '$Date: 2010-05-03 14:26:08 -0700 (Fri, 14 Aug 2009) $'
9
 * '$Revision: 5027 $'
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 */
25

  
26
package edu.ucsb.nceas.metacat.dataone;
27

  
28
import java.util.*;
29
import java.io.*;
30

  
31
import edu.ucsb.nceas.MCTestCase;
32
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
33
import edu.ucsb.nceas.metacat.client.MetacatException;
34
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
35
import edu.ucsb.nceas.metacat.dataone.CrudService;
36
import junit.framework.Test;
37
import junit.framework.TestSuite;
38

  
39
/**
40
 * A JUnit test for testing the dataone CrudService class
41
 */
42
public class CrudServiceTest extends MCTestCase 
43
{
44
  /**
45
   * consstructor for the test
46
   */
47
  public CrudServiceTest(String name)
48
  {
49
    super(name);
50
  }
51
  
52
  /**
53
	 * Establish a testing framework by initializing appropriate objects
54
	 */
55
	public void setUp() throws Exception 
56
	{
57
		super.setUp();
58
	}
59

  
60
	/**
61
	 * Release any objects after tests are complete
62
	 */
63
	public void tearDown() 
64
	{
65
	}
66

  
67
	/**
68
	 * Create a suite of tests to be run together
69
	 */
70
	public static Test suite() 
71
	{
72
		TestSuite suite = new TestSuite();
73
		suite.addTest(new CrudServiceTest("initialize"));
74

  
75
		return suite;
76
	}
77

  
78
	/**
79
	 * Run an initial test that always passes to check that the test harness is
80
	 * working.
81
	 */
82
	public void initialize() 
83
	{
84
		assertTrue(1 == 1);
85
	}
86
  
87
}
test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
105 105
    
106 106
    /**
107 107
     * Test that we are able to create mappings from guids to localIds, and that
108
     * improperly formatted docids generate the proper exceptions.
108
     * improperly formatted docids generate the proper exceptions.  This also tests
109
     * getLocalId() and getGUID()
109 110
     */
110 111
    public void testCreateMapping() {
111
        IdentifierManager im = IdentifierManager.getInstance();
112
        String docid = insertTestDocument();
113
        im.createMapping("test:"+docid, docid);
114
        try {
115
            assertEquals(im.getLocalId("test:"+docid), docid);
112
       try
113
       {
114
            IdentifierManager im = IdentifierManager.getInstance();
115
            String docid = insertTestDocument();
116
            String guid = "test:" + docid;
117
            im.createMapping(guid, docid);
118
            String guiddocid = docid.substring(0, docid.length() - 2);
119
            System.out.println("guiddocid: " + guiddocid);
120
            String guid2 = im.getGUID(guiddocid, 1);
121
            assertTrue(guid2.equals(guid));
122
            String docid2 = im.getLocalId(guid);
123
            assertTrue(docid.equals(docid2));
116 124
        } catch (McdbDocNotFoundException e) {
117
            fail("createMapping failed to create proper localId from guid.");
125
            e.printStackTrace();
126
            fail("createMapping failed to create proper localId from guid: " + e.getMessage());
118 127
        }
119 128
    }
129
    
130
    /**
131
     * test createSystemMetadataMapping and getSystemMetadataId
132
     */
133
    public void testCreateSystemMetadataMapping()
134
    {
135
        try
136
        {
137
            IdentifierManager im = IdentifierManager.getInstance();
138
            String docid = insertTestDocument();
139
            String guid = "test:" + docid;
140
            im.createSystemMetadataMapping(guid, docid);
141
            String docid2 = im.getSystemMetadataId(guid);
142
            assertTrue(docid2.equals(docid));
143
        } catch (McdbDocNotFoundException e) {
144
          e.printStackTrace();
145
          fail("createSystemMetadataMapping failed to create proper localId from guid: " + e.getMessage());
146
        }
147
    }
148
    
149
    /**
150
     * test the local id creation
151
     */
152
    public void testGenerateLocalId() {
153
      IdentifierManager im = IdentifierManager.getInstance();
154
      String localid = im.generateLocalId("mynewid.1.3.3.2", 1);
155
      System.out.println("localid: " + localid);
156
      assertTrue(localid != null);
157
    }
120 158

  
121
    /** Insert a test document, returning the docid that was used. */
159
    /** 
160
     * Insert a test document, returning the docid that was used. 
161
     */
122 162
    private String insertTestDocument() {
123 163
        String accessBlock = getAccessBlock("public", true, true,
124 164
                false, false, false);

Also available in: Unified diff