Revision 9075
Added by Jing Tao almost 10 years ago
test/edu/ucsb/nceas/metacat/dataone/convert/LogV2toV1ConverterTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2010 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* '$Author: tao $' |
|
6 |
* '$Date: 2014-10-15 16:56:19 -0700 (Wed, 15 Oct 2014) $' |
|
7 |
* '$Revision: 8907 $' |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or modify |
|
10 |
* it under the terms of the GNU General Public License as published by |
|
11 |
* the Free Software Foundation; either version 2 of the License, or |
|
12 |
* (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
*/ |
|
23 |
|
|
24 |
package edu.ucsb.nceas.metacat.dataone.convert; |
|
25 |
|
|
26 |
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest; |
|
27 |
|
|
28 |
import java.util.Date; |
|
29 |
|
|
30 |
import junit.framework.Test; |
|
31 |
import junit.framework.TestSuite; |
|
32 |
|
|
33 |
import org.dataone.service.types.v1.Event; |
|
34 |
import org.dataone.service.types.v1.Identifier; |
|
35 |
import org.dataone.service.types.v1.NodeReference; |
|
36 |
import org.dataone.service.types.v1.Subject; |
|
37 |
import org.dataone.service.types.v2.Log; |
|
38 |
import org.dataone.service.types.v2.LogEntry; |
|
39 |
import org.junit.After; |
|
40 |
import org.junit.Before; |
|
41 |
|
|
42 |
import edu.ucsb.nceas.metacat.dataone.convert.LogV2toV1Converter; |
|
43 |
|
|
44 |
|
|
45 |
public class LogV2toV1ConverterTest extends D1NodeServiceTest { |
|
46 |
/** |
|
47 |
* Set up the test fixtures |
|
48 |
* |
|
49 |
* @throws Exception |
|
50 |
*/ |
|
51 |
@Before |
|
52 |
public void setUp() throws Exception { |
|
53 |
|
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Remove the test fixtures |
|
58 |
*/ |
|
59 |
@After |
|
60 |
public void tearDown() { |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Build the test suite |
|
65 |
* @return |
|
66 |
*/ |
|
67 |
public static Test suite() { |
|
68 |
|
|
69 |
TestSuite suite = new TestSuite(); |
|
70 |
suite.addTest(new LogV2toV1ConverterTest("initialize")); |
|
71 |
// MNStorage tests |
|
72 |
suite.addTest(new LogV2toV1ConverterTest("testConvert")); |
|
73 |
return suite; |
|
74 |
|
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Constructor for the tests |
|
79 |
* |
|
80 |
* @param name - the name of the test |
|
81 |
*/ |
|
82 |
public LogV2toV1ConverterTest(String name) { |
|
83 |
super(name); |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Initial blank test |
|
89 |
*/ |
|
90 |
public void initialize() { |
|
91 |
assertTrue(1 == 1); |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* Junit test for the convert method |
|
98 |
*/ |
|
99 |
public void testConvert() throws Exception { |
|
100 |
Log v2Log = new Log(); |
|
101 |
LogEntry v2LogEntry = new LogEntry(); |
|
102 |
String entryId1 = "1"; |
|
103 |
String event1 = "delete"; |
|
104 |
Identifier identifier1 = new Identifier(); |
|
105 |
identifier1.setValue("tao..345.34"); |
|
106 |
String ip = "1.1.1.1"; |
|
107 |
String userAgent = "morpho"; |
|
108 |
Subject subject = new Subject(); |
|
109 |
subject.setValue("uid=tao2,o=NCEAS,dc=ecoinformatics,dc=org"); |
|
110 |
NodeReference node = new NodeReference(); |
|
111 |
node.setValue("valley.duckdns.org"); |
|
112 |
Date date1 = new Date(); |
|
113 |
v2LogEntry.setEntryId(entryId1); |
|
114 |
v2LogEntry.setEvent(event1); |
|
115 |
v2LogEntry.setDateLogged(date1); |
|
116 |
v2LogEntry.setIdentifier(identifier1); |
|
117 |
v2LogEntry.setIpAddress(ip); |
|
118 |
v2LogEntry.setNodeIdentifier(node); |
|
119 |
v2LogEntry.setSubject(subject); |
|
120 |
v2LogEntry.setUserAgent(userAgent); |
|
121 |
v2Log.addLogEntry(v2LogEntry); |
|
122 |
|
|
123 |
LogEntry v2LogEntry2 = new LogEntry(); |
|
124 |
Identifier identifier2 = new Identifier(); |
|
125 |
identifier2.setValue("tao..345.35"); |
|
126 |
Date date2 = new Date(); |
|
127 |
String entryId2 = "2"; |
|
128 |
String event2 = "create"; |
|
129 |
v2LogEntry2.setEntryId(entryId2); |
|
130 |
v2LogEntry2.setEvent(event2); |
|
131 |
v2LogEntry2.setDateLogged(date2); |
|
132 |
v2LogEntry2.setIdentifier(identifier2); |
|
133 |
v2LogEntry2.setIpAddress(ip); |
|
134 |
v2LogEntry2.setNodeIdentifier(node); |
|
135 |
v2LogEntry2.setSubject(subject); |
|
136 |
v2LogEntry2.setUserAgent(userAgent); |
|
137 |
v2Log.addLogEntry(v2LogEntry2); |
|
138 |
|
|
139 |
int start = 3; |
|
140 |
int count = 2; |
|
141 |
int total = 500; |
|
142 |
v2Log.setCount(count); |
|
143 |
v2Log.setStart(start); |
|
144 |
v2Log.setTotal(total); |
|
145 |
|
|
146 |
LogV2toV1Converter convert = new LogV2toV1Converter(); |
|
147 |
org.dataone.service.types.v1.Log v1Log = convert.convert(v2Log); |
|
148 |
|
|
149 |
assertTrue("The start number should be same for v1 and v2 Log", v1Log.getStart() == v2Log.getStart()); |
|
150 |
assertTrue("The start number should be "+start+" for v1", v1Log.getStart() == start); |
|
151 |
|
|
152 |
assertTrue("The count number should be same for v1 and v2 Log", v1Log.getCount() == v2Log.getCount()); |
|
153 |
assertTrue("The count number should be "+count+" for v1", v1Log.getCount() == count); |
|
154 |
|
|
155 |
assertTrue("The total number should be same for v1 and v2 Log", v1Log.getTotal() == v2Log.getTotal()); |
|
156 |
assertTrue("The toal number should be "+total+" for v1", v1Log.getTotal() == total); |
|
157 |
|
|
158 |
org.dataone.service.types.v1.LogEntry v1LogEntry1 = v1Log.getLogEntry(0); |
|
159 |
assertTrue(v1LogEntry1.getDateLogged().equals(date1)); |
|
160 |
assertTrue(v1LogEntry1.getEntryId().equals(entryId1)); |
|
161 |
assertTrue(v1LogEntry1.getEvent().equals(Event.DELETE)); |
|
162 |
assertTrue(v1LogEntry1.getIdentifier().equals(identifier1)); |
|
163 |
assertTrue(v1LogEntry1.getIpAddress().equals(ip)); |
|
164 |
assertTrue(v1LogEntry1.getNodeIdentifier().equals(node)); |
|
165 |
assertTrue(v1LogEntry1.getSubject().equals(subject)); |
|
166 |
assertTrue(v1LogEntry1.getUserAgent().equals(userAgent)); |
|
167 |
|
|
168 |
org.dataone.service.types.v1.LogEntry v1LogEntry2 = v1Log.getLogEntry(1); |
|
169 |
assertTrue(v1LogEntry2.getDateLogged().equals(date2)); |
|
170 |
assertTrue(v1LogEntry2.getEntryId().equals(entryId2)); |
|
171 |
assertTrue(v1LogEntry2.getEvent().equals(Event.CREATE)); |
|
172 |
assertTrue(v1LogEntry2.getIdentifier().equals(identifier2)); |
|
173 |
assertTrue(v1LogEntry2.getIpAddress().equals(ip)); |
|
174 |
assertTrue(v1LogEntry2.getNodeIdentifier().equals(node)); |
|
175 |
assertTrue(v1LogEntry2.getSubject().equals(subject)); |
|
176 |
assertTrue(v1LogEntry2.getUserAgent().equals(userAgent)); |
|
177 |
} |
|
178 |
|
|
179 |
} |
Also available in: Unified diff
Add a junit test for the converter.