Skip to content

Commit ab437cf

Browse files
gurunraolukasj
authored andcommitted
jsonp signature test enhancements.
Signed-off-by: [email protected] <[email protected]>
1 parent 90d823d commit ab437cf

File tree

3 files changed

+102
-101
lines changed

3 files changed

+102
-101
lines changed

impl-tck/tck-tests/pom.xml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,6 @@
5656

5757
<build>
5858
<plugins>
59-
<plugin>
60-
<groupId>org.apache.maven.plugins</groupId>
61-
<artifactId>maven-dependency-plugin</artifactId>
62-
<version>3.2.0</version>
63-
<executions>
64-
<execution>
65-
<id>copy-jsonp-tck-signature-files</id>
66-
<phase>generate-test-sources</phase>
67-
<goals>
68-
<goal>unpack</goal>
69-
</goals>
70-
<configuration>
71-
<artifactItems>
72-
<artifactItem>
73-
<groupId>jakarta.json</groupId>
74-
<artifactId>jakarta.json-tck-tests</artifactId>
75-
<version>${jsonp-tck.version}</version>
76-
<type>jar</type>
77-
<overWrite>true</overWrite>
78-
</artifactItem>
79-
</artifactItems>
80-
<!-- We need the signature file, mapping file and package list file -->
81-
<includes>**/*sig-test*,**/*jakarta.json.sig_*,**/*sig-test-pkg-list.txt</includes>
82-
<outputDirectory>${project.build.directory}/signaturedirectory</outputDirectory>
83-
</configuration>
84-
</execution>
85-
</executions>
86-
</plugin>
8759
<plugin>
8860
<groupId>org.apache.maven.plugins</groupId>
8961
<artifactId>maven-dependency-plugin</artifactId>
@@ -120,9 +92,6 @@
12092
<dependenciesToScan>jakarta.json:jakarta.json-tck-tests</dependenciesToScan>
12193
<systemPropertyVariables>
12294
<jimage.dir>${project.build.directory}/jdk11-bundle</jimage.dir>
123-
<signature.mapfile>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest/sig-test.map</signature.mapfile>
124-
<signature.repositoryDir>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest</signature.repositoryDir>
125-
<signature.packagelist>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest/sig-test-pkg-list.txt</signature.packagelist>
12695
<signature.sigTestClasspath>${project.build.directory}/signaturedirectory/jakarta.json-api.jar:${project.build.directory}/jdk11-bundle/java.base:${project.build.directory}/jdk11-bundle/java.rmi:${project.build.directory}/jdk11-bundle/java.sql:${project.build.directory}/jdk11-bundle/java.naming</signature.sigTestClasspath>
12796
</systemPropertyVariables>
12897
</configuration>
@@ -149,9 +118,6 @@
149118
</includes>
150119
<systemPropertyVariables>
151120
<jimage.dir>${project.build.directory}/jdk11-bundle</jimage.dir>
152-
<signature.mapfile>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest/sig-test.map</signature.mapfile>
153-
<signature.repositoryDir>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest</signature.repositoryDir>
154-
<signature.packagelist>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest/sig-test-pkg-list.txt</signature.packagelist>
155121
<signature.sigTestClasspath>${project.build.directory}/signaturedirectory/jakarta.json-api.jar:${project.build.directory}/jdk11-bundle/java.base:${project.build.directory}/jdk11-bundle/java.rmi:${project.build.directory}/jdk11-bundle/java.sql:${project.build.directory}/jdk11-bundle/java.naming</signature.sigTestClasspath>
156122
</systemPropertyVariables>
157123
</configuration>

tck/tck-tests/src/main/java/jakarta/jsonp/tck/signaturetest/README

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,67 +30,21 @@ For TCK developers :-
3030

3131
The signature file name expected is jakarta.json.sig_${version} , where version is the api version for which the signature is generated.
3232

33-
2. Place the required files in the TCK folder :
34-
35-
All the below files has to be placed in the folder tck/tck-tests/src/main/java/jakarta/jsonp/tck/signaturetest, so they are included as part of the TCK jar during the build.
36-
37-
-The signature file generated from above of the name jakarta.json.sig_${version}
38-
-The mapping file will be named sig-test.map, it contains the api to version mapping. This file will be used to pick the right signature file when running the signature test.
39-
-The package list file will be named sig-test-pkg-list.txt, contains the list of packages tested.
40-
41-
4233

4334
For TCK users (to run the signature test as a Junit test) :-
4435

45-
1. The signature test related files will need to be extracted from the jar to a known location to be used for running the test.
46-
For eg: in maven we can use the below code to extract the signature file, mapping file and package list file to ${project.build.directory}/signaturedirectory.
47-
48-
<plugin>
49-
<groupId>org.apache.maven.plugins</groupId>
50-
<artifactId>maven-dependency-plugin</artifactId>
51-
<version>3.2.0</version>
52-
<executions>
53-
<execution>
54-
<id>copy-jsonp-tck-signature-files</id>
55-
<phase>generate-test-sources</phase>
56-
<goals>
57-
<goal>unpack</goal>
58-
</goals>
59-
<configuration>
60-
<artifactItems>
61-
<artifactItem>
62-
<groupId>jakarta.json</groupId>
63-
<artifactId>jakarta.json-tck-tests</artifactId>
64-
<version>${jsonp-tck.version}</version>
65-
<type>jar</type>
66-
<overWrite>true</overWrite>
67-
</artifactItem>
68-
</artifactItems>
69-
<!-- We need the signature file, mapping file and package list file -->
70-
<includes>**/*sig-test*,**/*jakarta.json.sig_*,**/*sig-test-pkg-list.txt</includes>
71-
<outputDirectory>${project.build.directory}/signaturedirectory</outputDirectory>
72-
</configuration>
73-
</execution>
74-
</executions>
75-
</plugin>
76-
2. Set the below system properties correctly :
36+
1.Set the below system properties correctly :
7737

