From 3f668c6f09f2f959a90060cf47b4af6c3133bea7 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 4 Oct 2019 09:58:11 +0200 Subject: [PATCH] Apply modernization to pcep-impl This mostly ditches Lists.newArrayList(), but also formats some of the code to remove checkstyle complaints. Change-Id: Ic525079300dfbec0f12e9da8710fd900b24a9d8b Signed-off-by: Robert Varga --- .../pcep/impl/AbstractPCEPSessionTest.java | 22 ++- .../pcep/impl/PCEPEROSubobjectParserTest.java | 159 +++++++++++------- .../pcep/impl/PCEPObjectParserTest.java | 17 +- .../protocol/pcep/impl/PCEPTlvParserTest.java | 59 ++++--- .../protocol/pcep/impl/PCEPValidatorTest.java | 136 +++++++++------ .../pcep/impl/SimpleSessionListener.java | 6 +- 6 files changed, 242 insertions(+), 157 deletions(-) diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java index f2d81dd842..f3215531a1 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.pcep.impl; import static org.mockito.ArgumentMatchers.any; @@ -13,7 +12,6 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import com.google.common.collect.Lists; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; @@ -24,6 +22,7 @@ import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.ScheduledFuture; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -70,7 +69,7 @@ public class AbstractPCEPSessionTest { protected final String ipAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress(); protected final int port = InetSocketAddressUtil.getRandomPort(); - protected final List msgsSend = Lists.newArrayList(); + protected final List msgsSend = new ArrayList<>(); protected Open openMsg; @@ -100,16 +99,23 @@ public class AbstractPCEPSessionTest { doReturn(this.eventLoop).when(this.channel).eventLoop(); doReturn(true).when(this.future).cancel(false); doReturn(this.future).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class)); - doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class)); + doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), + any(ChannelHandler.class)); doReturn(this.pipeline).when(this.pipeline).addFirst(any(ChannelHandler.class)); doReturn(true).when(this.channel).isActive(); doReturn(mock(ChannelFuture.class)).when(this.channel).close(); doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).remoteAddress(); doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).localAddress(); - this.openMsg = new OpenBuilder().setOpenMessage( - new OpenMessageBuilder().setOpen( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder().setDeadTimer( - DEADTIMER).setKeepalive(KEEP_ALIVE).setSessionId((short) 0).build()).build()).build(); + this.openMsg = new OpenBuilder() + .setOpenMessage(new OpenMessageBuilder() + .setOpen(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .open.object.OpenBuilder() + .setDeadTimer(DEADTIMER) + .setKeepalive(KEEP_ALIVE) + .setSessionId((short) 0) + .build()) + .build()) + .build(); this.kaMsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build(); this.startTlsMsg = new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build(); this.closeMsg = new CloseBuilder().setCCloseMessage( diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java index 556dc6a531..441e939e9b 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java @@ -11,9 +11,9 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -52,22 +52,33 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.generalized.label._case.GeneralizedLabelBuilder; public class PCEPEROSubobjectParserTest { - private static final byte[] ip4PrefixBytes = { (byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0x16, (byte) 0x00 }; - private static final byte[] ip6PrefixBytes = { (byte) 0x02, (byte) 0x14, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 }; - private static final byte[] asNumberBytes = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 }; - private static final byte[] unnumberedBytes = { (byte) 0x84, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, - (byte) 0x50, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; - private static final byte[] pathKey32Bytes = { (byte) 0xc0, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, - (byte) 0x50, (byte) 0x00 }; - private static final byte[] pathKey128Bytes = { (byte) 0xc1, (byte) 0x14, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, - (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; - private static final byte[] labelBytes = { (byte) 0x83, (byte) 0x08, (byte) 0x80, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, - (byte) 0xFF }; - private static final byte[] exrsBytes = { (byte) 0xa1, (byte) 0x06, (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 }; + private static final byte[] IP4_PREFIX_BYTES = { + (byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 + }; + private static final byte[] IP6_PREFIX_BYTES = { + (byte) 0x02, (byte) 0x14, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 + }; + private static final byte[] AS_NUMBER_BYTES = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 }; + private static final byte[] UNNUMBERED_BYTES = { + (byte) 0x84, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF + }; + private static final byte[] PATH_KEY32_BYTES = { + (byte) 0xc0, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 + }; + private static final byte[] PATH_KEY128_BYTES = { + (byte) 0xc1, (byte) 0x14, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, + (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 + }; + private static final byte[] LABEL_BYTES = { + (byte) 0x83, (byte) 0x08, (byte) 0x80, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF + }; + private static final byte[] EXRS_BYTES = { + (byte) 0xa1, (byte) 0x06, (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 + }; private SimplePCEPExtensionProviderContext ctx; private BaseParserExtensionActivator act; @@ -86,10 +97,11 @@ public class PCEPEROSubobjectParserTest { subs.setLoose(true); subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix( new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2)), true)); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(IP4_PREFIX_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(IP4_PREFIX_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -108,17 +120,22 @@ public class PCEPEROSubobjectParserTest { @Test public void testEROIp6PrefixSubobject() throws PCEPDeserializerException { final EROIpv6PrefixSubobjectParser parser = new EROIpv6PrefixSubobjectParser(); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix( - new IpPrefixBuilder().setIpPrefix( - new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build()).build()); - subs.setLoose(false); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2)), false)); + final SubobjectBuilder subs = new SubobjectBuilder() + .setSubobjectType(new IpPrefixCaseBuilder() + .setIpPrefix(new IpPrefixBuilder() + .setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF + }, 22))) + .build()) + .build()) + .setLoose(false); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(IP6_PREFIX_BYTES, 2)), false)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(IP6_PREFIX_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -137,13 +154,16 @@ public class PCEPEROSubobjectParserTest { @Test public void testEROAsNumberSubobject() throws PCEPDeserializerException { final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser(); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setLoose(true); - subs.setSubobjectType(new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(asNumberBytes, 2)), true)); + final SubobjectBuilder subs = new SubobjectBuilder() + .setLoose(true) + .setSubobjectType(new AsNumberCaseBuilder() + .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()) + .build()); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(AS_NUMBER_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(asNumberBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(AS_NUMBER_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -166,10 +186,11 @@ public class PCEPEROSubobjectParserTest { subs.setLoose(true); subs.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered( new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(unnumberedBytes, 2)), true)); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(UNNUMBERED_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(unnumberedBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(UNNUMBERED_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -194,10 +215,11 @@ public class PCEPEROSubobjectParserTest { pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })); pBuilder.setPathKey(new PathKey(4660)); subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey32Bytes, 2)), true)); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY32_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(pathKey32Bytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(PATH_KEY32_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -219,14 +241,18 @@ public class PCEPEROSubobjectParserTest { final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true); final PathKeyBuilder pBuilder = new PathKeyBuilder(); - pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, - (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 })); + pBuilder.setPceId(new PceId(new byte[] { + (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, + (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00 + })); pBuilder.setPathKey(new PathKey(4660)); subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2)), true)); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY128_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(pathKey128Bytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(PATH_KEY128_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -246,17 +272,23 @@ public class PCEPEROSubobjectParserTest { public void testEROLabelSubobject() throws Exception { final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(this.ctx.getLabelHandlerRegistry()); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setLoose(true); - subs.setSubobjectType(new LabelCaseBuilder().setLabel( - new LabelBuilder().setUniDirectional(true).setLabelType( - new GeneralizedLabelCaseBuilder().setGeneralizedLabel( - new GeneralizedLabelBuilder().setGeneralizedLabel( - new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build()).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(labelBytes, 2)), true)); + final SubobjectBuilder subs = new SubobjectBuilder() + .setLoose(true) + .setSubobjectType(new LabelCaseBuilder() + .setLabel(new LabelBuilder() + .setUniDirectional(true) + .setLabelType(new GeneralizedLabelCaseBuilder() + .setGeneralizedLabel(new GeneralizedLabelBuilder() + .setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }) + .build()) + .build()) + .build()) + .build()); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(LABEL_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(labelBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(LABEL_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); @@ -274,19 +306,24 @@ public class PCEPEROSubobjectParserTest { @Test public void testEROEXRSSubobject() throws Exception { - final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(this.ctx.getXROSubobjectHandlerRegistry()); - final SubobjectBuilder subs = new SubobjectBuilder(); - subs.setLoose(true); - final List list = Lists.newArrayList(); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder(); - builder.setMandatory(true); - builder.setSubobjectType(new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build()); - list.add(builder.build()); - subs.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(list).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(exrsBytes, 2)), true)); + final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser( + this.ctx.getXROSubobjectHandlerRegistry()); + final List list = new ArrayList<>(); + list.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route + .subobjects.subobject.type.exrs._case.exrs.ExrsBuilder() + .setMandatory(true) + .setSubobjectType(new AsNumberCaseBuilder() + .setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()) + .build()) + .build()); + final SubobjectBuilder subs = new SubobjectBuilder().setLoose(true) + .setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(list).build()).build()); + assertEquals(subs.build(), + parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(EXRS_BYTES, 2)), true)); final ByteBuf buff = Unpooled.buffer(); parser.serializeSubobject(subs.build(), buff); - assertArrayEquals(exrsBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(EXRS_BYTES, ByteArray.getAllBytes(buff)); try { parser.parseSubobject(null, true); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java index 69295fd642..c88fe38bf5 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java @@ -19,6 +19,7 @@ import com.google.common.primitives.UnsignedBytes; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -286,7 +287,7 @@ public class PCEPObjectParserTest { final EroBuilder builder = new EroBuilder(); builder.setProcessingRule(false); builder.setIgnore(false); - final List subs = Lists.newArrayList(); + final List subs = new ArrayList<>(); subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setLoose( true).setSubobjectType( new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build()); @@ -323,7 +324,7 @@ public class PCEPObjectParserTest { final IroBuilder builder = new IroBuilder(); builder.setProcessingRule(false); builder.setIgnore(false); - final List subs = Lists.newArrayList(); + final List subs = new ArrayList<>(); subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder().setSubobjectType( new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).setLoose(true).build()); subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.iro.SubobjectBuilder().setSubobjectType( @@ -366,7 +367,7 @@ public class PCEPObjectParserTest { final RroBuilder builder = new RroBuilder(); builder.setProcessingRule(false); builder.setIgnore(false); - final List subs = Lists.newArrayList(); + final List subs = new ArrayList<>(); subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder().setSubobjectType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix( @@ -944,7 +945,7 @@ public class PCEPObjectParserTest { builder.setLinkDiverse(true); builder.setSrlgDiverse(true); - final List requestIDs = Lists.newArrayList(); + final List requestIDs = new ArrayList<>(); requestIDs.add(new RequestId(0xFFFFFFFFL)); requestIDs.add(new RequestId(0x00000001L)); requestIDs.add(new RequestId(0x01234567L)); @@ -1016,7 +1017,7 @@ public class PCEPObjectParserTest { builder.setProcessingRule(false); builder.setIgnore(false); builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro.Flags(true)); - final List subs = Lists.newArrayList(); + final List subs = new ArrayList<>(); subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType( new IpPrefixCaseBuilder().setIpPrefix( new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute( @@ -1052,7 +1053,7 @@ public class PCEPObjectParserTest { final PathKeyBuilder builder = new PathKeyBuilder(); builder.setProcessingRule(true); builder.setIgnore(false); - final List list = Lists.newArrayList(); + final List list = new ArrayList<>(); list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId( new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build()); builder.setPathKeys(list); @@ -1457,7 +1458,7 @@ public class PCEPObjectParserTest { builder.setProcessingRule(false); builder.setIgnore(false); final List subs = Lists.newArrayList(); + .route.object.ero.Subobject> subs = new ArrayList<>(); subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit .route.object.ero.SubobjectBuilder() .setLoose(true) @@ -1496,7 +1497,7 @@ public class PCEPObjectParserTest { builder.setProcessingRule(false); builder.setIgnore(false); final List subs = Lists.newArrayList(); + .route.object.ero.Subobject> subs = new ArrayList<>(); subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit .route.object.ero.SubobjectBuilder() .setLoose(true) diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java index 2ccb52338a..2d27f3904e 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java @@ -11,9 +11,9 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation; @@ -44,13 +44,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlvBuilder; public class PCEPTlvParserTest { - - private static final byte[] noPathVectorBytes = { 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, (byte) 0xa7 }; - private static final byte[] overloadedBytes = { 0x00, 0x02, 0x00, 0x04, 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff }; - private static final byte[] reqMissingBytes = { 0x00, 0x03, 0x00, 0x04, (byte) 0xF7, (byte) 0x82, 0x35, 0x17 }; - private static final byte[] orderBytes = { 0x00, 0x05, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x00, 0x00, - 0x00, 0x01 }; - private static final byte[] ofListBytes = { 0x00, 0x04, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78 }; + private static final byte[] NO_PATH_VECTOR_BYTES = { + 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, (byte) 0xa7 + }; + private static final byte[] OVERLOADED_BYTES = { + 0x00, 0x02, 0x00, 0x04, 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff + }; + private static final byte[] REQ_MISSING_BYTES = { + 0x00, 0x03, 0x00, 0x04, (byte) 0xF7, (byte) 0x82, 0x35, 0x17 + }; + private static final byte[] ORDER_BYTES = { + 0x00, 0x05, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x00, 0x00, 0x00, 0x01 + }; + private static final byte[] OF_LIST_BYTES = { 0x00, 0x04, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78 }; private static final byte[] VENDOR_INFO_BYTES = { 0x00, 0x07, 0x00, 0x08, /* Enterprise number */ @@ -66,12 +72,14 @@ public class PCEPTlvParserTest { @Test public void testNoPathVectorTlv() throws PCEPDeserializerException { final NoPathVectorTlvParser parser = new NoPathVectorTlvParser(); - final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build(); - assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(noPathVectorBytes, 4)))); + final NoPathVectorTlv tlv = new NoPathVectorBuilder() + .setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)) + .build(); + assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(NO_PATH_VECTOR_BYTES, 4)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeTlv(tlv, buff); - assertArrayEquals(noPathVectorBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(NO_PATH_VECTOR_BYTES, ByteArray.getAllBytes(buff)); assertNull(parser.parseTlv(null)); } @@ -79,10 +87,10 @@ public class PCEPTlvParserTest { public void testOverloadedDurationTlv() throws PCEPDeserializerException { final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser(); final OverloadDuration tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build(); - assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(overloadedBytes, 4)))); + assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(OVERLOADED_BYTES, 4)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeTlv(tlv, buff); - assertArrayEquals(overloadedBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(OVERLOADED_BYTES, ByteArray.getAllBytes(buff)); assertNull(parser.parseTlv(null)); } @@ -90,10 +98,10 @@ public class PCEPTlvParserTest { public void testReqMissingTlv() throws PCEPDeserializerException { final ReqMissingTlvParser parser = new ReqMissingTlvParser(); final ReqMissing tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build(); - assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(reqMissingBytes, 4)))); + assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(REQ_MISSING_BYTES, 4)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeTlv(tlv, buff); - assertArrayEquals(reqMissingBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(REQ_MISSING_BYTES, ByteArray.getAllBytes(buff)); assertNull(parser.parseTlv(null)); } @@ -101,24 +109,24 @@ public class PCEPTlvParserTest { public void testOrderTlv() throws PCEPDeserializerException { final OrderTlvParser parser = new OrderTlvParser(); final Order tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build(); - assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(orderBytes, 4)))); + assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(ORDER_BYTES, 4)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeTlv(tlv, buff); - assertArrayEquals(orderBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(ORDER_BYTES, ByteArray.getAllBytes(buff)); assertNull(parser.parseTlv(null)); } @Test public void testOFListTlv() throws PCEPDeserializerException { final OFListTlvParser parser = new OFListTlvParser(); - final List ids = Lists.newArrayList(); + final List ids = new ArrayList<>(); ids.add(new OfId(0x1234)); ids.add(new OfId(0x5678)); final OfList tlv = new OfListBuilder().setCodes(ids).build(); - assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(ofListBytes, 4)))); + assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(OF_LIST_BYTES, 4)))); final ByteBuf buff = Unpooled.buffer(); parser.serializeTlv(tlv, buff); - assertArrayEquals(ofListBytes, ByteArray.getAllBytes(buff)); + assertArrayEquals(OF_LIST_BYTES, ByteArray.getAllBytes(buff)); assertNull(parser.parseTlv(null)); } @@ -126,10 +134,13 @@ public class PCEPTlvParserTest { public void testVendorInformationTlv() throws PCEPDeserializerException { final TestVendorInformationTlvParser parser = new TestVendorInformationTlvParser(); final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5); - final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)) - .setEnterpriseSpecificInformation(esInfo).build(); + final VendorInformationTlv viTlv = new VendorInformationTlvBuilder() + .setEnterpriseNumber(new EnterpriseNumber(0L)) + .setEnterpriseSpecificInformation(esInfo) + .build(); - final VendorInformationTlv parsedTlv = parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(VENDOR_INFO_BYTES, 8))); + final VendorInformationTlv parsedTlv = parser.parseTlv( + Unpooled.wrappedBuffer(ByteArray.cutBytes(VENDOR_INFO_BYTES, 8))); assertEquals(viTlv, parsedTlv); final ByteBuf buff = Unpooled.buffer(VENDOR_INFO_BYTES.length); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java index b9c96f925c..21385fedd0 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java @@ -207,19 +207,23 @@ public class PCEPValidatorTest { rpBuilder.setEroCompression(false); rpBuilder.setPriority((short) 1); rpBuilder.setRequestId(new RequestId(10L)); - rpBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.rp.TlvsBuilder().build()); + rpBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp + .object.rp.TlvsBuilder().build()); this.rpTrue = rpBuilder.build(); rpBuilder.setProcessingRule(false); this.rpFalse = rpBuilder.build(); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder openBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder(); + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object + .OpenBuilder openBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types + .rev181109.open.object.OpenBuilder(); openBuilder.setProcessingRule(false); openBuilder.setIgnore(false); openBuilder.setDeadTimer((short) 1); openBuilder.setKeepalive((short) 1); openBuilder.setSessionId((short) 0); openBuilder.setVersion(new ProtocolVersion((short) 1)); - openBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder().build()); + openBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .open.object.open.TlvsBuilder().build()); this.open = openBuilder.build(); final NoPathBuilder npbuilder = new NoPathBuilder(); @@ -227,7 +231,8 @@ public class PCEPValidatorTest { npbuilder.setIgnore(false); npbuilder.setNatureOfIssue((short) 0); npbuilder.setUnsatisfiedConstraints(false); - npbuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().build()); + npbuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().build()); this.noPath = npbuilder.build(); final LspaBuilder lspaBuilder = new LspaBuilder(); @@ -239,7 +244,8 @@ public class PCEPValidatorTest { lspaBuilder.setExcludeAny(new AttributeFilter(0L)); lspaBuilder.setIncludeAll(new AttributeFilter(0L)); lspaBuilder.setIncludeAny(new AttributeFilter(0L)); - lspaBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.lspa.TlvsBuilder().build()); + lspaBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .lspa.object.lspa.TlvsBuilder().build()); this.lspa = lspaBuilder.build(); final MetricBuilder mBuilder = new MetricBuilder(); @@ -251,14 +257,17 @@ public class PCEPValidatorTest { mBuilder.setValue(new Float32(new byte[4])); this.metrics = new MetricsBuilder().setMetric(mBuilder.build()).build(); - this.eroASSubobject = new AsNumberCaseBuilder().setAsNumber( - new AsNumberBuilder().setAsNumber( - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber(0xFFFFL)).build()).build(); + this.eroASSubobject = new AsNumberCaseBuilder() + .setAsNumber(new AsNumberBuilder() + .setAsNumber(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715 + .AsNumber(0xFFFFL)) + .build()) + .build(); final IroBuilder iroBuilder = new IroBuilder(); iroBuilder.setIgnore(false); iroBuilder.setProcessingRule(false); - final List iroSubs = Lists.newArrayList(); + final List iroSubs = new ArrayList<>(); iroSubs.add(new SubobjectBuilder().setSubobjectType(this.eroASSubobject).setLoose(false).build()); iroBuilder.setSubobject(iroSubs); this.iro = iroBuilder.build(); @@ -266,9 +275,10 @@ public class PCEPValidatorTest { final EroBuilder eroBuilder = new EroBuilder(); eroBuilder.setIgnore(false); eroBuilder.setProcessingRule(false); - final List eroSubs = Lists.newArrayList(); - eroSubs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setSubobjectType( - this.eroASSubobject).setLoose(false).build()); + final List eroSubs = new ArrayList<>(); + eroSubs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit + .route.object.ero.SubobjectBuilder().setSubobjectType(this.eroASSubobject).setLoose(false).build()); eroBuilder.setSubobject(eroSubs); this.ero = eroBuilder.build(); @@ -276,7 +286,8 @@ public class PCEPValidatorTest { ofBuilder.setIgnore(false); ofBuilder.setProcessingRule(false); ofBuilder.setCode(new OfId(0)); - ofBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.of.TlvsBuilder().build()); + ofBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of + .object.of.TlvsBuilder().build()); this.of = ofBuilder.build(); final Ipv4Builder afi = new Ipv4Builder(); @@ -300,18 +311,25 @@ public class PCEPValidatorTest { sBuilder.setRequestsIds(Lists.newArrayList(new RequestId(1L))); this.svec = sBuilder.build(); - this.viObjects = Lists.newArrayList(); + this.viObjects = new ArrayList<>(); final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5); - final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)) - .setEnterpriseSpecificInformation(esInfo).build(); + final VendorInformationObject viObj = new VendorInformationObjectBuilder() + .setEnterpriseNumber(new EnterpriseNumber(0L)) + .setEnterpriseSpecificInformation(esInfo) + .build(); this.viObjects.add(viObj); this.monitoring = new MonitoringBuilder() .setMonitoringId(100L) .setFlags(new Flags(false, false, false, false, false)) - .setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.monitoring.TlvsBuilder().build()).build(); - this.pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))).build(); - this.pceId = new PceIdBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.2"))).build(); + .setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .monitoring.object.monitoring.TlvsBuilder().build()).build(); + this.pccIdReq = new PccIdReqBuilder() + .setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))) + .build(); + this.pceId = new PceIdBuilder() + .setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.2"))) + .build(); final ProcTimeBuilder procTimeBuilder = new ProcTimeBuilder(); procTimeBuilder.setEstimated(false); @@ -330,14 +348,17 @@ public class PCEPValidatorTest { final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry()); final OpenMessageBuilder builder = new OpenMessageBuilder(); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder(); + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object + .OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109 + .open.object.OpenBuilder(); b.setProcessingRule(false); b.setIgnore(false); b.setVersion(new ProtocolVersion((short) 1)); b.setKeepalive((short) 30); b.setDeadTimer((short) 120); b.setSessionId((short) 1); - b.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder().build()); + b.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object + .open.TlvsBuilder().build()); builder.setOpen(b.build()); assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, @@ -358,7 +379,8 @@ public class PCEPValidatorTest { public void testKeepAliveMsg() throws PCEPDeserializerException { final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { 32, 2, 0, 4 }); final PCEPKeepAliveMessageParser parser = new PCEPKeepAliveMessageParser(this.objectRegistry); - final KeepaliveBuilder builder = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()); + final KeepaliveBuilder builder = new KeepaliveBuilder() + .setKeepaliveMessage(new KeepaliveMessageBuilder().build()); assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); @@ -372,7 +394,8 @@ public class PCEPValidatorTest { final PCEPStartTLSMessageParser parser = new PCEPStartTLSMessageParser(this.objectRegistry); final StarttlsBuilder builder = new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()); - assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); + assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), + Collections.emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(builder.build(), buf); assertArrayEquals(result.array(), buf.array()); @@ -383,16 +406,25 @@ public class PCEPValidatorTest { final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin")); final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry); - final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose( - new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason((short) 5).setTlvs(new TlvsBuilder().build()).build()).build()); - - assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList())); + final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder() + .setCClose(new CCloseBuilder() + .setIgnore(false) + .setProcessingRule(false) + .setReason((short) 5) + .setTlvs(new TlvsBuilder().build()) + .build()) + .build()); + + assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), + Collections.emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(builder.build(), buf); assertArrayEquals(result.array(), buf.array()); try { - parser.serializeMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().build()).build(), null); + parser.serializeMessage(new CloseBuilder() + .setCCloseMessage(new CCloseMessageBuilder().build()) + .build(), null); fail(); } catch (final IllegalArgumentException e) { assertEquals("Close Object must be present in Close Message.", e.getMessage()); @@ -406,7 +438,7 @@ public class PCEPValidatorTest { final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry); final PcreqMessageBuilder builder = new PcreqMessageBuilder(); - final List reqs1 = Lists.newArrayList(); + final List reqs1 = new ArrayList<>(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder(); rBuilder.setRp(this.rpTrue); rBuilder.setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build()); @@ -422,7 +454,7 @@ public class PCEPValidatorTest { result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.3.bin")); - final List reqs2 = Lists.newArrayList(); + final List reqs2 = new ArrayList<>(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder(); rBuilder1.setRp(this.rpTrue); final P2pBuilder p2pBuilder = new P2pBuilder(); @@ -542,7 +574,7 @@ public class PCEPValidatorTest { final PcrepMessageBuilder builder = new PcrepMessageBuilder(); RepliesBuilder rBuilder = new RepliesBuilder(); - final List replies1 = Lists.newArrayList(); + final List replies1 = new ArrayList<>(); rBuilder.setRp(this.rpTrue); replies1.add(rBuilder.build()); builder.setReplies(replies1); @@ -555,7 +587,7 @@ public class PCEPValidatorTest { // simple Failure result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.2.bin")); - final List replies2 = Lists.newArrayList(); + final List replies2 = new ArrayList<>(); rBuilder = new RepliesBuilder(); rBuilder.setRp(this.rpTrue); replies2.add(rBuilder.build()); @@ -573,7 +605,7 @@ public class PCEPValidatorTest { // Failure with attributes result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.3.bin")); - final List replies3 = Lists.newArrayList(); + final List replies3 = new ArrayList<>(); rBuilder = new RepliesBuilder(); rBuilder.setRp(this.rpTrue); rBuilder.setResult(new FailureCaseBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro( @@ -589,10 +621,10 @@ public class PCEPValidatorTest { // Success result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.5.bin")); - final List replies4 = Lists.newArrayList(); + final List replies4 = new ArrayList<>(); rBuilder = new RepliesBuilder(); rBuilder.setRp(this.rpTrue); - final List paths = Lists.newArrayList(); + final List paths = new ArrayList<>(); final PathsBuilder paBuilder = new PathsBuilder(); paBuilder.setEro(this.ero); paBuilder.setLspa(this.lspa); @@ -629,10 +661,10 @@ public class PCEPValidatorTest { final CNotification cn1 = new CNotificationBuilder().setIgnore(false).setProcessingRule(false).setType((short) 1).setValue( (short) 1).build(); - final List innerNot = Lists.newArrayList(); + final List innerNot = new ArrayList<>(); innerNot.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification( cn1).build()); - final List rps = Lists.newArrayList(); + final List rps = new ArrayList<>(); rps.add(new RpsBuilder().setRp(this.rpFalse).build()); final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCNtf.5.bin")); @@ -640,18 +672,18 @@ public class PCEPValidatorTest { final PCEPNotificationMessageParser parser = new PCEPNotificationMessageParser(this.objectRegistry); final PcntfMessageBuilder builder = new PcntfMessageBuilder(); - final List nots = Lists.newArrayList(); + final List nots = new ArrayList<>(); final NotificationsBuilder b = new NotificationsBuilder(); b.setNotifications(innerNot); b.setRps(rps); nots.add(b.build()); - final List innerNot1 = Lists.newArrayList(); + final List innerNot1 = new ArrayList<>(); innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification( cn1).build()); innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification( cn1).build()); - final List rps1 = Lists.newArrayList(); + final List rps1 = new ArrayList<>(); rps1.add(new RpsBuilder().setRp(this.rpFalse).build()); rps1.add(new RpsBuilder().setRp(this.rpFalse).build()); @@ -679,7 +711,7 @@ public class PCEPValidatorTest { final PcerrMessageBuilder builder = new PcerrMessageBuilder(); - final List rps = Lists.newArrayList(); + final List rps = new ArrayList<>(); rps.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder().setRp( this.rpFalse).build()); @@ -730,7 +762,7 @@ public class PCEPValidatorTest { final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry); final PcreqMessageBuilder builder = new PcreqMessageBuilder(); - final List reqs1 = Lists.newArrayList(); + final List reqs1 = new ArrayList<>(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder(); rBuilder.setRp(this.rpTrue); rBuilder.setVendorInformationObject(this.viObjects); @@ -757,11 +789,11 @@ public class PCEPValidatorTest { final PcrepMessageBuilder builder = new PcrepMessageBuilder(); RepliesBuilder rBuilder = new RepliesBuilder(); final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.6.bin")); - final List replies = Lists.newArrayList(); + final List replies = new ArrayList<>(); rBuilder = new RepliesBuilder(); rBuilder.setRp(this.rpTrue); rBuilder.setVendorInformationObject(this.viObjects); - final List paths = Lists.newArrayList(); + final List paths = new ArrayList<>(); final PathsBuilder paBuilder = new PathsBuilder(); paBuilder.setEro(this.ero); paths.add(paBuilder.build()); @@ -802,12 +834,12 @@ public class PCEPValidatorTest { builder.setPccIdReq(this.pccIdReq); final SpecificMetricsBuilder smBuilder = new SpecificMetricsBuilder(); smBuilder.setRp(this.rpTrue); - final List metricPces = Lists.newArrayList(); + final List metricPces = new ArrayList<>(); metricPces.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).setProcTime(this.procTime).build()); metricPces.add(new MetricPceBuilder().setPceId(this.pceId).setProcTime(this.procTime).build()); smBuilder.setMetricPce(metricPces); final SpecificMetricsBuilder smBuilder2 = new SpecificMetricsBuilder(); - final List metricPces2 = Lists.newArrayList(); + final List metricPces2 = new ArrayList<>(); smBuilder2.setRp(this.rpTrue); metricPces2.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).build()); smBuilder2.setMetricPce(metricPces2); @@ -829,13 +861,13 @@ public class PCEPValidatorTest { RepliesBuilder rBuilder = new RepliesBuilder(); final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin")); - final List replies4 = Lists.newArrayList(); + final List replies4 = new ArrayList<>(); rBuilder = new RepliesBuilder(); rBuilder.setRp(this.rpTrue); rBuilder.setMonitoring(this.monitoring); rBuilder.setPccIdReq(this.pccIdReq); rBuilder.setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())); - final List paths = Lists.newArrayList(); + final List paths = new ArrayList<>(); final PathsBuilder paBuilder = new PathsBuilder(); paBuilder.setEro(this.ero); paBuilder.setLspa(this.lspa); @@ -861,7 +893,7 @@ public class PCEPValidatorTest { final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry); final PcreqMessageBuilder builder = new PcreqMessageBuilder(); - final List reqs1 = Lists.newArrayList(); + final List reqs1 = new ArrayList<>(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder(); rBuilder.setRp(this.rpTrue); rBuilder.setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build()); @@ -905,7 +937,7 @@ public class PCEPValidatorTest { assertArrayEquals(result.array(), buf.array()); result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonReq.bin")); - final List reqs2 = Lists.newArrayList(); + final List reqs2 = new ArrayList<>(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder(); rBuilder1.setRp(this.rpTrue); final P2pBuilder p2pBuilder = new P2pBuilder(); @@ -940,7 +972,7 @@ public class PCEPValidatorTest { final PcrepMessageBuilder builder = new PcrepMessageBuilder(); RepliesBuilder rBuilder = new RepliesBuilder(); - final List replies = Lists.newArrayList(); + final List replies = new ArrayList<>(); final BandwidthBuilder bwBuilder = new BandwidthBuilder(); bwBuilder.setIgnore(false); @@ -949,7 +981,7 @@ public class PCEPValidatorTest { rBuilder = new RepliesBuilder(); rBuilder.setRp(this.rpTrue); - final List paths = Lists.newArrayList(); + final List paths = new ArrayList<>(); final PathsBuilder paBuilder1 = new PathsBuilder(); paBuilder1.setEro(this.ero); paBuilder1.setBandwidth(bwBuilder.build()); diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java index 1030a3ad16..3fbc5e38f6 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java @@ -7,10 +7,8 @@ */ package org.opendaylight.protocol.pcep.impl; -import com.google.common.collect.Lists; - +import java.util.ArrayList; import java.util.List; - import org.opendaylight.protocol.pcep.PCEPSession; import org.opendaylight.protocol.pcep.PCEPSessionListener; import org.opendaylight.protocol.pcep.PCEPTerminationReason; @@ -23,7 +21,7 @@ import org.slf4j.LoggerFactory; */ public class SimpleSessionListener implements PCEPSessionListener { - public final List messages = Lists.newArrayList(); + public final List messages = new ArrayList<>(); public boolean up = false; -- 2.36.6