Skip to content

Commit

Permalink
JSONB TCK pluggability test added
Browse files Browse the repository at this point in the history
Signed-off-by: David Kral <david.k.kral@oracle.com>
  • Loading branch information
Verdent committed Feb 9, 2022
1 parent 373f1a8 commit 91f3bd7
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/com/sun/ts/tests/jsonb/pluggability/build.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<!--
$Id$
-->
<project name="jsonb_pluggability" basedir="." default="usage">
<import file="../../../../../../../bin/xml/ts.nonleafimport.xml" />
</project>
148 changes: 148 additions & 0 deletions src/com/sun/ts/tests/jsonb/pluggability/jsonbprovidertests/Client.java
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

/*
* $Id$
*/
package com.sun.ts.tests.jsonb.pluggability.jsonbprovidertests;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;

import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.spi.JsonbProvider;

import com.sun.javatest.Status;
import com.sun.ts.lib.harness.ServiceEETest;

public class Client extends ServiceEETest {
private static final String MY_JSONBROVIDER_CLASS = "com.sun.ts.tests.jsonb.provider.MyJsonbProvider";
private static final String MY_JSONBBUILDER_CLASS = "com.sun.ts.tests.jsonb.provider.MyJsonbBuilder";

public static void main(String[] args) {
Client theTests = new Client();
Status s = theTests.run(args, System.out, System.err);
s.exit();
}


/* Test setup */

/*
* @class.setup_props:
*/
public void setup(String[] args, Properties p) throws Fault {
logMsg("setup ok");
}

public void cleanup() throws Fault {
logMsg("cleanup ok");
}

/* Tests */

/*
* @testName: jsonbProviderTest1
*
* @test_Strategy: Test call of SPI provider method with signature: o public
* static JsonbProvider provider()
*/
public void jsonbProviderTest1() throws Fault {
boolean pass = true;
try {
// Load my provider
JsonbProvider provider = JsonbProvider.provider();
String providerClass = provider.getClass().getName();
logMsg("provider class=" + providerClass);
if (providerClass.equals(MY_JSONBROVIDER_CLASS))
logMsg("Current provider is my provider - expected.");
else {
logErr("Current provider is not my provider - unexpected.");
pass = false;
ServiceLoader<JsonbProvider> loader = ServiceLoader.load(JsonbProvider.class);
Iterator<JsonbProvider> it = loader.iterator();
List<JsonbProvider> providers = new ArrayList<>();
while(it.hasNext()) {
providers.add(it.next());
}
logMsg("Providers: "+providers);
}
} catch (Exception e) {
throw new Fault("jsonbProviderTest1 Failed: ", e);
}
if (!pass)
throw new Fault("jsonbProviderTest1 Failed");
}

/*
* @testName: jsonbProviderTest2
*
* @test_Strategy: Test call of SPI provider method with signature: o public
* static JsonbProvider provider(String provider)
*/
public void jsonbProviderTest2() throws Fault {
boolean pass = true;
try {
// Load my provider
JsonbProvider provider = JsonbProvider.provider(MY_JSONBROVIDER_CLASS);
String providerClass = provider.getClass().getName();
logMsg("provider class=" + providerClass);
if (providerClass.equals(MY_JSONBROVIDER_CLASS))
logMsg("Current provider is my provider - expected.");
else {
logErr("Current provider is not my provider - unexpected.");
pass = false;
ServiceLoader<JsonbProvider> loader = ServiceLoader.load(JsonbProvider.class);
Iterator<JsonbProvider> it = loader.iterator();
List<JsonbProvider> providers = new ArrayList<>();
while(it.hasNext()) {
providers.add(it.next());
}
logMsg("Providers: "+providers);
}
} catch (Exception e) {
throw new Fault("jsonbProviderTest2 Failed: ", e);
}
if (!pass)
throw new Fault("jsonbProviderTest2 Failed");
}

/*
* @testName: jsonbProviderTest3
*
* @test_Strategy: Test call of provider method with signature: o public JsonbBuilder create()
*/
public void jsonbProviderTest3() throws Fault {
try {
// Load my provider
JsonbBuilder builder = JsonbProvider.provider(MY_JSONBROVIDER_CLASS).create();
String providerClass = builder.getClass().getName();
logMsg("jsonb builder class=" + providerClass);
if (providerClass.equals(MY_JSONBBUILDER_CLASS))
logMsg("Current jsonb builder is my builder - expected.");
else {
logErr("Current jsonb builder is not my builder - unexpected.");
throw new Fault("jsonbProviderTest3 Failed");
}
} catch (Exception e) {
throw new Fault("jsonbProviderTest3 Failed: ", e);
}
}

}
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<!--
$Id$
-->
<project name="jsonb_pluggability_jsonbprovidertests" basedir="." default="usage">
<import file="../../../../../../../../bin/xml/ts.import.xml" />
<property name="app.name" value="jsonbprovidertests" />
<property name="client.class" value="com.sun.ts.tests.jsonb.pluggability.jsonbprovidertests.Client"/>

