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.openflowjava.protocol.impl.serialization.factories;
\r
11 import io.netty.buffer.ByteBuf;
\r
12 import io.netty.buffer.UnpooledByteBufAllocator;
\r
14 import org.junit.Test;
\r
15 import org.mockito.Matchers;
\r
16 import org.mockito.Mock;
\r
17 import org.mockito.Mockito;
\r
18 import org.mockito.MockitoAnnotations;
\r
19 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
\r
20 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
\r
21 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
\r
22 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterIdSerializerKey;
\r
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
24 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
\r
25 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;
\r
31 * @author michal.polkorab
\r
34 public class ExperimenterInputMessageFactoryTest {
\r
36 @Mock SerializerRegistry registry;
\r
37 @Mock OFSerializer<ExperimenterInput> serializer;
\r
38 private OFSerializer<ExperimenterInput> expFactory;
\r
41 * Sets up ExperimenterInputMessageFactory
\r
42 * @param real true if setup should use real registry, false when mock is desired
\r
44 public void startUp(boolean real) {
\r
45 MockitoAnnotations.initMocks(this);
\r
46 expFactory = new ExperimenterInputMessageFactory();
\r
48 SerializerRegistry realRegistry = new SerializerRegistryImpl();
\r
49 realRegistry.init();
\r
50 ((SerializerRegistryInjector) expFactory).injectSerializerRegistry(realRegistry);
\r
52 ((SerializerRegistryInjector) expFactory).injectSerializerRegistry(registry);
\r
57 * Testing of {@link ExperimenterInputMessageFactory} for correct serializer
\r
58 * lookup and serialization
\r
59 * @throws Exception
\r
61 @Test(expected=IllegalStateException.class)
\r
62 public void testV10Real() throws Exception {
\r
64 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
65 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
\r
66 builder.setExperimenter(new ExperimenterId(42L));
\r
67 ExperimenterInput input = builder.build();
\r
69 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
70 expFactory.serialize(input, out);
\r
74 * Testing of {@link ExperimenterInputMessageFactory} for correct serializer
\r
75 * lookup and serialization
\r
76 * @throws Exception
\r
78 @Test(expected=IllegalStateException.class)
\r
79 public void testV13Real() throws Exception {
\r
81 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
82 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
\r
83 builder.setExperimenter(new ExperimenterId(42L));
\r
84 ExperimenterInput input = builder.build();
\r
86 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
87 expFactory.serialize(input, out);
\r
91 * Testing of {@link ExperimenterInputMessageFactory} for correct serializer
\r
92 * lookup and serialization
\r
93 * @throws Exception
\r
96 public void testV10() throws Exception {
\r
98 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
99 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
\r
100 builder.setExperimenter(new ExperimenterId(42L));
\r
101 ExperimenterInput input = builder.build();
\r
103 Mockito.when(registry.getSerializer(
\r
104 (ExperimenterIdSerializerKey<?>) Matchers.any())).thenReturn(serializer);
\r
106 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
107 expFactory.serialize(input, out);
\r
111 * Testing of {@link ExperimenterInputMessageFactory} for correct serializer
\r
112 * lookup and serialization
\r
113 * @throws Exception
\r
116 public void testV13() throws Exception {
\r
118 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
119 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
\r
120 builder.setExperimenter(new ExperimenterId(42L));
\r
121 ExperimenterInput input = builder.build();
\r
123 Mockito.when(registry.getSerializer(
\r
124 (ExperimenterIdSerializerKey<?>) Matchers.any())).thenReturn(serializer);
\r
126 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
127 expFactory.serialize(input, out);
\r