/**
 * Copyright (c) 2011-2012 EBM WebSourcing, 2012-2013 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see <http://www.gnu.org/licenses/>
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.se.jsr181;

import java.util.Map;

import javax.jbi.messaging.ExchangeStatus;
import javax.xml.namespace.QName;

import org.junit.Ignore;
import org.junit.Test;
import org.ow2.easywsdl.wsdl.api.abstractItf.AbsItfOperation;
import org.ow2.petals.commons.log.FlowAttributes;
import org.ow2.petals.component.api.Component;
import org.ow2.petals.component.api.ComponentConfiguration;
import org.ow2.petals.component.api.Message;
import org.ow2.petals.component.api.ServiceConfiguration;

import com.ebmwebsourcing.jbi.adaptor.impl.AbstractJBIComponentTest;
import com.ebmwebsourcing.jbi.adaptor.impl.ComponentType;
import com.ebmwebsourcing.jbi.adaptor.impl.WrappedComponent;
import com.ebmwebsourcing.jbi.adaptor.impl.WrappedRequestToProviderMessage;
import com.ebmwebsourcing.jbi.adaptor.impl.WrappedStatusFromConsumerMessage;

/**
 * @author Marc Jambert - EBM WebSourcing
 */
public class Jsr181ComponentTest extends AbstractJBIComponentTest {

    private static final QName TEST_OPERATION = new QName("http://testProvideService", "sayHello");

    @Override
    protected Component createComponentUnderTest(ComponentConfiguration componentConfiguration) {
        return new WrappedComponent(ComponentType.SE_JSR181, componentConfiguration);
    }

    @Override
    protected ServiceConfiguration createTestProvideServiceConfiguration() throws Exception {
        ServiceConfiguration testProvideServiceConguration = createTestProvideServiceBaseConfiguration();
        testProvideServiceConguration.setParameter(
                "{http://petals.ow2.org/components/jsr181/version-1}class",
                "org.ow2.petals.se.jsr181.Jsr181TestCass");
        return testProvideServiceConguration;
    }

    @Override
    protected Message createTestStatusMessage(ServiceConfiguration testServiceConfiguration,
            ExchangeStatus status) throws Exception {
        String payload = "<sayHello><name>world</name></sayHello>";

        return new WrappedStatusFromConsumerMessage(testServiceConfiguration, TEST_OPERATION,
                AbsItfOperation.MEPPatternConstants.IN_OUT.value(),
                createPayloadInputStream(payload), new FlowAttributes("testFlowInstanceId",
                        "testFlowStepId"), status);
    }

    @Test
    @Ignore
    public void testProcessMessageAsConsumerLogsNothingBecauseMonitDisabled() throws Exception {
    }

    @Test
    @Ignore
    public void testProcessMessageAsConsumerLogsMonitMessageBecauseMonitEnabled() throws Exception {
    }

    @Override
    protected ServiceConfiguration createTestConsumeServiceConfiguration() throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected Map<String, String> generateExternalEvent() throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected Message createMessageToProcessAsProvider(ServiceConfiguration testServiceConfiguration)
            throws Exception {
        String payload = "<sayHello><name>world</name></sayHello>";
        return new WrappedRequestToProviderMessage(testServiceConfiguration, TEST_OPERATION,
                AbsItfOperation.MEPPatternConstants.IN_OUT.value(),
                createPayloadInputStream(payload), new FlowAttributes("testFlowInstanceId",
                        "testFlowStepId"));
    }

}
