Sho SHIMIZU | 13bf46e | 2016-06-01 12:23:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.store.resource.impl; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.resource.DiscreteResource; |
| 25 | import org.onosproject.net.resource.Resources; |
| 26 | |
| 27 | import java.util.Set; |
| 28 | |
| 29 | import static org.hamcrest.Matchers.is; |
| 30 | import static org.junit.Assert.*; |
| 31 | |
| 32 | public class EncodedDiscreteResourcesTest { |
| 33 | private static final DeviceId DID = DeviceId.deviceId("device1"); |
| 34 | private static final PortNumber PN = PortNumber.portNumber(1); |
| 35 | private static final VlanId VID1 = VlanId.vlanId((short) 1); |
| 36 | private static final VlanId VID2 = VlanId.vlanId((short) 2); |
| 37 | private static final VlanId VID3 = VlanId.vlanId((short) 3); |
| 38 | |
| 39 | @Test |
| 40 | public void testContains() { |
| 41 | DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource(); |
| 42 | DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource(); |
| 43 | DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource(); |
| 44 | |
| 45 | Set<DiscreteResource> resources = ImmutableSet.of(res1, res2); |
| 46 | |
| 47 | EncodedDiscreteResources sut = EncodedDiscreteResources.of(resources, new VlanIdCodec()); |
| 48 | |
| 49 | assertThat(sut.contains(res1), is(true)); |
| 50 | assertThat(sut.contains(res3), is(false)); |
| 51 | } |
| 52 | |
Sho SHIMIZU | b42d383 | 2016-06-09 14:21:17 -0700 | [diff] [blame] | 53 | @Test |
| 54 | public void testDifference() { |
| 55 | DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource(); |
| 56 | DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource(); |
| 57 | DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource(); |
| 58 | |
| 59 | EncodedDiscreteResources sut = EncodedDiscreteResources.of(ImmutableSet.of(res1, res2), new VlanIdCodec()); |
| 60 | EncodedDiscreteResources other = EncodedDiscreteResources.of(ImmutableSet.of(res1, res3), new VlanIdCodec()); |
| 61 | |
| 62 | assertThat(sut.difference(other), is(EncodedDiscreteResources.of(ImmutableSet.of(res2), new VlanIdCodec()))); |
| 63 | } |
| 64 | |
Sho SHIMIZU | 13bf46e | 2016-06-01 12:23:15 -0700 | [diff] [blame] | 65 | } |