Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
add testcases.
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Mar 15, 2018
1 parent f2654b5 commit 03d77b6
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1500/Issue1588.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.alibaba.json.bvt.issue_1500;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Issue1588 extends TestCase {
public void test_for_issue() throws Exception {
String dateString = "2017-11-17 00:00:00";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("test", date);
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat));
System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX"));
}
}
25 changes: 25 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1600/Issue1665.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.alibaba.json.bvt.issue_1600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.util.TypeUtils;
import junit.framework.TestCase;

import java.util.Collection;

public class Issue1665 extends TestCase {
public void test_for_issue() throws Exception {
TypeReference<Collection<Model>> typeReference = new TypeReference<Collection<Model>>() {};


Collection<Model> collection = TypeUtils.cast(JSON.parse("[{\"id\":101}]"), typeReference.getType(), ParserConfig.getGlobalInstance());
assertEquals(1, collection.size());
Model model = collection.iterator().next();
assertEquals(101, model.id);
}

public static class Model {
public int id;
}
}
130 changes: 130 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1600/Issue_for_gaorui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.alibaba.json.bvt.issue_1600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import junit.framework.TestCase;

public class Issue_for_gaorui extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"@type\":\"java.util.HashMap\",\"COUPON\":[{\"@type\":\"com.alibaba.json.bvt.issue_1600.Issue_for_gaorui.PromotionTermDetail\",\"activityId\":\"1584034\",\"choose\":true,\"couponId\":1251068987,\"couponType\":\"limitp\",\"match\":true,\"realPrice\":{\"amount\":0.6,\"currency\":\"USD\"}}],\"grayTrade\":\"true\"}";

JSON.parseObject(json, Object.class, Feature.SupportAutoType);
}

public static class PromotionTermDetail {
/**
* 卡券Id
*/
private Long couponId;
/**
* 营销Id
*/
private String promotionId;
/**
* 实际单价
*/
private Money realPrice;
/**
* 活动Id
*/
private String activityId;

/**
* 卡券类型
*/
private String couponType;

/**
* 是否能够获取到该优惠
*/
private boolean isMatch = false;
/**
* 是否选择了该优惠
*/
private boolean isChoose = false;
/**
* 未获取到优惠的原因
*/
private String reasonForLose;
/**
* 未获取优惠的标识码
*/
private String codeForLose;

public Long getCouponId() {
return couponId;
}

public void setCouponId(Long couponId) {
this.couponId = couponId;
}

public String getPromotionId() {
return promotionId;
}

public void setPromotionId(String promotionId) {
this.promotionId = promotionId;
}

public Money getRealPrice() {
return realPrice;
}

public void setRealPrice(Money realPrice) {
this.realPrice = realPrice;
}

public String getActivityId() {
return activityId;
}

public void setActivityId(String activityId) {
this.activityId = activityId;
}

public String getCouponType() {
return couponType;
}

public void setCouponType(String couponType) {
this.couponType = couponType;
}

public boolean isMatch() {
return isMatch;
}

public void setMatch(boolean match) {
isMatch = match;
}

public boolean isChoose() {
return isChoose;
}

public void setChoose(boolean choose) {
isChoose = choose;
}

public String getReasonForLose() {
return reasonForLose;
}

public void setReasonForLose(String reasonForLose) {
this.reasonForLose = reasonForLose;
}

public String getCodeForLose() {
return codeForLose;
}

public void setCodeForLose(String codeForLose) {
this.codeForLose = codeForLose;
}
}

public static class Money {

}
}
13 changes: 13 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1700/Issue1761.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.alibaba.json.bvt.issue_1700;

import com.alibaba.fastjson.JSONObject;
import junit.framework.TestCase;

public class Issue1761 extends TestCase {
public void test_for_issue() throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("null","");
double d = jsonObject.getDoubleValue("null");
assertEquals(d, 0.0D);
}
}
10 changes: 4 additions & 6 deletions src/test/java/com/alibaba/json/bvt/kotlin/Issue1483.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ public void test_user() throws Exception {
Object obj = JSON.parseObject(json, clazz);
assertSame(clazz, obj.getClass());
//
// String text = JSON.parseObject(JSON.toJSONString(obj), Feature.OrderedField).toJSONString();
// if ("{\"age\":99,\"desc\":\"[robohorse\",\"name\":\"xx]\"}".equals(text)) {
// return;
// }
//
// assertEquals("{\"age\":99,\"desc\":\"xx\",\"name\":\"robohorse\"}", text);
for (int i = 0; i < 10; ++i) {
String text = JSON.parseObject(JSON.toJSONString(obj), Feature.OrderedField).toJSONString();
assertEquals("{\"age\":99,\"desc\":\"xx\",\"name\":\"robohorse\"}", text);
}
}

public static class ExtClassLoader extends ClassLoader {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.alibaba.json.bvt.parser.autoType;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import junit.framework.TestCase;

public class AutoTypeTest3_deny extends TestCase {
public void test_for_x() throws Exception {
Exception error = null;
try {
String json = "{\"@type\":\"java.util.logging.FileHandler\",\"pattern\":\"xxx.txt\"}";
Object obj = JSON.parse(json, Feature.SupportAutoType);
} catch (Exception ex) {
error = ex;
}
assertNotNull(error);
}

public void test_for_jar() throws Exception {
Exception error = null;
try {
String json = "{\"@type\":\"java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
Object obj = JSON.parse(json, Feature.SupportAutoType);
} catch (Exception ex) {
error = ex;
}
assertNotNull(error);
}

public void test_for_array() throws Exception {
Exception error = null;
try {
String json = "{\"@type\":\"[java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}";
Object obj = JSON.parse(json, Feature.SupportAutoType);
} catch (Exception ex) {
ex.printStackTrace();
error = ex;
}
assertNotNull(error);
}


public void test_for_array_1() throws Exception {
Exception error = null;
try {
String json = "{\"@type\":\"L[java.util.jar.JarFile.JarFile;\",\"name\":\"xxx.txt\"}";
Object obj = JSON.parse(json, Feature.SupportAutoType);
} catch (Exception ex) {
ex.printStackTrace();
error = ex;
}
assertNotNull(error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public void test_1 () throws Exception {
feature = SerializerFeature.config(feature, SerializerFeature.BrowserSecure, false);
Assert.assertEquals(false, SerializerFeature.isEnabled(feature, SerializerFeature.BrowserSecure));
}

public void test_assert_cnt() throws Exception {
int len = SerializerFeature.values().length;
assertTrue(len <= 32);
}
}

0 comments on commit 03d77b6

Please sign in to comment.