Use normal service loading and clean tests up a bit.
Change-Id: I9c5e09ee8e9cb0d0158ca8c1a82e2e244c7a6e60
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.util.ServiceLoader;
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.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
.build())
.build();
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
+
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(RESULT, actual);
+ registry.serializeAttribute(RESULT, actual);
assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(RESULT.getAggregator(), attributeOut.getAggregator());
}
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder()
- .setAggregator(new AggregatorBuilder()
- .build())
- .build(), actual);
+ registry.serializeAttribute(new AttributesBuilder().setAggregator(new AggregatorBuilder().build()).build(),
+ actual);
assertEquals(Unpooled.buffer(), actual);
}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
+import java.util.ServiceLoader;
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.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.SegmentsBuilder;
import org.opendaylight.yangtools.yang.common.Uint32;
};
private static final byte[] EMPTY_ATTRIBUTE_BYTES = { (byte) 0x40, (byte) 0x02, (byte) 0x00 };
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
+
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
- final List<Segments> segments = new ArrayList<>();
- segments.add(new SegmentsBuilder()
- .setAsSet(Arrays.asList(new AsNumber(Uint32.ONE), new AsNumber(Uint32.TWO))).build());
- segments.add(new SegmentsBuilder()
- .setAsSequence(Arrays.asList(new AsNumber(Uint32.valueOf(3)), new AsNumber(Uint32.valueOf(4))))
- .build());
- final Attributes attr = new AttributesBuilder().setAsPath(new AsPathBuilder()
- .setSegments(segments)
- .build())
- .build();
+ final Attributes attr = new AttributesBuilder()
+ .setAsPath(new AsPathBuilder()
+ .setSegments(List.of(
+ new SegmentsBuilder().setAsSet(List.of(new AsNumber(Uint32.ONE), new AsNumber(Uint32.TWO))).build(),
+ new SegmentsBuilder()
+ .setAsSequence(List.of(new AsNumber(Uint32.valueOf(3)), new AsNumber(Uint32.valueOf(4))))
+ .build()))
+ .build())
+ .build();
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(attr, actual);
+ registry.serializeAttribute(attr, actual);
assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(attr.getAsPath(), attributeOut.getAsPath());
}
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder()
- .setAsPath(new AsPathBuilder()
- .build())
- .build(), actual);
+ registry.serializeAttribute(new AttributesBuilder().setAsPath(new AsPathBuilder().build()).build(), actual);
assertEquals(Unpooled.buffer().writeBytes(EMPTY_ATTRIBUTE_BYTES), actual);
}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.util.ServiceLoader;
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.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
private static final byte[] ATTRIBUTE_BYTES = {(byte) 0x40, (byte) 0x06, (byte) 0x00};
private static final Attributes RESULT = new AttributesBuilder()
- .setAtomicAggregate(new AtomicAggregateBuilder().build()).build();
+ .setAtomicAggregate(new AtomicAggregateBuilder().build())
+ .build();
+
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(RESULT, actual);
+ registry.serializeAttribute(RESULT, actual);
assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(RESULT.getAtomicAggregate(), attributeOut.getAtomicAggregate());
}
}
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
+import java.util.ServiceLoader;
import org.junit.Test;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.NoopReferenceCache;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
(byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x07
};
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
+
@Test
public void testCommunitiesAttributeParser() throws Exception {
final List<Communities> comms = new ArrayList<>();
paBuilder.setCommunities(comms);
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(paBuilder.build(), actual);
+ registry.serializeAttribute(paBuilder.build(), actual);
assertArrayEquals(COMMUNITIES_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(comms, attributeOut.getCommunities());
}
public void testParseEmptyListAttribute() {
final List<Communities> comms = new ArrayList<>();
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder().setCommunities(comms).build(), actual);
+ registry.serializeAttribute(new AttributesBuilder().setCommunities(comms).build(), actual);
assertEquals(Unpooled.buffer(), actual);
}
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder().build(), actual);
+ registry.serializeAttribute(new AttributesBuilder().build(), actual);
assertEquals(Unpooled.buffer(), actual);
}
}
\ No newline at end of file
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.util.ServiceLoader;
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.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
.setLocalPref(new LocalPrefBuilder().setPref(Uint32.ONE).build())
.build();
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
+
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(RESULT, actual);
+ registry.serializeAttribute(RESULT, actual);
assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(RESULT.getLocalPref(), attributeOut.getLocalPref());
}
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder()
- .setLocalPref(new LocalPrefBuilder().build())
- .build(), actual);
+ registry.serializeAttribute(new AttributesBuilder().setLocalPref(new LocalPrefBuilder().build()).build(),
+ actual);
assertEquals(Unpooled.buffer(), actual);
}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.util.ServiceLoader;
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.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
};
private static final Attributes RESULT = new AttributesBuilder()
- .setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ONE).build()).build();
+ .setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ONE).build())
+ .build();
+
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(RESULT, actual);
+ registry.serializeAttribute(RESULT, actual);
assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(RESULT.getMultiExitDisc(), attributeOut.getMultiExitDisc());
}
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder()
- .setMultiExitDisc(new MultiExitDiscBuilder().build())
- .build(), actual);
+ registry.serializeAttribute(new AttributesBuilder()
+ .setMultiExitDisc(new MultiExitDiscBuilder().build())
+ .build(), actual);
assertEquals(Unpooled.buffer(), actual);
}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.util.ServiceLoader;
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.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
.build())
.build();
+ private final AttributeRegistry registry = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
+ .orElseThrow().getAttributeRegistry();
+
@Test
public void testAttributeParser() throws BGPParsingException, BGPDocumentedException {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(RESULT, actual);
+ registry.serializeAttribute(RESULT, actual);
assertArrayEquals(ATTRIBUTE_BYTES, ByteArray.getAllBytes(actual));
- final Attributes attributeOut = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance()
- .getAttributeRegistry().parseAttributes(actual, null).getAttributes();
+ final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(RESULT.getOriginatorId(), attributeOut.getOriginatorId());
}
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
- .serializeAttribute(new AttributesBuilder()
- .setOriginatorId(new OriginatorIdBuilder().build())
- .build(), actual);
+ registry.serializeAttribute(new AttributesBuilder().setOriginatorId(new OriginatorIdBuilder().build()).build(),
+ actual);
assertEquals(Unpooled.buffer(), actual);
}
}