<commit_before>package com.worth.ifs.assessment.controller;

import com.worth.ifs.BaseControllerMockMVCTest;
import com.worth.ifs.application.resource.ApplicationResource;
import com.worth.ifs.application.resource.QuestionResource;
import com.worth.ifs.assessment.model.AssessmentApplicationSummaryModelPopulator;
import com.worth.ifs.assessment.resource.AssessmentFeedbackResource;
import com.worth.ifs.assessment.service.AssessmentFeedbackService;
import com.worth.ifs.assessment.service.AssessmentService;
import com.worth.ifs.assessment.viewmodel.AssessmentApplicationSummaryQuestionViewModel;
import com.worth.ifs.assessment.viewmodel.AssessmentApplicationSummaryViewModel;
import com.worth.ifs.competition.resource.CompetitionResource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;

import java.util.List;

import static com.worth.ifs.application.builder.ApplicationResourceBuilder.newApplicationResource;
import static com.worth.ifs.application.builder.QuestionResourceBuilder.newQuestionResource;
import static com.worth.ifs.application.service.Futures.settable;
import static com.worth.ifs.assessment.builder.AssessmentFeedbackResourceBuilder.newAssessmentFeedbackResource;
import static com.worth.ifs.assessment.builder.AssessmentResourceBuilder.newAssessmentResource;
import static com.worth.ifs.competition.builder.CompetitionResourceBuilder.newCompetitionResource;
import static com.worth.ifs.user.builder.ProcessRoleResourceBuilder.newProcessRoleResource;
import static com.worth.ifs.util.MapFunctions.asMap;
import static java.lang.Boolean.TRUE;
import static java.time.LocalDateTime.now;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(MockitoJUnitRunner.class)
@TestPropertySource(locations = "classpath:application.properties")
public class AssessmentApplicationSummaryControllerTest extends BaseControllerMockMVCTest<AssessmentApplicationSummaryController> {

    @Mock
    private AssessmentService assessmentService;

    @Mock
    private AssessmentFeedbackService assessmentFeedbackService;

    @Spy
    @InjectMocks
    private AssessmentApplicationSummaryModelPopulator assessmentApplicationSummaryModelPopulator;

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

