Simon Hunt

CORD Subscriber GUI -- More bundle wrangling.

Change-Id: I2fafdb281712d7747399d61611c3d4bb663a39b5
...@@ -17,9 +17,75 @@ ...@@ -17,9 +17,75 @@
17 17
18 package org.onosproject.cord.gui; 18 package org.onosproject.cord.gui;
19 19
20 +import com.google.common.collect.ImmutableList;
21 +import org.onosproject.cord.gui.model.Bundle;
22 +import org.onosproject.cord.gui.model.BundleDescriptor;
23 +import org.onosproject.cord.gui.model.BundleFactory;
24 +import org.onosproject.cord.gui.model.SubscriberUser;
25 +
26 +import java.util.ArrayList;
27 +import java.util.List;
28 +
20 /** 29 /**
21 * In memory cache of the model of the subscriber's account. 30 * In memory cache of the model of the subscriber's account.
22 */ 31 */
23 public class CordModelCache { 32 public class CordModelCache {
24 33
34 + // faked for the demo
35 + private static final int SUBSCRIBER_ID = 92;
36 + private static final String MAC_1 = "010203040506";
37 + private static final String MAC_2 = "010203040507";
38 + private static final String MAC_3 = "010203040508";
39 + private static final String MAC_4 = "010203040509";
40 +
41 + private Bundle currentBundle;
42 + private final List<SubscriberUser> users;
43 +
44 + /**
45 + * Constructs a model cache, initializing it with basic bundle.
46 + */
47 + public CordModelCache() {
48 + currentBundle = new Bundle(BundleFactory.BASIC_BUNDLE);
49 + users = new ArrayList<SubscriberUser>();
50 + initUsers();
51 + }
52 +
53 + /**
54 + * Used to initialize users for the demo. These are currently fake.
55 + */
56 + public void initUsers() {
57 + users.add(new SubscriberUser(1, "Mom's MacBook", MAC_1));
58 + users.add(new SubscriberUser(2, "Dad's iPad", MAC_2));
59 + users.add(new SubscriberUser(3, "Dick's laptop", MAC_3));
60 + users.add(new SubscriberUser(4, "Jane's laptop", MAC_4));
61 + }
62 +
63 + /**
64 + * Returns the currently selected bundle.
65 + *
66 + * @return current bundle
67 + */
68 + public Bundle getCurrentBundle() {
69 + return currentBundle;
70 + }
71 +
72 + /**
73 + * Sets a new bundle.
74 + *
75 + * @param bundleId bundle identifier
76 + * @throws IllegalArgumentException if bundle ID is unknown
77 + */
78 + public void setCurrentBundle(String bundleId) {
79 + BundleDescriptor bdesc = BundleFactory.bundleFromId(bundleId);
80 + currentBundle = new Bundle(bdesc);
81 + }
82 +
83 + /**
84 + * Returns the list of current users for this subscriber account.
85 + *
86 + * @return the list of users
87 + */
88 + public List<SubscriberUser> getUsers() {
89 + return ImmutableList.copyOf(users);
90 + }
25 } 91 }
......
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 +/**
21 + * Encapsulates a bundle, including current state.
22 + */
23 +public class Bundle {
24 + private final BundleDescriptor bundleDescriptor;
25 +
26 + /**
27 + * Constructs a new bundle instance.
28 + *
29 + * @param bundleDescriptor the descriptor
30 + */
31 + public Bundle(BundleDescriptor bundleDescriptor) {
32 + this.bundleDescriptor = bundleDescriptor;
33 + }
34 +
35 + /**
36 + * Returns the bundle descriptor.
37 + *
38 + * @return the descriptor
39 + */
40 + public BundleDescriptor descriptor() {
41 + return bundleDescriptor;
42 + }
43 +
44 +}
...@@ -17,14 +17,20 @@ ...@@ -17,14 +17,20 @@
17 17
18 package org.onosproject.cord.gui.model; 18 package org.onosproject.cord.gui.model;
19 19
20 +import com.fasterxml.jackson.databind.node.ArrayNode;
21 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 import com.google.common.collect.ImmutableList; 22 import com.google.common.collect.ImmutableList;
21 23
22 import java.util.List; 24 import java.util.List;
23 25
24 /** 26 /**
25 - * Utility factory for creating bundles and functions etc. 27 + * Utility factory for creating and/or operating on bundles.
26 */ 28 */
27 -public class BundleFactory { 29 +public class BundleFactory extends JsonFactory {
30 +
31 + private static final String BUNDLE = "bundle";
32 + private static final String BUNDLES = "bundles";
33 + private static final String FUNCTIONS = "functions";
28 34
29 private static final String BASIC_ID = "basic"; 35 private static final String BASIC_ID = "basic";
30 private static final String BASIC_DISPLAY_NAME = "Basic Bundle"; 36 private static final String BASIC_DISPLAY_NAME = "Basic Bundle";
...@@ -35,23 +41,83 @@ public class BundleFactory { ...@@ -35,23 +41,83 @@ public class BundleFactory {
35 // no instantiation 41 // no instantiation
36 private BundleFactory() {} 42 private BundleFactory() {}
37 43
38 - private static final BundleDescriptor BASIC = 44 + /**
45 + * Designates the BASIC bundle.
46 + */
47 + public static final BundleDescriptor BASIC_BUNDLE =
39 new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME, 48 new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME,
40 XosFunctionDescriptor.INTERNET, 49 XosFunctionDescriptor.INTERNET,
41 XosFunctionDescriptor.FIREWALL); 50 XosFunctionDescriptor.FIREWALL);
42 51
43 - private static final BundleDescriptor FAMILY = 52 + /**
53 + * Designates the FAMILY bundle.
54 + */
55 + public static final BundleDescriptor FAMILY_BUNDLE =
44 new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME, 56 new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME,
45 XosFunctionDescriptor.INTERNET, 57 XosFunctionDescriptor.INTERNET,
46 XosFunctionDescriptor.FIREWALL, 58 XosFunctionDescriptor.FIREWALL,
47 XosFunctionDescriptor.URL_FILTER); 59 XosFunctionDescriptor.URL_FILTER);
48 60
61 + // all bundles, in the order they should be listed in the GUI
62 + private static final List<BundleDescriptor> ALL_BUNDLES = ImmutableList.of(
63 + BASIC_BUNDLE,
64 + FAMILY_BUNDLE
65 + );
66 +
49 /** 67 /**
50 * Returns the list of available bundles. 68 * Returns the list of available bundles.
51 * 69 *
52 * @return available bundles 70 * @return available bundles
53 */ 71 */
54 public static List<BundleDescriptor> availableBundles() { 72 public static List<BundleDescriptor> availableBundles() {
55 - return ImmutableList.of(BASIC, FAMILY); 73 + return ALL_BUNDLES;
74 + }
75 +
76 + /**
77 + * Returns the bundle descriptor for the given identifier.
78 + *
79 + * @param bundleId bundle identifier
80 + * @return bundle descriptor
81 + * @throws IllegalArgumentException if bundle ID is unknown
82 + */
83 + public static BundleDescriptor bundleFromId(String bundleId) {
84 + for (BundleDescriptor bd : ALL_BUNDLES) {
85 + if (bd.id().equals(bundleId)) {
86 + return bd;
87 + }
88 + }
89 + throw new IllegalArgumentException("unknown bundle: " + bundleId);
90 + }
91 +
92 + /**
93 + * Returns a JSON string representation of the given bundle.
94 + *
95 + * @param bundle the bundle
96 + * @return JSON string
97 + */
98 + public static String toJson(Bundle bundle) {
99 + ObjectNode root = objectNode();
100 +
101 + ObjectNode bnode = objectNode()
102 + .put(ID, bundle.descriptor().id())
103 + .put(NAME, bundle.descriptor().displayName());
104 +
105 + ArrayNode funcs = arrayNode();
106 + for (XosFunctionDescriptor xfd: bundle.descriptor().functions()) {
107 + funcs.add(XosFunctionFactory.toObjectNode(xfd));
108 + }
109 + bnode.set(FUNCTIONS, funcs);
110 + root.set(BUNDLE, bnode);
111 +
112 + ArrayNode bundles = arrayNode();
113 + for (BundleDescriptor bd: BundleFactory.availableBundles()) {
114 + ObjectNode bdnode = objectNode()
115 + .put(ID, bd.id())
116 + .put(NAME, bd.displayName());
117 + bundles.add(bdnode);
118 + }
119 + root.set(BUNDLES, bundles);
120 + return root.toString();
121 +
56 } 122 }
57 } 123 }
......
...@@ -57,4 +57,27 @@ public class DefaultBundleDescriptor implements BundleDescriptor { ...@@ -57,4 +57,27 @@ public class DefaultBundleDescriptor implements BundleDescriptor {
57 public Set<XosFunctionDescriptor> functions() { 57 public Set<XosFunctionDescriptor> functions() {
58 return functions; 58 return functions;
59 } 59 }
60 +
61 + @Override
62 + public String toString() {
63 + return "{BundleDescriptor: " + displayName + "}";
64 + }
65 +
66 + @Override
67 + public boolean equals(Object o) {
68 + if (this == o) {
69 + return true;
70 + }
71 + if (o == null || getClass() != o.getClass()) {
72 + return false;
73 + }
74 +
75 + DefaultBundleDescriptor that = (DefaultBundleDescriptor) o;
76 + return id.equals(that.id);
77 + }
78 +
79 + @Override
80 + public int hashCode() {
81 + return id.hashCode();
82 + }
60 } 83 }
......
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 com.fasterxml.jackson.databind.ObjectMapper;
21 +import com.fasterxml.jackson.databind.node.ArrayNode;
22 +import com.fasterxml.jackson.databind.node.ObjectNode;
23 +
24 +/**
25 + * Base class for factories that convert objects to JSON.
26 + */
27 +public abstract class JsonFactory {
28 +
29 + private static final ObjectMapper mapper = new ObjectMapper();
30 +
31 + protected static final String ID = "id";
32 + protected static final String NAME = "name";
33 +
34 + /**
35 + * Returns a freshly minted object node.
36 + *
37 + * @return empty object node
38 + */
39 + protected static ObjectNode objectNode() {
40 + return mapper.createObjectNode();
41 + }
42 +
43 + /**
44 + * Returns a freshly minted array node.
45 + *
46 + * @return empty array node
47 + */
48 + protected static ArrayNode arrayNode() {
49 + return mapper.createArrayNode();
50 + }
51 +}
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 +/**
21 + * Designates a user of a subscriber's account.
22 + */
23 +public class SubscriberUser {
24 + private final int id;
25 + private final String name;
26 + private final String mac;
27 +
28 + /**
29 + * Constructs a subscriber user from the given parameters.
30 + *
31 + * @param id internal identifier
32 + * @param name display name
33 + * @param mac MAC address of the associated device
34 + */
35 + public SubscriberUser(int id, String name, String mac) {
36 + this.id = id;
37 + this.name = name;
38 + this.mac = mac;
39 + }
40 +
41 + /**
42 + * Returns the internal identifier.
43 + *
44 + * @return the identifier
45 + */
46 + public int id() {
47 + return id;
48 + }
49 +
50 + /**
51 + * Returns the display name.
52 + *
53 + * @return display name
54 + */
55 + public String name() {
56 + return name;
57 + }
58 +
59 + /**
60 + * Returns the MAC address of the associated device.
61 + *
62 + * @return MAC address
63 + */
64 + public String mac() {
65 + return mac;
66 + }
67 +}
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 com.fasterxml.jackson.databind.node.ObjectNode;
21 +
22 +/**
23 + * Utility functions on users.
24 + */
25 +public class UserFactory extends JsonFactory {
26 +
27 + private static final String MAC = "mac";
28 + private static final String PROFILE = "profile";
29 +
30 + // no instantiation
31 + private UserFactory() {}
32 +
33 + /**
34 + * Returns an object node representation of the given user.
35 + *
36 + * @param user the user
37 + * @return object node
38 + */
39 + public static ObjectNode toObjectNode(SubscriberUser user) {
40 + ObjectNode root = objectNode()
41 + .put(ID, user.id())
42 + .put(NAME, user.name())
43 + .put(MAC, user.mac());
44 + // TODO: add profile data
45 + return root;
46 + }
47 +
48 +}
1 +package org.onosproject.cord.gui.model;
2 +
3 +import com.fasterxml.jackson.databind.JsonNode;
4 +import com.fasterxml.jackson.databind.node.ArrayNode;
5 +import com.fasterxml.jackson.databind.node.ObjectNode;
6 +
7 +import java.util.HashMap;
8 +import java.util.Map;
9 +
10 +/**
11 + * Utility factory for operating on XOS functions.
12 + */
13 +public class XosFunctionFactory extends JsonFactory {
14 +
15 + private static final String DESC = "desc";
16 + private static final String PARAMS = "params";
17 +
18 + private static final String LEVEL = "level";
19 + private static final String LEVELS = "levels";
20 +
21 +
22 + // URL Filtering Levels...
23 + private static final String PG = "PG";
24 + private static final String PG13 = "PG-13";
25 + private static final String R = "R";
26 +
27 + private static final String[] FILTER_LEVELS = { PG, PG13, R };
28 + private static final String DEFAULT_FILTER_LEVEL = PG;
29 +
30 +
31 + // no instantiation
32 + private XosFunctionFactory() {}
33 +
34 + /**
35 + * Produces the JSON representation of the given XOS function descriptor.
36 + *
37 + * @param xfd function descriptor
38 + * @return JSON encoding
39 + */
40 + public static ObjectNode toObjectNode(XosFunctionDescriptor xfd) {
41 + ObjectNode root = objectNode()
42 + .put(ID, xfd.id())
43 + .put(NAME, xfd.displayName())
44 + .put(DESC, xfd.description());
45 + root.set(PARAMS, paramsForXfd(xfd));
46 + return root;
47 + }
48 +
49 + private static JsonNode paramsForXfd(XosFunctionDescriptor xfd) {
50 + ParamStructFactory psf = PARAM_MAP.get(xfd);
51 + if (psf == null) {
52 + psf = DEF_PARAMS;
53 + }
54 + return psf.params();
55 + }
56 +
57 + // ==== handling different parameter structures...
58 + private static final Map<XosFunctionDescriptor, ParamStructFactory>
59 + PARAM_MAP = new HashMap<XosFunctionDescriptor, ParamStructFactory>();
60 +
61 + private static final ParamStructFactory DEF_PARAMS = new ParamStructFactory();
62 + static {
63 + PARAM_MAP.put(XosFunctionDescriptor.URL_FILTER, new UrlFilterParams());
64 + }
65 +
66 + // private parameter structure creator
67 + static class ParamStructFactory {
68 + ObjectNode params() {
69 + return objectNode();
70 + }
71 + }
72 +
73 + static class UrlFilterParams extends ParamStructFactory {
74 + @Override
75 + ObjectNode params() {
76 + ObjectNode result = objectNode();
77 + result.put(LEVEL, DEFAULT_FILTER_LEVEL);
78 + ArrayNode levels = arrayNode();
79 + for (String lvl: FILTER_LEVELS) {
80 + levels.add(lvl);
81 + }
82 + result.set(LEVELS, levels);
83 + return result;
84 + }
85 + }
86 +}
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
6 { 6 {
7 "id": "internet", 7 "id": "internet",
8 "name": "Internet", 8 "name": "Internet",
9 - "desc": "Basic internet connectivity", 9 + "desc": "Basic internet connectivity.",
10 "params": {} 10 "params": {}
11 }, 11 },
12 { 12 {
13 "id": "firewall", 13 "id": "firewall",
14 "name": "Firewall", 14 "name": "Firewall",
15 - "desc": "Normal firewall protection", 15 + "desc": "Normal firewall protection.",
16 "params": {} 16 "params": {}
17 } 17 }
18 ] 18 ]
......
...@@ -6,19 +6,19 @@ ...@@ -6,19 +6,19 @@
6 { 6 {
7 "id": "internet", 7 "id": "internet",
8 "name": "Internet", 8 "name": "Internet",
9 - "desc": "Basic internet connectivity", 9 + "desc": "Basic internet connectivity.",
10 "params": {} 10 "params": {}
11 }, 11 },
12 { 12 {
13 "id": "firewall", 13 "id": "firewall",
14 "name": "Firewall", 14 "name": "Firewall",
15 - "desc": "Normal firewall protection", 15 + "desc": "Normal firewall protection.",
16 "params": {} 16 "params": {}
17 }, 17 },
18 { 18 {
19 "id": "url_filter", 19 "id": "url_filter",
20 "name": "Parental Control", 20 "name": "Parental Control",
21 - "desc": "Variable levels of URL filtering", 21 + "desc": "Variable levels of URL filtering.",
22 "params": { 22 "params": {
23 "level": "PG", 23 "level": "PG",
24 "levels": [ "PG", "PG-13", "R" ] 24 "levels": [ "PG", "PG-13", "R" ]
......
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;
19 +
20 +import com.fasterxml.jackson.databind.JsonNode;
21 +import com.fasterxml.jackson.databind.ObjectMapper;
22 +import org.junit.Before;
23 +import org.junit.Test;
24 +import org.onosproject.cord.gui.model.BundleFactory;
25 +import org.onosproject.cord.gui.model.SubscriberUser;
26 +
27 +import java.io.IOException;
28 +import java.util.List;
29 +
30 +import static org.junit.Assert.assertEquals;
31 +import static org.junit.Assert.assertTrue;
32 +
33 +/**
34 + * Unit tests for {@link CordModelCache}.
35 + */
36 +public class CoreModelCacheTest {
37 +
38 + private CordModelCache cache;
39 +
40 + @Before
41 + public void setUp() {
42 + cache = new CordModelCache();
43 + }
44 +
45 + @Test
46 + public void basic() {
47 + assertEquals("wrong bundle", BundleFactory.BASIC_BUNDLE,
48 + cache.getCurrentBundle().descriptor());
49 + }
50 +
51 + @Test
52 + public void basicBundleJson() {
53 + String json = BundleFactory.toJson(cache.getCurrentBundle());
54 + assertTrue("bad basic json", sameJson(BASIC_BUNDLE_JSON, json));
55 + }
56 +
57 + @Test
58 + public void chooseFamilyBundle() {
59 + cache.setCurrentBundle("family");
60 + assertEquals("wrong bundle", BundleFactory.FAMILY_BUNDLE,
61 + cache.getCurrentBundle().descriptor());
62 + }
63 +
64 + @Test
65 + public void familyBundleJson() {
66 + cache.setCurrentBundle("family");
67 + String json = BundleFactory.toJson(cache.getCurrentBundle());
68 + System.out.println(json);
69 + assertTrue("bad family json", sameJson(FAMILY_BUNDLE_JSON, json));
70 + }
71 +
72 + @Test
73 + public void checkUsers() {
74 + List<SubscriberUser> users = cache.getUsers();
75 + assertEquals("wrong # users", 4, users.size());
76 + }
77 +
78 + // =============
79 +
80 + private boolean sameJson(String s1, String s2) {
81 + try {
82 + JsonNode tree1 = MAPPER.readTree(s1);
83 + JsonNode tree2 = MAPPER.readTree(s2);
84 + return tree1.equals(tree2);
85 + } catch (IOException e) {
86 + System.out.println("Exception: " + e);
87 + }
88 + return false;
89 + }
90 +
91 + private static final ObjectMapper MAPPER = new ObjectMapper();
92 +
93 + private static final String BASIC_BUNDLE_JSON = "{\n" +
94 + " \"bundle\": {\n" +
95 + " \"id\": \"basic\",\n" +
96 + " \"name\": \"Basic Bundle\",\n" +
97 + " \"functions\": [\n" +
98 + " {\n" +
99 + " \"id\": \"internet\",\n" +
100 + " \"name\": \"Internet\",\n" +
101 + " \"desc\": \"Basic internet connectivity.\",\n" +
102 + " \"params\": {}\n" +
103 + " },\n" +
104 + " {\n" +
105 + " \"id\": \"firewall\",\n" +
106 + " \"name\": \"Firewall\",\n" +
107 + " \"desc\": \"Normal firewall protection.\",\n" +
108 + " \"params\": {}\n" +
109 + " }\n" +
110 + " ]\n" +
111 + " },\n" +
112 + " \"bundles\": [\n" +
113 + " { \"id\": \"basic\", \"name\": \"Basic Bundle\" },\n" +
114 + " { \"id\": \"family\", \"name\": \"Family Bundle\" }\n" +
115 + " ]\n" +
116 + "}\n";
117 +
118 + private static final String FAMILY_BUNDLE_JSON = "{\n" +
119 + " \"bundle\": {\n" +
120 + " \"id\": \"family\",\n" +
121 + " \"name\": \"Family Bundle\",\n" +
122 + " \"functions\": [\n" +
123 + " {\n" +
124 + " \"id\": \"internet\",\n" +
125 + " \"name\": \"Internet\",\n" +
126 + " \"desc\": \"Basic internet connectivity.\",\n" +
127 + " \"params\": {}\n" +
128 + " },\n" +
129 + " {\n" +
130 + " \"id\": \"firewall\",\n" +
131 + " \"name\": \"Firewall\",\n" +
132 + " \"desc\": \"Normal firewall protection.\",\n" +
133 + " \"params\": {}\n" +
134 + " },\n" +
135 + " {\n" +
136 + " \"id\": \"url_filter\",\n" +
137 + " \"name\": \"Parental Control\",\n" +
138 + " \"desc\": \"Variable levels of URL filtering.\",\n" +
139 + " \"params\": {\n" +
140 + " \"level\": \"PG\",\n" +
141 + " \"levels\": [ \"PG\", \"PG-13\", \"R\" ]\n" +
142 + " }\n" +
143 + " }\n" +
144 + " ]\n" +
145 + " },\n" +
146 + " \"bundles\": [\n" +
147 + " { \"id\": \"basic\", \"name\": \"Basic Bundle\" },\n" +
148 + " { \"id\": \"family\", \"name\": \"Family Bundle\" }\n" +
149 + " ]\n" +
150 + "}\n";
151 +}
...@@ -22,7 +22,7 @@ import org.junit.Test; ...@@ -22,7 +22,7 @@ import org.junit.Test;
22 import java.util.Set; 22 import java.util.Set;
23 23
24 import static org.junit.Assert.*; 24 import static org.junit.Assert.*;
25 -import static org.onosproject.cord.gui.model.BundleFactory.availableBundles; 25 +import static org.onosproject.cord.gui.model.BundleFactory.*;
26 import static org.onosproject.cord.gui.model.XosFunctionDescriptor.*; 26 import static org.onosproject.cord.gui.model.XosFunctionDescriptor.*;
27 27
28 /** 28 /**
...@@ -33,11 +33,13 @@ public class BundleFactoryTest { ...@@ -33,11 +33,13 @@ public class BundleFactoryTest {
33 @Test 33 @Test
34 public void bundleCount() { 34 public void bundleCount() {
35 assertEquals("wrong count", 2, availableBundles().size()); 35 assertEquals("wrong count", 2, availableBundles().size());
36 + assertTrue("missing basic", availableBundles().contains(BASIC_BUNDLE));
37 + assertTrue("missing family", availableBundles().contains(FAMILY_BUNDLE));
36 } 38 }
37 39
38 @Test 40 @Test
39 public void basicBundle() { 41 public void basicBundle() {
40 - BundleDescriptor bundle = availableBundles().get(0); 42 + BundleDescriptor bundle = BundleFactory.BASIC_BUNDLE;
41 assertEquals("wrong id", "basic", bundle.id()); 43 assertEquals("wrong id", "basic", bundle.id());
42 assertEquals("wrong id", "Basic Bundle", bundle.displayName()); 44 assertEquals("wrong id", "Basic Bundle", bundle.displayName());
43 Set<XosFunctionDescriptor> funcs = bundle.functions(); 45 Set<XosFunctionDescriptor> funcs = bundle.functions();
...@@ -48,7 +50,7 @@ public class BundleFactoryTest { ...@@ -48,7 +50,7 @@ public class BundleFactoryTest {
48 50
49 @Test 51 @Test
50 public void familyBundle() { 52 public void familyBundle() {
51 - BundleDescriptor bundle = availableBundles().get(1); 53 + BundleDescriptor bundle = BundleFactory.FAMILY_BUNDLE;
52 assertEquals("wrong id", "family", bundle.id()); 54 assertEquals("wrong id", "family", bundle.id());
53 assertEquals("wrong id", "Family Bundle", bundle.displayName()); 55 assertEquals("wrong id", "Family Bundle", bundle.displayName());
54 Set<XosFunctionDescriptor> funcs = bundle.functions(); 56 Set<XosFunctionDescriptor> funcs = bundle.functions();
...@@ -57,5 +59,19 @@ public class BundleFactoryTest { ...@@ -57,5 +59,19 @@ public class BundleFactoryTest {
57 assertTrue("missing url-f", funcs.contains(URL_FILTER)); 59 assertTrue("missing url-f", funcs.contains(URL_FILTER));
58 } 60 }
59 61
62 + @Test
63 + public void bundleFromIdBasic() {
64 + assertEquals("wrong bundle", BASIC_BUNDLE, bundleFromId("basic"));
65 + }
66 +
67 + @Test
68 + public void bundleFromIdFamily() {
69 + assertEquals("wrong bundle", FAMILY_BUNDLE, bundleFromId("family"));
70 + }
71 +
72 + @Test(expected = IllegalArgumentException.class)
73 + public void bundleFromIdUnknown() {
74 + bundleFromId("unknown");
75 + }
60 } 76 }
61 77
......
...@@ -49,7 +49,7 @@ public class XosFunctionDescriptorTest { ...@@ -49,7 +49,7 @@ public class XosFunctionDescriptorTest {
49 49
50 @Test 50 @Test
51 public void urlFiltering() { 51 public void urlFiltering() {
52 - assertEquals("wrong id", "url_filtering", URL_FILTER.id()); 52 + assertEquals("wrong id", "url_filter", URL_FILTER.id());
53 assertEquals("wrong display", "Parental Control", URL_FILTER.displayName()); 53 assertEquals("wrong display", "Parental Control", URL_FILTER.displayName());
54 assertTrue("wrong desc", URL_FILTER.description().startsWith("Variable")); 54 assertTrue("wrong desc", URL_FILTER.description().startsWith("Variable"));
55 } 55 }
......