Skip to content

Commit 62d17c9

Browse files
committed
Modifications to split TCK out from jakartaee-tck repo, use JUnit, and use jakarta namespace
1 parent 2561bea commit 62d17c9

File tree

273 files changed

+2489
-2847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+2489
-2847
lines changed

tck/pom.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,27 @@
4848

4949
<properties>
5050
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
51-
<jakarta.json.version>2.0.0-RC1</jakarta.json.version>
51+
<maven.compiler.target>1.8</maven.compiler.target>
52+
<maven.compiler.source>1.8</maven.compiler.source>
5253
</properties>
5354

5455
<dependencies>
56+
<dependency>
57+
<groupId>jakarta.json.bind</groupId>
58+
<artifactId>jakarta.json.bind-api</artifactId>
59+
<version>${project.version}</version>
60+
<scope>provided</scope>
61+
</dependency>
5562
<dependency>
5663
<groupId>jakarta.json</groupId>
5764
<artifactId>jakarta.json-api</artifactId>
58-
<version>${jakarta.json.version}</version>
65+
<version>2.0.0-RC1</version>
66+
<scope>provided</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>jakarta.inject</groupId>
70+
<artifactId>jakarta.inject-api</artifactId>
71+
<version>1.0</version>
5972
<scope>provided</scope>
6073
</dependency>
6174
<dependency>

tck/src/main/java/jakarta/json/bind/MappingTester.java

Lines changed: 61 additions & 89 deletions
Large diffs are not rendered by default.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2020 IBM and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package jakarta.json.bind;
17+
18+
import org.hamcrest.Description;
19+
import org.hamcrest.TypeSafeMatcher;
20+
21+
public class RegexMatcher extends TypeSafeMatcher<String> {
22+
23+
private final String regex;
24+
25+
public RegexMatcher(final String regex) {
26+
this.regex = regex;
27+
}
28+
29+
@Override
30+
public void describeTo(final Description description) {
31+
description.appendText("matches regex=`" + regex + "`");
32+
}
33+
34+
@Override
35+
public boolean matchesSafely(final String string) {
36+
return string.matches(regex);
37+
}
38+
39+
40+
public static RegexMatcher matches(final String regex) {
41+
return new RegexMatcher(regex);
42+
}
43+
}

tck/src/main/java/jakarta/json/bind/SimpleMappingTester.java

Lines changed: 60 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
*/
1616

17-
/*
18-
* $Id$
19-
*/
17+
package jakarta.json.bind;
2018

21-
package com.sun.ts.tests.jsonb;
19+
import static org.junit.Assert.fail;
2220

2321
import java.io.ByteArrayInputStream;
2422
import java.io.ByteArrayOutputStream;
@@ -28,14 +26,6 @@
2826
import java.lang.reflect.Type;
2927
import java.nio.charset.StandardCharsets;
3028

31-
import javax.json.bind.Jsonb;
32-
import javax.json.bind.JsonbBuilder;
33-
34-
import com.sun.javatest.Status;
35-
import com.sun.ts.lib.harness.EETest.Fault;
36-
37-
import static com.sun.ts.tests.jsonb.MappingTester.combine;
38-
3929
public class SimpleMappingTester<T> {
4030
private final Jsonb jsonb = JsonbBuilder.create();
4131

@@ -45,103 +35,100 @@ public SimpleMappingTester(Class<T> typeClass) {
4535
this.typeClass = typeClass;
4636
}
4737

48-
public Status test(T value, String expectedRepresentationPattern,
49-
String expectedRepresentation, Object expectedOutput) throws Fault {
50-
return combine(testMarshalling(value, expectedRepresentationPattern),
51-
testMarshallingToStream(value, expectedRepresentationPattern),
52-
testMarshallingToWriter(value, expectedRepresentationPattern),
53-
testMarshallingByType(value, expectedRepresentationPattern),
54-
testMarshallingByTypeToStream(value, expectedRepresentationPattern),
55-
testMarshallingByTypeToWriter(value, expectedRepresentationPattern),
56-
testUnmarshallingByClass(expectedRepresentation, expectedOutput),
38+
public void test(T value, String expectedRepresentationPattern,
39+
String expectedRepresentation, Object expectedOutput) {
40+
testMarshalling(value, expectedRepresentationPattern);
41+
testMarshallingToStream(value, expectedRepresentationPattern);
42+
testMarshallingToWriter(value, expectedRepresentationPattern);
43+
testMarshallingByType(value, expectedRepresentationPattern);
44+
testMarshallingByTypeToStream(value, expectedRepresentationPattern);
45+
testMarshallingByTypeToWriter(value, expectedRepresentationPattern);
46+
testUnmarshallingByClass(expectedRepresentation, expectedOutput);
5747
testUnmarshallingByClassFromStream(expectedRepresentation,
58-
expectedOutput),
48+
expectedOutput);
5949
testUnmarshallingByClassFromReader(expectedRepresentation,
60-
expectedOutput),
61-
testUnmarshallingByType(expectedRepresentation, expectedOutput),
50+
expectedOutput);
51+
testUnmarshallingByType(expectedRepresentation, expectedOutput);
6252
testUnmarshallingByTypeFromStream(expectedRepresentation,
63-
expectedOutput),
53+
expectedOutput);
6454
testUnmarshallingByTypeFromReader(expectedRepresentation,
65-
expectedOutput));
55+
expectedOutput);
6656
}
6757

