/*
 * Copyright (c) eHealth
 */
package be.ehealth.businessconnector.dmg.mappers;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import be.ehealth.business.mycarenetcommons.domain.CareProvider;
import be.ehealth.business.mycarenetcommons.domain.CommonInput;
import be.ehealth.business.mycarenetcommons.domain.Nihii;
import be.ehealth.business.mycarenetcommons.domain.Origin;
import be.ehealth.technicalconnector.config.util.domain.PackageInfo;
import be.ehealth.technicalconnector.utils.ConnectorIOUtils;
import be.ehealth.technicalconnector.utils.MarshallerHelper;
import be.fgov.ehealth.globalmedicalfile.core.v1.CommonInputType;
import be.fgov.ehealth.technicalconnector.tests.utils.XmlAsserter;


/**
 * Test for {@link CommonInputMapper}
 * 
 * @author EHP
 * 
 */
public class CommonInputMapperTest {

    private static final Logger LOG = LoggerFactory.getLogger(CommonInputMapperTest.class);

    @Test
    public void testCommonInputMapping() throws Exception {
        MarshallerHelper<CommonInputType, CommonInputType> helper = new MarshallerHelper<CommonInputType, CommonInputType>(CommonInputType.class, CommonInputType.class);
        CommonInputType commonInputExample = helper.toObjectNoRootElementRequired(ConnectorIOUtils.getBytes(ConnectorIOUtils.getResourceAsStream("/examples/commonInput-dmg.xml")));

        Boolean istest = commonInputExample.getRequest().isIsTest();
        String ref = new String(commonInputExample.getInputReference());
        Nihii nihii = new Nihii(commonInputExample.getOrigin().getCareProvider().getNihii().getQuality(), commonInputExample.getOrigin().getCareProvider().getNihii().getValue().getValue());
        CareProvider careProvider = new CareProvider(nihii);
        Origin origin = new Origin(new PackageInfo(commonInputExample.getOrigin().getPackage().getName().getValue(), commonInputExample.getOrigin().getPackage().getLicense().getUsername(), commonInputExample.getOrigin().getPackage().getLicense().getPassword()), careProvider);
        origin.setSiteId(commonInputExample.getOrigin().getSiteID().getValue());
        CommonInput input = new CommonInput(istest, origin, ref);
        CommonInputType output = CommonInputMapper.mapCommonInputType(input);

        LOG.debug(helper.toStringNoRootElementRequired(output));
        XmlAsserter.assertSimilar(helper.toStringNoRootElementRequired(commonInputExample), helper.toStringNoRootElementRequired(output));
    }

}
