<commit_before>package org.innovateuk.ifs.survey;

import org.innovateuk.ifs.BaseControllerMockMVCTest;
import org.innovateuk.ifs.survey.controller.SurveyController;
import org.innovateuk.ifs.util.NavigationUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import static org.innovateuk.ifs.commons.rest.RestResult.restSuccess;
import static org.mockito.Mockito.when;
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.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

@RunWith(MockitoJUnitRunner.class)
public class SurveyControllerTest extends BaseControllerMockMVCTest<SurveyController> {

    @Mock
    private SurveyRestService surveyRestService;

    @Spy
    @SuppressWarnings("unused")
    private NavigationUtils navigationUtils;

    private String ifsWebBaseURL = "http://localhost:80";

    @Override
    protected SurveyController supplyControllerUnderTest() {
        return new SurveyController();
    }

    @Test
    public void viewFeedback() throws Exception {

        long competitionId = 1L;

        mockMvc.perform(get("/{competitionId}/feedback", competitionId))
                .andExpect(status().is2xxSuccessful())
                .andExpect(view().name("survey/survey"));
    }

    @Test
    public void submitFeedbackInvalid() throws Exception {

        long competitionId = 1L;

        SurveyResource surveyResource = new SurveyResource();

        surveyResource.setSurveyType(SurveyType.APPLICATION_SUBMISSION);
        surveyResource.setTargetType(SurveyTargetType.COMPETITION);
        surveyResource.setTargetId(competitionId);
        surveyResource.setSatisfaction(null);
        surveyResource.setComments(null);

        when(surveyRestService.save(surveyResource)).
                thenReturn(restSuccess());

        mockMvc.perform(post("/{competitionId}/feedback", competitionId))
                .andExpect(status().is2xxSuccessful())
                .andExpect(view().name("survey/survey"));

    }

    @Test
    public void submitFeedbackValid() throws Exception {

        ReflectionTestUtils.setField(navigationUtils, "ifsWebBaseURL", ifsWebBaseURL);<commit_msg>[IFS-11434] drop BaseUnitTest.java<commit_after>package org.innovateuk.ifs.survey;

import org.innovateuk.ifs.BaseControllerMockMVCTest;
import org.innovateuk.ifs.survey.controller.SurveyController;
import org.innovateuk.ifs.util.NavigationUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import static org.innovateuk.ifs.commons.rest.RestResult.restSuccess;
import static org.mockito.Mockito.when;
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.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

@RunWith(MockitoJUnitRunner.class)
public class SurveyControllerTest extends BaseControllerMockMVCTest<SurveyController> {

    @Mock
    private SurveyRestService surveyRestService;

    @Spy
    @SuppressWarnings("unused")
    private NavigationUtils navigationUtils;

    private String ifsWebBaseURL = "http://localhost:80";

    @Override
    protected SurveyController supplyControllerUnderTest() {
        return new SurveyController();
    }

    @Test
    public void viewFeedback() throws Exception {

        long competitionId = 1L;

        mockMvc.perform(get("/{competitionId}/feedback", competitionId))
                .andExpect(status().is2xxSuccessful())
                .andExpect(view().name("survey/survey"));
    }

    @Test
    public void submitFeedbackInvalid() throws Exception {

        long competitionId = 1L;

        SurveyResource surveyResource = new SurveyResource();

        surveyResource.setSurveyType(SurveyType.APPLICATION_SUBMISSION);
        surveyResource.setTargetType(SurveyTargetType.COMPETITION);
        surveyResource.setTargetId(competitionId);
        surveyResource.setSatisfaction(null);
        surveyResource.setComments(null);

        mockMvc.perform(post("/{competitionId}/feedback", competitionId))
                .andExpect(status().is2xxSuccessful())
                .andExpect(view().name("survey/survey"));

    }

    @Test
    public void submitFeedbackValid() throws Exception {

        ReflectionTestUtils.setField(navigationUtils, "ifsWebBaseURL", ifsWebBaseURL);
{'fraction_non_alphanumeric': 0.09737000602288697, 'fraction_numerical': 0.0034129692832764505, 'mean_word_length': 4.222222222222222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4235736', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1382, 'n_words': 219}