68-
private Status testMarshalling(T value, String expectedRepresentation) {
58+
private void testMarshalling(T value, String expectedRepresentation) {
6959
String jsonString = jsonb.toJson(value);
7060
if (jsonString.matches(expectedRepresentation)) {
71-
return Status.passed("OK");
61+
return; // passed
7262
} else {
73-
return Status.failed("[testMarshalling] - Failed to correctly marshal "
63+
fail("[testMarshalling] - Failed to correctly marshal "
7464
+ value.getClass().getName() + " object");
7565
}
7666
}
7767

78-
private Status testMarshallingToStream(T value,
68+
private void testMarshallingToStream(T value,
7969
String expectedRepresentation) {
8070
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
8171
jsonb.toJson(value, stream);
8272
String jsonString = new String(stream.toByteArray(),
8373
StandardCharsets.UTF_8);
8474
if (jsonString.matches(expectedRepresentation)) {
85-
return Status.passed("OK");
75+
return; // passed
8676
} else {
87-
return Status
88-
.failed("[testMarshallingToStream] - Failed to correctly marshal "
77+
fail("[testMarshallingToStream] - Failed to correctly marshal "
8978
+ value.getClass().getName() + " object");
9079
}
9180
} catch (IOException e) {
92-
return Status.error(e.getMessage());
81+
fail(e.getMessage());
9382
}
9483
}
9584

96-
private Status testMarshallingToWriter(T value,
85+
private void testMarshallingToWriter(T value,
9786
String expectedRepresentation) {
9887
try (ByteArrayOutputStream stream = new ByteArrayOutputStream();
9988
OutputStreamWriter writer = new OutputStreamWriter(stream)) {
10089
jsonb.toJson(value, writer);
10190
String jsonString = new String(stream.toByteArray(),
10291
StandardCharsets.UTF_8);
10392
if (jsonString.matches(expectedRepresentation)) {
104-
return Status.passed("OK");
93+
return; // passed
10594
} else {
106-
return Status
107-
.failed("[testMarshallingToWriter] - Failed to correctly marshal "
95+
fail("[testMarshallingToWriter] - Failed to correctly marshal "
10896
+ value.getClass().getName() + " object");
10997
}
11098
} catch (IOException e) {
111-
return Status.error(e.getMessage());
99+
fail(e.getMessage());
112100
}
113101
}
114102

115-
private Status testMarshallingByType(T value, String expectedRepresentation) {
103+
private void testMarshallingByType(T value, String expectedRepresentation) {
116104
String jsonString = jsonb.toJson(value, TypeContainer.class);
117105
if (jsonString.matches(expectedRepresentation)) {
118-
return Status.passed("OK");
106+
return; // passed
119107
} else {
120-
return Status
121-
.failed("[testMarshallingByType] - Failed to correctly marshal "
108+
fail("[testMarshallingByType] - Failed to correctly marshal "
122109
+ value.getClass().getName() + " object");
123110
}
124111
}
125112

126-
private Status testMarshallingByTypeToStream(T value,
113+
private void testMarshallingByTypeToStream(T value,
127114
String expectedRepresentation) {
128115
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
129116
jsonb.toJson(value, TypeContainer.class, stream);
130117
String jsonString = new String(stream.toByteArray(),
131118
StandardCharsets.UTF_8);
132119
if (jsonString.matches(expectedRepresentation)) {
133-
return Status.passed("OK");
120+
return; // passed
134121
} else {
135-
return Status.failed(
122+
fail(
136123
"[testMarshallingByTypeToStream] - Failed to correctly marshal "
137124
+ value.getClass().getName() + " object");
138125
}
139126
} catch (IOException e) {
140-
return Status.error(e.getMessage());
127+
fail(e.getMessage());
141128
}
142129
}
143130

144-
private Status testMarshallingByTypeToWriter(T value,
131+
private void testMarshallingByTypeToWriter(T value,
145132
String expectedRepresentation) {
146133
try (ByteArrayOutputStream stream = new ByteArrayOutputStream();
147134
OutputStreamWriter writer = new OutputStreamWriter(stream)) {
@@ -150,48 +137,47 @@ private Status testMarshallingByTypeToWriter(T value,
150137
String jsonString = new String(stream.toByteArray(),
151138
StandardCharsets.UTF_8);
152139
if (jsonString.matches(expectedRepresentation)) {
153-
return Status.passed("OK");
140+
return; // passed
154141
} else {
155-
return Status.failed(
142+
fail(
156143
"[testMarshallingByTypeToWriter] - Failed to correctly marshal "
157144
+ value.getClass().getName() + " object");
158145
}
159146
} catch (IOException e) {
160-
return Status.error(e.getMessage());
147+
fail(e.getMessage());
161148
}
162149
}
163150

164-
private Status testUnmarshallingByClass(String expectedRepresentation,
151+
private void testUnmarshallingByClass(String expectedRepresentation,
165152
Object value) {
166153
Object unmarshalledObject = jsonb.fromJson(expectedRepresentation,
167154
typeClass);
168155
if (value.equals(unmarshalledObject)) {
169-
return Status.passed("OK");
156+
return; // passed
170157
} else {
171-
return Status
172-
.failed("[testUnmarshallingByClass] - Failed to correctly unmarshal "
158+
fail("[testUnmarshallingByClass] - Failed to correctly unmarshal "
173159
+ value.getClass().getName() + " object");
174160
}
175161
}
176162

177-
private Status testUnmarshallingByClassFromStream(
163+
private void testUnmarshallingByClassFromStream(
178164
String expectedRepresentation, Object value) {
179165
try (ByteArrayInputStream stream = new ByteArrayInputStream(
180166
expectedRepresentation.getBytes(StandardCharsets.UTF_8))) {
181167
Object unmarshalledObject = jsonb.fromJson(stream, typeClass);
182168
if (value.equals(unmarshalledObject)) {
183-
return Status.passed("OK");
169+
return; // passed
184170
} else {
185-
return Status.failed(
171+
fail(
186172
"[testUnmarshallingByClassFromStream] - Failed to correctly unmarshal "
187173
+ value.getClass().getName() + " object");
188174
}
189175
} catch (IOException e) {
190-
return Status.error(e.getMessage());
176+
fail(e.getMessage());
191177
}
192178
}
193179

194-
private Status testUnmarshallingByClassFromReader(
180+
private void testUnmarshallingByClassFromReader(
195181
String expectedRepresentation, Object value) {
196182
try (
197183
ByteArrayInputStream stream = new ByteArrayInputStream(
@@ -200,48 +186,47 @@ private Status testUnmarshallingByClassFromReader(
200186

201187
Object unmarshalledObject = jsonb.fromJson(reader, typeClass);
202188
if (value.equals(unmarshalledObject)) {
203-
return Status.passed("OK");
189+
return; // passed
204190
} else {
205-
return Status.failed(
191+
fail(
206192
"[testUnmarshallingByClassFromReader] - Failed to correctly unmarshal "
207193
+ value.getClass().getName() + " object");
208194
}
209195
} catch (IOException e) {
210-
return Status.error(e.getMessage());
196+
fail(e.getMessage());
211197
}
212198
}
213199

214-
private Status testUnmarshallingByType(String expectedRepresentation,
200+
private void testUnmarshallingByType(String expectedRepresentation,
215201
Object value) {
216202
Object unmarshalledObject = jsonb.fromJson(expectedRepresentation,
217203
(Type) typeClass);
218204
if (value.equals(unmarshalledObject)) {
219-
return Status.passed("OK");
205+
return; // passed
220206
} else {
221-
return Status
222-
.failed("[testUnmarshallingByType] - Failed to correctly unmarshal "
207+
fail("[testUnmarshallingByType] - Failed to correctly unmarshal "
223208
+ value.getClass().getName() + " object");
224209
}
225210
}
226211

227-
private Status testUnmarshallingByTypeFromStream(
212+
private void testUnmarshallingByTypeFromStream(
228213
String expectedRepresentation, Object value) {
229214
try (ByteArrayInputStream stream = new ByteArrayInputStream(
230215
expectedRepresentation.getBytes(StandardCharsets.UTF_8))) {
231216
Object unmarshalledObject = jsonb.fromJson(stream, (Type) typeClass);
232217
if (value.equals(unmarshalledObject)) {
233-
return Status.passed("OK");
218+
return; // passed
234219
} else {
235-
return Status.failed(
220+
fail(
236221
"[testUnmarshallingByTypeFromStream] - Failed to correctly unmarshal "
237222
+ value.getClass().getName() + " object");
238223
}
239224
} catch (IOException e) {
240-
return Status.error(e.getMessage());
225+
fail(e.getMessage());
241226
}
242227
}
243228

244-
private Status testUnmarshallingByTypeFromReader(
229+
private void testUnmarshallingByTypeFromReader(
245230
String expectedRepresentation, Object value) {
246231
try (
247232
ByteArrayInputStream stream = new ByteArrayInputStream(
@@ -250,14 +235,14 @@ private Status testUnmarshallingByTypeFromReader(
250235

251236
Object unmarshalledObject = jsonb.fromJson(reader, (Type) typeClass);
252237
if (value.equals(unmarshalledObject)) {
253-
return Status.passed("OK");
238+
return; // passed
254239
} else {
255-
return Status.failed(
240+
fail(
256241
"[testUnmarshallingByTypeFromReader] - Failed to correctly unmarshal "
257242
+ value.getClass().getName() + " object");
258243
}
259244
} catch (IOException e) {
260-
return Status.error(e.getMessage());
245+
fail(e.getMessage());
261246
}
262247
}
263248
}

tck/src/main/java/jakarta/json/bind/TypeContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* $Id$
1919
*/
2020

21-
package com.sun.ts.tests.jsonb;
21+
package jakarta.json.bind;
2222

2323
public interface TypeContainer<T> {
2424
T getInstance();

0 commit comments

Comments
 (0)