package de.digitalcollections.iiif.presentation.frontend.impl.springmvc.controller.v2;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = TestConfiguration.class)
public class IIIFPresentationApiControllerTest {

  @Autowired
  protected IIIFPresentationApiController iiifController;

  private MockMvc mockMvc;

  @SuppressWarnings("SpringJavaAutowiringInspection")
  @Autowired
  protected WebApplicationContext wac;

  @BeforeClass
  public static void beforeClass() {
    System.setProperty("spring.profiles.active", "TEST");
  }

  @Before
  public void setup() {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
  }

  /**
   * Test of getManifest method, of class IIIFPresentationApiController.
   */
  @Test
  public void testGetManifest() throws Exception {
    mockMvc.perform(get("/presentation/" + IIIFPresentationApiController.VERSION + "/abcdef/manifest"))
            .andExpect(status().isOk());
  }

}

@@ -507,16 +507,75 @@
 ockMvc;%0A
+import org.springframework.test.web.servlet.ResultActions;%0A
 import s
@@ -653,16 +653,104 @@
 rs.get;%0A
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;%0A
 import s
@@ -1855,10 +1855,391 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void testCorsHeadersArePresent() throws Exception %7B%0A    ResultActions result = mockMvc.perform(get(%22/presentation/%22 + IIIFPresentationApiController.VERSION + %22/abcdef/manifest%22)%0A        .header(%22Origin%22, %22http://example.com%22));%0A    result.andExpect(status().isOk());%0A    result.andExpect(header().string(%22Access-Control-Allow-Origin%22, %22http://example.com%22));%0A  %7D%0A%0A
 %7D%0A

Add test to verify CORS headers are present