package at.ac.tuwien.inso.integration_tests;

import at.ac.tuwien.inso.entity.*;
import at.ac.tuwien.inso.repository.*;
import org.junit.*;
import org.junit.runner.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.boot.test.autoconfigure.web.servlet.*;
import org.springframework.boot.test.context.*;
import org.springframework.test.context.*;
import org.springframework.test.context.junit4.*;
import org.springframework.test.web.servlet.*;
import org.springframework.transaction.annotation.*;

import static java.util.Arrays.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
@Transactional
public class SemestersTest {

    @Autowired
    MockMvc mockMvc;

    @Autowired
    private SemesterRepository semesterRepository;

    @Test
    public void itListsAllSemesters() throws Exception {
        Semester ss2016 = semesterRepository.save(new Semester(2016, SemesterType.SummerSemester));
        Semester ws2016 = semesterRepository.save(new Semester(2016, SemesterType.WinterSemester));

        mockMvc.perform(
                get("/admin/semester").with(user("admin").roles("ADMIN"))
        ).andExpect(
                model().attribute("allSemesters", asList(ws2016.toDto(), ss2016.toDto()))
        ).andExpect(
                model().attribute("currentSemester", ws2016.toDto())
        );
    }

}

@@ -39,16 +39,152 @@
 tests;%0A%0A
+import at.ac.tuwien.inso.clock.FixedClock;%0Aimport at.ac.tuwien.inso.clock.FixedClockListener;%0Aimport at.ac.tuwien.inso.dto.SemesterDto;%0A
 import a
@@ -554,24 +554,114 @@
 t.junit4.*;%0A
+import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;%0A
 import org.s
@@ -1166,16 +1166,128 @@
 ctional%0A
+@FixedClock%0A@TestExecutionListeners(%7BFixedClockListener.class, DependencyInjectionTestExecutionListener.class%7D)%0A
 public c
@@ -1421,69 +1421,262 @@
    @
-Test%0A    public void itListsAllSemesters() throws Exception %7B
+After%0A    public void terDown() %7B%0A        semesterRepository.deleteAll();%0A    %7D%0A%0A    @Test%0A    @FixedClock(%222016-11-11T11:00:00Z%22)%0A    public void itListsAllSemesters() throws Exception %7B%0A        // no new semester should be added since it already exists
 %0A   
@@ -2191,10 +2191,1289 @@
 %0A    %7D%0A%0A
+    @Test%0A    @FixedClock(%222020-11-11T11:00:00Z%22)%0A    public void itListsCurrentSemesterAsWS2020() throws Exception %7B%0A        SemesterDto expected = new SemesterDto(2020, SemesterType.WinterSemester);%0A%0A        mockMvc.perform(%0A                get(%22/admin/semester%22).with(user(%22admin%22).roles(%22ADMIN%22))%0A        ).andExpect(%0A                model().attribute(%22allSemesters%22, asList(expected))%0A        ).andExpect(%0A                model().attribute(%22currentSemester%22, expected)%0A        );%0A    %7D%0A%0A    @Test%0A    @FixedClock(%222019-05-11T11:00:00Z%22)%0A    public void itListsCurrentSemesterAsWS2019WithOlderSemesters() throws Exception %7B%0A%0A        // 2 older semesters already given%0A        Semester ss2016 = semesterRepository.save(new Semester(2016, SemesterType.SummerSemester));%0A        Semester ws2016 = semesterRepository.save(new Semester(2016, SemesterType.WinterSemester));%0A%0A        SemesterDto expected = new SemesterDto(2019, SemesterType.SummerSemester);%0A%0A        mockMvc.perform(%0A                get(%22/admin/semester%22).with(user(%22admin%22).roles(%22ADMIN%22))%0A        ).andExpect(%0A                model().attribute(%22allSemesters%22, asList(expected, ws2016.toDto(), ss2016.toDto()))%0A        ).andExpect(%0A                model().attribute(%22currentSemester%22, expected)%0A        );%0A    %7D%0A%0A
 %7D%0A

use the new FixedClock annotation to write tests with clock injection.