/*
 * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.config.yang.messagebus.app.impl;

import org.junit.Before;
import org.junit.BeforeClreplaced;
import org.junit.Test;
import org.opendaylight.controller.config.api.DependencyResolver;
import org.opendaylight.controller.config.api.JmxAttribute;
import org.opendaylight.controller.config.api.ModuleIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.MountPointService;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.controller.sal.core.api.Provider;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.framework.BundleContext;

import com.google.common.util.concurrent.CheckedFuture;

import javax.management.ObjectName;

import static org.junit.replacedert.replacedertEquals;
import static org.junit.replacedert.replacedertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

public clreplaced MessageBusAppImplModuleTest {

    MessageBusAppImplModule messageBusAppImplModule;
    ModuleIdentifier moduleIdentifier;
    DependencyResolver dependencyResolverMock;

    @BeforeClreplaced
    public static void initTestClreplaced() throws IllegalAccessException, InstantiationException {
    }

    @Before
    public void setUp() throws Exception {
        moduleIdentifier = new ModuleIdentifier("factoryName1", "instanceName1");
        dependencyResolverMock = mock(DependencyResolver.clreplaced);
        messageBusAppImplModule = new MessageBusAppImplModule(moduleIdentifier, dependencyResolverMock);
    }

    @Test
    public void constructorTest() {
        replacedertNotNull("Instance has not been created correctly.", messageBusAppImplModule);
    }

    @Test
    public void constructorBTest() {
        MessageBusAppImplModule messageBusAppImplModuleOld = mock(MessageBusAppImplModule.clreplaced);
        java.lang.AutoCloseable oldInstanceAutocloseableMock = mock(AutoCloseable.clreplaced);
        MessageBusAppImplModule messageBusAppImplModule = new MessageBusAppImplModule(moduleIdentifier, dependencyResolverMock, messageBusAppImplModuleOld, oldInstanceAutocloseableMock);
        replacedertNotNull("Instance has not been created correctly.", messageBusAppImplModule);
    }

    @Test
    public void setGetBundleContextTest() {
        BundleContext bundleContext = mock(BundleContext.clreplaced);
        messageBusAppImplModule.setBundleContext(bundleContext);
        replacedertEquals("Set and/or get method/s don't work correctly.", bundleContext, messageBusAppImplModule.getBundleContext());
    }

    @Test
    public void createInstanceTest() throws Exception{
        org.opendaylight.controller.sal.binding.api.BindingAwareBroker bindingAwareBrokerMock = mock(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.clreplaced);
        Broker brokerMock = mock(Broker.clreplaced);
        doReturn(brokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.clreplaced), any(ObjectName.clreplaced), any(JmxAttribute.clreplaced));
        doReturn(bindingAwareBrokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.clreplaced), any(ObjectName.clreplaced), any(JmxAttribute.clreplaced));
        messageBusAppImplModule.resolveDependencies();

        BindingAwareBroker.ProviderContext providerContext = mock(BindingAwareBroker.ProviderContext.clreplaced);
        doReturn(providerContext).when(bindingAwareBrokerMock).registerProvider(any(BindingAwareProvider.clreplaced));
        Broker.ProviderSession providerSessionMock = mock(Broker.ProviderSession.clreplaced);
        doReturn(providerSessionMock).when(brokerMock).registerProvider(any(Provider.clreplaced));
        DataBroker dataBrokerMock = mock(DataBroker.clreplaced);
        doReturn(dataBrokerMock).when(providerContext).getSALService(eq(DataBroker.clreplaced));
        DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.clreplaced);
        doReturn(domNotificationPublishServiceMock).when(providerSessionMock).getService(DOMNotificationPublishService.clreplaced);
        DOMMountPointService domMountPointServiceMock = mock(DOMMountPointService.clreplaced);
        doReturn(domMountPointServiceMock).when(providerSessionMock).getService(DOMMountPointService.clreplaced);
        MountPointService mountPointServiceMock = mock(MountPointService.clreplaced);
        doReturn(mountPointServiceMock).when(providerContext).getSALService(eq(MountPointService.clreplaced));
        RpcProviderRegistry rpcProviderRegistryMock = mock(RpcProviderRegistry.clreplaced);
        doReturn(rpcProviderRegistryMock).when(providerContext).getSALService(eq(RpcProviderRegistry.clreplaced));

        WriteTransaction writeTransactionMock = mock(WriteTransaction.clreplaced);
        doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
        doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.clreplaced), any(InstanceIdentifier.clreplaced), any(DataObject.clreplaced), eq(true));
        CheckedFuture checkedFutureMock = mock(CheckedFuture.clreplaced);
        doReturn(checkedFutureMock).when(writeTransactionMock).submit();
        replacedertNotNull("EventSourceRegistryWrapper has not been created correctly.", messageBusAppImplModule.createInstance());
    }

}