    @Test
    public void testGetSummary() throws Exception {
        Long competitionId = 1L;
        Long processRoleId = 2L;
        Long applicationId = 3L;
        Long assessmentId = 4L;

        when(assessmentService.getById(assessmentId)).thenReturn(newAssessmentResource()
                .withProcessRole(processRoleId)
                .build());

        when(processRoleService.getById(processRoleId)).thenReturn(settable(newProcessRoleResource()
                .withApplication(applicationId)
                .build()));

        ApplicationResource expectedApplication = newApplicationResource()
                .withCompetition(competitionId)
                .build();
        when(applicationService.getById(applicationId)).thenReturn(expectedApplication);

        CompetitionResource expectedCompetition = newCompetitionResource()
                .withAssessmentStartDate(now().minusDays(2))
                .withAssessmentEndDate(now().plusDays(4))
                .build();
        when(competitionService.getById(competitionId)).thenReturn(expectedCompetition);

        List<AssessmentFeedbackResource> assessmentFeedback = newAssessmentFeedbackResource()
                .withQuestion(1L, 2L)
                .build(2);

        List<QuestionResource> questions = newQuestionResource()
                .withId(1L, 2L)
                .withSection(2L, 2L)
                .withQuestionNumber("1", "2")
                .withShortName("Business opportunity", "Potential market")
                .withNeedingAssessorScore(TRUE, TRUE)
                .build(2);

        when(assessmentFeedbackService.getAllAssessmentFeedback(assessmentId))
                .thenReturn(assessmentFeedback);
        when(assessmentService.getAllQuestionsById(assessmentId)).thenReturn(questions);

        MvcResult result = mockMvc.perform(get("/{assessmentId}/summary", assessmentId))
                .andExpect(status().isOk())
                .andExpect(model().attributeExists("model"))
                .andExpect(view().name("assessor-application-summary"))
                .andReturn();

        AssessmentApplicationSummaryViewModel model = (AssessmentApplicationSummaryViewModel) result.getModelAndView().getModel().get("model");

        assertEquals(assessmentId, model.getAssessmentId());
        assertEquals(50, model.getDaysLeftPercentage());
        assertEquals(3, model.getDaysLeft());
        assertEquals(expectedCompetition, model.getCompetition());
        assertEquals(expectedApplication, model.getApplication());
        assertEquals(2, model.getQuestions().size());
        assertEquals(Integer.valueOf(21), model.getTotalScoreGiven());
        assertEquals(Integer.valueOf(100), model.getTotalScorePossible());
        assertEquals(Integer.valueOf(21), model.getTotalScorePercentage());

        AssessmentApplicationSummaryQuestionViewModel summaryQuestion1 = model.getQuestions().get(0);
        assertEquals(Long.valueOf(1L), summaryQuestion1.getQuestionId());
        assertEquals("Business opportunity", summaryQuestion1.getDisplayLabel());
        assertEquals("Q1", summaryQuestion1.getDisplayLabelShort());
        assertEquals(Integer.valueOf(10), summaryQuestion1.getScorePossible());<commit_msg>INFUND-550 Fixing test compilation error.<commit_after>package com.worth.ifs.assessment.controller;

import com.worth.ifs.BaseControllerMockMVCTest;
import com.worth.ifs.application.resource.ApplicationResource;
import com.worth.ifs.application.resource.QuestionResource;
import com.worth.ifs.assessment.model.AssessmentApplicationSummaryModelPopulator;
import com.worth.ifs.assessment.resource.AssessmentFeedbackResource;
import com.worth.ifs.assessment.service.AssessmentFeedbackService;
import com.worth.ifs.assessment.service.AssessmentService;
import com.worth.ifs.assessment.viewmodel.AssessmentApplicationSummaryQuestionViewModel;
import com.worth.ifs.assessment.viewmodel.AssessmentApplicationSummaryViewModel;
import com.worth.ifs.competition.resource.CompetitionResource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;

import java.util.List;

import static com.worth.ifs.application.builder.ApplicationResourceBuilder.newApplicationResource;
import static com.worth.ifs.application.builder.QuestionResourceBuilder.newQuestionResource;
import static com.worth.ifs.application.service.Futures.settable;
import static com.worth.ifs.assessment.builder.AssessmentFeedbackResourceBuilder.newAssessmentFeedbackResource;
import static com.worth.ifs.assessment.builder.AssessmentResourceBuilder.newAssessmentResource;
import static com.worth.ifs.competition.builder.CompetitionResourceBuilder.newCompetitionResource;
import static com.worth.ifs.user.builder.ProcessRoleResourceBuilder.newProcessRoleResource;
import static com.worth.ifs.util.MapFunctions.asMap;
import static java.lang.Boolean.TRUE;
import static java.time.LocalDateTime.now;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(MockitoJUnitRunner.class)
@TestPropertySource(locations = "classpath:application.properties")
public class AssessmentApplicationSummaryControllerTest extends BaseControllerMockMVCTest<AssessmentApplicationSummaryController> {

    @Mock
    private AssessmentService assessmentService;

    @Mock
    private AssessmentFeedbackService assessmentFeedbackService;

    @Spy
    @InjectMocks
    private AssessmentApplicationSummaryModelPopulator assessmentApplicationSummaryModelPopulator;

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

    @Test
    public void testGetSummary() throws Exception {
        Long competitionId = 1L;
        Long processRoleId = 2L;
        Long applicationId = 3L;
        Long assessmentId = 4L;

        when(assessmentService.getById(assessmentId)).thenReturn(newAssessmentResource()
                .withProcessRole(processRoleId)
                .build());

        when(processRoleService.getById(processRoleId)).thenReturn(settable(newProcessRoleResource()
                .withApplication(applicationId)
                .build()));

        ApplicationResource expectedApplication = newApplicationResource()
                .withCompetition(competitionId)
                .build();
        when(applicationService.getById(applicationId)).thenReturn(expectedApplication);

        CompetitionResource expectedCompetition = newCompetitionResource()
                .withAssessmentStartDate(now().minusDays(2))
                .withAssessmentEndDate(now().plusDays(4))
                .build();
        when(competitionService.getById(competitionId)).thenReturn(expectedCompetition);

        List<AssessmentFeedbackResource> assessmentFeedback = newAssessmentFeedbackResource()
                .withQuestion(1L, 2L)
                .build(2);

        List<QuestionResource> questions = newQuestionResource()
                .withId(1L, 2L)
                .withSection(2L, 2L)
                .withQuestionNumber("1", "2")
                .withShortName("Business opportunity", "Potential market")
                .build(2);

        when(assessmentFeedbackService.getAllAssessmentFeedback(assessmentId))
                .thenReturn(assessmentFeedback);
        when(assessmentService.getAllQuestionsById(assessmentId)).thenReturn(questions);

        MvcResult result = mockMvc.perform(get("/{assessmentId}/summary", assessmentId))
                .andExpect(status().isOk())
                .andExpect(model().attributeExists("model"))
                .andExpect(view().name("assessor-application-summary"))
                .andReturn();

        AssessmentApplicationSummaryViewModel model = (AssessmentApplicationSummaryViewModel) result.getModelAndView().getModel().get("model");

        assertEquals(assessmentId, model.getAssessmentId());
        assertEquals(50, model.getDaysLeftPercentage());
        assertEquals(3, model.getDaysLeft());
        assertEquals(expectedCompetition, model.getCompetition());
        assertEquals(expectedApplication, model.getApplication());
        assertEquals(2, model.getQuestions().size());
        assertEquals(Integer.valueOf(21), model.getTotalScoreGiven());
        assertEquals(Integer.valueOf(100), model.getTotalScorePossible());
        assertEquals(Integer.valueOf(21), model.getTotalScorePercentage());

        AssessmentApplicationSummaryQuestionViewModel summaryQuestion1 = model.getQuestions().get(0);
        assertEquals(Long.valueOf(1L), summaryQuestion1.getQuestionId());
        assertEquals("Business opportunity", summaryQuestion1.getDisplayLabel());
        assertEquals("Q1", summaryQuestion1.getDisplayLabelShort());
        assertEquals(Integer.valueOf(10), summaryQuestion1.getScorePossible());
{'fraction_non_alphanumeric': 0.094489491974185, 'fraction_numerical': 0.00637100777759391, 'mean_word_length': 4.415322580645161, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6352401', 'n_tokens_mistral': 3126, 'n_tokens_neox': 2960, 'n_words': 435}