blob: 747e8509f66076905f078ba38663703f33a90ebf [file] [log] [blame]
Sho SHIMIZU047f5b72016-06-08 12:00:19 -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;
Sho SHIMIZU8f4f7af2016-07-06 15:03:39 -070021import org.onlab.packet.VlanId;
Sho SHIMIZU047f5b72016-06-08 12:00:19 -070022import org.onosproject.net.DeviceId;
23import org.onosproject.net.resource.DiscreteResource;
24import org.onosproject.net.resource.Resources;
25
26import java.util.Optional;
27
28import static org.hamcrest.Matchers.is;
29import static org.junit.Assert.*;
30
31public class EmptyDiscreteResourcesTest {
32 private EmptyDiscreteResources sut = EmptyDiscreteResources.INSTANCE;
33
34 @Test
35 public void testLookup() {
36 assertThat(sut.lookup(Resources.discrete(DeviceId.deviceId("a")).id()), is(Optional.empty()));
37 }
38
39 @Test
40 public void testDifference() {
41 DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a")).resource();
42 DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("b")).resource();
43
44 assertThat(sut.difference(DiscreteResources.of(ImmutableSet.of(res1))),
45 is(EmptyDiscreteResources.INSTANCE));
46 assertThat(sut.difference(DiscreteResources.of(ImmutableSet.of(res2))),
47 is(EmptyDiscreteResources.INSTANCE));
48 }
49
50 @Test
51 public void testIsEmpty() {
52 assertThat(sut.isEmpty(), is(true));
53 }
54
55 @Test
Sho SHIMIZU8f4f7af2016-07-06 15:03:39 -070056 public void testValuesOf() {
57 // doesn't match any types of resources
58 assertThat(sut.valuesOf(Object.class), is(ImmutableSet.of()));
59 assertThat(sut.valuesOf(VlanId.class), is(ImmutableSet.of()));
60 }
61
62 @Test
Sho SHIMIZU047f5b72016-06-08 12:00:19 -070063 public void testContainsAny() {
64 DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a")).resource();
65 DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("b")).resource();
66
67 assertThat(sut.containsAny(ImmutableSet.of(res1)), is(false));
68 assertThat(sut.containsAny(ImmutableSet.of(res2)), is(false));
69 }
70
71 @Test
72 public void testAdd() {
73 DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a")).resource();
74 DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("b")).resource();
75
76 assertThat(sut.add(DiscreteResources.of(ImmutableSet.of(res1))),
77 is(DiscreteResources.of(ImmutableSet.of(res1))));
78 assertThat(sut.add(DiscreteResources.of(ImmutableSet.of(res2))),
79 is(DiscreteResources.of(ImmutableSet.of(res2))));
80 }
81
82 @Test
83 public void testValues() {
84 assertThat(sut.values(), is(ImmutableSet.of()));
85 }
86}