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.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
16 import java.util.Iterator;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.NeutronByGbpMappings;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.EndpointsByPorts;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.endpoints.by.ports.EndpointByPort;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.ExternalGatewaysAsL3Endpoints;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.neutron.by.gbp.mappings.external.gateways.as.l3.endpoints.ExternalGatewayAsL3Endpoint;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
37 public class NeutronOvsdbIidFactoryTest {
39 private static final String OVSDB_TOPOLOGY_ID = "topologyId";
40 private static final String UUID = "e0bb2cf8-8855-434e-839b-d2e59e045218";
43 public void test_OvsdbNodeAugmentationIid() {
44 InstanceIdentifier<OvsdbNodeAugmentation> iid =
45 NeutronOvsdbIidFactory.ovsdbNodeAugmentationIid(new TopologyId(OVSDB_TOPOLOGY_ID));
48 Class<?>[] expectedTypes = {NetworkTopology.class, Topology.class, Node.class, OvsdbNodeAugmentation.class};
49 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
50 assertEquals(OvsdbNodeAugmentation.class, iid.getTargetType());
51 assertTrue(iid.isWildcarded());
52 assertEquals(OVSDB_TOPOLOGY_ID, iid.firstKeyOf(Topology.class).getTopologyId().getValue());
56 public void test_NeutronGbpExternalGatewayIidWildcard() {
57 InstanceIdentifier<ExternalGatewayAsL3Endpoint> iid =
58 NeutronOvsdbIidFactory.neutronGbpExternalGatewayIidWildcard();
60 Class<?>[] expectedTypes =
61 {Mappings.class, NeutronByGbpMappings.class, ExternalGatewaysAsL3Endpoints.class,
62 ExternalGatewayAsL3Endpoint.class};
63 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
64 assertEquals(ExternalGatewayAsL3Endpoint.class, iid.getTargetType());
65 assertTrue(iid.isWildcarded());
69 public void test_EndpointByPortIid() {
71 InstanceIdentifier<EndpointByPort> iid = NeutronOvsdbIidFactory.endpointByPortIid(new UniqueId(portId));
73 Class<?>[] expectedTypes =
74 {Mappings.class, GbpByNeutronMappings.class, EndpointsByPorts.class, EndpointByPort.class};
75 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
76 assertEquals(EndpointByPort.class, iid.getTargetType());
77 assertFalse(iid.isWildcarded());
78 assertEquals(portId, iid.firstKeyOf(EndpointByPort.class).getPortId().getValue());
82 public void test_NeutronGbpMappingsIidWildcard() {
83 InstanceIdentifier<NeutronByGbpMappings> iid = NeutronOvsdbIidFactory.neutronGbpMappingsIidWildcard();
86 Class<?>[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class};
87 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
88 assertEquals(NeutronByGbpMappings.class, iid.getTargetType());
89 assertFalse(iid.isWildcarded());
93 public void test_NodeIid_topology() {
94 InstanceIdentifier<Node> iid =
95 NeutronOvsdbIidFactory.nodeIid(new TopologyId(OVSDB_TOPOLOGY_ID), new NodeId(UUID));
97 Class<?>[] expectedTypes = {NetworkTopology.class, Topology.class, Node.class};
98 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
99 assertEquals(Node.class, iid.getTargetType());
100 assertFalse(iid.isWildcarded());
104 public void test_NodeIid_inventory() {
105 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId =
106 new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(UUID);
107 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> iid =
108 NeutronOvsdbIidFactory.nodeIid(nodeId);
110 Class<?>[] expectedTypes =
111 {Nodes.class, org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class};
112 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
113 assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
114 iid.getTargetType());
115 assertFalse(iid.isWildcarded());
118 private static void assertPathArgumentTypes(Iterable<PathArgument> pathArguments, Class<?>[] expectedTypes) {
119 assertNotNull(pathArguments);
120 Iterator<PathArgument> it = pathArguments.iterator();
121 for (int i = 0; i < expectedTypes.length; ++i) {
122 assertTrue("Next path argument expected.", it.hasNext());
123 assertEquals("Unexpected path argument type.", expectedTypes[i], it.next().getType());