package ru.yandex.autoschool.splinter.PostResources;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Before;
import org.junit.Test;
import ru.yandex.autoschool.splinter.resources.PostResource;

import javax.ws.rs.core.Application;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
 * autor:maksim
 * date: 25.01.15
 * time: 15:13.
 */
public class PostTest extends JerseyTest {
    String title;
    String content;
    Response expectedResponse;
    Client client;
    WebResource webResource;
    @Before
    public void init(){
        client=Client.create();
        webResource=client.resource("http://localhost:8080/posts/new");
        title="test title";
        content="test content";
        expectedResponse=Response.ok().build();
    }
    @Override
    protected Application configure(){
        return new ResourceConfig(PostResource.class);
    }
    @Test
    public void shouldBeCreated(){
        MultivaluedMap formData = new MultivaluedMapImpl();
        formData.add("title", title);
        formData.add("content", content);
        ClientResponse actualResponse = webResource.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);
        assertThat(expectedResponse.getStatus(),is(actualResponse.getStatus()));
    }

}
@@ -375,24 +375,97 @@
 junit.Test;%0A
+import org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized;%0A
 import ru.ya
@@ -513,16 +513,16 @@
 source;%0A
-
 %0Aimport 
@@ -624,16 +624,41 @@
 esponse;
+%0Aimport java.util.Arrays;
 %0A%0Aimport
@@ -802,16 +802,46 @@
 13.%0A */%0A
+@RunWith(Parameterized.class)%0A
 public c
@@ -1140,30 +1140,102 @@
     
+%7D%0A
     
+public PostTest(String title,String content,Response response)%7B%0A        this.
 title=
-%22test 
 title
-%22
 ;%0A  
@@ -1244,16 +1244,21 @@
     
+this.
 content=
 %22tes
@@ -1257,69 +1257,494 @@
 ent=
-%22test content%22;%0A        expectedResponse=Response.ok().build(
+content;%0A        expectedResponse=response;%0A    %7D%0A    @Parameterized.Parameters(name = %22%7Bindex%7D: title:%7B0%7D ,content:%7B1%7D) expResponse%7B2%7D%22)%0A    public static Iterable%3CObject%5B%5D%3E data1() %7B%0A        return Arrays.asList(new Object%5B%5D%5B%5D%7B%0A                %7B%22test%22, %22test%22, Response.status(200).build()%7D,%0A                %7B%22%22,%22%22,Response.status(400).build()%7D,%0A                %7B%22%22,%22only content%22,Response.status(400).build()%7D,%0A                %7B%22only title%22,%22%22,Response.status(400).build()%7D%0A        %7D
 );%0A 
@@ -1871,16 +1871,18 @@
    @Test
+()
 %0A    pub
@@ -2200,24 +2200,22 @@
 ertThat(
-expected
+actual
 Response
@@ -2230,22 +2230,24 @@
 us(),is(
-actual
+expected
 Response

set parameters on post test