package com.alibaba.json.bvt.issue_1341;


import com.alibaba.fastjson.support.jaxrs.FastJsonProvider;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.server.JSONP;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.Assert;
import org.junit.Test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import java.util.Date;

public class TestIssue1341 extends JerseyTest {

    @Path("book")
    public static class BookRestFul {

        @GET
        @Path("{id}")
        @Produces({"application/javascript", "application/json"})
        @JSONP(queryParam = "callback")
        public Book getBookById(@PathParam("id") Long id) {

            Book book = new Book();
            book.setBookId(2);
            book.setBookName("Python源码剖析");
            book.setPublisher("电子工业出版社");
            book.setPublishTime(new Date());
            book.setIsbn("911122");

            return book;
        }
    }

    @Override
    protected void configureClient(ClientConfig config) {
        config.register(new FastJsonFeature()).register(FastJsonProvider.class);
    }

    @Override
    protected Application configure() {
        enable(TestProperties.LOG_TRAFFIC);
        enable(TestProperties.DUMP_ENTITY);

        ResourceConfig config = new ResourceConfig();

        config.register(new FastJsonFeature()).register(new FastJsonProvider());
        config.packages("com.alibaba.json.bvt.issue_1341");
        return config;
    }

    @Test
    public void test() {

        final String reponse = target("book").path("123").request().accept("application/javascript").get(String.class);

        Assert.assertTrue(reponse.indexOf("Python源码剖析") > 0);
        Assert.assertTrue(reponse.indexOf("电子工业出版社") > 0);
        //Assert.assertTrue(reponse.indexOf("\"hello\":null") > 0);
    }

}

@@ -921,17 +921,17 @@
 tBookId(
-2
+0
 );%0A     
@@ -1089,24 +1089,463 @@
 %22911122%22);%0A%0A
+            return book;%0A        %7D%0A%0A        @GET%0A        @Path(%22/2/%7Bid%7D%22)%0A        @Produces(%7B%22application/javascript%22, %22application/json%22%7D)%0A        public Book getBookById2(@PathParam(%22id%22) Long id) %7B%0A%0A            Book book = new Book();%0A            book.setBookId(2);%0A            book.setBookName(%22Python%E6%BA%90%E7%A0%81%E5%89%96%E6%9E%902%22);%0A            book.setPublisher(%22%E7%94%B5%E5%AD%90%E5%B7%A5%E4%B8%9A%E5%87%BA%E7%89%88%E7%A4%BE2%22);%0A            book.setPublishTime(new Date());%0A            book.setIsbn(%22911122%22);%0A%0A
             
@@ -1934,90 +1934,8 @@
 g();
-%0A%0A        config.register(new FastJsonFeature()).register(new FastJsonProvider());
 %0A   
@@ -2174,24 +2174,85 @@
 ng.class);%0A%0A
+        Assert.assertTrue(reponse.indexOf(%22callback%22) %3E -1);%0A
         Asse
@@ -2368,63 +2368,286 @@
     
+%7D%0A%0A
     
-//Assert.assertTrue(reponse.indexOf(%22%5C%22hello%5C%22:null
+@Test%0A    public void test2() %7B%0A%0A        final String reponse = target(%22book%22).path(%22/2/123%22).request().accept(%22application/javascript%22).get(String.class);%0A%0A        Assert.assertTrue(reponse.indexOf(%22Python%E6%BA%90%E7%A0%81%E5%89%96%E6%9E%902%22) %3E 0);%0A        Assert.assertTrue(reponse.indexOf(%22%E7%94%B5%E5%AD%90%E5%B7%A5%E4%B8%9A%E5%87%BA%E7%89%88%E7%A4%BE2
 %22) %3E
@@ -2657,11 +2657,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

add testcase