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

import org.joda.time.DateTime;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unitils.reflectionassert.ReflectionComparatorMode;

import be.ehealth.business.mycarenetcommons.domain.CareReceiverId;
import be.ehealth.business.mycarenetcommons.domain.Routing;
import be.ehealth.technicalconnector.utils.ConnectorIOUtils;
import be.ehealth.technicalconnector.utils.MarshallerHelper;
import be.fgov.ehealth.globalmedicalfile.core.v1.RoutingType;


/**
 * Test for {@link RoutingMapper}
 * 
 * @author EHP
 * 
 */
public class RoutingMapperTest {

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


    @Test
    public void testRoutingMapper() throws Exception {
        MarshallerHelper<RoutingType, RoutingType> helper = new MarshallerHelper<RoutingType, RoutingType>(RoutingType.class, RoutingType.class);

        RoutingType routingExample = helper.toObjectNoRootElementRequired(ConnectorIOUtils.getBytes(ConnectorIOUtils.getResourceAsStream("/examples/routing.xml")));

        String niss = routingExample.getCareReceiver().getSsin();
        String mutuality = routingExample.getCareReceiver().getMutuality();
        String regWithMut = routingExample.getCareReceiver().getRegNrWithMut();
        DateTime dateReference = routingExample.getReferenceDate();

        // Create Routing object
        CareReceiverId careReceiver = new CareReceiverId(niss, regWithMut, mutuality);

        Routing input = new Routing();

        input.setPeriod(null);
        input.setCareReceiver(careReceiver);
        input.setReferenceDate(dateReference);

        RoutingType routingType = RoutingMapper.mapRoutingType(input);

        LOG.debug(helper.toStringNoRootElementRequired(routingType));

        org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals(routingExample, routingType, ReflectionComparatorMode.IGNORE_DEFAULTS);
    }
}
