/**
 * Copyright 2015 d-fens GmbH
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 biz.dfch.activiti.wrapper.controller;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MockServletContext.class)
@WebAppConfiguration
public class ProcessInvocationControllerTest {

    private MockMvc mvc;

    @Before
    public void setUp() throws Exception {
        mvc = MockMvcBuilders.standaloneSetup(new ProcessInvocationController()).build();
    }

    @Test
    public void invokeProcess() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(content().string(equalTo("Greetings from Spring Boot!")));
    }
}

@@ -1848,16 +1848,51 @@
 eProcess
+WithValidPayloadReturnsHttpStatusOk
 () throw
@@ -1952,50 +1952,613 @@
 ers.
-ge
+pos
 t(%22/
-%22).accept(MediaType.APPLICATION_JSON
+api/process-invocation%22)%0A                .accept(MediaType.APPLICATION_JSON)%0A                .content(%22%7B%22 +%0A                        %22    %5C%22assetId%5C%22: %5C%22123%5C%22,%22 +%0A                        %22    %5C%22assetType%5C%22: %5C%22System%5C%22,%22 +%0A                        %22    %5C%22action%5C%22: %5C%22create%5C%22,%22 +%0A                        %22    %5C%22decisionId%5C%22: %5C%221234%5C%22,%22 +%0A                        %22    %5C%22userId%5C%22: %5C%2212345%5C%22,%22 +%0A                        %22    %5C%22tenantId%5C%22: %5C%22123456%5C%22,%22 +%0A                        %22    %5C%22type%5C%22: %5C%22PRE-ACTION%5C%22,%22 +%0A                        %22    %5C%22bpeURI%5C%22: %5C%22http://localhost%5C%22%22 +%0A                        %22%7D%22
 ))%0A 
@@ -2603,91 +2603,820 @@
 k())
+;
 %0A    
+%7D%0A%0A
     
-        .andExpect(content().string(equalTo(%22Greetings from Spring Boot!%22)
+@Test%0A    public void invokeProcessWithInValidPayloadReturnsHttpStatusBadRequest() throws Exception %7B%0A        mvc.perform(MockMvcRequestBuilders.post(%22/api/process-invocation%22)%0A                .accept(MediaType.APPLICATION_JSON)%0A                .content(%22%7B%22 +%0A                        %22    %5C%22assetId%5C%22: %5C%22%5C%22,%22 +%0A                        %22    %5C%22assetType%5C%22: %5C%22System%5C%22,%22 +%0A                        %22    %5C%22action%5C%22: %5C%22create%5C%22,%22 +%0A                        %22    %5C%22decisionId%5C%22: %5C%221234%5C%22,%22 +%0A                        %22    %5C%22userId%5C%22: %5C%2212345%5C%22,%22 +%0A                        %22    %5C%22tenantId%5C%22: %5C%22123456%5C%22,%22 +%0A                        %22    %5C%22type%5C%22: %5C%22PRE-ACTION%5C%22,%22 +%0A                        %22    %5C%22bpeURI%5C%22: %5C%22http://localhost%5C%22%22 +%0A                        %22%7D%22))%0A                .andExpect(status().isBadRequest(
 ));%0A

test class adjusted