blob: a935c1bdf6b5214b9c10f591c82409164fdb38da [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska02aeb032015-01-06 22:36:30 -08003 *
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 */
16package org.onosproject.app;
17
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080018import com.google.common.collect.ImmutableList;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080019import com.google.common.collect.ImmutableSet;
20import org.junit.Test;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090021import org.onosproject.core.ApplicationRole;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080022import org.onosproject.core.Version;
Changhoon Yoonb856b812015-08-10 03:47:19 +090023import org.onosproject.security.AppPermission;
24import org.onosproject.security.Permission;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080025
26import java.net.URI;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080027import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080028import java.util.Set;
29
30import static org.junit.Assert.assertEquals;
31import static org.junit.Assert.assertTrue;
Ray Milkey47c95412017-09-15 10:40:48 -070032import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090033
Thomas Vachuska02aeb032015-01-06 22:36:30 -080034
35/**
36 * Basic tests of the default app description.
37 */
38public class DefaultApplicationDescriptionTest {
39
40 public static final String APP_NAME = "org.foo.app";
41 public static final Version VER = Version.version(1, 2, "a", null);
Simon Huntafae2f72016-03-04 21:18:23 -080042 public static final String TITLE = "Awesome App";
Thomas Vachuskaad35c342015-06-11 17:25:36 -070043 public static final String DESC = "Awesome application from Circus, Inc.";
Thomas Vachuska02aeb032015-01-06 22:36:30 -080044 public static final String ORIGIN = "Circus";
Jian Lic35415d2016-01-14 17:22:31 -080045 public static final String CATEGORY = "other";
46 public static final String URL = "http://www.onosproject.org";
47 public static final String README = "Awesome application from Circus, Inc.";
48 public static final byte[] ICON = new byte[] {};
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090049 public static final ApplicationRole ROLE = ApplicationRole.ADMIN;
Changhoon Yoonb856b812015-08-10 03:47:19 +090050 public static final Set<Permission> PERMS = ImmutableSet.of(
51 new Permission(AppPermission.class.getName(), "FLOWRULE_WRITE"),
52 new Permission(AppPermission.class.getName(), "FLOWRULE_READ"));
Thomas Vachuska02aeb032015-01-06 22:36:30 -080053 public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features");
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080054 public static final List<String> FEATURES = ImmutableList.of("foo", "bar");
Thomas Vachuska761f0042015-11-11 19:10:17 -080055 public static final List<String> APPS = ImmutableList.of("fifi");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080056
Ray Milkey47c95412017-09-15 10:40:48 -070057 /**
58 * Checks that the DefaultApplicationDescription class is immutable.
59 */
60 @Test
61 public void testImmutability() {
62 assertThatClassIsImmutable(DefaultApplicationDescription.class);
63 }
64
Thomas Vachuska02aeb032015-01-06 22:36:30 -080065 @Test
66 public void basics() {
67 ApplicationDescription app =
Ray Milkey47c95412017-09-15 10:40:48 -070068 DefaultApplicationDescription.builder()
69 .withName(APP_NAME)
70 .withVersion(VER)
71 .withTitle(TITLE)
72 .withDescription(DESC)
73 .withOrigin(ORIGIN)
74 .withCategory(CATEGORY)
75 .withUrl(URL)
76 .withReadme(README)
77 .withIcon(ICON)
78 .withRole(ROLE)
79 .withPermissions(PERMS)
80 .withFeaturesRepo(FURL)
81 .withFeatures(FEATURES)
82 .withRequiredApps(APPS)
83 .build();
84
Thomas Vachuska02aeb032015-01-06 22:36:30 -080085 assertEquals("incorrect id", APP_NAME, app.name());
86 assertEquals("incorrect version", VER, app.version());
Simon Huntafae2f72016-03-04 21:18:23 -080087 assertEquals("incorrect title", TITLE, app.title());
Thomas Vachuska02aeb032015-01-06 22:36:30 -080088 assertEquals("incorrect description", DESC, app.description());
89 assertEquals("incorrect origin", ORIGIN, app.origin());
Jian Lic35415d2016-01-14 17:22:31 -080090 assertEquals("incorrect category", CATEGORY, app.category());
91 assertEquals("incorrect URL", URL, app.url());
92 assertEquals("incorrect readme", README, app.readme());
93 assertEquals("incorrect role", ROLE, app.role());
Thomas Vachuska02aeb032015-01-06 22:36:30 -080094 assertEquals("incorrect permissions", PERMS, app.permissions());
95 assertEquals("incorrect features repo", FURL, app.featuresRepo().get());
96 assertEquals("incorrect features", FEATURES, app.features());
Thomas Vachuska761f0042015-11-11 19:10:17 -080097 assertEquals("incorrect apps", APPS, app.requiredApps());
Thomas Vachuska02aeb032015-01-06 22:36:30 -080098 assertTrue("incorrect toString", app.toString().contains(APP_NAME));
99 }
Ray Milkey47c95412017-09-15 10:40:48 -0700100}