ONOS-542 Defining application subsystem interfaces & public constructs.
Change-Id: Iba0d2cb69dace5beee8a68def9918059ce755b5c
diff --git a/core/api/src/test/java/org/onosproject/app/ApplicationAdminServiceAdapter.java b/core/api/src/test/java/org/onosproject/app/ApplicationAdminServiceAdapter.java
new file mode 100644
index 0000000..4e5ccf8
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/app/ApplicationAdminServiceAdapter.java
@@ -0,0 +1,78 @@
+/*
+ * 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.app;
+
+import org.onosproject.core.Application;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.Permission;
+
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ * Adapter for testing against application admin service.
+ */
+public class ApplicationAdminServiceAdapter extends ApplicationServiceAdapter
+ implements ApplicationAdminService {
+ @Override
+ public Set<Application> getApplications() {
+ return null;
+ }
+
+ @Override
+ public Application getApplication(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public ApplicationState getState(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public Set<Permission> getPermissions(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public void addListener(ApplicationListener listener) {
+ }
+
+ @Override
+ public void removeListener(ApplicationListener listener) {
+ }
+
+ @Override
+ public Application install(InputStream appDescStream) {
+ return null;
+ }
+
+ @Override
+ public void uninstall(ApplicationId appId) {
+ }
+
+ @Override
+ public void activate(ApplicationId appId) {
+ }
+
+ @Override
+ public void deactivate(ApplicationId appId) {
+ }
+
+ @Override
+ public void setPermissions(ApplicationId appId, Set<Permission> permissions) {
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java b/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java
new file mode 100644
index 0000000..4a882c3
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.app;
+
+import org.junit.Test;
+import org.onosproject.core.Application;
+import org.onosproject.core.DefaultApplication;
+import org.onosproject.event.AbstractEventTest;
+
+import java.util.Optional;
+
+import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED;
+import static org.onosproject.app.DefaultApplicationDescriptionTest.*;
+import static org.onosproject.core.DefaultApplicationTest.APP_ID;
+
+/**
+ * Test of the application event.
+ */
+public class ApplicationEventTest extends AbstractEventTest {
+
+ private Application createApp() {
+ return new DefaultApplication(APP_ID, VER, DESC, ORIGIN,
+ PERMS, Optional.of(FURL), FEATURES);
+ }
+
+ @Test
+ public void withoutTime() {
+ Application app = createApp();
+ ApplicationEvent event = new ApplicationEvent(APP_ACTIVATED, app, 123L);
+ validateEvent(event, APP_ACTIVATED, app, 123L);
+ }
+
+ @Test
+ public void withTime() {
+ Application app = createApp();
+ long before = System.currentTimeMillis();
+ ApplicationEvent event = new ApplicationEvent(APP_ACTIVATED, app);
+ long after = System.currentTimeMillis();
+ validateEvent(event, APP_ACTIVATED, app, before, after);
+ }
+
+}
\ No newline at end of file
diff --git a/core/api/src/test/java/org/onosproject/app/ApplicationExceptionTest.java b/core/api/src/test/java/org/onosproject/app/ApplicationExceptionTest.java
new file mode 100644
index 0000000..a0c7ef1
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/app/ApplicationExceptionTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.app;
+
+import org.onlab.junit.ExceptionTest;
+
+public class ApplicationExceptionTest extends ExceptionTest {
+
+ @Override
+ protected Exception getDefault() {
+ return new ApplicationException();
+ }
+
+ @Override
+ protected Exception getWithMessage() {
+ return new ApplicationException(MESSAGE);
+ }
+
+ @Override
+ protected Exception getWithMessageAndCause() {
+ return new ApplicationException(MESSAGE, CAUSE);
+ }
+}
\ No newline at end of file
diff --git a/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java b/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java
new file mode 100644
index 0000000..ff1822a
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java
@@ -0,0 +1,60 @@
+/*
+ * 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.app;
+
+import org.onosproject.core.Application;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.Permission;
+
+import java.util.Set;
+
+/**
+ * Adapter for testing against application service.
+ */
+public class ApplicationServiceAdapter implements ApplicationService {
+ @Override
+ public Set<Application> getApplications() {
+ return null;
+ }
+
+ @Override
+ public ApplicationId getId(String name) {
+ return null;
+ }
+
+ @Override
+ public Application getApplication(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public ApplicationState getState(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public Set<Permission> getPermissions(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public void addListener(ApplicationListener listener) {
+ }
+
+ @Override
+ public void removeListener(ApplicationListener listener) {
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/app/ApplicationStoreAdapter.java b/core/api/src/test/java/org/onosproject/app/ApplicationStoreAdapter.java
new file mode 100644
index 0000000..265c2a6
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/app/ApplicationStoreAdapter.java
@@ -0,0 +1,78 @@
+/*
+ * 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.app;
+
+import org.onosproject.core.Application;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.Permission;
+import org.onosproject.store.AbstractStore;
+
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ * Adapter for application testing against application store.
+ */
+public class ApplicationStoreAdapter
+ extends AbstractStore<ApplicationEvent, ApplicationStoreDelegate>
+ implements ApplicationStore {
+ @Override
+ public Set<Application> getApplications() {
+ return null;
+ }
+
+ @Override
+ public ApplicationId getId(String name) {
+ return null;
+ }
+
+ @Override
+ public Application getApplication(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public ApplicationState getState(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public Application create(InputStream appDescStream) {
+ return null;
+ }
+
+ @Override
+ public void remove(ApplicationId appId) {
+ }
+
+ @Override
+ public void activate(ApplicationId appId) {
+ }
+
+ @Override
+ public void deactivate(ApplicationId appId) {
+ }
+
+ @Override
+ public Set<Permission> getPermissions(ApplicationId appId) {
+ return null;
+ }
+
+ @Override
+ public void setPermissions(ApplicationId appId, Set<Permission> permissions) {
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java b/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java
new file mode 100644
index 0000000..7079427
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.app;
+
+import com.google.common.collect.ImmutableSet;
+import org.junit.Test;
+import org.onosproject.core.Permission;
+import org.onosproject.core.Version;
+
+import java.net.URI;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Basic tests of the default app description.
+ */
+public class DefaultApplicationDescriptionTest {
+
+ public static final String APP_NAME = "org.foo.app";
+ public static final Version VER = Version.version(1, 2, "a", null);
+ public static final String DESC = "Awesome application from Circus";
+ public static final String ORIGIN = "Circus";
+ public static final Set<Permission> PERMS = ImmutableSet.of();
+ public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features");
+ public static final Set<String> FEATURES = ImmutableSet.of("foo");
+
+ @Test
+ public void basics() {
+ ApplicationDescription app =
+ new DefaultApplicationDescription(APP_NAME, VER, DESC, ORIGIN,
+ PERMS, FURL, FEATURES);
+ assertEquals("incorrect id", APP_NAME, app.name());
+ assertEquals("incorrect version", VER, app.version());
+ assertEquals("incorrect description", DESC, app.description());
+ assertEquals("incorrect origin", ORIGIN, app.origin());
+ assertEquals("incorrect permissions", PERMS, app.permissions());
+ assertEquals("incorrect features repo", FURL, app.featuresRepo().get());
+ assertEquals("incorrect features", FEATURES, app.features());
+ assertTrue("incorrect toString", app.toString().contains(APP_NAME));
+ }
+
+}
\ No newline at end of file