CORD Subscriber GUI - Added levels OFF, G, and NONE to UrlFilterFunction.Level enum.
- added some unit tests for UrlFilterFunction. Change-Id: Ic241818e260b84541665031e659c87f61f8899cf
Showing
5 changed files
with
93 additions
and
17 deletions
| ... | @@ -72,7 +72,7 @@ public class Bundle { | ... | @@ -72,7 +72,7 @@ public class Bundle { |
| 72 | XosFunction func; | 72 | XosFunction func; |
| 73 | switch (xfd) { | 73 | switch (xfd) { |
| 74 | case URL_FILTER: | 74 | case URL_FILTER: |
| 75 | - func = new UrlFilterFunction(xfd); | 75 | + func = new UrlFilterFunction(); |
| 76 | break; | 76 | break; |
| 77 | 77 | ||
| 78 | default: | 78 | default: | ... | ... |
| ... | @@ -29,17 +29,19 @@ public class UrlFilterFunction extends DefaultXosFunction { | ... | @@ -29,17 +29,19 @@ public class UrlFilterFunction extends DefaultXosFunction { |
| 29 | private static final String LEVEL = "level"; | 29 | private static final String LEVEL = "level"; |
| 30 | 30 | ||
| 31 | /** | 31 | /** |
| 32 | - * Denotes the URL filtering levels available. | 32 | + * Denotes the URL filtering levels available. From most restrictive |
| 33 | + * to least restrictive. Note: <em>OFF</em> denies everything; | ||
| 34 | + * <em>NONE</em> allows everything. | ||
| 33 | */ | 35 | */ |
| 34 | - public enum Level { PG, PG_13, R } | 36 | + public enum Level { OFF, G, PG, PG_13, R, NONE } |
| 35 | 37 | ||
| 36 | /** | 38 | /** |
| 37 | * The default URL filtering level | 39 | * The default URL filtering level |
| 38 | */ | 40 | */ |
| 39 | - public static final Level DEFAULT_LEVEL = Level.PG; | 41 | + public static final Level DEFAULT_LEVEL = Level.G; |
| 40 | 42 | ||
| 41 | - public UrlFilterFunction(XosFunctionDescriptor xfd) { | 43 | + public UrlFilterFunction() { |
| 42 | - super(xfd); | 44 | + super(XosFunctionDescriptor.URL_FILTER); |
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | @Override | 47 | @Override | ... | ... |
| ... | @@ -17,9 +17,6 @@ public class XosFunctionFactory extends JsonFactory { | ... | @@ -17,9 +17,6 @@ public class XosFunctionFactory extends JsonFactory { |
| 17 | private static final String LEVEL = "level"; | 17 | private static final String LEVEL = "level"; |
| 18 | private static final String LEVELS = "levels"; | 18 | private static final String LEVELS = "levels"; |
| 19 | 19 | ||
| 20 | - private static final UrlFilterFunction.Level DEFAULT_FILTER_LEVEL = | ||
| 21 | - UrlFilterFunction.Level.PG; | ||
| 22 | - | ||
| 23 | 20 | ||
| 24 | // no instantiation | 21 | // no instantiation |
| 25 | private XosFunctionFactory() {} | 22 | private XosFunctionFactory() {} |
| ... | @@ -91,7 +88,7 @@ public class XosFunctionFactory extends JsonFactory { | ... | @@ -91,7 +88,7 @@ public class XosFunctionFactory extends JsonFactory { |
| 91 | @Override | 88 | @Override |
| 92 | ObjectNode params() { | 89 | ObjectNode params() { |
| 93 | ObjectNode result = objectNode(); | 90 | ObjectNode result = objectNode(); |
| 94 | - result.put(LEVEL, DEFAULT_FILTER_LEVEL.name()); | 91 | + result.put(LEVEL, UrlFilterFunction.DEFAULT_LEVEL.name()); |
| 95 | ArrayNode levels = arrayNode(); | 92 | ArrayNode levels = arrayNode(); |
| 96 | for (UrlFilterFunction.Level lvl: UrlFilterFunction.Level.values()) { | 93 | for (UrlFilterFunction.Level lvl: UrlFilterFunction.Level.values()) { |
| 97 | levels.add(lvl.name()); | 94 | levels.add(lvl.name()); | ... | ... |
| ... | @@ -95,7 +95,7 @@ public class CoreModelCacheTest { | ... | @@ -95,7 +95,7 @@ public class CoreModelCacheTest { |
| 95 | public void setNewLevel() { | 95 | public void setNewLevel() { |
| 96 | cache.setCurrentBundle("family"); | 96 | cache.setCurrentBundle("family"); |
| 97 | JsonNode node = fromString(cache.jsonUsers()); | 97 | JsonNode node = fromString(cache.jsonUsers()); |
| 98 | - assertEquals("wrong level", "PG", getMomsLevel(node)); | 98 | + assertEquals("wrong level", "G", getMomsLevel(node)); |
| 99 | 99 | ||
| 100 | cache.applyPerUserParam("1", "url_filter", "level", "R"); | 100 | cache.applyPerUserParam("1", "url_filter", "level", "R"); |
| 101 | 101 | ||
| ... | @@ -191,11 +191,14 @@ public class CoreModelCacheTest { | ... | @@ -191,11 +191,14 @@ public class CoreModelCacheTest { |
| 191 | " \"name\": \"Parental Control\",\n" + | 191 | " \"name\": \"Parental Control\",\n" + |
| 192 | " \"desc\": \"Variable levels of URL filtering.\",\n" + | 192 | " \"desc\": \"Variable levels of URL filtering.\",\n" + |
| 193 | " \"params\": {\n" + | 193 | " \"params\": {\n" + |
| 194 | - " \"level\": \"PG\",\n" + | 194 | + " \"level\": \"G\",\n" + |
| 195 | " \"levels\": [\n" + | 195 | " \"levels\": [\n" + |
| 196 | + " \"OFF\",\n" + | ||
| 197 | + " \"G\",\n" + | ||
| 196 | " \"PG\",\n" + | 198 | " \"PG\",\n" + |
| 197 | " \"PG_13\",\n" + | 199 | " \"PG_13\",\n" + |
| 198 | - " \"R\"\n" + | 200 | + " \"R\",\n" + |
| 201 | + " \"NONE\"\n" + | ||
| 199 | " ]\n" + | 202 | " ]\n" + |
| 200 | " }\n" + | 203 | " }\n" + |
| 201 | " }\n" + | 204 | " }\n" + |
| ... | @@ -252,7 +255,7 @@ public class CoreModelCacheTest { | ... | @@ -252,7 +255,7 @@ public class CoreModelCacheTest { |
| 252 | " \"mac\": \"010203040506\",\n" + | 255 | " \"mac\": \"010203040506\",\n" + |
| 253 | " \"profile\": {\n" + | 256 | " \"profile\": {\n" + |
| 254 | " \"url_filter\": {\n" + | 257 | " \"url_filter\": {\n" + |
| 255 | - " \"level\": \"PG\"\n" + | 258 | + " \"level\": \"G\"\n" + |
| 256 | " }\n" + | 259 | " }\n" + |
| 257 | " }\n" + | 260 | " }\n" + |
| 258 | " },\n" + | 261 | " },\n" + |
| ... | @@ -262,7 +265,7 @@ public class CoreModelCacheTest { | ... | @@ -262,7 +265,7 @@ public class CoreModelCacheTest { |
| 262 | " \"mac\": \"010203040507\",\n" + | 265 | " \"mac\": \"010203040507\",\n" + |
| 263 | " \"profile\": {\n" + | 266 | " \"profile\": {\n" + |
| 264 | " \"url_filter\": {\n" + | 267 | " \"url_filter\": {\n" + |
| 265 | - " \"level\": \"PG\"\n" + | 268 | + " \"level\": \"G\"\n" + |
| 266 | " }\n" + | 269 | " }\n" + |
| 267 | " }\n" + | 270 | " }\n" + |
| 268 | " },\n" + | 271 | " },\n" + |
| ... | @@ -272,7 +275,7 @@ public class CoreModelCacheTest { | ... | @@ -272,7 +275,7 @@ public class CoreModelCacheTest { |
| 272 | " \"mac\": \"010203040508\",\n" + | 275 | " \"mac\": \"010203040508\",\n" + |
| 273 | " \"profile\": {\n" + | 276 | " \"profile\": {\n" + |
| 274 | " \"url_filter\": {\n" + | 277 | " \"url_filter\": {\n" + |
| 275 | - " \"level\": \"PG\"\n" + | 278 | + " \"level\": \"G\"\n" + |
| 276 | " }\n" + | 279 | " }\n" + |
| 277 | " }\n" + | 280 | " }\n" + |
| 278 | " },\n" + | 281 | " },\n" + |
| ... | @@ -282,7 +285,7 @@ public class CoreModelCacheTest { | ... | @@ -282,7 +285,7 @@ public class CoreModelCacheTest { |
| 282 | " \"mac\": \"010203040509\",\n" + | 285 | " \"mac\": \"010203040509\",\n" + |
| 283 | " \"profile\": {\n" + | 286 | " \"profile\": {\n" + |
| 284 | " \"url_filter\": {\n" + | 287 | " \"url_filter\": {\n" + |
| 285 | - " \"level\": \"PG\"\n" + | 288 | + " \"level\": \"G\"\n" + |
| 286 | " }\n" + | 289 | " }\n" + |
| 287 | " }\n" + | 290 | " }\n" + |
| 288 | " }\n" + | 291 | " }\n" + | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 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 | + | ||
| 31 | + private SubscriberUser user = new SubscriberUser(1, "foo", "fooMAC"); | ||
| 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 | +} |
-
Please register or login to post a comment