Merge "Bug 5117 - DOS chars in shell script"
[groupbasedpolicy.git] / neutron-ovsdb / src / test / java / org / opendaylight / groupbasedpolicy / neutron / ovsdb / util / NeutronOvsdbIidFactoryTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.groupbasedpolicy.neutron.ovsdb.util;
10
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;
15
16 import java.util.Iterator;
17
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.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
34
35 public class NeutronOvsdbIidFactoryTest {
36
37     @Test
38     public void ovsdbNodeAugmentationIidTest() {
39         final String ovsdbTopologyId = "topologyId";
40         InstanceIdentifier<OvsdbNodeAugmentation> id = NeutronOvsdbIidFactory.ovsdbNodeAugmentationIid(new TopologyId(ovsdbTopologyId));
41         assertNotNull(id);
42         Class<?>[] expectedTypes = {NetworkTopology.class, Topology.class, Node.class, OvsdbNodeAugmentation.class};
43         assertPathArgumentTypes(id.getPathArguments(), expectedTypes);
44         assertEquals(OvsdbNodeAugmentation.class, id.getTargetType());
45         assertTrue(id.isWildcarded());
46         assertEquals(ovsdbTopologyId, id.firstKeyOf(Topology.class).getTopologyId().getValue());
47     }
48
49     @Test
50     public void neutronGbpExternalGatewayIidWildcardTest() {
51         InstanceIdentifier<ExternalGatewayAsL3Endpoint> id = NeutronOvsdbIidFactory.neutronGbpExternalGatewayIidWildcard();
52         assertNotNull(id);
53         Class<?>[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class,
54                 ExternalGatewaysAsL3Endpoints.class, ExternalGatewayAsL3Endpoint.class};
55         assertPathArgumentTypes(id.getPathArguments(), expectedTypes);
56         assertEquals(ExternalGatewayAsL3Endpoint.class, id.getTargetType());
57         assertTrue(id.isWildcarded());
58     }
59
60     @Test
61     public void endpointByPortIidTest() {
62         final String portId = "e0bb2cf8-8855-434e-839b-d2e59e045218";
63         InstanceIdentifier<EndpointByPort> id = NeutronOvsdbIidFactory.endpointByPortIid(new UniqueId(portId));
64         assertNotNull(id);
65         Class<?>[] expectedTypes = {Mappings.class, GbpByNeutronMappings.class,
66                 EndpointsByPorts.class, EndpointByPort.class};
67         assertPathArgumentTypes(id.getPathArguments(), expectedTypes);
68         assertEquals(EndpointByPort.class, id.getTargetType());
69         assertFalse(id.isWildcarded());
70         assertEquals(portId, id.firstKeyOf(EndpointByPort.class).getPortId().getValue());
71     }
72
73     @Test
74     public void neutronGbpMappingsIidWildcardTest() {
75         InstanceIdentifier<NeutronByGbpMappings> id = NeutronOvsdbIidFactory.neutronGbpMappingsIidWildcard();
76         assertNotNull(id);
77         Class<?>[] expectedTypes = {Mappings.class, NeutronByGbpMappings.class};
78         assertPathArgumentTypes(id.getPathArguments(), expectedTypes);
79         assertEquals(NeutronByGbpMappings.class, id.getTargetType());
80         assertFalse(id.isWildcarded());
81     }
82
83     private static void assertPathArgumentTypes(Iterable<PathArgument> pathArguments, Class<?>[] expectedTypes) {
84         assertNotNull(pathArguments);
85         Iterator<PathArgument> it = pathArguments.iterator();
86         for (int i = 0; i < expectedTypes.length; ++i) {
87             assertTrue("Next path argument expected.", it.hasNext());
88             assertEquals("Unexpected path argument type.", expectedTypes[i] , it.next().getType());
89         }
90     }
91 }