7838
jimage.dir //The jdk9+(jdk11 for this release) will be extracted to this location as to use the Java modules in the path.
7939
optional.tech.packages.to.ignore // The optional package that should be ignored while running the signature test
80-
signature.mapfile //The full path of the signature mapping file
81-
signature.repositoryDir // The directory where the signature file is placed.
82-
signature.packagelist //The full path of the list of packages that will be tested.
8340
signature.sigTestClasspath // the sigTestClasspath that will contain the implementation jar that needs to be tested along with dependent jars.
8441

8542
For eg:
8643

8744
<jimage.dir>${project.build.directory}/jdk11-bundle</jimage.dir>
8845
<optional.tech.packages.to.ignore>jakarta.xml.bind</optional.tech.packages.to.ignore>
89-
<signature.mapfile>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest/sig-test.map</signature.mapfile>
90-
<signature.repositoryDir>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest</signature.repositoryDir>
91-
<signature.packagelist>${project.build.directory}/signaturedirectory/jakarta/jsonp/tck/signaturetest/sig-test-pkg-list.txt</signature.packagelist>
9246
<signature.sigTestClasspath>${project.build.directory}/signaturedirectory/jakarta.json-api.jar:${project.build.directory}/jdk11-bundle/java.base:${project.build.directory}/jdk11-bundle/java.rmi:${project.build.directory}/jdk11-bundle/java.sql:${project.build.directory}/jdk11-bundle/java.naming</signature.sigTestClasspath>
9347

94-
3. The signature test alone can be run using below command within jersey-tck/ directory.
48+
2. The signature test alone can be run using below command within impl-tck/ directory.
9549

96-
mvn clean verify -Dit.test=jakarta.jsonp.tck.signaturetest.**
50+
mvn clean test -Dtest=jakarta.jsonp.tck.signaturetest.jsonp.JSONPSigTest#signatureTest

tck/tck-tests/src/main/java/jakarta/jsonp/tck/signaturetest/jsonp/JSONPSigTest.java

