/*
 * Copyright (c) eHealth
 */
package be.ehealth.businessconnector.dics.validator;

import static org.junit.Assert.assertTrue;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Test;

import be.ehealth.technicalconnector.exception.TechnicalConnectorException;
import be.ehealth.technicalconnector.utils.ConnectorIOUtils;
import be.ehealth.technicalconnector.utils.MarshallerHelper;
import be.fgov.ehealth.dics.protocol.v1.FindCNKResponse;


/**
 * tests the class XmlValidator.
 * 
 * @author EH076
 * 
 * @since
 * 
 */
public class XmlValidatorTest {

    /**
     * Test method for {@link be.ehealth.businessconnector.dics.validator.XmlValidator#validateXml(java.lang.Object)}.
     */
    @Test
    public void testValidateFindCNKResponse() throws TechnicalConnectorException, FileNotFoundException {
        String path = ConnectorIOUtils.getResourceFilePath("/response/findCNKResponse.xml");
        MarshallerHelper<FindCNKResponse, FindCNKResponse> helper = new MarshallerHelper<FindCNKResponse, FindCNKResponse>(FindCNKResponse.class, FindCNKResponse.class);
        FindCNKResponse xmlObject = helper.toObject(new FileInputStream(path));
        // fix $ {ignore} content
        xmlObject.setId("dummyId");
        xmlObject.setIssueInstant(new DateTime());
        XmlValidator.validateXml(xmlObject);
    }


    @Test
    public void testConstructorIsPrivate() throws Exception {
        Constructor<XmlValidator> constructor = XmlValidator.class.getDeclaredConstructor();
        assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));

        constructor.setAccessible(true);
        try {
            constructor.newInstance();
            Assert.fail("should have thrown UnsupportedOperationException");
        } catch (InvocationTargetException e) {
            Assert.assertTrue(e.getTargetException() instanceof UnsupportedOperationException);
            UnsupportedOperationException usoe = (UnsupportedOperationException) e.getTargetException();
            Assert.assertEquals("class may not be initialized, only static methods should be used", usoe.getMessage());
        }
    }
}
