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 = {Mappings.class, NeutronByGbpMappings.class, ExternalGatewaysAsL3Endpoints.class,
61 ExternalGatewayAsL3Endpoint.class};
62 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
63 assertEquals(ExternalGatewayAsL3Endpoint.class, iid.getTargetType());
64 assertTrue(iid.isWildcarded());
68 public void test_EndpointByPortIid() {
70 InstanceIdentifier<EndpointByPort> iid = NeutronOvsdbIidFactory.endpointByPortIid(new UniqueId(portId));
72 Class<?>[] expectedTypes =
73 {Mappings.class, GbpByNeutronMappings.class, EndpointsByPorts.class, EndpointByPort.class};
74 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
75 assertEquals(EndpointByPort.class, iid.getTargetType());
76 assertFalse(iid.isWildcarded());
77 assertEquals(portId, iid.firstKeyOf(EndpointByPort.class).getPortId().getValue());
81 public void test_NeutronGbpMappingsIidWildcard() {
82 InstanceIdentifier<NeutronByGbpMappings> iid = NeutronOvsdbIidFactory.neutronGbpMappingsIidWildcard();
85 Class<?>[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class};
86 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
87 assertEquals(NeutronByGbpMappings.class, iid.getTargetType());
88 assertFalse(iid.isWildcarded());
92 public void test_NodeIid_topology() {
93 InstanceIdentifier<Node> iid =
94 NeutronOvsdbIidFactory.nodeIid(new TopologyId(OVSDB_TOPOLOGY_ID), new NodeId(UUID));
96 Class<?>[] expectedTypes = {NetworkTopology.class, Topology.class, Node.class};
97 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
98 assertEquals(Node.class, iid.getTargetType());
99 assertFalse(iid.isWildcarded());
103 public void test_NodeIid_inventory() {
104 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId =
105 new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(UUID);
106 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> iid =
107 NeutronOvsdbIidFactory.nodeIid(nodeId);
109 Class<?>[] expectedTypes =
110 {Nodes.class, org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class};
111 assertPathArgumentTypes(iid.getPathArguments(), expectedTypes);
112 assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
113 iid.getTargetType());
114 assertFalse(iid.isWildcarded());
117 private static void assertPathArgumentTypes(Iterable<PathArgument> pathArguments, Class<?>[] expectedTypes) {
118 assertNotNull(pathArguments);
119 Iterator<PathArgument> it = pathArguments.iterator();
120 for (int i = 0; i < expectedTypes.length; ++i) {
121 assertTrue("Next path argument expected.", it.hasNext());
122 assertEquals("Unexpected path argument type.", expectedTypes[i], it.next().getType());