Simon Hunt

CORD Subscriber GUI - Added levels OFF, G, and NONE to UrlFilterFunction.Level enum.

- added some unit tests for UrlFilterFunction.

Change-Id: Ic241818e260b84541665031e659c87f61f8899cf
......@@ -72,7 +72,7 @@ public class Bundle {
XosFunction func;
switch (xfd) {
case URL_FILTER:
func = new UrlFilterFunction(xfd);
func = new UrlFilterFunction();
break;
default:
......
......@@ -29,17 +29,19 @@ public class UrlFilterFunction extends DefaultXosFunction {
private static final String LEVEL = "level";
/**
* Denotes the URL filtering levels available.
* Denotes the URL filtering levels available. From most restrictive
* to least restrictive. Note: <em>OFF</em> denies everything;
* <em>NONE</em> allows everything.
*/
public enum Level { PG, PG_13, R }
public enum Level { OFF, G, PG, PG_13, R, NONE }
/**
* The default URL filtering level
*/
public static final Level DEFAULT_LEVEL = Level.PG;
public static final Level DEFAULT_LEVEL = Level.G;
public UrlFilterFunction(XosFunctionDescriptor xfd) {
super(xfd);
public UrlFilterFunction() {
super(XosFunctionDescriptor.URL_FILTER);
}
@Override
......
......@@ -17,9 +17,6 @@ public class XosFunctionFactory extends JsonFactory {
private static final String LEVEL = "level";
private static final String LEVELS = "levels";
private static final UrlFilterFunction.Level DEFAULT_FILTER_LEVEL =
UrlFilterFunction.Level.PG;
// no instantiation
private XosFunctionFactory() {}
......@@ -91,7 +88,7 @@ public class XosFunctionFactory extends JsonFactory {
@Override
ObjectNode params() {
ObjectNode result = objectNode();
result.put(LEVEL, DEFAULT_FILTER_LEVEL.name());
result.put(LEVEL, UrlFilterFunction.DEFAULT_LEVEL.name());
ArrayNode levels = arrayNode();
for (UrlFilterFunction.Level lvl: UrlFilterFunction.Level.values()) {
levels.add(lvl.name());
......
......@@ -95,7 +95,7 @@ public class CoreModelCacheTest {
public void setNewLevel() {
cache.setCurrentBundle("family");
JsonNode node = fromString(cache.jsonUsers());
assertEquals("wrong level", "PG", getMomsLevel(node));
assertEquals("wrong level", "G", getMomsLevel(node));
cache.applyPerUserParam("1", "url_filter", "level", "R");
......@@ -191,11 +191,14 @@ public class CoreModelCacheTest {
" \"name\": \"Parental Control\",\n" +
" \"desc\": \"Variable levels of URL filtering.\",\n" +
" \"params\": {\n" +
" \"level\": \"PG\",\n" +
" \"level\": \"G\",\n" +
" \"levels\": [\n" +
" \"OFF\",\n" +
" \"G\",\n" +
" \"PG\",\n" +
" \"PG_13\",\n" +
" \"R\"\n" +
" \"R\",\n" +
" \"NONE\"\n" +
" ]\n" +
" }\n" +
" }\n" +
......@@ -252,7 +255,7 @@ public class CoreModelCacheTest {
" \"mac\": \"010203040506\",\n" +
" \"profile\": {\n" +
" \"url_filter\": {\n" +
" \"level\": \"PG\"\n" +
" \"level\": \"G\"\n" +
" }\n" +
" }\n" +
" },\n" +
......@@ -262,7 +265,7 @@ public class CoreModelCacheTest {
" \"mac\": \"010203040507\",\n" +
" \"profile\": {\n" +
" \"url_filter\": {\n" +
" \"level\": \"PG\"\n" +
" \"level\": \"G\"\n" +
" }\n" +
" }\n" +
" },\n" +
......@@ -272,7 +275,7 @@ public class CoreModelCacheTest {
" \"mac\": \"010203040508\",\n" +
" \"profile\": {\n" +
" \"url_filter\": {\n" +
" \"level\": \"PG\"\n" +
" \"level\": \"G\"\n" +
" }\n" +
" }\n" +
" },\n" +
......@@ -282,7 +285,7 @@ public class CoreModelCacheTest {
" \"mac\": \"010203040509\",\n" +
" \"profile\": {\n" +
" \"url_filter\": {\n" +
" \"level\": \"PG\"\n" +
" \"level\": \"G\"\n" +
" }\n" +
" }\n" +
" }\n" +
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.onosproject.cord.gui.model;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link UrlFilterFunction}.
*/
public class UrlFilterFunctionTest {
private SubscriberUser user = new SubscriberUser(1, "foo", "fooMAC");
private UrlFilterFunction fn;
@Before
public void setUp() {
fn = new UrlFilterFunction();
}
@Test
public void basic() {
assertEquals("wrong enum const count",
6, UrlFilterFunction.Level.values().length);
}
@Test
public void memento() {
XosFunction.Memento memo = fn.createMemento();
assertTrue("wrong class", memo instanceof UrlFilterFunction.UrlFilterMemento);
UrlFilterFunction.UrlFilterMemento umemo =
(UrlFilterFunction.UrlFilterMemento) memo;
assertEquals("wrong default level", "G", umemo.level());
}
@Test
public void memoNewLevel() {
XosFunction.Memento memo = fn.createMemento();
assertTrue("wrong class", memo instanceof UrlFilterFunction.UrlFilterMemento);
UrlFilterFunction.UrlFilterMemento umemo =
(UrlFilterFunction.UrlFilterMemento) memo;
assertEquals("wrong default level", "G", umemo.level());
umemo.setLevel(UrlFilterFunction.Level.R);
assertEquals("wrong new level", "R", umemo.level());
}
@Test
public void applyMemo() {
UrlFilterFunction.UrlFilterMemento memo =
(UrlFilterFunction.UrlFilterMemento) fn.createMemento();
memo.setLevel(UrlFilterFunction.Level.PG_13);
user.setMemento(XosFunctionDescriptor.URL_FILTER, memo);
assertEquals("wrong URL suffix", "url_filter/PG_13", fn.xosUrlApply(user));
}
}