/*
 * DatasourceConfigTest.java
 *
 * Copyright (C) 2018 [ A Legge Up ]
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

package com.aleggeup.confagrid.config;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.aleggeup.confagrid.filter.JwtFilter;

@RunWith(MockitoJUnitRunner.class)
public class SystemConfigTest {

    @Mock
    private CorsRegistry mockCorsRegistry;

    @Mock
    private CorsRegistration mockCorsRegistration;

    private SystemConfig systemConfig;

    @Before
    public void setUp() {
        systemConfig = new SystemConfig();
    }

    @After
    public void tearDown() {
        Mockito.verifyNoMoreInteractions(mockCorsRegistry, mockCorsRegistration);
    }

    @Test
    public void testCorsRegistration() {
        Mockito.when(mockCorsRegistration.allowedOrigins(SystemConfig.CORS_ALLOWED_ORIGINS))
            .thenReturn(mockCorsRegistration);
        Mockito.when(mockCorsRegistry.addMapping(SystemConfig.CORS_MAPPING)).thenReturn(mockCorsRegistration);
        Mockito.when(mockCorsRegistration.allowedHeaders("*")).thenReturn(mockCorsRegistration);
        Mockito.when(mockCorsRegistration.exposedHeaders(JwtFilter.HEADER_CLAIMS, JwtFilter.HEADER_CLAIMS_SUBJECT))
            .thenReturn(mockCorsRegistration);

        final WebMvcConfigurer configurer = systemConfig.corsConfigurer();
        configurer.addCorsMappings(mockCorsRegistry);

        Mockito.verify(mockCorsRegistry).addMapping(SystemConfig.CORS_MAPPING);
        Mockito.verify(mockCorsRegistration).allowedOrigins(SystemConfig.CORS_ALLOWED_ORIGINS);
        Mockito.verify(mockCorsRegistration).allowedHeaders("*");
        Mockito.verify(mockCorsRegistration).exposedHeaders(JwtFilter.HEADER_CLAIMS, JwtFilter.HEADER_CLAIMS_SUBJECT);
    }
}

@@ -435,24 +435,86 @@
 UnitRunner;%0A
+import org.springframework.web.bind.annotation.RequestMethod;%0A
 import org.s
@@ -1507,32 +1507,246 @@
 sRegistration);%0A
+        Mockito%0A            .when(mockCorsRegistration%0A                .allowedMethods(RequestMethod.GET.name(), RequestMethod.POST.name(), RequestMethod.PUT.name()))%0A            .thenReturn(mockCorsRegistration);%0A
         Mockito.
@@ -2296,16 +2296,169 @@
 IGINS);%0A
+        Mockito.verify(mockCorsRegistration)%0A            .allowedMethods(RequestMethod.GET.name(), RequestMethod.POST.name(), RequestMethod.PUT.name());%0A
         

Update test to handle new allowed methods in system config