Lines changed: 99 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@
3131
import jakarta.jsonp.tck.signaturetest.SigTestResult;
3232

3333

34-
import java.io.BufferedReader;
35-
import java.io.File;
36-
import java.io.InputStreamReader;
37-
import java.io.IOException;
38-
import java.io.PrintWriter;
39-
import java.io.PrintStream;
34+
import java.io.*;
4035

4136
import java.util.ArrayList;
4237
import java.util.Properties;
@@ -72,6 +67,62 @@ protected String[] getPackages(String vehicleName) {
7267

7368
}
7469

70+
71+
public File writeStreamToTempFile(InputStream inputStream, String tempFilePrefix, String tempFileSuffix) throws IOException {
72+
FileOutputStream outputStream = null;
73+
74+
try {
75+
File file = File.createTempFile(tempFilePrefix, tempFileSuffix);
76+
outputStream = new FileOutputStream(file);
77+
byte[] buffer = new byte[1024];
78+
while (true) {
79+
int bytesRead = inputStream.read(buffer);
80+
if (bytesRead == -1) {
81+
break;
82+
}
83+
outputStream.write(buffer, 0, bytesRead);
84+
}
85+
return file;
86+
}
87+
88+
finally {
89+
if (outputStream != null) {
90+
outputStream.close();
91+
}
92+
}
93+
}
94+
95+
public File writeStreamToSigFile(InputStream inputStream, String packageVersion) throws IOException {
96+
FileOutputStream outputStream = null;
97+
String tmpdir = System.getProperty("java.io.tmpdir");
98+
try {
99+
File sigfile = new File(tmpdir+File.separator+"jakarta.json.sig_"+packageVersion);
100+
if(sigfile.exists()){
101+
sigfile.delete();
102+
System.out.println("Existing signature file deleted to create new one");
103+
}
104+
if(!sigfile.createNewFile()){
105+
System.out.println("signature file is not created");
106+
}
107+
outputStream = new FileOutputStream(sigfile);
108+
byte[] buffer = new byte[1024];
109+
while (true) {
110+
int bytesRead = inputStream.read(buffer);
111+
if (bytesRead == -1) {
112+
break;
113+
}
114+
outputStream.write(buffer, 0, bytesRead);
115+
}
116+
return sigfile;
117+
}
118+
119+
finally {
120+
if (outputStream != null) {
121+
outputStream.close();
122+
}
123+
}
124+
}
125+
75126
/***** Boilerplate Code *****/
76127

77128

