blob: ca263ee13effba5382a0dcdae071ae772242ee59 [file] [log] [blame]
Ray Milkeyf19b7152014-11-21 10:56:52 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Ray Milkeyf19b7152014-11-21 10:56:52 -08003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
Ray Milkeyf19b7152014-11-21 10:56:52 -080017
Ray Milkeyf19b7152014-11-21 10:56:52 -080018import org.junit.Test;
Ray Milkey7bf273c2017-09-27 16:15:15 -070019import org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry;
20import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation;
21import org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.intent.IntentTestsMocks;
Ray Milkeyf19b7152014-11-21 10:56:52 -080023
Brian O'Connor72cb19a2015-01-16 16:14:41 -080024import java.util.HashSet;
25import java.util.List;
26import java.util.Set;
Brian O'Connor427a1762014-11-19 18:40:32 -080027
Ray Milkeyf19b7152014-11-21 10:56:52 -080028import static org.hamcrest.MatcherAssert.assertThat;
29import static org.hamcrest.Matchers.hasSize;
30import static org.hamcrest.Matchers.is;
Ray Milkey7bf273c2017-09-27 16:15:15 -070031import static org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry.FlowRuleOperation.ADD;
32import static org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry.FlowRuleOperation.REMOVE;
Ray Milkeyf19b7152014-11-21 10:56:52 -080033
34/**
35 * Unit tests for the FlowRuleBatchRequest class.
36 */
37public class FlowRuleBatchRequestTest {
38
39 /**
40 * Tests that construction of FlowRuleBatchRequest objects returns the
41 * correct objects.
42 */
43 @Test
44 public void testConstruction() {
45 final FlowRule rule1 = new IntentTestsMocks.MockFlowRule(1);
46 final FlowRule rule2 = new IntentTestsMocks.MockFlowRule(2);
Brian O'Connor72cb19a2015-01-16 16:14:41 -080047 final Set<FlowRuleBatchEntry> batch = new HashSet<>();
48 batch.add(new FlowRuleBatchEntry(ADD, rule1));
49
50 batch.add(new FlowRuleBatchEntry(REMOVE, rule2));
Ray Milkeyf19b7152014-11-21 10:56:52 -080051
52
53 final FlowRuleBatchRequest request =
Brian O'Connor72cb19a2015-01-16 16:14:41 -080054 new FlowRuleBatchRequest(1, batch);
Ray Milkeyf19b7152014-11-21 10:56:52 -080055
Brian O'Connor72cb19a2015-01-16 16:14:41 -080056 assertThat(request.ops(), hasSize(2));
57 assertThat(request.batchId(), is(1L));
Ray Milkeyf19b7152014-11-21 10:56:52 -080058
Brian O'Connor72cb19a2015-01-16 16:14:41 -080059 final FlowRuleBatchOperation op = request.asBatchOperation(rule1.deviceId());
Ray Milkeyf19b7152014-11-21 10:56:52 -080060 assertThat(op.size(), is(2));
61
62 final List<FlowRuleBatchEntry> ops = op.getOperations();
63 assertThat(ops, hasSize(2));
64 }
65
66}