2 * Copyright (c) 2016 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
8 package org.opendaylight.unimgr.impl;
10 import org.opendaylight.yang.gen.v1.urn.mef.unimgr.ext.rev160725.ActivationStatus;
11 import org.opendaylight.yang.gen.v1.urn.mef.unimgr.ext.rev160725.ForwardingConstruct1;
12 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.ForwardingConstructs;
13 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.forwarding.constructs.ForwardingConstruct;
14 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.forwarding.constructs.ForwardingConstructBuilder;
15 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.forwarding.constructs.ForwardingConstructKey;
16 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.g_forwardingconstruct.FcPort;
17 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.g_forwardingconstruct.FcPortBuilder;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.junit.Assert;
24 import java.util.Arrays;
25 import java.util.HashSet;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
32 * @author krzysztof.bijakowski@amartus.com
34 class ForwardingConstructTestUtils {
35 private static final ForwardingConstructKey fcKey = new ForwardingConstructKey("fc");
37 static ForwardingConstructKey fcKey() {
41 static InstanceIdentifier<ForwardingConstruct> fcIid() {
42 return InstanceIdentifier
43 .builder(ForwardingConstructs.class)
44 .child(ForwardingConstruct.class, fcKey)
47 static ForwardingConstruct fcSingleNode() {
49 port("a", "localhost", "80"),
50 port("z", "localhost", "8080")
54 static ForwardingConstruct fcTwoNodes() {
56 port("a", "192.168.1.1", "80"),
57 port("z", "192.168.1.2", "80")
61 static void assertEquals(ForwardingConstruct expectedFc, ForwardingConstruct actualFc) {
62 assertNotNull(expectedFc);
63 assertNotNull(actualFc);
65 assertNotNull(expectedFc.getFcPort());
66 assertNotNull(actualFc.getFcPort());
68 Set<FcPort> expectedFcPorts = new HashSet<>(expectedFc.getFcPort());
69 Set<FcPort> actualFcPorts = new HashSet<>(actualFc.getFcPort());
71 assertTrue(expectedFcPorts.size() == actualFcPorts.size());
73 for (FcPort expectedFcPort : expectedFcPorts) {
74 boolean equal = false;
76 for (FcPort actualFcPort : actualFcPorts) {
77 equal = compareFcPort(expectedFcPort, actualFcPort);
86 //TODO assertions for other parameters
89 static void assertActivationState(ForwardingConstruct fc, ActivationStatus expectedActivationStatus) {
90 assertNotNull(fc.getAugmentation(ForwardingConstruct1.class));
91 assertNotNull((fc.getAugmentation(ForwardingConstruct1.class).getUnimgrAttrs()));
93 ActivationStatus actualActivationStatus = fc.getAugmentation(ForwardingConstruct1.class).getUnimgrAttrs().getStatus();
94 assertNotNull(actualActivationStatus);
96 Assert.assertEquals(expectedActivationStatus, actualActivationStatus);
99 private static boolean compareFcPort(FcPort expectedFcPort, FcPort actualFcPort) {
100 assertNotNull(expectedFcPort);
101 assertNotNull(actualFcPort);
103 assertNotNull(expectedFcPort.getTopology());
104 assertNotNull(expectedFcPort.getTopology().getValue());
105 assertNotNull(actualFcPort.getTopology());
106 assertNotNull(actualFcPort.getTopology().getValue());
108 assertNotNull(expectedFcPort.getNode());
109 assertNotNull(expectedFcPort.getNode().getValue());
110 assertNotNull(actualFcPort.getNode());
111 assertNotNull(actualFcPort.getNode().getValue());
113 assertNotNull(expectedFcPort.getTp());
114 assertNotNull(expectedFcPort.getTp().getValue());
115 assertNotNull(actualFcPort.getTp());
116 assertNotNull(actualFcPort.getTp().getValue());
118 //TODO assertions for other parameters
119 //TODO add possibility of null paramaters
122 expectedFcPort.getTopology().getValue().equals(actualFcPort.getTopology().getValue()) &&
123 expectedFcPort.getNode().getValue().equals(actualFcPort.getNode().getValue()) &&
124 expectedFcPort.getTp().getValue().equals(actualFcPort.getTp().getValue());
129 private static ForwardingConstruct fc(FcPort... ports) {
130 return new ForwardingConstructBuilder()
131 .setFcPort(Arrays.asList(ports))
136 private static FcPort port(String topo, String host, String port) {
137 return new FcPortBuilder()
138 .setTopology(new TopologyId(topo))
139 .setNode(new NodeId(host))
140 .setTp(new TpId(port))