blob: 2110a5fcdd482a242137ba0191a7bc24b06fd379 [file] [log] [blame]
Simon Huntab5232e2015-05-26 16:59:46 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Huntab5232e2015-05-26 16:59:46 -07003 *
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
18package org.onosproject.cord.gui.model;
19
20import org.junit.Before;
21import org.junit.Test;
22
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertTrue;
25
26/**
27 * Unit tests for {@link UrlFilterFunction}.
28 */
29public class UrlFilterFunctionTest {
30
Simon Hunt7d02c082015-05-29 12:17:09 -070031 private SubscriberUser user = new SubscriberUser(1, "foo", "fooMAC", "levelX");
Simon Huntab5232e2015-05-26 16:59:46 -070032 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}