summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/common/src/test/java/org/onosproject/common
diff options
context:
space:
mode:
authorCNlucius <lukai1@huawei.com>2016-09-13 11:40:12 +0800
committerCNlucius <lukai1@huawei.com>2016-09-13 11:41:53 +0800
commitb731e2f1dd0972409b136aebc7b463dd72c9cfad (patch)
tree5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/core/common/src/test/java/org/onosproject/common
parentee93993458266114c29271a481ef9ce7ce621b2a (diff)
ONOSFW-171
O/S-SFC-ONOS scenario documentation Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365 Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/core/common/src/test/java/org/onosproject/common')
-rw-r--r--framework/src/onos/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java141
-rw-r--r--framework/src/onos/core/common/src/test/java/org/onosproject/common/app/ApplicationArchiveTest.java157
-rw-r--r--framework/src/onos/core/common/src/test/java/org/onosproject/common/event/impl/TestEventDispatcher.java48
3 files changed, 0 insertions, 346 deletions
diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
deleted file mode 100644
index ef0f3324..00000000
--- a/framework/src/onos/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2014-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.common;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.packet.ChassisId;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultDevice;
-import org.onosproject.net.DefaultLink;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.topology.ClusterId;
-import org.onosproject.net.topology.DefaultGraphDescription;
-import org.onosproject.net.topology.GraphDescription;
-import org.onosproject.net.topology.LinkWeight;
-import org.onosproject.net.topology.TopologyCluster;
-
-import java.util.Set;
-
-import static com.google.common.collect.ImmutableSet.of;
-import static org.junit.Assert.*;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
-/**
- * Test of the default topology implementation.
- */
-public class DefaultTopologyTest {
-
- public static final ProviderId PID = new ProviderId("of", "foo.bar");
-
- public static final DeviceId D1 = deviceId("of:1");
- public static final DeviceId D2 = deviceId("of:2");
- public static final DeviceId D3 = deviceId("of:3");
- public static final DeviceId D4 = deviceId("of:4");
- public static final DeviceId D5 = deviceId("of:5");
-
- public static final PortNumber P1 = portNumber(1);
- public static final PortNumber P2 = portNumber(2);
-
- public static final LinkWeight WEIGHT = edge ->
- edge.src().deviceId().equals(D4) || edge.dst().deviceId().equals(D4)
- ? 2.0 : 1.0;
-
- private DefaultTopology dt;
-
- @Before
- public void setUp() {
- long now = System.currentTimeMillis();
- Set<Device> devices = of(device("1"), device("2"),
- device("3"), device("4"),
- device("5"));
- Set<Link> links = of(link("1", 1, "2", 1), link("2", 1, "1", 1),
- link("3", 2, "2", 2), link("2", 2, "3", 2),
- link("1", 3, "4", 3), link("4", 3, "1", 3),
- link("3", 4, "4", 4), link("4", 4, "3", 4));
- GraphDescription graphDescription =
- new DefaultGraphDescription(now, System.currentTimeMillis(), devices, links);
-
- dt = new DefaultTopology(PID, graphDescription);
- assertEquals("incorrect supplier", PID, dt.providerId());
- assertEquals("incorrect time", now, dt.time());
- assertEquals("incorrect device count", 5, dt.deviceCount());
- assertEquals("incorrect link count", 8, dt.linkCount());
- assertEquals("incorrect cluster count", 2, dt.clusterCount());
- assertEquals("incorrect broadcast set size", 6,
- dt.broadcastSetSize(ClusterId.clusterId(0)));
- }
-
- @Test
- public void pathRelated() {
- Set<Path> paths = dt.getPaths(D1, D2);
- assertEquals("incorrect path count", 1, paths.size());
-
- paths = dt.getPaths(D1, D3);
- assertEquals("incorrect path count", 2, paths.size());
-
- paths = dt.getPaths(D1, D5);
- assertTrue("no paths expected", paths.isEmpty());
-
- paths = dt.getPaths(D1, D3, WEIGHT);
- assertEquals("incorrect path count", 1, paths.size());
- }
-
- @Test
- public void pointRelated() {
- assertTrue("should be infrastructure point",
- dt.isInfrastructure(new ConnectPoint(D1, P1)));
- assertFalse("should not be infrastructure point",
- dt.isInfrastructure(new ConnectPoint(D1, P2)));
- }
-
- @Test
- public void clusterRelated() {
- Set<TopologyCluster> clusters = dt.getClusters();
- assertEquals("incorrect cluster count", 2, clusters.size());
-
- TopologyCluster c = dt.getCluster(D1);
- Set<DeviceId> devs = dt.getClusterDevices(c);
- assertEquals("incorrect cluster device count", 4, devs.size());
- assertTrue("cluster should contain D2", devs.contains(D2));
- assertFalse("cluster should not contain D5", devs.contains(D5));
- }
-
- // Short-hand for creating a link.
- public static Link link(String src, int sp, String dst, int dp) {
- return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)),
- new ConnectPoint(did(dst), portNumber(dp)),
- Link.Type.DIRECT);
- }
-
- // Crates a new device with the specified id
- public static Device device(String id) {
- return new DefaultDevice(PID, did(id), Device.Type.SWITCH,
- "mfg", "1.0", "1.1", "1234", new ChassisId());
- }
-
- // Short-hand for producing a device id from a string
- public static DeviceId did(String id) {
- return deviceId("of:" + id);
- }
-
-}
diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/common/app/ApplicationArchiveTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/common/app/ApplicationArchiveTest.java
deleted file mode 100644
index 97012c4e..00000000
--- a/framework/src/onos/core/common/src/test/java/org/onosproject/common/app/ApplicationArchiveTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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.common.app;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Files;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.util.Tools;
-import org.onosproject.app.ApplicationDescription;
-import org.onosproject.app.ApplicationException;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Set;
-
-import static org.junit.Assert.*;
-import static org.onosproject.app.DefaultApplicationDescriptionTest.*;
-
-/**
- * Suite of tests for the application archive utility.
- */
-public class ApplicationArchiveTest {
-
- static final File STORE = Files.createTempDir();
-
- private ApplicationArchive aar = new ApplicationArchive();
-
- @Before
- public void setUp() {
- aar.setRootPath(STORE.getAbsolutePath());
- }
-
- @After
- public void tearDown() throws IOException {
- if (STORE.exists()) {
- Tools.removeDirectory(STORE);
- }
- }
-
- private void validate(ApplicationDescription app) {
- assertEquals("incorrect name", APP_NAME, app.name());
- assertEquals("incorrect version", VER, app.version());
- assertEquals("incorrect origin", ORIGIN, app.origin());
- assertEquals("incorrect role", ROLE, app.role());
-
- assertEquals("incorrect description", DESC, app.description());
- assertEquals("incorrect features URI", FURL, app.featuresRepo().get());
- assertEquals("incorrect permissions", PERMS, app.permissions());
- assertEquals("incorrect features", FEATURES, app.features());
- }
-
- @Test
- public void saveZippedApp() throws IOException {
- InputStream stream = getClass().getResourceAsStream("app.zip");
- ApplicationDescription app = aar.saveApplication(stream);
- validate(app);
- stream.close();
- }
-
- @Test
- public void savePlainApp() throws IOException {
- InputStream stream = getClass().getResourceAsStream("app.xml");
- ApplicationDescription app = aar.saveApplication(stream);
- validate(app);
- stream.close();
- }
-
- @Test
- public void loadApp() throws IOException {
- saveZippedApp();
- ApplicationDescription app = aar.getApplicationDescription(APP_NAME);
- validate(app);
- }
-
- @Test
- public void getAppNames() throws IOException {
- saveZippedApp();
- Set<String> names = aar.getApplicationNames();
- assertEquals("incorrect names", ImmutableSet.of(APP_NAME), names);
- }
-
- @Test
- public void purgeApp() throws IOException {
- saveZippedApp();
- aar.purgeApplication(APP_NAME);
- assertEquals("incorrect names", ImmutableSet.<String>of(),
- aar.getApplicationNames());
- }
-
- @Test
- public void getAppZipStream() throws IOException {
- saveZippedApp();
- InputStream stream = aar.getApplicationInputStream(APP_NAME);
- byte[] orig = ByteStreams.toByteArray(getClass().getResourceAsStream("app.zip"));
- byte[] loaded = ByteStreams.toByteArray(stream);
- assertArrayEquals("incorrect stream", orig, loaded);
- stream.close();
- }
-
- @Test
- public void getAppXmlStream() throws IOException {
- savePlainApp();
- InputStream stream = aar.getApplicationInputStream(APP_NAME);
- byte[] orig = ByteStreams.toByteArray(getClass().getResourceAsStream("app.xml"));
- byte[] loaded = ByteStreams.toByteArray(stream);
- assertArrayEquals("incorrect stream", orig, loaded);
- stream.close();
- }
-
- @Test
- public void active() throws IOException {
- savePlainApp();
- assertFalse("should not be active", aar.isActive(APP_NAME));
- aar.setActive(APP_NAME);
- assertTrue("should not be active", aar.isActive(APP_NAME));
- aar.clearActive(APP_NAME);
- assertFalse("should not be active", aar.isActive(APP_NAME));
- }
-
- @Test(expected = ApplicationException.class)
- public void getBadAppDesc() throws IOException {
- aar.getApplicationDescription("org.foo.BAD");
- }
-
- @Test(expected = ApplicationException.class)
- public void getBadAppStream() throws IOException {
- aar.getApplicationInputStream("org.foo.BAD");
- }
-
- @Test(expected = ApplicationException.class)
- public void setBadActive() throws IOException {
- aar.setActive("org.foo.BAD");
- }
-
- @Test // (expected = ApplicationException.class)
- public void purgeBadApp() throws IOException {
- aar.purgeApplication("org.foo.BAD");
- }
-
-} \ No newline at end of file
diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/common/event/impl/TestEventDispatcher.java b/framework/src/onos/core/common/src/test/java/org/onosproject/common/event/impl/TestEventDispatcher.java
deleted file mode 100644
index 4ea371a0..00000000
--- a/framework/src/onos/core/common/src/test/java/org/onosproject/common/event/impl/TestEventDispatcher.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2014-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.common.event.impl;
-
-import org.onosproject.event.DefaultEventSinkRegistry;
-import org.onosproject.event.Event;
-import org.onosproject.event.EventDeliveryService;
-import org.onosproject.event.EventSink;
-
-import static com.google.common.base.Preconditions.checkState;
-
-/**
- * Implements event delivery system that delivers events synchronously, or
- * in-line with the post method invocation.
- */
-public class TestEventDispatcher extends DefaultEventSinkRegistry
- implements EventDeliveryService {
-
- @Override
- @SuppressWarnings("unchecked")
- public synchronized void post(Event event) {
- EventSink sink = getSink(event.getClass());
- checkState(sink != null, "No sink for event %s", event);
- sink.process(event);
- }
-
- @Override
- public void setDispatchTimeLimit(long millis) {
- }
-
- @Override
- public long getDispatchTimeLimit() {
- return 0;
- }
-}