Enforce findbug and checkstyle for pcep auto bandwith 68/66668/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 20 Dec 2017 10:29:16 +0000 (11:29 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Thu, 21 Dec 2017 07:24:03 +0000 (07:24 +0000)
Change-Id: I69959b94839f6b16836a2123a7f481fccdaafd6b
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
pcep/auto-bandwidth-extension/pom.xml
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/Activator.java
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/BandwidthUsageObjectCodec.java
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodec.java
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PCEPBandwidthUsageObjectCodecTest.java
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodecTest.java

index 83463e5c500ad662196c44a46c72f2e0a14f27b4..01268771d15c1ae9212603202d444255c689716d 100644 (file)
         </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>findbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
     <scm>
         <connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
         <developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
index 2e6508ddc5ef18e9c93613df1f7724508a881131..316875971990ab01aaf17caa6ae7c69cccb8dd00 100644 (file)
@@ -33,8 +33,10 @@ public class Activator extends AbstractPCEPExtensionProviderActivator {
     protected List<AutoCloseable> startImpl(final PCEPExtensionProviderContext context) {
         final List<AutoCloseable> regs = new ArrayList<>();
 
-        final BandwidthUsageObjectCodec bandwidthUsageObjectCodec = new BandwidthUsageObjectCodec(this.bandwidthUsageObjectType);
-        regs.add(context.registerObjectParser(BandwidthUsageObjectCodec.CLASS, bandwidthUsageObjectCodec.getType(), bandwidthUsageObjectCodec));
+        final BandwidthUsageObjectCodec bandwidthUsageObjectCodec =
+                new BandwidthUsageObjectCodec(this.bandwidthUsageObjectType);
+        regs.add(context.registerObjectParser(BandwidthUsageObjectCodec.CLASS, bandwidthUsageObjectCodec.getType(),
+                bandwidthUsageObjectCodec));
         regs.add(context.registerObjectSerializer(BandwidthUsage.class, bandwidthUsageObjectCodec));
 
         final PcRptMessageCodec pcRptMessageCodec = new PcRptMessageCodec(context.getObjectHandlerRegistry());
index 45ca2ba0e3b156eda814cf7d65822fe7f878a17e..c60e6d31d4020c8094325e2c95113ee47cec246d 100644 (file)
@@ -28,7 +28,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 
 public class BandwidthUsageObjectCodec implements ObjectParser, ObjectSerializer {
 
-    public static final int CLASS = 5;
+    static final int CLASS = 5;
 
     private static final int BW_LENGTH = 4;
 
@@ -40,10 +40,11 @@ public class BandwidthUsageObjectCodec implements ObjectParser, ObjectSerializer
 
     @Override
     public BandwidthUsage parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
+                "Array of bytes is mandatory. Can't be null or empty.");
         if (bytes.readableBytes() % BW_LENGTH != 0) {
-            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected multiple of "
-                    + BW_LENGTH + ".");
+            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
+                    + "; Expected multiple of " + BW_LENGTH + ".");
         }
         final BandwidthUsageBuilder builder = new BandwidthUsageBuilder();
         builder.setIgnore(header.isIgnore());
@@ -58,7 +59,8 @@ public class BandwidthUsageObjectCodec implements ObjectParser, ObjectSerializer
 
     @Override
     public void serializeObject(final Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof BandwidthUsage, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthUsage.", object.getClass());
+        Preconditions.checkArgument(object instanceof BandwidthUsage,
+                "Wrong instance of PCEPObject. Passed %s. Needed BandwidthUsage.", object.getClass());
         final List<Bandwidth> bwSample = ((BandwidthUsage) object).getBwSample();
         final ByteBuf body = Unpooled.buffer(bwSample.size() * BW_LENGTH);
         for (final Bandwidth bw : bwSample) {
index 75450f746b427482796683233b5bab767fecb3a2..6a7a64b0d2584dd0277a35775155afe82fb0bdb6 100644 (file)
@@ -74,7 +74,8 @@ public class PcRptMessageCodec extends Stateful07PCReportMessageParser {
         } else {
             bandwidthBuilder = new BandwidthBuilder();
         }
-        bandwidthBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder().setBwSample(bwUsage.getBwSample()).build()).build();
+        bandwidthBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder()
+                .setBwSample(bwUsage.getBwSample()).build()).build();
         return bandwidthBuilder.build();
     }
 