<!-- Our test JsonProvider info -->
<property name="provider.class" value="com/sun/ts/tests/jsonb/provider/MyJsonbProvider.class"/>
<property name="provider.dir" value="${src.dir}/com/sun/ts/tests/jsonb/provider"/>
<property name="provider.jar" value="jsonb_alternate_provider.jar"/>

<!-- Build dependency test JsonbProvider jar -> jsonb_alternate_provider.jar -->
<target name="-precompile">
<echo message="Building dependency dir: ${provider.dir}"/>
<ant dir="${provider.dir}" target="build" inheritAll="false"/>
</target>

<!-- Build pluggability tests and package test provider jar within each ear -->
<target name="package">
<ts.vehicles name="${app.name}">
<ejb-elements/>
<client-elements/>
<servlet-elements>
<zipfileset dir="${ts.home}/lib" includes="${provider.jar}"
prefix="WEB-INF/lib"/>
</servlet-elements>
<jsp-elements>
<zipfileset dir="${ts.home}/lib" includes="${provider.jar}"
prefix="WEB-INF/lib"/>
</jsp-elements>
</ts.vehicles>
</target>
</project>
@@ -0,0 +1 @@
com.sun.ts.tests.jsonb.provider.MyJsonbProvider
42 changes: 42 additions & 0 deletions src/com/sun/ts/tests/jsonb/provider/MyJsonbBuilder.java
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

/*
* $Id$
*/
package com.sun.ts.tests.jsonb.provider;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import jakarta.json.spi.JsonProvider;

public class MyJsonbBuilder implements JsonbBuilder {
@Override
public JsonbBuilder withConfig(JsonbConfig jsonbConfig) {
return null;
}

@Override
public JsonbBuilder withProvider(JsonProvider jsonProvider) {
return null;
}

@Override
public Jsonb build() {
return null;
}
}
32 changes: 32 additions & 0 deletions src/com/sun/ts/tests/jsonb/provider/MyJsonbProvider.java
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

/*
* $Id$
*/
package com.sun.ts.tests.jsonb.provider;

import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.spi.JsonbProvider;

public class MyJsonbProvider extends JsonbProvider {

@Override
public JsonbBuilder create() {
return new MyJsonbBuilder();
}

}
49 changes: 49 additions & 0 deletions src/com/sun/ts/tests/jsonb/provider/build.xml
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<!--
$Id$
-->
<project name="jsonb_provider" basedir="." default="usage">
<import file="../../../../../../../bin/xml/ts.import.xml"/>

<property name="provider.jar" value="jsonb_alternate_provider.jar"/>

<target name="build">
<!-- compile classes -->
<ts.javac includes="${pkg.dir}/**">
<classpath>
<pathelement path="${ts.classpath}" />
</classpath>
</ts.javac>

<!-- build provider jar -->
<jar destfile="${lib.dir}/${provider.jar}">
<fileset dir="${class.dir}" includes="${pkg.dir}/*.class"/>
<fileset dir="${src.dir}/${pkg.dir}" includes="META-INF/services/jakarta.json.bind.spi.JsonbProvider"/>
</jar>
</target>

<target name="-preclean">
<delete failonerror="false">
<fileset dir="${lib.dir}" includes="${provider.jar}" />
</delete>
</target>

</project>

0 comments on commit 91f3bd7

Please sign in to comment.