package fr.adrienbrault.idea.symfony2plugin.tests.dic;

import fr.adrienbrault.idea.symfony2plugin.dic.ServiceMap;
import fr.adrienbrault.idea.symfony2plugin.dic.ServiceMapParser;
import org.junit.Test;
import org.junit.Assert;

import java.io.ByteArrayInputStream;

/**
 * @author Adrien Brault <adrien.brault@gmail.com>
 */
public class ServiceMapParserTest extends Assert {

    @Test
    public void testParse() throws Exception {
        ServiceMapParser serviceMapParser = new ServiceMapParser();

        String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<container>" +
                "<service id=\"adrienbrault\" class=\"AdrienBrault\\Awesome\"/>" +
                "<service id=\"secret\" class=\"AdrienBrault\\Secret\" public=\"false\"/>" +
                "<service id=\"translator\" alias=\"adrienbrault\"/>" +
            "</container>";
        ServiceMap serviceMap = serviceMapParser.parse(new ByteArrayInputStream(xmlString.getBytes()));

        assertTrue(serviceMap instanceof ServiceMap);

        assertEquals("AdrienBrault\\Awesome", serviceMap.getMap().get("adrienbrault"));
        assertEquals("AdrienBrault\\Awesome", serviceMap.getPublicMap().get("adrienbrault"));

        assertEquals("AdrienBrault\\Secret", serviceMap.getMap().get("secret"));
        assertNull(serviceMap.getPublicMap().get("secret"));

        assertEquals("Symfony\\Component\\HttpFoundation\\Request", serviceMap.getMap().get("request"));
        assertEquals("Symfony\\Component\\HttpFoundation\\Request", serviceMap.getPublicMap().get("request"));
        assertEquals("Symfony\\Component\\DependencyInjection\\ContainerInterface", serviceMap.getMap().get("service_container"));
        assertEquals("Symfony\\Component\\DependencyInjection\\ContainerInterface", serviceMap.getPublicMap().get("service_container"));
        assertEquals("Symfony\\Component\\HttpKernel\\KernelInterface", serviceMap.getMap().get("kernel"));
        assertEquals("Symfony\\Component\\HttpKernel\\KernelInterface", serviceMap.getPublicMap().get("kernel"));
        assertEquals("Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface", serviceMap.getMap().get("controller_resolver"));
        assertEquals("Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface", serviceMap.getPublicMap().get("controller_resolver"));

        assertEquals("AdrienBrault\\Awesome", serviceMap.getMap().get("translator"));
        assertEquals("AdrienBrault\\Awesome", serviceMap.getPublicMap().get("translator"));
    }

}

@@ -1365,1011 +1365,8 @@
 );%0A%0A
-        assertEquals(%22Symfony%5C%5CComponent%5C%5CHttpFoundation%5C%5CRequest%22, serviceMap.getMap().get(%22request%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CHttpFoundation%5C%5CRequest%22, serviceMap.getPublicMap().get(%22request%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CDependencyInjection%5C%5CContainerInterface%22, serviceMap.getMap().get(%22service_container%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CDependencyInjection%5C%5CContainerInterface%22, serviceMap.getPublicMap().get(%22service_container%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CHttpKernel%5C%5CKernelInterface%22, serviceMap.getMap().get(%22kernel%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CHttpKernel%5C%5CKernelInterface%22, serviceMap.getPublicMap().get(%22kernel%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CHttpKernel%5C%5CController%5C%5CControllerResolverInterface%22, serviceMap.getMap().get(%22controller_resolver%22));%0A        assertEquals(%22Symfony%5C%5CComponent%5C%5CHttpKernel%5C%5CController%5C%5CControllerResolverInterface%22, serviceMap.getPublicMap().get(%22controller_resolver%22));%0A%0A
     

drop tests for static service names on compiled container file