Skip to content

Commit

Permalink
Modified json-lib ITs to cover more versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lioolli committed May 25, 2015
1 parent cc2e3f8 commit f51e9eb
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 140 deletions.
15 changes: 12 additions & 3 deletions agent/pom.xml
Expand Up @@ -35,6 +35,11 @@


<!-- for tests -->
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand All @@ -52,10 +57,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-test</artifactId>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -95,7 +103,8 @@
</execution>
</executions>
<configuration>
<!-- AbstractPinpointPluginTestSuite needs this to resolve path of required jars -->
<!-- AbstractPinpointPluginTestSuite needs this to resolve
path of required jars -->
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
Expand Down
Expand Up @@ -14,70 +14,43 @@
*/
package com.navercorp.pinpoint.plugin.json_lib;

import static com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.ExpectedAnnotation.*;

import java.lang.reflect.Method;

import net.sf.json.JSONArray;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.BlockType;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.ExpectedAnnotation;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.JvmVersion;

import net.sf.json.JSONSerializer;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import net.sf.json.JSON;

/**
*@author Sangyoon Lee
*/
@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent("target/pinpoint-agent-1.5.0-SNAPSHOT")
@Dependency({"log4j:log4j:1.2.17", "net.sf.json-lib:json-lib:jar:jdk15:2.3"})
@JvmVersion({6,7})
@Dependency({"net.sf.json-lib:json-lib:jar:jdk15:[1.0,)"})
public class JsonLibJSONArrayIT {

@Test
public void fromObjecttest() throws Exception {
public void jsonToArrayTest() throws Exception {
Method fromObject = JSONArray.class.getMethod("fromObject", Object.class);
Method toArray = JSONArray.class.getMethod("toArray", JSONArray.class);

String test = "[{'string':'JSON'}]";

JSONArray jsn = new JSONArray();
jsn.fromObject(test);
JSONArray jsn = JSONArray.fromObject(test);
// JSONArray.toArray() of json-lib 2.0 and below have different return type. so we invoke it by reflection to avoid NoSuchMethodError
toArray.invoke(null, jsn);

PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache(System.out);
verifier.printBlocks(System.out);

Method targetMethod = JSONArray.class.getMethod("fromObject", Object.class);

verifier.verifyApi("JsonLib", targetMethod);
verifier.verifyTraceBlockCount(0);
}

@Test
public void toArraytest() throws Exception {

JSONObject obj = new JSONObject();
JSONArray test = new JSONArray();
test.add(obj);

JSONArray.toArray(test);

PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache(System.out);
verifier.printBlocks(System.out);
verifier.verifyApi("JSON-LIB", fromObject);
verifier.verifyApi("JSON-LIB", toArray);

Method targetMethod = JSONArray.class.getMethod("toArray", JSONArray.class);

verifier.verifyApi("JsonLib", targetMethod);
verifier.verifyTraceBlockCount(1);
verifier.verifyTraceBlockCount(0);
}
}
Expand Up @@ -14,68 +14,42 @@
*/
package com.navercorp.pinpoint.plugin.json_lib;

import static com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.ExpectedAnnotation.*;

import java.lang.reflect.Method;

import net.sf.json.JSONObject;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.BlockType;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.ExpectedAnnotation;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.JvmVersion;

import net.sf.json.JSONSerializer;
import net.sf.json.JSONObject;
import net.sf.json.JSON;

/**
*@author Sangyoon Lee
*/
@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent("target/pinpoint-agent-1.5.0-SNAPSHOT")
@Dependency({"log4j:log4j:1.2.17", "net.sf.json-lib:json-lib:jar:jdk15:2.3"})
@JvmVersion({6,7})
@Dependency({"net.sf.json-lib:json-lib:jar:jdk15:[1.0,)"})
public class JsonLibJSONObjectIT {

@Test
public void fromObjecttest() throws Exception {

public void jsonToBeanTest() throws Exception {
String test = "{'string':'JSON'}";

JSONObject jsn = new JSONObject();
jsn.fromObject(test);
JSONObject jsn = JSONObject.fromObject(test);
JSONObject.toBean(jsn);

PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache(System.out);
verifier.printBlocks(System.out);

Method targetMethod = JSONObject.class.getMethod("fromObject", Object.class);

verifier.verifyApi("JsonLib", targetMethod);
verifier.verifyTraceBlockCount(0);
}

@Test
public void toBeantest() throws Exception {

JSONObject test = new JSONObject();
test.put("string", "JSON");

JSONObject.toBean(test);
Method fromObject = JSONObject.class.getMethod("fromObject", Object.class);
Method toBean = JSONObject.class.getMethod("toBean", JSONObject.class);

PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache(System.out);
verifier.printBlocks(System.out);
verifier.verifyApi("JSON-LIB", fromObject);
verifier.verifyApi("JSON-LIB", toBean);

Method targetMethod = JSONObject.class.getMethod("toBean", JSONObject.class);

verifier.verifyApi("JsonLib", targetMethod);
verifier.verifyTraceBlockCount(0);
}
}
Expand Up @@ -14,69 +14,50 @@
*/
package com.navercorp.pinpoint.plugin.json_lib;

import static com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.ExpectedAnnotation.*;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.BlockType;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier.ExpectedAnnotation;
import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import com.navercorp.pinpoint.test.plugin.JvmVersion;

import net.sf.json.JSONSerializer;
import net.sf.json.JSONObject;
import net.sf.json.JSON;

/**
*@author Sangyoon Lee
*/
@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent("target/pinpoint-agent-1.5.0-SNAPSHOT")
@Dependency({"log4j:log4j:1.2.17", "net.sf.json-lib:json-lib:jar:jdk15:2.3"})
@JvmVersion({6,7})
@Dependency({"net.sf.json-lib:json-lib:jar:jdk15:[1.0,)"})
public class JsonLibJSONSerializerIT {

@Test
public void toJSONtest() throws Exception {
public void test() throws Exception {
Method toJSON = JSONSerializer.class.getMethod("toJSON", Object.class);
Method toJava = JSONSerializer.class.getMethod("toJava", JSON.class);

String test = "{'string':'JSON'}";

JSONSerializer jsn = new JSONSerializer();
jsn.toJSON(test);
JSON json = JSONSerializer.toJSON(test);

PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache(System.out);
verifier.printBlocks(System.out);
if (Modifier.isStatic(toJava.getModifiers())) {
toJava.invoke(null, json);
} else {
// JSONSerializer.toJava(JSON) of json-lib 2.0 and below is instance method.
toJava.invoke(new JSONSerializer(), json);
}

Method targetMethod = JSONSerializer.class.getMethod("toJSON", Object.class);

verifier.verifyApi("JsonLib", targetMethod);
verifier.verifyTraceBlockCount(0);
}

@Test
public void toJAVAtest() throws Exception {

JSONObject test = new JSONObject();
test.put("string", "JSON");

JSONSerializer jsn = new JSONSerializer();
jsn.toJava(test);

PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache(System.out);
verifier.printBlocks(System.out);

Method targetMethod = JSONSerializer.class.getMethod("toJava", JSON.class);

verifier.verifyApi("JsonLib", targetMethod);
verifier.verifyTraceBlockCount(1);
verifier.verifyApi("JSON-LIB", toJSON);
verifier.verifyApi("JSON-LIB", toJava);
verifier.verifyTraceBlockCount(0);
}
}
14 changes: 0 additions & 14 deletions plugins/json-lib/pom.xml
Expand Up @@ -16,20 +16,6 @@
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap</artifactId>
</dependency>

<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>

</dependencies>
</project>
Expand Up @@ -24,5 +24,5 @@
*
*/
public interface JsonLibConstants {
public static final ServiceType SERVICE_TYPE = ServiceType.of(10000, "JsonLib", NORMAL_SCHEMA);
public static final ServiceType SERVICE_TYPE = ServiceType.of(5012, "JSON-LIB", NORMAL_SCHEMA);
}
Expand Up @@ -31,6 +31,7 @@
*
*/
public class JsonLibPlugin implements ProfilerPlugin {
private static final String GROUP = "json-lib";

@Override
public void setup(ProfilerPluginContext context) {
Expand All @@ -41,29 +42,29 @@ public void setup(ProfilerPluginContext context) {

private void addJSONSerializerInterceptor(ProfilerPluginContext context) {
ClassFileTransformerBuilder builder = context.getClassFileTransformerBuilder("net.sf.json.JSONSerializer");
builder.editMethod("toJSON", "java.lang.Object").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE);
builder.editMethod("toJSON", "java.lang.Object").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE).group(GROUP);

builder.editMethod("toJava", "net.sf.json.JSON").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE);
builder.editMethod("toJava", "net.sf.json.JSON").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE).group(GROUP);
ClassFileTransformer transformer = builder.build();
context.addClassFileTransformer(transformer);
}

private void addJSONObjectInterceptor(ProfilerPluginContext context) {
ClassFileTransformerBuilder builder = context.getClassFileTransformerBuilder("net.sf.json.JSONObject");

builder.editMethod("fromObject", "java.lang.Object").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE);
builder.editMethod("fromObject", "java.lang.Object").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE).group(GROUP);

builder.editMethod("toBean", "net.sf.json.JSONObject").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE);
builder.editMethod("toBean", "net.sf.json.JSONObject").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE).group(GROUP);

