<commit_before>package org.innovateuk.ifs.project.pendingpartner.controller;

import org.innovateuk.ifs.BaseControllerMockMVCTest;
import org.innovateuk.ifs.organisation.resource.OrganisationResource;
import org.innovateuk.ifs.project.pendingpartner.form.ProjectTermsForm;
import org.innovateuk.ifs.project.pendingpartner.populator.ProjectTermsModelPopulator;
import org.innovateuk.ifs.project.pendingpartner.viewmodel.ProjectTermsViewModel;
import org.innovateuk.ifs.project.projectteam.PendingPartnerProgressRestService;
import org.innovateuk.ifs.project.resource.ProjectResource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.innovateuk.ifs.commons.error.Error.fieldError;
import static org.innovateuk.ifs.commons.rest.RestResult.restFailure;
import static org.innovateuk.ifs.commons.rest.RestResult.restSuccess;
import static org.innovateuk.ifs.organisation.builder.OrganisationResourceBuilder.newOrganisationResource;
import static org.innovateuk.ifs.project.builder.ProjectResourceBuilder.newProjectResource;
import static org.mockito.Mockito.*;
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.*;

@RunWith(MockitoJUnitRunner.class)
public class ProjectTermsControllerTest extends BaseControllerMockMVCTest<ProjectTermsController> {

    private ProjectResource project;
    private OrganisationResource organisation;
    private boolean termsAccepted;
    private String competitionTermsTemplate;

    @Mock
    private ProjectTermsModelPopulator projectTermsModelPopulator;
    @Mock
    private PendingPartnerProgressRestService pendingPartnerProgressRestService;

    @Override
    protected ProjectTermsController supplyControllerUnderTest() {
        return new ProjectTermsController(projectTermsModelPopulator, pendingPartnerProgressRestService);
    }

    @Before
    public void setUp() {
        project = newProjectResource().withId(3L).build();
        organisation = newOrganisationResource().withId(5L).build();
        competitionTermsTemplate = "terms-template";
        termsAccepted = false;
    }

    @Test
    public void getTerms() throws Exception {
        ProjectTermsViewModel viewModel = new ProjectTermsViewModel(project.getId(), organisation.getId(), competitionTermsTemplate, termsAccepted, null);

        when(projectTermsModelPopulator.populate(project.getId(), organisation.getId())).thenReturn(viewModel);

        mockMvc.perform(get("/project/{projectId}/organisation/{organisationId}/terms-and-conditions", project.getId(), organisation.getId()))
                .andExpect(status().isOk())<commit_msg>IFS-6492 - Fix to failing unit test.<commit_after>package org.innovateuk.ifs.project.pendingpartner.controller;

import org.innovateuk.ifs.BaseControllerMockMVCTest;
import org.innovateuk.ifs.organisation.resource.OrganisationResource;
import org.innovateuk.ifs.project.pendingpartner.form.ProjectTermsForm;
import org.innovateuk.ifs.project.pendingpartner.populator.ProjectTermsModelPopulator;
import org.innovateuk.ifs.project.pendingpartner.viewmodel.ProjectTermsViewModel;
import org.innovateuk.ifs.project.projectteam.PendingPartnerProgressRestService;
import org.innovateuk.ifs.project.resource.ProjectResource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.innovateuk.ifs.commons.error.Error.fieldError;
import static org.innovateuk.ifs.commons.rest.RestResult.restFailure;
import static org.innovateuk.ifs.commons.rest.RestResult.restSuccess;
import static org.innovateuk.ifs.organisation.builder.OrganisationResourceBuilder.newOrganisationResource;
import static org.innovateuk.ifs.project.builder.ProjectResourceBuilder.newProjectResource;
import static org.mockito.Mockito.*;
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.*;

@RunWith(MockitoJUnitRunner.class)
public class ProjectTermsControllerTest extends BaseControllerMockMVCTest<ProjectTermsController> {

    private ProjectResource project;
    private OrganisationResource organisation;
    private boolean termsAccepted;
    private String competitionTermsTemplate;

    @Mock
    private ProjectTermsModelPopulator projectTermsModelPopulator;
    @Mock
    private PendingPartnerProgressRestService pendingPartnerProgressRestService;

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

    @Before
    public void setUp() {
        project = newProjectResource().withId(3L).build();
        organisation = newOrganisationResource().withId(5L).build();
        competitionTermsTemplate = "terms-template";
        termsAccepted = false;
    }

    @Test
    public void getTerms() throws Exception {
        ProjectTermsViewModel viewModel = new ProjectTermsViewModel(project.getId(), organisation.getId(), competitionTermsTemplate, termsAccepted, null);

        when(projectTermsModelPopulator.populate(project.getId(), organisation.getId())).thenReturn(viewModel);

        mockMvc.perform(get("/project/{projectId}/organisation/{organisationId}/terms-and-conditions", project.getId(), organisation.getId()))
                .andExpect(status().isOk())
{'fraction_non_alphanumeric': 0.09055944055944055, 'fraction_numerical': 0.0013986013986013986, 'mean_word_length': 5.835125448028674, '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': '2776656', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1564, 'n_words': 241}