Sho SHIMIZU
Committed by Gerrit Code Review

Improve test coverage

Change-Id: I12d6827c644f45189f3a5929a8c1837aa112bdb9
...@@ -27,6 +27,7 @@ import org.onosproject.net.resource.ResourceAllocation; ...@@ -27,6 +27,7 @@ import org.onosproject.net.resource.ResourceAllocation;
27 import org.onosproject.net.resource.ResourceConsumer; 27 import org.onosproject.net.resource.ResourceConsumer;
28 import org.onosproject.net.resource.Resources; 28 import org.onosproject.net.resource.Resources;
29 29
30 +import static org.hamcrest.Matchers.hasItem;
30 import static org.hamcrest.Matchers.is; 31 import static org.hamcrest.Matchers.is;
31 import static org.junit.Assert.assertThat; 32 import static org.junit.Assert.assertThat;
32 33
...@@ -138,4 +139,47 @@ public class ContinuousResourceAllocationTest { ...@@ -138,4 +139,47 @@ public class ContinuousResourceAllocationTest {
138 assertThat(allocations.size(), is(1)); 139 assertThat(allocations.size(), is(1));
139 assertThat(allocations.get(0).resource().equals(allocated), is(true)); 140 assertThat(allocations.get(0).resource().equals(allocated), is(true));
140 } 141 }
142 +
143 + @Test
144 + public void testAllocateDifferentValue() {
145 + ContinuousResource original =
146 + Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
147 + ContinuousResource allocated =
148 + Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
149 + ResourceConsumer consumer = IntentId.valueOf(1);
150 +
151 + ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original,
152 + ImmutableList.of(new ResourceAllocation(allocated, consumer)));
153 +
154 + ContinuousResource request =
155 + Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(200).bps());
156 +
157 + ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
158 +
159 + assertThat(newValue.allocations().size(), is(2));
160 + assertThat(newValue.allocations(), hasItem(new ResourceAllocation(allocated, consumer)));
161 + assertThat(newValue.allocations(), hasItem(new ResourceAllocation(request, consumer)));
162 + }
163 +
164 + @Test
165 + public void testAllocateSameValue() {
166 + ContinuousResource original =
167 + Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
168 + ContinuousResource allocated =
169 + Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).bps());
170 + ResourceConsumer consumer = IntentId.valueOf(1);
171 +
172 + ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original,
173 + ImmutableList.of(new ResourceAllocation(allocated, consumer)));
174 +
175 + ContinuousResource request =
176 + Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).bps());
177 +
178 + ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
179 +
180 + assertThat(newValue.allocations().size(), is(2));
181 + assertThat(newValue.allocations()
182 + .stream()
183 + .allMatch(x -> x.equals(new ResourceAllocation(allocated, consumer))), is(true));
184 + }
141 } 185 }
......