/*
 * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. 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.netvirt.bgpmanager.test;

import static org.junit.Assert.assertEquals;

import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
import org.opendaylight.netvirt.bgpmanager.BgpUtil;
import org.opendaylight.netvirt.bgpmanager.FibDSWriter;
import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;

@RunWith(MockitoJUnitRunner.class)

public class BgpManagerTest extends AbstractDataBrokerTest {
    DataBroker dataBroker;
    FibDSWriter bgpFibWriter = null;
    MockFibManager fibManager = null;

    @Before
    public void setUp() throws Exception {
        dataBroker = getDataBroker();
        bgpFibWriter = new FibDSWriter(dataBroker, new BgpUtil(dataBroker));
        fibManager = new MockFibManager(dataBroker);
    }

    @Test
    public void testAddSinglePrefix() {
        String rd = "101";
        String prefix = "10.10.10.10/32";
        List<String> nexthop = Collections.singletonList("100.100.100.100");
        int label = 1234;

        bgpFibWriter.addFibEntryToDS(rd,  /*macAddress*/ prefix, nexthop,
                VrfEntry.EncapType.Mplsgre, label, 0 /*l3vni*/, null /*gatewayMacAddress*/, RouteOrigin.LOCAL);
        //assertEquals(1, fibManager.getDataChgCount());
        assertEquals(1, 1);
    }


    @Test
    public void testConnectedRoutNullNextHop() {
        String rd = "101";
        String prefix = "10.10.10.10/32";
        int label = 1234;
        try {
            bgpFibWriter.addFibEntryToDS(rd,  /*macAddress*/ prefix, null,
                    VrfEntry.EncapType.Mplsgre, label, 0 /*l3vni*/, null /*gatewayMacAddress*/, RouteOrigin.CONNECTED);
            assertEquals(1,0); //The code is not launching NullPointerException
        } catch (NullPointerException e) {
            //The code must launch NullPointerException
            assertEquals(1, 1);
        }
    }

/*
    @Test
    public void testAddPrefixesInRd() {
        String rd = "101";
        String prefix = "10.10.10.10/32";
        String nexthop = "100.100.100.100";
        int label = 1234;

        bgpFibWriter.addFibEntryToDS(rd, prefix, nexthop, label);
        assertEquals(1, fibManager.getDataChgCount());

        prefix = "10.10.10.11/32";
        label = 3456;
        bgpFibWriter.addFibEntryToDS(rd, prefix, nexthop, label);
        assertEquals(2, fibManager.getDataChgCount());


    }

    @Test
    public void testAddPrefixesAcrossRd() {
        String rd = "101";
        String prefix = "10.10.10.10/32";
        String nexthop = "100.100.100.100";
        int label = 1234;

        bgpFibWriter.addFibEntryToDS(rd, prefix, nexthop, label);
        assertEquals(1, fibManager.getDataChgCount());

        rd = "102";
        prefix = "10.10.10.11/32";
        nexthop = "200.200.200.200";
        label = 3456;
        bgpFibWriter.addFibEntryToDS(rd, prefix, nexthop, label);
        assertEquals(2, fibManager.getDataChgCount());

    }


    @Test
    public void testRemovePrefix() {
        String rd = "101";
        String prefix = "10.10.10.10/32";
        String nexthop = "100.100.100.100";
        int label = 1234;

        //add and then remove prefix
        bgpFibWriter.addFibEntryToDS(rd, prefix, nexthop, label);
        assertEquals(1, fibManager.getDataChgCount());
        bgpFibWriter.removeFibEntryFromDS(rd, prefix);
        assertEquals(0, fibManager.getDataChgCount());

    }
*/
}

@@ -724,32 +724,42 @@
 ng.test.Abstract
+Concurrent
 DataBrokerTest;%0A
@@ -1110,16 +1110,26 @@
 Abstract
+Concurrent
 DataBrok
@@ -1141,16 +1141,24 @@
 t %7B%0A    
+private 
 DataBrok
@@ -1176,16 +1176,24 @@
 er;%0A    
+private 
 FibDSWri
@@ -1221,16 +1221,24 @@
 ll;%0A    
+private 
 MockFibM
@@ -1303,25 +1303,8 @@
 Up()
- throws Exception
  %7B%0A 

Remove last use of AbstractDataBrokerTest