Simon Hunt | ab5232e | 2015-05-26 16:59:46 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | ab5232e | 2015-05-26 16:59:46 -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 | */ |
| 17 | |
| 18 | package org.onosproject.cord.gui.model; |
| 19 | |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for {@link UrlFilterFunction}. |
| 28 | */ |
| 29 | public class UrlFilterFunctionTest { |
| 30 | |
Simon Hunt | 7d02c08 | 2015-05-29 12:17:09 -0700 | [diff] [blame] | 31 | private SubscriberUser user = new SubscriberUser(1, "foo", "fooMAC", "levelX"); |
Simon Hunt | ab5232e | 2015-05-26 16:59:46 -0700 | [diff] [blame] | 32 | private UrlFilterFunction fn; |
| 33 | |
| 34 | @Before |
| 35 | public void setUp() { |
| 36 | fn = new UrlFilterFunction(); |
| 37 | } |
| 38 | |
| 39 | @Test |
| 40 | public void basic() { |
| 41 | assertEquals("wrong enum const count", |
| 42 | 6, UrlFilterFunction.Level.values().length); |
| 43 | } |
| 44 | |
| 45 | @Test |
| 46 | public void memento() { |
| 47 | XosFunction.Memento memo = fn.createMemento(); |
| 48 | assertTrue("wrong class", memo instanceof UrlFilterFunction.UrlFilterMemento); |
| 49 | UrlFilterFunction.UrlFilterMemento umemo = |
| 50 | (UrlFilterFunction.UrlFilterMemento) memo; |
| 51 | assertEquals("wrong default level", "G", umemo.level()); |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void memoNewLevel() { |
| 56 | XosFunction.Memento memo = fn.createMemento(); |
| 57 | assertTrue("wrong class", memo instanceof UrlFilterFunction.UrlFilterMemento); |
| 58 | UrlFilterFunction.UrlFilterMemento umemo = |
| 59 | (UrlFilterFunction.UrlFilterMemento) memo; |
| 60 | assertEquals("wrong default level", "G", umemo.level()); |
| 61 | umemo.setLevel(UrlFilterFunction.Level.R); |
| 62 | assertEquals("wrong new level", "R", umemo.level()); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void applyMemo() { |
| 67 | UrlFilterFunction.UrlFilterMemento memo = |
| 68 | (UrlFilterFunction.UrlFilterMemento) fn.createMemento(); |
| 69 | memo.setLevel(UrlFilterFunction.Level.PG_13); |
| 70 | user.setMemento(XosFunctionDescriptor.URL_FILTER, memo); |
| 71 | |
| 72 | assertEquals("wrong URL suffix", "url_filter/PG_13", fn.xosUrlApply(user)); |
| 73 | } |
| 74 | } |