Ray Milkey | 24e60b3 | 2015-08-12 11:39:54 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Ray Milkey | 24e60b3 | 2015-08-12 11:39:54 -0700 | [diff] [blame] | 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 | package org.onosproject.store.flowobjective.impl; |
| 17 | |
| 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.behaviour.DefaultNextGroup; |
| 22 | import org.onosproject.net.behaviour.NextGroup; |
| 23 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 24 | import org.onosproject.store.service.TestStorageService; |
| 25 | |
| 26 | import com.google.common.base.Charsets; |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.hamcrest.Matchers.*; |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for distributed flow objective store. |
| 32 | */ |
| 33 | public class DistributedFlowObjectiveStoreTest { |
| 34 | DistributedFlowObjectiveStore storeImpl; |
| 35 | FlowObjectiveStore store; |
| 36 | |
| 37 | @Before |
| 38 | public void setUp() { |
| 39 | storeImpl = new DistributedFlowObjectiveStore(); |
| 40 | storeImpl.storageService = new TestStorageService(); |
| 41 | storeImpl.activate(); |
| 42 | store = storeImpl; |
| 43 | } |
| 44 | |
| 45 | @After |
| 46 | public void tearDown() { |
| 47 | storeImpl.deactivate(); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void testFlowObjectiveStore() { |
| 52 | NextGroup group2 = new DefaultNextGroup("2".getBytes(Charsets.US_ASCII)); |
| 53 | int group1Id = store.allocateNextId(); |
| 54 | int group2Id = store.allocateNextId(); |
| 55 | |
| 56 | NextGroup group1add = store.getNextGroup(group1Id); |
| 57 | assertThat(group1add, nullValue()); |
| 58 | |
| 59 | store.putNextGroup(group2Id, group2); |
| 60 | NextGroup group2Query = store.getNextGroup(group2Id); |
| 61 | assertThat(group2Query.data(), is(group2.data())); |
| 62 | } |
| 63 | } |