2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.neutron.ovsdb.util;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.when;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPort;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import com.google.common.base.Optional;
29 import com.google.common.util.concurrent.CheckedFuture;
31 public class NeutronHelperTest {
33 private UniqueId externalId;
34 private DataBroker dataBroker;
35 private Optional<EndpointByPort> optionalEp;
37 @SuppressWarnings("unchecked")
39 public void initialise() throws Exception {
40 externalId = mock(UniqueId.class);
41 dataBroker = mock(DataBroker.class);
43 ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
44 when(dataBroker.newReadWriteTransaction()).thenReturn(transaction);
45 CheckedFuture<Optional<EndpointByPort>, ReadFailedException> resultFuture = mock(CheckedFuture.class);
46 when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(resultFuture);
47 optionalEp = mock(Optional.class);
48 when(resultFuture.checkedGet()).thenReturn(optionalEp);
52 public void getEpKeyFromNeutronMapperTest() throws Exception {
53 when(optionalEp.isPresent()).thenReturn(true);
54 EndpointByPort epByPort = mock(EndpointByPort.class);
55 when(optionalEp.get()).thenReturn(epByPort);
56 when(epByPort.getL2Context()).thenReturn(mock(L2BridgeDomainId.class));
57 when(epByPort.getMacAddress()).thenReturn(mock(MacAddress.class));
59 Assert.assertNotNull(NeutronHelper.getEpKeyFromNeutronMapper(externalId, dataBroker));
63 public void getEpKeyFromNeutronMapperTestPresentFalse() throws Exception {
64 when(optionalEp.isPresent()).thenReturn(false);
66 Assert.assertNull(NeutronHelper.getEpKeyFromNeutronMapper(externalId, dataBroker));