package org.apereo.cas.services;

import org.apereo.cas.util.services.RegisteredServiceJsonSerializer;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.io.ClassPathResource;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

/**
 * Handles test cases for {@link JsonServiceRegistryDao}.
 *
 * @author Misagh Moayyed
 * @since 4.1.0
 */
public class JsonServiceRegistryDaoTests extends AbstractResourceBasedServiceRegistryDaoTests {

    @Before
    public void setUp() {
        try {
            this.dao = new JsonServiceRegistryDao(RESOURCE, false, mock(ApplicationEventPublisher.class));
        } catch (final Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    @Test
    public void verifyLegacyServiceDefn() throws Exception {
        final ClassPathResource resource = new ClassPathResource("Legacy-10000003.json");
        final RegisteredServiceJsonSerializer serializer = new RegisteredServiceJsonSerializer();
        final RegisteredService service = serializer.from(resource.getInputStream());
        assertNotNull(service);
    }
}

@@ -259,16 +259,90 @@
 esource;
+%0Aimport org.springframework.core.io.Resource;%0A%0Aimport java.io.IOException;
 %0A%0Aimport
@@ -1262,11 +1262,429 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void verifyExistingDefinitionForCompatibility() throws IOException %7B%0A        final Resource resource = new ClassPathResource(%22returnMappedAttributeReleasePolicyTest1.json%22);%0A        final RegisteredServiceJsonSerializer serializer = new RegisteredServiceJsonSerializer();%0A        final RegisteredService service = serializer.from(resource.getInputStream());%0A        assertNotNull(service);%0A    %7D
 %0A%7D%0A

Clean up transformations of multimaps into JSON