import static org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType.AS_SEQUENCE;
import static org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType.AS_SET;
+
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.Collections;
}
private AsPathSegmentParser() {
-
+ throw new UnsupportedOperationException();
}
static int serializeType(final SegmentType type) {
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser;
import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.NoopReferenceCache;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
}
}
- @Test
- public void testBGPHeaderParser() throws Exception {
- final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
- try {
- msgReg.parseMessage(Unpooled.copiedBuffer(new byte[] { (byte) 0, (byte) 0 }));
- fail("Exception should have occured.");
- } catch (final IllegalArgumentException e) {
- assertEquals("Too few bytes in passed array. Passed: 2. Expected: >= 19.", e.getMessage());
- }
- }
- @Test
- public void testMessageParser() throws Exception {
- final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
- String ex = "";
+ @Test(expected=UnsupportedOperationException.class)
+ public void testAsPathSegmentParserPrivateConstructor() throws Throwable {
+ final Constructor<AsPathSegmentParser> c = AsPathSegmentParser.class.getDeclaredConstructor();
+ c.setAccessible(true);
try {
- msgReg.serializeMessage(null, Unpooled.EMPTY_BUFFER);
- } catch (final NullPointerException e) {
- ex = e.getMessage();
+ c.newInstance();
+ } catch (final InvocationTargetException e) {
+ throw e.getCause();
}
- assertEquals("BGPMessage is mandatory.", ex);
}
}
package org.opendaylight.protocol.bgp.parser.spi;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.KeepaliveBuilder;
}
@Override
- protected Notification parseBody(int type, ByteBuf body, int messageLength) throws BGPDocumentedException {
+ protected Notification parseBody(final int type, final ByteBuf body, final int messageLength) throws BGPDocumentedException {
return new KeepaliveBuilder().build();
}
};
Assert.assertTrue(e.getMessage().startsWith("Size doesn't match size specified in header."));
}
}
+
+ @Test
+ public void testBGPHeaderParser() throws Exception {
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
+ try {
+ msgReg.parseMessage(Unpooled.copiedBuffer(new byte[] { (byte) 0, (byte) 0 }));
+ fail("Exception should have occured.");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Too few bytes in passed array. Passed: 2. Expected: >= 19.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testMessageParser() throws Exception {
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
+ String ex = "";
+ try {
+ msgReg.serializeMessage(null, Unpooled.EMPTY_BUFFER);
+ } catch (final NullPointerException e) {
+ ex = e.getMessage();
+ }
+ assertEquals("BGPMessage is mandatory.", ex);
+ }
}
parserReg.close();
serializerReg.close();
+ serializerReg.close();
Assert.assertNull(registry.getParser(TYPE));
Assert.assertNull(registry.getSerializer(Object.class));
}
parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buffer = Unpooled.buffer();
parser.serializeObject(builder.build(), buffer);
+ parser.serializeTlvs(null, Unpooled.EMPTY_BUFFER);
+ parser.serializeTlvs(new TlvsBuilder().build(), Unpooled.EMPTY_BUFFER);
assertArrayEquals(openObjectBytes, ByteArray.getAllBytes(buffer));
}