ClassFileTransformer transformer = builder.build();
context.addClassFileTransformer(transformer);
}

private void addJSONArrayInterceptor(ProfilerPluginContext context) {
ClassFileTransformerBuilder builder = context.getClassFileTransformerBuilder("net.sf.json.JSONArray");
builder.editMethod("fromObject", "java.lang.Object").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE);
builder.editMethod("fromObject", "java.lang.Object").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE).group(GROUP);

builder.editMethod("toArray", "net.sf.json.JSONArray").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE);
builder.editMethod("toArray", "net.sf.json.JSONArray").injectInterceptor("com.navercorp.pinpoint.bootstrap.interceptor.BasicMethodInterceptor", JsonLibConstants.SERVICE_TYPE).group(GROUP);

ClassFileTransformer transformer = builder.build();
context.addClassFileTransformer(transformer);
Expand Down
8 changes: 4 additions & 4 deletions plugins/pom.xml
Expand Up @@ -10,16 +10,16 @@
<artifactId>pinpoint-plugins</artifactId>
<name>pinpoint-plugins</name>
<packaging>pom</packaging>

<modules>
<module>httpclient4</module>
<module>gson</module>
<module>jdbc-driver</module>
<module>jdk-http</module>
<module>redis</module>
<module>servlet</module>
<module>tomcat</module>
<module>json-lib</module>
<module>tomcat</module>
<module>json-lib</module>
</modules>

<dependencies>
Expand Down Expand Up @@ -64,7 +64,7 @@
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down

0 comments on commit f51e9eb

Please sign in to comment.