2 * Copyright (c) 2014 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.serialization.factories.multipart;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactory;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.features._case.MultipartRequestMeterFeaturesBuilder;
28 import org.opendaylight.yangtools.yang.common.Empty;
31 * Unit tests for MultipartRequestMeterFeatures.
33 * @author michal.polkorab
35 public class MultipartRequestMeterFeaturesTest {
37 private SerializerRegistry registry;
38 private OFSerializer<MultipartRequestInput> multipartFactory;
41 * Initializes serializer registry and stores correct factory in field.
44 public void startUp() {
45 registry = new SerializerRegistryImpl();
47 multipartFactory = registry.getSerializer(
48 new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, MultipartRequestInput.class));
52 * Tests {@link MultipartRequestInputFactory} - MeterFeatures case.
55 public void test() throws Exception {
56 MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
57 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
58 builder.setType(MultipartType.OFPMPMETERFEATURES);
59 builder.setFlags(new MultipartRequestFlags(false));
60 MultipartRequestMeterFeaturesCaseBuilder caseBuilder = new MultipartRequestMeterFeaturesCaseBuilder();
61 MultipartRequestMeterFeaturesBuilder featuresBuilder = new MultipartRequestMeterFeaturesBuilder();
62 featuresBuilder.setEmpty(Empty.value());
63 caseBuilder.setMultipartRequestMeterFeatures(featuresBuilder.build());
64 builder.setMultipartRequestBody(caseBuilder.build());
65 MultipartRequestInput message = builder.build();
67 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
68 multipartFactory.serialize(message, out);
70 BufferHelper.checkHeaderV13(out, (byte) 18, 16);
71 Assert.assertEquals("Wrong type", 11, out.readUnsignedShort());
72 Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
73 out.skipBytes(4); // skip padding
74 Assert.assertTrue("Unexpected data", out.readableBytes() == 0);