/*
 * Copyright (C) 2016 Dominik Schadow, dominikschadow@gmail.com
 *
 * This file is part of the Application Intrusion Detection project.
 *
 * 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 de.dominikschadow.dukeencounters.encounter;

import de.dominikschadow.dukeencounters.DukeEncountersApplication;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Tests the [@link EncounterController} class.
 *
 * @author Dominik Schadow
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DukeEncountersApplication.class)
@WebAppConfiguration
public class EncounterControllerTest {
    @Autowired
    private WebApplicationContext context;

    private MockMvc mvc;

    @Before
    public void setup() {
        mvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();
    }

    @Test
    public void listEncounters() throws Exception {
        mvc.perform(get("/encounters"))
                .andExpect(status().isOk())
                .andExpect(view().name("encounters"))
                .andExpect(model().attributeExists("encounters"))
                .andExpect(model().attribute("encounters", hasSize(21)));
    }

    @Test
    public void searchEncounter() throws Exception {
        mvc.perform(post("/encounters").with(csrf())
                .contentType(MediaType.APPLICATION_FORM_URLENCODED)
                .param("event", "JavaOne 2015")
                .param("location", "San Francisco")
                .param("likelihood", "ANY")
                .param("country", "USA"))
                .andExpect(status().isOk())
                .andExpect(view().name("encounters"))
                .andExpect(model().attribute("encounters", hasSize(1)));
    }
}

@@ -20,9 +20,9 @@
  201
-6
+7
  Dom
@@ -1372,57 +1372,8 @@
 t;%0A%0A
-import static org.hamcrest.Matchers.greaterThan;%0A
 impo
@@ -2735,16 +2735,58 @@
 ncounter
+WithCompleteSearchFilterShouldReturnResult
 () throw
@@ -3104,16 +3104,648 @@
 , %22USA%22)
+%0A                .param(%22year%22, %222015%22)%0A                .param(%22confirmations%22, %221%22))%0A                .andExpect(status().isOk())%0A                .andExpect(view().name(%22encounters%22))%0A                .andExpect(model().attribute(%22encounters%22, hasSize(1)));%0A    %7D%0A%0A    @Test%0A    public void searchEncounterWithMinimalisticSearchFilterShouldReturnResult() throws Exception %7B%0A        mvc.perform(post(%22/encounters%22).with(csrf())%0A                .contentType(MediaType.APPLICATION_FORM_URLENCODED)%0A                .param(%22event%22, %22JavaOne%22)%0A                .param(%22location%22, %22San Francisco%22)%0A                .param(%22likelihood%22, %22ANY%22)
 )%0A      
@@ -3828,32 +3828,32 @@
 (%22encounters%22))%0A
-
                 
@@ -3895,30 +3895,31 @@
 nters%22, hasSize(
+2
 1)));%0A    %7D%0A%7D%0A

Test complete search filter