@@ -96,8 +147,8 @@ protected String[] getPackages(String vehicleName) {
96147
/*
97148
* @testName: signatureTest
98149
*
99-
* @assertion: A JSONB container must implement the required classes and APIs
100-
* specified in the JSONB Specification.
150+
* @assertion: A JSONP container must implement the required classes and APIs
151+
* specified in the JSONP Specification.
101152
*
102153
* @test_Strategy: Using reflection, gather the implementation specific
103154
* classes and APIs. Compare these results with the expected (required)
@@ -106,13 +157,40 @@ protected String[] getPackages(String vehicleName) {
106157
*/
107158
@Test
108159
public void signatureTest() throws Fault {
109-
System.out.println("$$$ JSONBSigTest.signatureTest() called");
160+
System.out.println("$$$ JSONPSigTest.signatureTest() called");
110161
SigTestResult results = null;
111-
String mapFile = System.getProperty("signature.mapfile");
112-
String repositoryDir = System.getProperty("signature.repositoryDir");
162+
String mapFile = null;
163+
String packageFile = null;
164+
String repositoryDir = null;
165+
Properties mapFileAsProps = null;
166+
try {
167+
168+
InputStream inStreamMapfile = JSONPSigTest.class.getClassLoader().getResourceAsStream("jakarta/jsonp/tck/signaturetest/sig-test.map");
169+
File mFile = writeStreamToTempFile(inStreamMapfile, "sig-test", ".map");
170+
mapFile = mFile.getCanonicalPath();
171+
System.out.println("mapFile location is :"+mapFile);
172+
173+
InputStream inStreamPackageFile = JSONPSigTest.class.getClassLoader().getResourceAsStream("jakarta/jsonp/tck/signaturetest/sig-test-pkg-list.txt");
174+
File pFile = writeStreamToTempFile(inStreamPackageFile, "sig-test-pkg-list", ".txt");
175+
packageFile = pFile.getCanonicalPath();
176+
System.out.println("packageFile location is :"+packageFile);
177+
178+
mapFileAsProps = getSigTestDriver().loadMapFile(mapFile);
179+
String packageVersion = mapFileAsProps.getProperty("jakarta.json");
180+
System.out.println("Package version from mapfile :"+ packageVersion);
181+
182+
InputStream inStreamSigFile = JSONPSigTest.class.getClassLoader().getResourceAsStream("jakarta/jsonp/tck/signaturetest/jakarta.json.sig_"+packageVersion);
183+
File sigFile = writeStreamToSigFile(inStreamSigFile, packageVersion);
184+
System.out.println("signature File location is :"+sigFile.getCanonicalPath());
185+
repositoryDir = System.getProperty("java.io.tmpdir");
186+
187+
188+
} catch(IOException ex){
189+
System.out.println("Exception while creating temp files :"+ex);
190+
}
191+
113192
String[] packages = getPackages(testInfo.getVehicle());
114193
String[] classes = getClasses(testInfo.getVehicle());
115-
String packageFile = System.getProperty("signature.packagelist");
116194
String testClasspath = System.getProperty("signature.sigTestClasspath");
117195
String optionalPkgToIgnore = testInfo.getOptionalTechPackagesToIgnore();
118196

@@ -168,10 +246,9 @@ public void signatureTest() throws Fault {
168246
// Call verifyJtaJarTest based on some conditions, please check the
169247
// comment for verifyJtaJarTest.
170248
if ("standalone".equalsIgnoreCase(testInfo.getVehicle())) {
171-
Properties mapFileAsProps = getSigTestDriver().loadMapFile(mapFile);
172249
if (mapFileAsProps == null || mapFileAsProps.size() == 0) {
173250
// empty signature file, something unusual
174-
System.out.println("JSONBSigTest.signatureTest() returning, " +
251+
System.out.println("JSONPSigTest.signatureTest() returning, " +
175252
"as signature map file is empty.");
176253
return;
177254
}
@@ -182,7 +259,7 @@ public void signatureTest() throws Fault {
182259
// jakarta.transaction
183260
String jtaVersion = mapFileAsProps.getProperty("jakarta.transaction");
184261
if (jtaVersion == null || "".equals(jtaVersion.trim())) {
185-
System.out.println("JSONBSigTest.signatureTest() returning, " +
262+
System.out.println("JSONPSigTest.signatureTest() returning, " +
186263
"as this is neither JTA TCK run, not Java EE CTS run.");
187264
return;
188265
}
@@ -198,16 +275,20 @@ public void signatureTest() throws Fault {
198275
verifyJtaJarTest();
199276
}
200277
}
201-
System.out.println("$$$ JSONBSigTest.signatureTest() returning");
278+
System.out.println("$$$ JSONPSigTest.signatureTest() returning");
202279
} catch (Exception e) {
203280
if (results != null && !results.passed()) {
204-
throw new Fault("JSONBSigTest.signatureTest() failed!, diffs found");
281+
throw new Fault("JSONPSigTest.signatureTest() failed!, diffs found");
205282
} else {
206283
System.out.println("Unexpected exception " + e.getMessage());
207284
throw new Fault("signatureTest failed with an unexpected exception", e);
208285
}
209286
}
210287
}
211288

289+
/*
290+
* Call the parent class's cleanup method.
291+
*/
292+
212293

213-
} // end class JSONBSigTest
294+
} // end class JSONPSigTest

0 commit comments

Comments
 (0)