package be.ehealth.technicalconnector.service.sts;

import be.ehealth.technicalconnector.exception.TechnicalConnectorException;
import be.ehealth.technicalconnector.service.sts.security.SAMLToken;
import be.ehealth.technicalconnector.session.AbstractSessionManagerIntegrationTest;
import be.ehealth.technicalconnector.session.Session;
import be.ehealth.technicalconnector.session.SessionItem;
import org.junit.Assert;
import org.junit.Test;

import static be.ehealth.technicalconnector.service.sts.security.SAMLToken.Version.SAML1_1;
import static be.ehealth.technicalconnector.service.sts.security.SAMLToken.Version.SAML2_0;

public class SAMLTokenExchangeServiceIntegrationTest extends AbstractSessionManagerIntegrationTest {

    @Test
    public void test() throws TechnicalConnectorException {
        SessionItem session = Session.getInstance().createFallbackSession(props.getProperty("test.session.holderofkey.password"), props.getProperty("test.session.encryption.password"));
        Assert.assertEquals(1, session.getActiveSAMLTokenVersions().size());
        Assert.assertEquals(SAMLToken.Version.SAML1_1, session.getActiveSAMLTokenVersions().get(0));

        SAMLToken saml11Token = session.getSAMLToken(SAML1_1);
        Assert.assertEquals(SAML1_1, saml11Token.getSamlVersion());
        Assert.assertEquals(1, session.getActiveSAMLTokenVersions().size());
        Assert.assertEquals(SAMLToken.Version.SAML1_1, session.getActiveSAMLTokenVersions().get(0));

        SAMLToken saml20Token = session.getSAMLToken(SAML2_0);
        Assert.assertEquals(SAML2_0, saml20Token.getSamlVersion());
        Assert.assertEquals(2, session.getActiveSAMLTokenVersions().size());

    }
}