Bug 1764 - moved Session related interfaces to openflowplugin-api
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / translator / FeaturesV10ToNodeConnectorUpdatedTranslatorTest.java
1 /*
2  * Copyright (c) 2014 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.openflowplugin.openflow.md.core.translator;
10
11 import static org.mockito.Mockito.when;
12
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.List;
16 import junit.framework.TestCase;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.MockitoAnnotations;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.openflowplugin.api.OFConstants;
23 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
24 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
25 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 import org.opendaylight.yangtools.yang.binding.DataContainer;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39
40 @RunWith(MockitoJUnitRunner.class)
41 public class FeaturesV10ToNodeConnectorUpdatedTranslatorTest extends TestCase {
42
43     private static final FeaturesV10ToNodeConnectorUpdatedTranslator FEATURES_V_10_TO_NODE_CONNECTOR_UPDATED_TRANSLATOR = new FeaturesV10ToNodeConnectorUpdatedTranslator();
44     private static final PortFeatures PORT_FEATURES = new PortFeatures(true, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false);
45
46     @MockitoAnnotations.Mock
47     SwitchConnectionDistinguisher switchConnectionDistinguisher;
48     private static final PortConfig PORT_CONFIG = new PortConfig(true, false, false, false);
49     @MockitoAnnotations.Mock
50     SessionContext sessionContext;
51     @MockitoAnnotations.Mock
52     GetFeaturesOutput featuresOutput;
53
54     @Before
55     public void setup() {
56         OpenflowPortsUtil.init();
57     }
58
59     @Test
60     /**
61      * Test method for basic functionality of {@link FeaturesV10ToNodeConnectorUpdatedTranslator#translate(org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher, org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)}
62      */
63     public void testTranslate() throws Exception {
64
65         when(sessionContext.getFeatures()).thenReturn(featuresOutput);
66         when(featuresOutput.getDatapathId()).thenReturn(BigInteger.valueOf(42));
67         List<DataObject> data = FEATURES_V_10_TO_NODE_CONNECTOR_UPDATED_TRANSLATOR.translate(switchConnectionDistinguisher, sessionContext, new MockOfHeader());
68         assertNotNull(data);
69         assertEquals(10, data.size());
70     }
71
72     private final class MockOfHeader implements OfHeader, GetFeaturesOutput {
73
74         @Override
75         public Short getVersion() {
76             return OFConstants.OFP_VERSION_1_3;
77         }
78
79         @Override
80         public Long getXid() {
81             return new Long(1);
82         }
83
84         @Override
85         public Class<? extends DataContainer> getImplementedInterface() {
86             return GetFeaturesOutput.class;
87         }
88
89         @Override
90         public <E extends Augmentation<GetFeaturesOutput>> E getAugmentation(Class<E> eClass) {
91             return null;
92         }
93
94         @Override
95         public BigInteger getDatapathId() {
96             return null;
97         }
98
99         @Override
100         public Long getBuffers() {
101             return null;
102         }
103
104         @Override
105         public Short getTables() {
106             return null;
107         }
108
109         @Override
110         public Short getAuxiliaryId() {
111             return null;
112         }
113
114         @Override
115         public Capabilities getCapabilities() {
116             return null;
117         }
118
119         @Override
120         public Long getReserved() {
121             return null;
122         }
123
124         @Override
125         public CapabilitiesV10 getCapabilitiesV10() {
126             return null;
127         }
128
129         @Override
130         public ActionTypeV10 getActionsV10() {
131             return null;
132         }
133
134         @Override
135         public List<PhyPort> getPhyPort() {
136             List<PhyPort> phyPorts = new ArrayList();
137             for (int i = 0; i < 10; i++) {
138                 PhyPortBuilder phyPortBuilder = new PhyPortBuilder();
139                 phyPortBuilder.setAdvertisedFeatures(PORT_FEATURES);
140                 phyPortBuilder.setConfig(PORT_CONFIG);
141                 phyPortBuilder.setCurrentFeatures(PORT_FEATURES);
142                 phyPortBuilder.setPeerFeatures(PORT_FEATURES);
143                 phyPortBuilder.setState(PortState.getDefaultInstance("live"));
144                 phyPortBuilder.setSupportedFeatures(PORT_FEATURES);
145                 phyPortBuilder.setPortNo(new Long(42));
146                 phyPorts.add(phyPortBuilder.build());
147             }
148             return phyPorts;
149         }
150     }
151
152 }