use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.
the class EncodableDiscreteResourcesTest method testSerializeInstanceContainingEmptyEncodedDiscreteResources.
@Test
public void testSerializeInstanceContainingEmptyEncodedDiscreteResources() {
DiscreteResource device = Resources.discrete(DeviceId.deviceId("a")).resource();
List<PortNumber> ports = IntStream.range(0, 1).mapToObj(PortNumber::portNumber).collect(Collectors.toList());
List<VlanId> vlans = IntStream.range(0, 2).mapToObj(x -> VlanId.vlanId((short) x)).collect(Collectors.toList());
Set<DiscreteResource> originalResources = Stream.concat(ports.stream(), vlans.stream()).map(device::child).collect(Collectors.toSet());
DiscreteResources sut = EncodableDiscreteResources.of(originalResources);
Set<DiscreteResource> portOnlyResources = ports.stream().map(device::child).collect(Collectors.toSet());
DiscreteResources other = EncodableDiscreteResources.of(portOnlyResources);
DiscreteResources diff = sut.difference(other);
byte[] bytes = serializer.encode(diff);
assertThat(serializer.decode(bytes), is(diff));
}
use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.
the class EncodableDiscreteResourcesTest method testAdd.
@Test
public void testAdd() {
DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1)).resource();
DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(2)).resource();
DiscreteResources sut = EncodableDiscreteResources.of(ImmutableSet.of(res1));
DiscreteResources other = EncodableDiscreteResources.of(ImmutableSet.of(res2));
DiscreteResources expected = EncodableDiscreteResources.of(ImmutableSet.of(res1, res2));
assertThat(sut.add(other), is(expected));
}
use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.
the class EncodedDiscreteResourcesTest method testDifference.
@Test
public void testDifference() {
DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource();
DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource();
DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource();
EncodedDiscreteResources sut = EncodedDiscreteResources.of(ImmutableSet.of(res1, res2), new VlanIdCodec());
EncodedDiscreteResources other = EncodedDiscreteResources.of(ImmutableSet.of(res1, res3), new VlanIdCodec());
assertThat(sut.difference(other), is(EncodedDiscreteResources.of(ImmutableSet.of(res2), new VlanIdCodec())));
}
use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.
the class EncodedDiscreteResourcesTest method testContains.
@Test
public void testContains() {
DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource();
DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource();
DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource();
Set<DiscreteResource> resources = ImmutableSet.of(res1, res2);
EncodedDiscreteResources sut = EncodedDiscreteResources.of(resources, new VlanIdCodec());
assertThat(sut.contains(res1), is(true));
assertThat(sut.contains(res3), is(false));
}
use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.
the class EncodedDiscreteResourcesTest method testAdd.
@Test
public void testAdd() {
DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource();
DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource();
DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource();
EncodedDiscreteResources sut = EncodedDiscreteResources.of(ImmutableSet.of(res1, res2), new VlanIdCodec());
EncodedDiscreteResources other = EncodedDiscreteResources.of(ImmutableSet.of(res1, res3), new VlanIdCodec());
assertThat(sut.add(other), is(EncodedDiscreteResources.of(ImmutableSet.of(res1, res2, res3), new VlanIdCodec())));
}
Aggregations