index 02127b7500f814996894d289d0a6e02d36114389..079ec1e97000fb23478c2b81173c81cd13d03785 100644 (file)
@@ -24,7 +24,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.
 
 public class PCEPBandwidthUsageObjectCodecTest {
 
-    private static final byte[] BW_BYTES = new byte[] { 0x05, 0x50, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x40, 0x00};
+    private static final byte[] BW_BYTES = new byte[]{0x05, 0x50, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00,
+        0x00, 0x00, 0x40, 0x00};
 
     @Test
     public void testCodec() throws PCEPDeserializerException {
@@ -32,10 +33,12 @@ public class PCEPBandwidthUsageObjectCodecTest {
         assertEquals(5, codec.getType());
 
         final BandwidthUsageBuilder builder = new BandwidthUsageBuilder();
-        builder.setBwSample(Lists.newArrayList(new Bandwidth(new byte [] {0x00, 0x00, 0x10, 0x00}), new Bandwidth(new byte[] {0x00, 0x00, 0x40, 0x00})));
+        builder.setBwSample(Lists.newArrayList(new Bandwidth(new byte[]{0x00, 0x00, 0x10, 0x00}),
+                new Bandwidth(new byte[]{0x00, 0x00, 0x40, 0x00})));
         builder.setIgnore(false);
         builder.setProcessingRule(false);
-        final BandwidthUsage parsedObject = codec.parseObject(new ObjectHeaderImpl(false, false), Unpooled.wrappedBuffer(BW_BYTES, 4, BW_BYTES.length - 4));
+        final BandwidthUsage parsedObject = codec.parseObject(new ObjectHeaderImpl(false, false),
+                Unpooled.wrappedBuffer(BW_BYTES, 4, BW_BYTES.length - 4));
         assertEquals(builder.build(), parsedObject);
 
         final ByteBuf buffer = Unpooled.buffer(BW_BYTES.length);
index 748383f33fb1d78288170ceadde43b369f2560a9..c1fd8963d011baacee57dd01b32d4346b4910fdf 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.protocol.pcep.auto.bandwidth.extension;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -53,6 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 public class PcRptMessageCodecTest {
 
+    private static final List<Bandwidth> BW = Collections.singletonList(new Bandwidth(new byte[]{0, 0, 0, 1}));
     private SimplePCEPExtensionProviderContext ctx;
     private BaseParserExtensionActivator act;
     private StatefulActivator statefulAct;
@@ -65,7 +67,8 @@ public class PcRptMessageCodecTest {
         this.act.start(this.ctx);
         this.statefulAct = new StatefulActivator();
         this.statefulAct.start(this.ctx);
-        this.autoBwActivator = new org.opendaylight.protocol.pcep.auto.bandwidth.extension.Activator(5);
+        this.autoBwActivator = new org.opendaylight.protocol.pcep.auto.bandwidth.extension
+                .Activator(5);
         this.autoBwActivator.start(this.ctx);
     }
 
@@ -79,7 +82,7 @@ public class PcRptMessageCodecTest {
     @Test
     public void testGetValidReportsPositive() {
         final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
-        final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(Lists.newArrayList(new Bandwidth(new byte[] {0, 0, 0, 1}))).build();
+        final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(BW).build();
         final Ipv4Builder builder = new Ipv4Builder();
         builder.setIpv4TunnelSenderAddress(new Ipv4Address("127.0.1.1"));
         builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(new Ipv4Address("127.0.1.2")));
@@ -87,8 +90,10 @@ public class PcRptMessageCodecTest {
         final AddressFamily afiLsp = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
         final LspId lspId = new LspId(1L);
         final TunnelId tunnelId = new TunnelId(1);
-        final LspIdentifiers identifier = new LspIdentifiersBuilder().setAddressFamily(afiLsp).setLspId(lspId).setTunnelId(tunnelId).build();
-        final Lsp lsp = new LspBuilder().setPlspId(new PlspId(1L)).setTlvs(new TlvsBuilder().setLspIdentifiers(identifier).build()).build();
+        final LspIdentifiers identifier = new LspIdentifiersBuilder().setAddressFamily(afiLsp)
+                .setLspId(lspId).setTunnelId(tunnelId).build();
+        final Lsp lsp = new LspBuilder().setPlspId(new PlspId(1L))
+                .setTlvs(new TlvsBuilder().setLspIdentifiers(identifier).build()).build();
         final Ero ero = new EroBuilder().build();
         final List<Object> objects = Lists.newArrayList(lsp, ero, bw);
         final Reports validReports = codec.getValidReports(objects, Collections.emptyList());
@@ -99,7 +104,7 @@ public class PcRptMessageCodecTest {
     @Test
     public void testGetValidReportsNegative() {
         final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
-        final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(Lists.newArrayList(new Bandwidth(new byte[] {0, 0, 0, 1}))).build();
+        final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(BW).build();
         final Ipv4Builder builder = new Ipv4Builder();
         builder.setIpv4TunnelSenderAddress(new Ipv4Address("127.0.1.1"));
         builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(new Ipv4Address("127.0.1.2")));
@@ -115,8 +120,7 @@ public class PcRptMessageCodecTest {
     public void testserializeObject() {
         final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
         final BandwidthBuilder bwBuilder = new BandwidthBuilder();
-        bwBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder().setBwSample(
-                Lists.newArrayList(new Bandwidth(new byte[] {0, 0, 0, 1}))).build());
+        bwBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder().setBwSample(BW).build());
         final ByteBuf buffer = Unpooled.buffer();
         codec.serializeObject(bwBuilder.build(), buffer);
         Assert.assertTrue(buffer.readableBytes() > 0);
@@ -124,9 +128,15 @@ public class PcRptMessageCodecTest {
 
     @Test
     public void testReportMsgWithRro() throws PCEPDeserializerException {
-        final byte[] parseHexBinary = DatatypeConverter.parseHexBinary("2010003c0084a019001100106e79636e7932316372735f7432313231001200100a0000d2004008490a0000d40a0000d4001f0006000005dd700000000710001401080a000706200001080a0000d420000910001400000000000000000000000005050100051000084998968005500008513a43b70810002401080a0000d42020030801010000000001080a00070620000308010100000000");
-        final Pcrpt msg = (Pcrpt) this.ctx.getMessageHandlerRegistry().parseMessage(10, Unpooled.wrappedBuffer(parseHexBinary), Collections.emptyList());
-        Assert.assertNotNull(msg.getPcrptMessage().getReports().get(0).getPath().getBandwidth().getAugmentation(Bandwidth1.class));
+        final byte[] parseHexBinary = DatatypeConverter
+                .parseHexBinary("2010003c0084a019001100106e79636e7932316372735f7432313231001200100a0"
+                        + "000d2004008490a0000d40a0000d4001f0006000005dd700000000710001401080a000706200001080a0000d420"
+                        + "000910001400000000000000000000000005050100051000084998968005500008513a43b70810002401080a000"
+                        + "0d42020030801010000000001080a00070620000308010100000000");
+        final Pcrpt msg = (Pcrpt) this.ctx.getMessageHandlerRegistry().parseMessage(10,
+                Unpooled.wrappedBuffer(parseHexBinary), Collections.emptyList());
+        Assert.assertNotNull(msg.getPcrptMessage().getReports().get(0).getPath()
+                .getBandwidth().getAugmentation(Bandwidth1.class));
     }
 
 }