blob: fe1e781fca668901591a56663b0b348e81060c64 [file] [log] [blame]
Sho SHIMIZU13bf46e2016-06-01 12:23:15 -07001/*
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
17package org.onosproject.store.resource.impl;
18
19import com.google.common.collect.ImmutableSet;
20import org.junit.Test;
21import org.onlab.packet.VlanId;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.PortNumber;
24import org.onosproject.net.resource.DiscreteResource;
25import org.onosproject.net.resource.Resources;
26
27import java.util.Set;
28
29import static org.hamcrest.Matchers.is;
30import static org.junit.Assert.*;
31
32public 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 SHIMIZUb42d3832016-06-09 14:21:17 -070053 @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 SHIMIZU13bf46e2016-06-01 12:23:15 -070065}