package be.fgov.ehealth.technicalconnector.bootstrap.bcp.parser;

import be.ehealth.technicalconnector.exception.TechnicalConnectorException;
import be.ehealth.technicalconnector.utils.ConnectorIOUtils;
import be.fgov.ehealth.technicalconnector.bootstrap.bcp.domain.EndPointInformation;
import org.junit.Assert;
import org.junit.Test;

public class StatusPageParserIntegrationTest {

    @Test
    public void production_v1() throws TechnicalConnectorException {
        String xml = ConnectorIOUtils.getResourceAsString("https://servicelist.ehealth.fgov.be/servicelist.xml");
        EndPointInformation info = StatusPageParser.parse(xml);

        assertEndPointInformation(info, 0, 16, 24);
    }

    @Test
    public void production_v2() throws TechnicalConnectorException {
        String xml = ConnectorIOUtils.getResourceAsString("https://servicelist.ehealth.fgov.be/servicelistv2.xml");
        EndPointInformation info = StatusPageParser.parse(xml);

        assertEndPointInformation(info, 1, 16, 24);
    }

    @Test
    public void acceptance_V2() throws TechnicalConnectorException {
        String xml = ConnectorIOUtils.getResourceAsString("https://servicelist-acpt.ehealth.fgov.be/servicelistv2.xml");
        EndPointInformation info = StatusPageParser.parse(xml);

        assertEndPointInformation(info, 1, 16, 24);
    }

    @Test
    public void acceptance_V1() throws TechnicalConnectorException {
        String xml = ConnectorIOUtils.getResourceAsString("https://servicelist-acpt.ehealth.fgov.be/servicelist.xml");
        EndPointInformation info = StatusPageParser.parse(xml);

        assertEndPointInformation(info, 0, 16, 24);
    }

    public void assertEndPointInformation(EndPointInformation info, int... expected) {
        Assert.assertEquals(expected[0], info.getService2CacheInformation().size());
        Assert.assertEquals(expected[1], info.getService2AllEndpoints().size());
        Assert.assertEquals(expected[2], info.getUrl2Service().size());
    }
}
