2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowplugin.openflow.md.core.translator;
\r
11 import java.math.BigInteger;
\r
12 import java.util.List;
\r
14 import static org.mockito.Mockito.when;
\r
16 import org.junit.Assert;
\r
17 import org.junit.Before;
\r
18 import org.junit.Test;
\r
19 import org.mockito.Mock;
\r
20 import org.mockito.MockitoAnnotations;
\r
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
22 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
\r
23 import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationQueueWrapper;
\r
24 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
\r
29 import org.opendaylight.yangtools.yang.binding.DataObject;
\r
32 * @author michal.polkorab
\r
35 public class NotificationPlainTranslatorTest {
\r
37 @Mock SwitchConnectionDistinguisher cookie;
\r
38 @Mock SessionContext sc;
\r
39 @Mock GetFeaturesOutput features;
\r
41 NotificationPlainTranslator translator = new NotificationPlainTranslator();
\r
47 public void startUp() {
\r
48 MockitoAnnotations.initMocks(this);
\r
52 * Tests {@link NotificationPlainTranslator#translate(SwitchConnectionDistinguisher, SessionContext, OfHeader)}
\r
55 public void testIncorrectInput() {
\r
56 HelloMessageBuilder helloBuilder = new HelloMessageBuilder();
\r
57 HelloMessage message = helloBuilder.build();
\r
59 List<DataObject> list = translator.translate(cookie, sc, message);
\r
61 Assert.assertEquals("Wrong list size", 0, list.size());
\r
65 * Tests {@link NotificationPlainTranslator#translate(SwitchConnectionDistinguisher, SessionContext, OfHeader)}
\r
68 public void test() {
\r
69 when(sc.getFeatures()).thenReturn(features);
\r
70 when(features.getDatapathId()).thenReturn(new BigInteger("64"));
\r
71 HelloMessageBuilder helloBuilder = new HelloMessageBuilder();
\r
72 helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
\r
73 helloBuilder.setXid(42L);
\r
74 HelloMessage message = helloBuilder.build();
\r
75 NotificationQueueWrapper wrapper = new NotificationQueueWrapper(message, message.getVersion());
\r
77 List<DataObject> list = translator.translate(cookie, sc, wrapper);
\r
79 Assert.assertEquals("Wrong list size", 1, list.size());
\r
80 HelloMessage hello = (HelloMessage) list.get(0);
\r
81 Assert.assertEquals("Wrong output", 4, hello.getVersion().intValue());
\r
82 Assert.assertEquals("Wrong output", 42, hello.getXid().intValue());
\r