Simon Hunt
Committed by Gerrit Code Review

CORD Subscriber GUI -- First shot at modeling bundles from functions.

Change-Id: I7ce653058d2e669b9252efbd50fe2314950e5a9a
...@@ -54,6 +54,21 @@ ...@@ -54,6 +54,21 @@
54 <artifactId>commons-io</artifactId> 54 <artifactId>commons-io</artifactId>
55 <version>2.4</version> 55 <version>2.4</version>
56 </dependency> 56 </dependency>
57 + <dependency>
58 + <groupId>com.fasterxml.jackson.core</groupId>
59 + <artifactId>jackson-core</artifactId>
60 + <version>2.4.4</version>
61 + </dependency>
62 + <dependency>
63 + <groupId>com.fasterxml.jackson.core</groupId>
64 + <artifactId>jackson-databind</artifactId>
65 + <version>2.4.4</version>
66 + </dependency>
67 + <dependency>
68 + <groupId>com.google.guava</groupId>
69 + <artifactId>guava</artifactId>
70 + <version>18.0</version>
71 + </dependency>
57 </dependencies> 72 </dependencies>
58 73
59 </project> 74 </project>
......
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 java.util.Set;
21 +
22 +/**
23 + * Defines a bundle of {@link XosFunctionDescriptor XOS functions}.
24 + */
25 +public interface BundleDescriptor {
26 +
27 + /**
28 + * Bundle internal identifier.
29 + *
30 + * @return bundle identifier
31 + */
32 + String id();
33 +
34 + /**
35 + * Bundle display name.
36 + *
37 + * @return display name
38 + */
39 + String displayName();
40 +
41 + /**
42 + * The set of functions in this bundle instance.
43 + *
44 + * @return the functions
45 + */
46 + Set<XosFunctionDescriptor> functions();
47 +}
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.google.common.collect.ImmutableList;
21 +
22 +import java.util.List;
23 +
24 +/**
25 + * Utility factory for creating bundles and functions etc.
26 + */
27 +public class BundleFactory {
28 +
29 + private static final String BASIC_ID = "basic";
30 + private static final String BASIC_DISPLAY_NAME = "Basic Bundle";
31 +
32 + private static final String FAMILY_ID = "family";
33 + private static final String FAMILY_DISPLAY_NAME = "Family Bundle";
34 +
35 + // no instantiation
36 + private BundleFactory() {}
37 +
38 + private static final BundleDescriptor BASIC =
39 + new DefaultBundleDescriptor(BASIC_ID, BASIC_DISPLAY_NAME,
40 + XosFunctionDescriptor.INTERNET,
41 + XosFunctionDescriptor.FIREWALL);
42 +
43 + private static final BundleDescriptor FAMILY =
44 + new DefaultBundleDescriptor(FAMILY_ID, FAMILY_DISPLAY_NAME,
45 + XosFunctionDescriptor.INTERNET,
46 + XosFunctionDescriptor.FIREWALL,
47 + XosFunctionDescriptor.URL_FILTERING);
48 +
49 + /**
50 + * Returns the list of available bundles.
51 + *
52 + * @return available bundles
53 + */
54 + public static List<BundleDescriptor> availableBundles() {
55 + return ImmutableList.of(BASIC, FAMILY);
56 + }
57 +}
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.google.common.collect.ImmutableSet;
21 +
22 +import java.util.Set;
23 +
24 +
25 +/**
26 + * Base implementation of BundleDescriptor.
27 + */
28 +public class DefaultBundleDescriptor implements BundleDescriptor {
29 +
30 + private final String id;
31 + private final String displayName;
32 + private final Set<XosFunctionDescriptor> functions;
33 +
34 + /**
35 + * Constructs a bundle descriptor.
36 + *
37 + * @param id bundle identifier
38 + * @param displayName bundle display name
39 + * @param functions functions that make up this bundle
40 + */
41 + DefaultBundleDescriptor(String id, String displayName,
42 + XosFunctionDescriptor... functions) {
43 + this.id = id;
44 + this.displayName = displayName;
45 + this.functions = ImmutableSet.copyOf(functions);
46 + }
47 +
48 +
49 + public String id() {
50 + return id;
51 + }
52 +
53 + public String displayName() {
54 + return displayName;
55 + }
56 +
57 + public Set<XosFunctionDescriptor> functions() {
58 + return functions;
59 + }
60 +}
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.JsonNode;
21 +import com.fasterxml.jackson.databind.ObjectMapper;
22 +import com.fasterxml.jackson.databind.node.ObjectNode;
23 +
24 +/**
25 + * Default implementation of an XOS function.
26 + */
27 +public class DefaultXosFunction implements XosFunction {
28 +
29 + private static final ObjectMapper MAPPER = new ObjectMapper();
30 +
31 + private final XosFunctionDescriptor descriptor;
32 +
33 + public DefaultXosFunction(XosFunctionDescriptor xfd) {
34 + descriptor = xfd;
35 + }
36 +
37 + public XosFunctionDescriptor descriptor() {
38 + return descriptor;
39 + }
40 +
41 + public ObjectNode params() {
42 + return MAPPER.createObjectNode();
43 + }
44 +
45 + public String toJson() {
46 + return null;
47 + }
48 +
49 + public JsonNode toJsonNode() {
50 + return null;
51 + }
52 +}
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.JsonNode;
21 +
22 +/**
23 + * An object that can be serialized to JSON.
24 + */
25 +public interface JsonBlob {
26 +
27 + /**
28 + * Returns an Object Node representation of this object.
29 + *
30 + * @return object node hierarchy
31 + */
32 + JsonNode toJsonNode();
33 +
34 + /**
35 + * Returns a JSON string representation of this object.
36 + *
37 + * @return JSON serialization
38 + */
39 + String toJson();
40 +}
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 +import com.fasterxml.jackson.databind.node.ObjectNode;
22 +
23 +/**
24 + * Designates a specific instance of an XOS function.
25 + */
26 +public interface XosFunction extends JsonBlob {
27 +
28 + /**
29 + * Returns the descriptor for this function.
30 + *
31 + * @return function identifier
32 + */
33 + XosFunctionDescriptor descriptor();
34 +
35 + /**
36 + * Returns the current state of this function, encapsulated
37 + * as a JSON node.
38 + *
39 + * @return parameters for the function
40 + */
41 + ObjectNode params();
42 +}
43 +
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 XOS Functions.
22 + */
23 +public enum XosFunctionDescriptor {
24 + /**
25 + * Internet function.
26 + */
27 + INTERNET("internet",
28 + "Internet",
29 + "Basic internet connectivity."),
30 +
31 + /**
32 + * Firewall function.
33 + */
34 + FIREWALL("firewall",
35 + "Firewall",
36 + "Normal firewall protection."),
37 +
38 + /**
39 + * URL Filtering function (parental controls).
40 + */
41 + URL_FILTERING("url_filtering",
42 + "Parental Control",
43 + "Variable levels of URL filtering.");
44 +
45 + private final String id;
46 + private final String displayName;
47 + private final String description;
48 +
49 + XosFunctionDescriptor(String id, String displayName, String description) {
50 + this.id = id;
51 + this.displayName = displayName;
52 + this.description = description;
53 + }
54 +
55 + /**
56 + * Returns this function's internal identifier.
57 + *
58 + * @return the identifier
59 + */
60 + public String id() {
61 + return id;
62 + }
63 +
64 + /**
65 + * Returns this function's display name.
66 + *
67 + * @return display name
68 + */
69 + public String displayName() {
70 + return displayName;
71 + }
72 +
73 + /**
74 + * Returns a short, textual description of the function.
75 + *
76 + * @return textual description
77 + */
78 + public String description() {
79 + return description;
80 + }
81 +
82 +}
1 { 1 {
2 "bundle": { 2 "bundle": {
3 + "id": "basic",
3 "name": "Basic Bundle", 4 "name": "Basic Bundle",
4 "functions": [ 5 "functions": [
5 { 6 {
......
1 { 1 {
2 "bundle": { 2 "bundle": {
3 + "id": "family",
3 "name": "Family Bundle", 4 "name": "Family Bundle",
4 "functions": [ 5 "functions": [
5 { 6 {
......
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.Test;
21 +
22 +import java.util.Set;
23 +
24 +import static org.junit.Assert.*;
25 +import static org.onosproject.cord.gui.model.BundleFactory.availableBundles;
26 +import static org.onosproject.cord.gui.model.XosFunctionDescriptor.*;
27 +
28 +/**
29 + * Unit tests for {@link BundleFactory}.
30 + */
31 +public class BundleFactoryTest {
32 +
33 + @Test
34 + public void bundleCount() {
35 + assertEquals("wrong count", 2, availableBundles().size());
36 + }
37 +
38 + @Test
39 + public void basicBundle() {
40 + BundleDescriptor bundle = availableBundles().get(0);
41 + assertEquals("wrong id", "basic", bundle.id());
42 + assertEquals("wrong id", "Basic Bundle", bundle.displayName());
43 + Set<XosFunctionDescriptor> funcs = bundle.functions();
44 + assertTrue("missing internet", funcs.contains(INTERNET));
45 + assertTrue("missing firewall", funcs.contains(FIREWALL));
46 + assertFalse("unexpected url-f", funcs.contains(URL_FILTERING));
47 + }
48 +
49 + @Test
50 + public void familyBundle() {
51 + BundleDescriptor bundle = availableBundles().get(1);
52 + assertEquals("wrong id", "family", bundle.id());
53 + assertEquals("wrong id", "Family Bundle", bundle.displayName());
54 + Set<XosFunctionDescriptor> funcs = bundle.functions();
55 + assertTrue("missing internet", funcs.contains(INTERNET));
56 + assertTrue("missing firewall", funcs.contains(FIREWALL));
57 + assertTrue("missing url-f", funcs.contains(URL_FILTERING));
58 + }
59 +
60 +}
61 +
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.Test;
21 +
22 +import static org.junit.Assert.assertEquals;
23 +import static org.junit.Assert.assertTrue;
24 +import static org.onosproject.cord.gui.model.XosFunctionDescriptor.*;
25 +
26 +/**
27 + * Sanity unit tests for {@link XosFunctionDescriptor}.
28 + */
29 +public class XosFunctionDescriptorTest {
30 +
31 + @Test
32 + public void numberOfFunctions() {
33 + assertEquals("unexpected constant count", 3, values().length);
34 + }
35 +
36 + @Test
37 + public void internet() {
38 + assertEquals("wrong id", "internet", INTERNET.id());
39 + assertEquals("wrong display", "Internet", INTERNET.displayName());
40 + assertTrue("wrong desc", INTERNET.description().startsWith("Basic"));
41 + }
42 +
43 + @Test
44 + public void firewall() {
45 + assertEquals("wrong id", "firewall", FIREWALL.id());
46 + assertEquals("wrong display", "Firewall", FIREWALL.displayName());
47 + assertTrue("wrong desc", FIREWALL.description().startsWith("Normal"));
48 + }
49 +
50 + @Test
51 + public void urlFiltering() {
52 + assertEquals("wrong id", "url_filtering", URL_FILTERING.id());
53 + assertEquals("wrong display", "Parental Control", URL_FILTERING.displayName());
54 + assertTrue("wrong desc", URL_FILTERING.description().startsWith("Variable"));
55 + }
56 +}