/*
 * Copyright 2015 Dmitry Ustalov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mtsar;

import io.dropwizard.testing.junit.ResourceTestRule;
import mtsar.api.Stage;
import mtsar.api.Task;
import mtsar.api.sql.TaskDAO;
import mtsar.resources.TaskResource;
import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;

import static mtsar.TestHelper.fixture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

public class TaskResourceTest {
    private static final TaskDAO dao = mock(TaskDAO.class);
    private static final Stage stage = mock(Stage.class);

    @ClassRule
    public static final ResourceTestRule RULE = ResourceTestRule.builder()
            .setTestContainerFactory(new GrizzlyTestContainerFactory())
            .addProperty("jersey.config.server.provider.classnames", "org.glassfish.jersey.media.multipart.MultiPartFeature")
            .addResource(new TaskResource(stage, dao, null, null))
            .build();

    private static final Task task = fixture("task1.json", Task.class);

    @Before
    public void setup() {
        when(stage.getId()).thenReturn("1");
        when(dao.find(eq(1), eq("1"))).thenReturn(task);
    }

    @Test
    public void testGetTask() {
        assertThat(RULE.getJerseyTest().target("/tasks/1").request()
                .get(Task.class))
                .isEqualTo(task);
        verify(dao).find(1, "1");
    }
}

@@ -933,39 +933,147 @@
 ort 
-static mtsar.TestHelper.fixture
+javax.ws.rs.client.Entity;%0Aimport javax.ws.rs.core.Response;%0A%0Aimport static mtsar.TestHelper.fixture;%0Aimport static mtsar.TestHelper.params
 ;%0Aim
@@ -2133,11 +2133,579 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testPostTask() %7B%0A        reset(dao);%0A        when(dao.insert(any(Task.class))).then((invocation) -%3E %7B%0A            final Task task = new Task.Builder().mergeFrom(invocation.getArgumentAt(0, Task.class)).setId(2).build();%0A            when(dao.find(eq(task.getId()), eq(task.getStage()))).thenReturn(task);%0A            return task.getId();%0A        %7D);%0A        assertThat(RULE.getJerseyTest().target(%22/tasks%22).request()%0A                .post(Entity.form(params(task))).getStatusInfo())%0A                .isEqualTo(Response.Status.CREATED);%0A    %7D
 %0A%7D%0A

Add testPostTask