diff options
Diffstat (limited to 'framework/src/onos/core/api/src/test/java/org/onosproject/net/intent')
35 files changed, 0 insertions, 3794 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java deleted file mode 100644 index 6bb7e28f..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java +++ /dev/null @@ -1,35 +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.net.intent; - -import org.junit.After; -import org.junit.Before; -import org.onosproject.core.IdGenerator; - -public abstract class AbstractIntentTest { - - protected IdGenerator idGenerator = new MockIdGenerator(); - - @Before - public void setUp() throws Exception { - Intent.bindIdGenerator(idGenerator); - } - - @After - public void tearDown() { - Intent.unbindIdGenerator(idGenerator); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java deleted file mode 100644 index c510b60a..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.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.net.intent; - -import java.util.Set; - -import org.onosproject.core.ApplicationId; -import org.onosproject.TestApplicationId; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.PortNumber; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; - -/** - * Base facilities to test various connectivity tests. - */ -public abstract class ConnectivityIntentTest extends IntentTest { - - public static final ApplicationId APPID = new TestApplicationId("foo"); - public static final Key KEY = Key.of(1L, APPID); - - public static final IntentId IID = new IntentId(123); - public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector(); - public static final TrafficTreatment NOP = DefaultTrafficTreatment.emptyTreatment(); - - public static final ConnectPoint P1 = new ConnectPoint(DeviceId.deviceId("111"), PortNumber.portNumber(0x1)); - public static final ConnectPoint P2 = new ConnectPoint(DeviceId.deviceId("222"), PortNumber.portNumber(0x2)); - public static final ConnectPoint P3 = new ConnectPoint(DeviceId.deviceId("333"), PortNumber.portNumber(0x3)); - - public static final Set<ConnectPoint> PS1 = itemSet(new ConnectPoint[]{P1, P3}); - public static final Set<ConnectPoint> PS2 = itemSet(new ConnectPoint[]{P2, P3}); -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java deleted file mode 100644 index a33d3692..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java +++ /dev/null @@ -1,261 +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.net.intent; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * Fake implementation of the intent service to assist in developing tests of - * the interface contract. - */ -public class FakeIntentManager implements TestableIntentService { - - private final Map<Key, Intent> intents = new HashMap<>(); - private final Map<Key, IntentState> intentStates = new HashMap<>(); - private final Map<Key, List<Intent>> installables = new HashMap<>(); - private final Set<IntentListener> listeners = new HashSet<>(); - - private final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = new HashMap<>(); - - private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private final List<IntentException> exceptions = new ArrayList<>(); - - @Override - public List<IntentException> getExceptions() { - return exceptions; - } - - // Provides an out-of-thread simulation of intent submit life-cycle - private void executeSubmit(final Intent intent) { - registerSubclassCompilerIfNeeded(intent); - executor.execute(() -> { - try { - executeCompilingPhase(intent); - } catch (IntentException e) { - exceptions.add(e); - } - }); - } - - // Provides an out-of-thread simulation of intent withdraw life-cycle - private void executeWithdraw(final Intent intent) { - executor.execute(() -> { - try { - List<Intent> installable = getInstallable(intent.key()); - executeWithdrawingPhase(intent, installable); - } catch (IntentException e) { - exceptions.add(e); - } - }); - } - - private <T extends Intent> IntentCompiler<T> getCompiler(T intent) { - @SuppressWarnings("unchecked") - IntentCompiler<T> compiler = (IntentCompiler<T>) compilers.get(intent.getClass()); - if (compiler == null) { - throw new IntentException("no compiler for class " + intent.getClass()); - } - return compiler; - } - - private <T extends Intent> void executeCompilingPhase(T intent) { - setState(intent, IntentState.COMPILING); - try { - // For the fake, we compile using a single level pass - List<Intent> installable = new ArrayList<>(); - for (Intent compiled : getCompiler(intent).compile(intent, null, null)) { - installable.add(compiled); - } - executeInstallingPhase(intent, installable); - - } catch (IntentException e) { - setState(intent, IntentState.FAILED); - dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent)); - } - } - - private void executeInstallingPhase(Intent intent, - List<Intent> installable) { - setState(intent, IntentState.INSTALLING); - try { - setState(intent, IntentState.INSTALLED); - putInstallable(intent.key(), installable); - dispatch(new IntentEvent(IntentEvent.Type.INSTALLED, intent)); - - } catch (IntentException e) { - setState(intent, IntentState.FAILED); - dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent)); - } - } - - private void executeWithdrawingPhase(Intent intent, - List<Intent> installable) { - setState(intent, IntentState.WITHDRAWING); - try { - removeInstallable(intent.key()); - setState(intent, IntentState.WITHDRAWN); - dispatch(new IntentEvent(IntentEvent.Type.WITHDRAWN, intent)); - } catch (IntentException e) { - // FIXME: Rework this to always go from WITHDRAWING to WITHDRAWN! - setState(intent, IntentState.FAILED); - dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent)); - } - } - - // Sets the internal state for the given intent and dispatches an event - private void setState(Intent intent, IntentState state) { - intentStates.put(intent.key(), state); - } - - private void putInstallable(Key key, List<Intent> installable) { - installables.put(key, installable); - } - - private void removeInstallable(Key key) { - installables.remove(key); - } - - private List<Intent> getInstallable(Key key) { - List<Intent> installable = installables.get(key); - if (installable != null) { - return installable; - } else { - return Collections.emptyList(); - } - } - - @Override - public void submit(Intent intent) { - intents.put(intent.key(), intent); - setState(intent, IntentState.INSTALL_REQ); - dispatch(new IntentEvent(IntentEvent.Type.INSTALL_REQ, intent)); - executeSubmit(intent); - } - - @Override - public void withdraw(Intent intent) { - intents.remove(intent.key()); - executeWithdraw(intent); - } - - @Override - public void purge(Intent intent) { - IntentState currentState = intentStates.get(intent.key()); - if (currentState == IntentState.WITHDRAWN - || currentState == IntentState.FAILED) { - intents.remove(intent.key()); - installables.remove(intent.key()); - intentStates.remove(intent.key()); - } - } - - @Override - public Set<Intent> getIntents() { - return Collections.unmodifiableSet(new HashSet<>(intents.values())); - } - - @Override - public Iterable<IntentData> getIntentData() { - throw new UnsupportedOperationException(); - } - - @Override - public long getIntentCount() { - return intents.size(); - } - - @Override - public Intent getIntent(Key intentKey) { - return intents.get(intentKey); - } - - @Override - public IntentState getIntentState(Key intentKey) { - return intentStates.get(intentKey); - } - - @Override - public List<Intent> getInstallableIntents(Key intentKey) { - return installables.get(intentKey); - } - - @Override - public boolean isLocal(Key intentKey) { - return true; - } - - @Override - public Iterable<Intent> getPending() { - return Collections.emptyList(); - } - - @Override - public void addListener(IntentListener listener) { - listeners.add(listener); - } - - @Override - public void removeListener(IntentListener listener) { - listeners.remove(listener); - } - - private void dispatch(IntentEvent event) { - for (IntentListener listener : listeners) { - listener.event(event); - } - } - - @Override - public <T extends Intent> void registerCompiler(Class<T> cls, - IntentCompiler<T> compiler) { - compilers.put(cls, compiler); - } - - @Override - public <T extends Intent> void unregisterCompiler(Class<T> cls) { - compilers.remove(cls); - } - - @Override - public Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers() { - return Collections.unmodifiableMap(compilers); - } - - private void registerSubclassCompilerIfNeeded(Intent intent) { - if (!compilers.containsKey(intent.getClass())) { - Class<?> cls = intent.getClass(); - while (cls != Object.class) { - // As long as we're within the Intent class descendants - if (Intent.class.isAssignableFrom(cls)) { - IntentCompiler<?> compiler = compilers.get(cls); - if (compiler != null) { - compilers.put(intent.getClass(), compiler); - return; - } - } - cls = cls.getSuperclass(); - } - } - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java deleted file mode 100644 index c3a95473..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java +++ /dev/null @@ -1,178 +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.net.intent; - -import org.junit.Test; -import org.onlab.util.DataRateUnit; -import org.onosproject.TestApplicationId; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.HostId; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.intent.constraint.BandwidthConstraint; -import com.google.common.collect.ImmutableList; -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.hid; - -/** - * Unit tests for the HostToHostIntent class. - */ -public class HostToHostIntentTest extends IntentTest { - private final TrafficSelector selector = new IntentTestsMocks.MockSelector(); - private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); - private final HostId id1 = hid("12:34:56:78:91:ab/1"); - private final HostId id2 = hid("12:34:56:78:92:ab/1"); - private final HostId id3 = hid("12:34:56:78:93:ab/1"); - - private static final ApplicationId APPID = new TestApplicationId("foo"); - - private HostToHostIntent makeHostToHost(HostId one, HostId two) { - return HostToHostIntent.builder() - .appId(APPID) - .one(one) - .two(two) - .selector(selector) - .treatment(treatment) - .build(); - } - - /** - * Tests the equals() method where two HostToHostIntents have references - * to the same hosts. These should compare equal. - */ - @Test - public void testSameEquals() { - - HostId one = hid("00:00:00:00:00:01/-1"); - HostId two = hid("00:00:00:00:00:02/-1"); - HostToHostIntent i1 = makeHostToHost(one, two); - HostToHostIntent i2 = makeHostToHost(one, two); - - assertThat(i1.one(), is(equalTo(i2.one()))); - assertThat(i1.two(), is(equalTo(i2.two()))); - } - - /** - * Checks that the HostToHostIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(HostToHostIntent.class); - } - - /** - * Tests equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - final HostToHostIntent intent1 = HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id2) - .selector(selector) - .treatment(treatment) - .build(); - - final HostToHostIntent intent2 = HostToHostIntent.builder() - .appId(APPID) - .one(id2) - .two(id3) - .selector(selector) - .treatment(treatment) - .build(); - - new EqualsTester() - .addEqualityGroup(intent1) - .addEqualityGroup(intent2) - .testEquals(); - } - - @Test - public void testImplicitConstraintsAreAdded() { - final Constraint other = BandwidthConstraint.of(1, DataRateUnit.GBPS); - final HostToHostIntent intent = HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id2) - .selector(selector) - .treatment(treatment) - .constraints(ImmutableList.of(other)) - .build(); - - assertThat(intent.constraints(), hasItem(HostToHostIntent.NOT_OPTICAL)); - } - - @Test - public void testImplicitConstraints() { - final HostToHostIntent implicit = HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id2) - .selector(selector) - .treatment(treatment) - .build(); - final HostToHostIntent empty = HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id2) - .selector(selector) - .treatment(treatment) - .constraints(ImmutableList.of()) - .build(); - final HostToHostIntent exact = HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id2) - .selector(selector) - .treatment(treatment) - .constraints(ImmutableList.of(HostToHostIntent.NOT_OPTICAL)) - .build(); - - new EqualsTester() - .addEqualityGroup(implicit.constraints(), - empty.constraints(), - exact.constraints()) - .testEquals(); - - } - - @Override - protected Intent createOne() { - return HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id2) - .selector(selector) - .treatment(treatment) - .build(); - } - - @Override - protected Intent createAnother() { - return HostToHostIntent.builder() - .appId(APPID) - .one(id1) - .two(id3) - .selector(selector) - .treatment(treatment) - .build(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java deleted file mode 100644 index 9c4cf7e0..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java +++ /dev/null @@ -1,179 +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.net.intent; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.core.IdGenerator; -import org.onosproject.store.Timestamp; - -import com.google.common.testing.EqualsTester; - -import static junit.framework.TestCase.assertFalse; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertTrue; -import static org.onosproject.net.intent.IntentTestsMocks.MockIntent; -import static org.onosproject.net.intent.IntentTestsMocks.MockTimestamp; - -/** - * Unit tests for intent data objects. - */ -public class IntentDataTest { - - private Timestamp timestamp1; - private Timestamp timestamp2; - private Timestamp timestamp3; - - private Intent intent1; - private Intent intent2; - private Intent intent3; - - private IntentData data1; - private IntentData data1Copy; - private IntentData data2; - private IntentData data2Copy; - private IntentData data3; - private IntentData data3Copy; - - IdGenerator idGenerator; - - @Before - public void setUpTest() { - idGenerator = new MockIdGenerator(); - Intent.bindIdGenerator(idGenerator); - - timestamp1 = new MockTimestamp(1); - timestamp2 = new MockTimestamp(2); - timestamp3 = new MockTimestamp(3); - - intent1 = new MockIntent(1L); - intent2 = new MockIntent(2L); - intent3 = new MockIntent(3L); - - data1 = new IntentData(intent1, IntentState.INSTALLED, timestamp1); - data1Copy = new IntentData(intent1, IntentState.INSTALLED, timestamp1); - data2 = new IntentData(intent2, IntentState.INSTALLED, timestamp2); - data2Copy = new IntentData(intent2, IntentState.INSTALLED, timestamp2); - data3 = new IntentData(intent3, IntentState.INSTALLED, timestamp3); - data3Copy = new IntentData(intent3, IntentState.INSTALLED, timestamp3); - } - - @After - public void tearDownTest() { - Intent.unbindIdGenerator(idGenerator); - } - - /** - * Checks that intent data objects are properly constructed. - */ - @Test - public void checkConstruction() { - assertThat(data1.state(), is(IntentState.INSTALLED)); - assertThat(data1.version(), is(timestamp1)); - assertThat(data1.intent(), is(intent1)); - } - - /** - * Checks equals() for intent data objects. - */ - @Test - public void checkEquals() { - new EqualsTester() - .addEqualityGroup(data1, data1Copy) - .addEqualityGroup(data2, data2Copy) - .addEqualityGroup(data3, data3Copy) - .testEquals(); - } - - @Test - public void testIsUpdateAcceptable() { - // Going from null to something is always allowed - assertTrue(IntentData.isUpdateAcceptable(null, data1)); - - // we can go from older version to newer but not they other way - assertTrue(IntentData.isUpdateAcceptable(data1, data2)); - assertFalse(IntentData.isUpdateAcceptable(data2, data1)); - - IntentData installing = new IntentData(intent1, IntentState.INSTALLING, timestamp1); - IntentData installed = new IntentData(intent1, IntentState.INSTALLED, timestamp1); - IntentData withdrawing = new IntentData(intent1, IntentState.WITHDRAWING, timestamp1); - IntentData withdrawn = new IntentData(intent1, IntentState.WITHDRAWN, timestamp1); - - IntentData failed = new IntentData(intent1, IntentState.FAILED, timestamp1); - IntentData purgeReq = new IntentData(intent1, IntentState.PURGE_REQ, timestamp1); - - IntentData compiling = new IntentData(intent1, IntentState.COMPILING, timestamp1); - IntentData recompiling = new IntentData(intent1, IntentState.RECOMPILING, timestamp1); - IntentData installReq = new IntentData(intent1, IntentState.INSTALL_REQ, timestamp1); - IntentData withdrawReq = new IntentData(intent1, IntentState.WITHDRAW_REQ, timestamp1); - - // We can't change to the same state - assertFalse(IntentData.isUpdateAcceptable(installing, installing)); - assertFalse(IntentData.isUpdateAcceptable(installed, installed)); - - // From installing we can change to installed - assertTrue(IntentData.isUpdateAcceptable(installing, installed)); - - // Sanity checks in case the manager submits bogus state transitions - assertFalse(IntentData.isUpdateAcceptable(installing, withdrawing)); - assertFalse(IntentData.isUpdateAcceptable(installing, withdrawn)); - assertFalse(IntentData.isUpdateAcceptable(installed, withdrawing)); - assertFalse(IntentData.isUpdateAcceptable(installed, withdrawn)); - - // We can't change to the same state - assertFalse(IntentData.isUpdateAcceptable(withdrawing, withdrawing)); - assertFalse(IntentData.isUpdateAcceptable(withdrawn, withdrawn)); - - // From withdrawing we can change to withdrawn - assertTrue(IntentData.isUpdateAcceptable(withdrawing, withdrawn)); - - // Sanity checks in case the manager submits bogus state transitions - assertFalse(IntentData.isUpdateAcceptable(withdrawing, installing)); - assertFalse(IntentData.isUpdateAcceptable(withdrawing, installed)); - assertFalse(IntentData.isUpdateAcceptable(withdrawn, installing)); - assertFalse(IntentData.isUpdateAcceptable(withdrawn, installed)); - - // We can't go from failed to failed - assertFalse(IntentData.isUpdateAcceptable(failed, failed)); - - // But we can go from any install* or withdraw* state to failed - assertTrue(IntentData.isUpdateAcceptable(installing, failed)); - assertTrue(IntentData.isUpdateAcceptable(installed, failed)); - assertTrue(IntentData.isUpdateAcceptable(withdrawing, failed)); - assertTrue(IntentData.isUpdateAcceptable(withdrawn, failed)); - - // We can go from anything to purgeReq - assertTrue(IntentData.isUpdateAcceptable(installing, purgeReq)); - assertTrue(IntentData.isUpdateAcceptable(installed, purgeReq)); - assertTrue(IntentData.isUpdateAcceptable(withdrawing, purgeReq)); - assertTrue(IntentData.isUpdateAcceptable(withdrawn, purgeReq)); - assertTrue(IntentData.isUpdateAcceptable(failed, purgeReq)); - - // We can't go from purgeReq back to anything else - assertFalse(IntentData.isUpdateAcceptable(purgeReq, withdrawn)); - assertFalse(IntentData.isUpdateAcceptable(purgeReq, withdrawing)); - assertFalse(IntentData.isUpdateAcceptable(purgeReq, installed)); - assertFalse(IntentData.isUpdateAcceptable(purgeReq, installing)); - - // We're never allowed to store transient states - assertFalse(IntentData.isUpdateAcceptable(installing, compiling)); - assertFalse(IntentData.isUpdateAcceptable(installing, recompiling)); - assertFalse(IntentData.isUpdateAcceptable(installing, installReq)); - assertFalse(IntentData.isUpdateAcceptable(installing, withdrawReq)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentExceptionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentExceptionTest.java deleted file mode 100644 index f26ee639..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentExceptionTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Test of the intent exception. - */ -public class IntentExceptionTest { - - @Test - public void basics() { - validate(new IntentException(), null, null); - validate(new IntentException("foo"), "foo", null); - - Throwable cause = new NullPointerException("bar"); - validate(new IntentException("foo", cause), "foo", cause); - } - - /** - * Validates that the specified exception has the correct message and cause. - * - * @param e exception to test - * @param message expected message - * @param cause expected cause - */ - protected void validate(RuntimeException e, String message, Throwable cause) { - assertEquals("incorrect message", message, e.getMessage()); - assertEquals("incorrect cause", cause, e.getCause()); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentIdTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentIdTest.java deleted file mode 100644 index e2987b54..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentIdTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -import org.junit.Test; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -/** - * This class tests the immutability, equality, and non-equality of - * {@link IntentId}. - */ -public class IntentIdTest { - /** - * Tests the immutability of {@link IntentId}. - */ - @Test - public void intentIdFollowsGuidelineForImmutableObject() { - assertThatClassIsImmutable(IntentId.class); - } - - /** - * Tests equality of {@link IntentId}. - */ - @Test - public void testEquality() { - IntentId id1 = new IntentId(1L); - IntentId id2 = new IntentId(1L); - - assertThat(id1, is(id2)); - } - - /** - * Tests non-equality of {@link IntentId}. - */ - @Test - public void testNonEquality() { - IntentId id1 = new IntentId(1L); - IntentId id2 = new IntentId(2L); - - assertThat(id1, is(not(id2))); - } - - @Test - public void valueOf() { - IntentId id = new IntentId(0xdeadbeefL); - assertEquals("incorrect valueOf", id, IntentId.valueOf(0xdeadbeefL)); - } - - /** - * Tests the equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - final IntentId id1 = new IntentId(11111L); - final IntentId sameAsId1 = new IntentId(11111L); - final IntentId id2 = new IntentId(22222L); - - new EqualsTester() - .addEqualityGroup(id1, sameAsId1) - .addEqualityGroup(id2) - .testEquals(); - } - - /** - * Tests construction of an IntentId object. - */ - @Test - public void testConstruction() { - final IntentId id1 = new IntentId(987654321L); - assertEquals(id1.fingerprint(), 987654321L); - - final IntentId emptyId = new IntentId(); - assertEquals(emptyId.fingerprint(), 0L); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java deleted file mode 100644 index 13786b4e..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java +++ /dev/null @@ -1,89 +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.net.intent; - -import java.util.List; - -/** - * Test adapter for intent service. - */ -public class IntentServiceAdapter implements IntentService { - @Override - public void submit(Intent intent) { - - } - - @Override - public void withdraw(Intent intent) { - - } - - @Override - public void purge(Intent intent) { - - } - - @Override - public Iterable<Intent> getIntents() { - return null; - } - - @Override - public Iterable<IntentData> getIntentData() { - return null; - } - - @Override - public long getIntentCount() { - return 0; - } - - @Override - public Intent getIntent(Key intentKey) { - return null; - } - - @Override - public IntentState getIntentState(Key intentKey) { - return IntentState.INSTALLED; - } - - @Override - public List<Intent> getInstallableIntents(Key intentKey) { - return null; - } - - @Override - public boolean isLocal(Key intentKey) { - return false; - } - - @Override - public Iterable<Intent> getPending() { - return null; - } - - @Override - public void addListener(IntentListener listener) { - - } - - @Override - public void removeListener(IntentListener listener) { - - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java deleted file mode 100644 index 0067fb2d..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java +++ /dev/null @@ -1,232 +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.net.intent; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.core.IdGenerator; -import org.onosproject.net.resource.link.LinkResourceAllocations; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import static org.junit.Assert.*; -import static org.onosproject.net.intent.IntentEvent.Type.*; - -/** - * Suite of tests for the intent service contract. - */ -public class IntentServiceTest { - - public static final int IID = 123; - public static final int INSTALLABLE_IID = 234; - - protected static final int GRACE_MS = 500; // millis - - protected TestableIntentService service; - protected TestListener listener = new TestListener(); - protected IdGenerator idGenerator = new MockIdGenerator(); - - @Before - public void setUp() { - service = createIntentService(); - service.addListener(listener); - Intent.bindIdGenerator(idGenerator); - } - - @After - public void tearDown() { - service.removeListener(listener); - Intent.unbindIdGenerator(idGenerator); - } - - /** - * Creates a service instance appropriately instrumented for testing. - * - * @return testable intent service - */ - protected TestableIntentService createIntentService() { - return new FakeIntentManager(); - } - - @Test - public void basics() { - // Make sure there are no intents - assertEquals("incorrect intent count", 0, service.getIntentCount()); - - // Register a compiler and an installer both setup for success. - service.registerCompiler(TestIntent.class, new TestCompiler(new TestInstallableIntent(INSTALLABLE_IID))); - - final Intent intent = new TestIntent(IID); - service.submit(intent); - - // Allow a small window of time until the intent is in the expected state - TestTools.assertAfter(GRACE_MS, () -> - assertEquals("incorrect intent state", IntentState.INSTALLED, service.getIntentState(intent.key()))); - - // Make sure that all expected events have been emitted - validateEvents(intent, INSTALL_REQ, INSTALLED); - - // Make sure there is just one intent (and is ours) - assertEquals("incorrect intent count", 1, service.getIntentCount()); - - // Reset the listener events - listener.events.clear(); - - // Now withdraw the intent - service.withdraw(intent); - - // Allow a small window of time until the event is in the expected state - TestTools.assertAfter(GRACE_MS, () -> - assertEquals("incorrect intent state", IntentState.WITHDRAWN, service.getIntentState(intent.key()))); - - // Make sure that all expected events have been emitted - validateEvents(intent, WITHDRAWN); - - // TODO: discuss what is the fate of intents after they have been withdrawn - // Make sure that the intent is no longer in the system -// assertEquals("incorrect intent count", 0, service.getIntents().size()); -// assertNull("intent should not be found", service.getIntent(intent.id())); -// assertNull("intent state should not be found", service.getIntentState(intent.id())); - } - - @Test - public void failedCompilation() { - // Register a compiler programmed for success - service.registerCompiler(TestIntent.class, new TestCompiler(true)); - - // Submit an intent - final Intent intent = new TestIntent(IID); - service.submit(intent); - - // Allow a small window of time until the intent is in the expected state - TestTools.assertAfter(GRACE_MS, () -> - assertEquals("incorrect intent state", IntentState.FAILED, service.getIntentState(intent.key()))); - - // Make sure that all expected events have been emitted - validateEvents(intent, INSTALL_REQ, FAILED); - } - - /** - * Validates that the test event listener has received the following events - * for the specified intent. Events received for other intents will not be - * considered. - * - * @param intent intent subject - * @param types list of event types for which events are expected - */ - protected void validateEvents(Intent intent, IntentEvent.Type... types) { - Iterator<IntentEvent> events = listener.events.iterator(); - for (IntentEvent.Type type : types) { - IntentEvent event = events.hasNext() ? events.next() : null; - if (event == null) { - fail("expected event not found: " + type); - } else if (intent.equals(event.subject())) { - assertEquals("incorrect state", type, event.type()); - } - } - - // Remainder of events should not apply to this intent; make sure. - while (events.hasNext()) { - assertFalse("unexpected event for intent", - intent.equals(events.next().subject())); - } - } - - @Test - public void compilerBasics() { - // Make sure there are no compilers - assertEquals("incorrect compiler count", 0, service.getCompilers().size()); - - // Add a compiler and make sure that it appears in the map - IntentCompiler<TestIntent> compiler = new TestCompiler(false); - service.registerCompiler(TestIntent.class, compiler); - assertEquals("incorrect compiler", compiler, - service.getCompilers().get(TestIntent.class)); - - // Remove the same and make sure that it no longer appears in the map - service.unregisterCompiler(TestIntent.class); - assertNull("compiler should not be registered", - service.getCompilers().get(TestIntent.class)); - } - - @Test - public void implicitRegistration() { - // Add a compiler and make sure that it appears in the map - IntentCompiler<TestIntent> compiler = new TestCompiler(new TestSubclassInstallableIntent(INSTALLABLE_IID)); - service.registerCompiler(TestIntent.class, compiler); - assertEquals("incorrect compiler", compiler, - service.getCompilers().get(TestIntent.class)); - - // Submit an intent which is a subclass of the one we registered - final Intent intent = new TestSubclassIntent(IID); - service.submit(intent); - - // Allow some time for the intent to be compiled and installed - TestTools.assertAfter(GRACE_MS, () -> - assertEquals("incorrect intent state", IntentState.INSTALLED, service.getIntentState(intent.key()))); - - // Make sure that now we have an implicit registration of the compiler - // under the intent subclass - assertEquals("incorrect compiler", compiler, - service.getCompilers().get(TestSubclassIntent.class)); - - // TODO: discuss whether or if implicit registration should require implicit unregistration - // perhaps unregister by compiler or installer itself, rather than by class would be better - } - - - // Fixture to track emitted intent events - protected class TestListener implements IntentListener { - final List<IntentEvent> events = new ArrayList<>(); - - @Override - public void event(IntentEvent event) { - events.add(event); - } - } - - // Controllable compiler - private class TestCompiler implements IntentCompiler<TestIntent> { - private final boolean fail; - private final List<Intent> result; - - TestCompiler(boolean fail) { - this.fail = fail; - this.result = Collections.emptyList(); - } - - TestCompiler(Intent... result) { - this.fail = false; - this.result = Arrays.asList(result); - } - - @Override - public List<Intent> compile(TestIntent intent, List<Intent> installable, - Set<LinkResourceAllocations> resources) { - if (fail) { - throw new IntentException("compile failed by design"); - } - List<Intent> compiled = new ArrayList<>(result); - return compiled; - } - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTest.java deleted file mode 100644 index d713b8aa..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * Base facilities to test various intent tests. - */ -public abstract class IntentTest extends AbstractIntentTest { - /** - * Produces a set of items from the supplied items. - * - * @param items items to be placed in set - * @param <T> item type - * @return set of items - */ - protected static <T> Set<T> itemSet(T[] items) { - return new HashSet<>(Arrays.asList(items)); - } - - /** - * Creates a new intent, but always a like intent, i.e. all instances will - * be equal, but should not be the same. - * - * @return intent - */ - protected abstract Intent createOne(); - - /** - * Creates another intent, not equals to the one created by - * {@link #createOne()} and with a different hash code. - * - * @return another intent - */ - protected abstract Intent createAnother(); -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java deleted file mode 100644 index 14201472..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java +++ /dev/null @@ -1,496 +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.net.intent; - -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableSet; -import org.onlab.util.Bandwidth; -import org.onosproject.core.DefaultGroupId; -import org.onosproject.core.GroupId; -import org.onosproject.net.DeviceId; -import org.onosproject.net.ElementId; -import org.onosproject.net.Link; -import org.onosproject.net.NetTestTools; -import org.onosproject.net.NetworkResource; -import org.onosproject.net.Path; -import org.onosproject.net.flow.FlowId; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleExtPayLoad; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.criteria.Criterion; -import org.onosproject.net.flow.criteria.Criterion.Type; -import org.onosproject.net.flow.instructions.Instruction; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction; -import org.onosproject.net.resource.ResourceAllocation; -import org.onosproject.net.resource.ResourceRequest; -import org.onosproject.net.resource.ResourceType; -import org.onosproject.net.resource.link.BandwidthResource; -import org.onosproject.net.resource.link.BandwidthResourceRequest; -import org.onosproject.net.resource.link.LambdaResource; -import org.onosproject.net.resource.link.LambdaResourceAllocation; -import org.onosproject.net.resource.link.LambdaResourceRequest; -import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.onosproject.net.resource.link.LinkResourceListener; -import org.onosproject.net.resource.link.LinkResourceRequest; -import org.onosproject.net.resource.link.LinkResourceService; -import org.onosproject.net.resource.link.MplsLabel; -import org.onosproject.net.resource.link.MplsLabelResourceAllocation; -import org.onosproject.net.topology.DefaultTopologyEdge; -import org.onosproject.net.topology.DefaultTopologyVertex; -import org.onosproject.net.topology.LinkWeight; -import org.onosproject.net.topology.PathServiceAdapter; -import org.onosproject.net.topology.TopologyVertex; -import org.onosproject.store.Timestamp; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; - -import static org.onosproject.net.NetTestTools.*; - -/** - * Common mocks used by the intent framework tests. - */ -public class IntentTestsMocks { - /** - * Mock traffic selector class used for satisfying API requirements. - */ - public static class MockSelector implements TrafficSelector { - @Override - public Set<Criterion> criteria() { - return new HashSet<>(); - } - - @Override - public Criterion getCriterion(Type type) { - return null; - } - } - - /** - * Mock traffic treatment class used for satisfying API requirements. - */ - public static class MockTreatment implements TrafficTreatment { - @Override - public List<Instruction> deferred() { - return Collections.emptyList(); - } - - @Override - public List<Instruction> immediate() { - return Collections.emptyList(); - } - - @Override - public List<Instruction> allInstructions() { - return Collections.emptyList(); - } - - @Override - public Instructions.TableTypeTransition tableTransition() { - return null; - } - - @Override - public boolean clearedDeferred() { - return false; - } - - @Override - public MetadataInstruction writeMetadata() { - return null; - } - - @Override - public Instructions.MeterInstruction metered() { - return null; - } - } - - /** - * Mock path service for creating paths within the test. - */ - public static class MockPathService extends PathServiceAdapter { - - final String[] pathHops; - final String[] reversePathHops; - - /** - * Constructor that provides a set of hops to mock. - * - * @param pathHops path hops to mock - */ - public MockPathService(String[] pathHops) { - this.pathHops = pathHops; - String[] reversed = pathHops.clone(); - Collections.reverse(Arrays.asList(reversed)); - reversePathHops = reversed; - } - - @Override - public Set<Path> getPaths(ElementId src, ElementId dst) { - Set<Path> result = new HashSet<>(); - - String[] allHops = new String[pathHops.length]; - - if (src.toString().endsWith(pathHops[0])) { - System.arraycopy(pathHops, 0, allHops, 0, pathHops.length); - } else { - System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length); - } - - result.add(createPath(allHops)); - return result; - } - - @Override - public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { - final Set<Path> paths = getPaths(src, dst); - - for (Path path : paths) { - final DeviceId srcDevice = path.src().deviceId(); - final DeviceId dstDevice = path.dst().deviceId(); - final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice); - final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice); - final Link link = link(src.toString(), 1, dst.toString(), 1); - - final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link)); - if (weightValue < 0) { - return new HashSet<>(); - } - } - return paths; - } - } - - public static class MockLinkResourceAllocations implements LinkResourceAllocations { - @Override - public Set<ResourceAllocation> getResourceAllocation(Link link) { - return ImmutableSet.of( - new LambdaResourceAllocation(LambdaResource.valueOf(77)), - new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); - } - - @Override - public IntentId intentId() { - return null; - } - - @Override - public Collection<Link> links() { - return null; - } - - @Override - public Set<ResourceRequest> resources() { - return null; - } - - @Override - public ResourceType type() { - return null; - } - } - - public static class MockedAllocationFailure extends RuntimeException { } - - public static class MockResourceService implements LinkResourceService { - - double availableBandwidth = -1.0; - int availableLambda = -1; - - /** - * Allocates a resource service that will allow bandwidth allocations - * up to a limit. - * - * @param bandwidth available bandwidth limit - * @return resource manager for bandwidth requests - */ - public static MockResourceService makeBandwidthResourceService(double bandwidth) { - final MockResourceService result = new MockResourceService(); - result.availableBandwidth = bandwidth; - return result; - } - - /** - * Allocates a resource service that will allow lambda allocations. - * - * @param lambda Lambda to return for allocation requests. Currently unused - * @return resource manager for lambda requests - */ - public static MockResourceService makeLambdaResourceService(int lambda) { - final MockResourceService result = new MockResourceService(); - result.availableLambda = lambda; - return result; - } - - public void setAvailableBandwidth(double availableBandwidth) { - this.availableBandwidth = availableBandwidth; - } - - public void setAvailableLambda(int availableLambda) { - this.availableLambda = availableLambda; - } - - - @Override - public LinkResourceAllocations requestResources(LinkResourceRequest req) { - int lambda = -1; - double bandwidth = -1.0; - - for (ResourceRequest resourceRequest : req.resources()) { - if (resourceRequest.type() == ResourceType.BANDWIDTH) { - final BandwidthResourceRequest brr = (BandwidthResourceRequest) resourceRequest; - bandwidth = brr.bandwidth().toDouble(); - } else if (resourceRequest.type() == ResourceType.LAMBDA) { - lambda = 1; - } - } - - if (availableBandwidth < bandwidth) { - throw new MockedAllocationFailure(); - } - if (lambda > 0 && availableLambda == 0) { - throw new MockedAllocationFailure(); - } - - return new IntentTestsMocks.MockLinkResourceAllocations(); - } - - @Override - public void releaseResources(LinkResourceAllocations allocations) { - // Mock - } - - @Override - public LinkResourceAllocations updateResources(LinkResourceRequest req, - LinkResourceAllocations oldAllocations) { - return null; - } - - @Override - public Iterable<LinkResourceAllocations> getAllocations() { - return ImmutableSet.of( - new IntentTestsMocks.MockLinkResourceAllocations()); - } - - @Override - public Iterable<LinkResourceAllocations> getAllocations(Link link) { - return ImmutableSet.of( - new IntentTestsMocks.MockLinkResourceAllocations()); - } - - @Override - public LinkResourceAllocations getAllocations(IntentId intentId) { - return new IntentTestsMocks.MockLinkResourceAllocations(); - } - - @Override - public Iterable<ResourceRequest> getAvailableResources(Link link) { - final List<ResourceRequest> result = new LinkedList<>(); - if (availableBandwidth > 0.0) { - result.add(new BandwidthResourceRequest( - new BandwidthResource(Bandwidth.bps(availableBandwidth)))); - } - if (availableLambda > 0) { - result.add(new LambdaResourceRequest()); - } - return result; - } - - @Override - public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) { - return null; - } - - @Override - public void addListener(LinkResourceListener listener) { - - } - - @Override - public void removeListener(LinkResourceListener listener) { - - } - } - - private static final IntentTestsMocks.MockSelector SELECTOR = - new IntentTestsMocks.MockSelector(); - private static final IntentTestsMocks.MockTreatment TREATMENT = - new IntentTestsMocks.MockTreatment(); - - public static class MockFlowRule implements FlowRule { - static int nextId = 0; - - int priority; - int tableId; - long timestamp; - int id; - FlowRuleExtPayLoad payLoad; - - public MockFlowRule(int priority) { - this.priority = priority; - this.tableId = 0; - this.timestamp = System.currentTimeMillis(); - this.id = nextId++; - this.payLoad = null; - } - - public MockFlowRule(int priority, FlowRuleExtPayLoad payLoad) { - this.priority = priority; - this.timestamp = System.currentTimeMillis(); - this.id = nextId++; - this.payLoad = payLoad; - } - - @Override - public FlowId id() { - return FlowId.valueOf(id); - } - - @Override - public short appId() { - return 0; - } - - @Override - public GroupId groupId() { - return new DefaultGroupId(0); - } - - @Override - public int priority() { - return priority; - } - - @Override - public DeviceId deviceId() { - return did("1"); - } - - @Override - public TrafficSelector selector() { - return SELECTOR; - } - - @Override - public TrafficTreatment treatment() { - return TREATMENT; - } - - @Override - public int timeout() { - return 0; - } - - @Override - public boolean isPermanent() { - return false; - } - - @Override - public int hashCode() { - return priority; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - final MockFlowRule other = (MockFlowRule) obj; - return Objects.equals(this.timestamp, other.timestamp) && - this.id == other.id; - } - - @Override - public boolean exactMatch(FlowRule rule) { - return this.equals(rule); - } - - @Override - public int tableId() { - return tableId; - } - - @Override - public FlowRuleExtPayLoad payLoad() { - return payLoad; - } - } - - public static class MockIntent extends Intent { - private static AtomicLong counter = new AtomicLong(0); - - private final Long number; - - public MockIntent(Long number) { - super(NetTestTools.APP_ID, null, Collections.emptyList(), - Intent.DEFAULT_INTENT_PRIORITY); - this.number = number; - } - - public MockIntent(Long number, Collection<NetworkResource> resources) { - super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY); - this.number = number; - } - - public Long number() { - return number; - } - - public static Long nextId() { - return counter.getAndIncrement(); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("id", id()) - .add("appId", appId()) - .toString(); - } - } - - public static class MockTimestamp implements Timestamp { - final int value; - - public MockTimestamp(int value) { - this.value = value; - } - - @Override - public int compareTo(Timestamp o) { - if (!(o instanceof MockTimestamp)) { - return -1; - } - MockTimestamp that = (MockTimestamp) o; - return this.value - that.value; - } - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/KeyTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/KeyTest.java deleted file mode 100644 index dfc73442..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/KeyTest.java +++ /dev/null @@ -1,121 +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.net.intent; - -import org.junit.Test; -import org.onosproject.net.NetTestTools; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -/** - * Unit tests for the intent key class. - */ -public class KeyTest { - - private static final String KEY_1 = "key1"; - private static final String KEY_2 = "key2"; - private static final String KEY_3 = "key3"; - - private static final long LONG_KEY_1 = 0x1111; - private static final long LONG_KEY_2 = 0x2222; - private static final long LONG_KEY_3 = 0x3333; - - /** - * Tests that keys are properly immutable. - */ - @Test - public void keysAreImmutable() { - assertThatClassIsImmutableBaseClass(Key.class); - - // Will be a long based key, class is private so cannot be - // accessed directly - Key longKey = Key.of(0xabcdefL, NetTestTools.APP_ID); - assertThatClassIsImmutable(longKey.getClass()); - - // Will be a String based key, class is private so cannot be - // accessed directly. - Key stringKey = Key.of("some key", NetTestTools.APP_ID); - assertThatClassIsImmutable(stringKey.getClass()); - } - - /** - * Tests string key construction. - */ - @Test - public void stringKeyConstruction() { - Key stringKey1 = Key.of(KEY_3, NetTestTools.APP_ID); - assertThat(stringKey1, notNullValue()); - Key stringKey2 = Key.of(KEY_3, NetTestTools.APP_ID); - assertThat(stringKey2, notNullValue()); - - assertThat(stringKey1.hash(), is(stringKey2.hash())); - } - - /** - * Tests long key construction. - */ - @Test - public void longKeyConstruction() { - Key longKey1 = Key.of(LONG_KEY_3, NetTestTools.APP_ID); - assertThat(longKey1, notNullValue()); - Key longKey2 = Key.of(LONG_KEY_3, NetTestTools.APP_ID); - assertThat(longKey2, notNullValue()); - - assertThat(longKey1.hash(), is(longKey2.hash())); - } - - /** - * Tests equals for string based keys. - */ - @Test - public void stringKey() { - Key stringKey1 = Key.of(KEY_1, NetTestTools.APP_ID); - Key copyOfStringKey1 = Key.of(KEY_1, NetTestTools.APP_ID); - Key stringKey2 = Key.of(KEY_2, NetTestTools.APP_ID); - Key copyOfStringKey2 = Key.of(KEY_2, NetTestTools.APP_ID); - Key stringKey3 = Key.of(KEY_3, NetTestTools.APP_ID); - - new EqualsTester() - .addEqualityGroup(stringKey1, copyOfStringKey1) - .addEqualityGroup(stringKey2, copyOfStringKey2) - .addEqualityGroup(stringKey3) - .testEquals(); - } - - /** - * Tests equals for long based keys. - */ - @Test - public void longKey() { - Key longKey1 = Key.of(LONG_KEY_1, NetTestTools.APP_ID); - Key copyOfLongKey1 = Key.of(LONG_KEY_1, NetTestTools.APP_ID); - Key longKey2 = Key.of(LONG_KEY_2, NetTestTools.APP_ID); - Key copyOfLongKey2 = Key.of(LONG_KEY_2, NetTestTools.APP_ID); - Key longKey3 = Key.of(LONG_KEY_3, NetTestTools.APP_ID); - - new EqualsTester() - .addEqualityGroup(longKey1, copyOfLongKey1) - .addEqualityGroup(longKey2, copyOfLongKey2) - .addEqualityGroup(longKey3) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java deleted file mode 100644 index dd371c15..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java +++ /dev/null @@ -1,209 +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.net.intent; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.junit.Test; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; -import org.onosproject.net.NetTestTools; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.intent.constraint.LambdaConstraint; - -import com.google.common.collect.ImmutableSet; -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.APP_ID; -import static org.onosproject.net.NetTestTools.link; - -/** - * Unit tests for the LinkCollectionIntent class. - */ -public class LinkCollectionIntentTest extends IntentTest { - - final ConnectPoint ingress = NetTestTools.connectPoint("ingress", 2); - final ConnectPoint egress = NetTestTools.connectPoint("egress", 3); - final TrafficSelector selector = new IntentTestsMocks.MockSelector(); - final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); - - /** - * Checks that the LinkCollectionIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(LinkCollectionIntent.class); - } - - /** - * Tests equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - - final HashSet<Link> links1 = new HashSet<>(); - links1.add(link("src", 1, "dst", 2)); - final LinkCollectionIntent collectionIntent1 = - LinkCollectionIntent.builder() - .appId(APP_ID) - .selector(selector) - .treatment(treatment) - .links(links1) - .ingressPoints(ImmutableSet.of(ingress)) - .egressPoints(ImmutableSet.of(egress)) - .build(); - - final HashSet<Link> links2 = new HashSet<>(); - links2.add(link("src", 1, "dst", 3)); - final LinkCollectionIntent collectionIntent2 = - LinkCollectionIntent.builder() - .appId(APP_ID) - .selector(selector) - .treatment(treatment) - .links(links2) - .ingressPoints(ImmutableSet.of(ingress)) - .egressPoints(ImmutableSet.of(egress)) - .build(); - - new EqualsTester() - .addEqualityGroup(collectionIntent1) - .addEqualityGroup(collectionIntent2) - .testEquals(); - } - - /** - * Tests constructor without constraints. - */ - @Test - public void testConstructor() { - final HashSet<Link> links1 = new HashSet<>(); - links1.add(link("src", 1, "dst", 2)); - final LinkCollectionIntent collectionIntent = - LinkCollectionIntent.builder() - .appId(APP_ID) - .selector(selector) - .treatment(treatment) - .links(links1) - .ingressPoints(ImmutableSet.of(ingress)) - .egressPoints(ImmutableSet.of(egress)) - .build(); - - final Set<Link> createdLinks = collectionIntent.links(); - assertThat(createdLinks, hasSize(1)); - assertThat(collectionIntent.isInstallable(), is(false)); - assertThat(collectionIntent.treatment(), is(treatment)); - assertThat(collectionIntent.selector(), is(selector)); - assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress))); - assertThat(collectionIntent.egressPoints(), is(ImmutableSet.of(egress))); - assertThat(collectionIntent.resources(), hasSize(1)); - final List<Constraint> createdConstraints = collectionIntent.constraints(); - assertThat(createdConstraints, hasSize(0)); - } - - /** - * Tests constructor with constraints. - */ - @Test - public void testConstructorWithConstraints() { - final HashSet<Link> links1 = new HashSet<>(); - final LinkedList<Constraint> constraints = new LinkedList<>(); - - links1.add(link("src", 1, "dst", 2)); - constraints.add(new LambdaConstraint(new IndexedLambda(23))); - final LinkCollectionIntent collectionIntent = - LinkCollectionIntent.builder() - .appId(APP_ID) - .selector(selector) - .treatment(treatment) - .links(links1) - .ingressPoints(ImmutableSet.of(ingress)) - .egressPoints(ImmutableSet.of(egress)) - .constraints(constraints) - .priority(8888) - .build(); - - final Set<Link> createdLinks = collectionIntent.links(); - assertThat(createdLinks, hasSize(1)); - assertThat(collectionIntent.isInstallable(), is(false)); - assertThat(collectionIntent.treatment(), is(treatment)); - assertThat(collectionIntent.selector(), is(selector)); - assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress))); - assertThat(collectionIntent.egressPoints(), is(ImmutableSet.of(egress))); - - final List<Constraint> createdConstraints = collectionIntent.constraints(); - assertThat(createdConstraints, hasSize(1)); - assertThat(createdConstraints.get(0).toString(), startsWith("LambdaConstraint")); - } - - /** - * Tests constructor with constraints. - */ - @Test - public void testSerializerConstructor() { - - final LinkCollectionIntent collectionIntent = - new LinkCollectionIntent(); - - final Set<Link> createdLinks = collectionIntent.links(); - assertThat(createdLinks, nullValue()); - assertThat(collectionIntent.isInstallable(), is(false)); - assertThat(collectionIntent.treatment(), nullValue()); - assertThat(collectionIntent.selector(), nullValue()); - assertThat(collectionIntent.ingressPoints(), nullValue()); - assertThat(collectionIntent.egressPoints(), nullValue()); - - final List<Constraint> createdConstraints = collectionIntent.constraints(); - assertThat(createdConstraints, hasSize(0)); - } - - @Override - protected Intent createOne() { - HashSet<Link> links1 = new HashSet<>(); - links1.add(link("src", 1, "dst", 2)); - return LinkCollectionIntent.builder() - .appId(APP_ID) - .selector(selector) - .treatment(treatment) - .links(links1) - .ingressPoints(ImmutableSet.of(ingress)) - .egressPoints(ImmutableSet.of(egress)) - .build(); - } - - @Override - protected Intent createAnother() { - HashSet<Link> links2 = new HashSet<>(); - links2.add(link("src", 1, "dst", 3)); - return LinkCollectionIntent.builder() - .appId(APP_ID) - .selector(selector) - .treatment(treatment) - .links(links2) - .ingressPoints(ImmutableSet.of(ingress)) - .egressPoints(ImmutableSet.of(egress)) - .build(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java deleted file mode 100644 index 5e84cd8c..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -import org.onosproject.core.IdGenerator; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * Mock id generator for testing. - */ -public class MockIdGenerator implements IdGenerator { - private AtomicLong nextId = new AtomicLong(0); - - @Override - public long getNewId() { - return nextId.getAndIncrement(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java deleted file mode 100644 index 7fbdf232..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java +++ /dev/null @@ -1,116 +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.net.intent; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.MplsLabel; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.APP_ID; -import static org.onosproject.net.NetTestTools.connectPoint; - -/** - * Unit tests for the MplsIntent class. - */ - -public class MplsIntentTest extends AbstractIntentTest { - static final int PRIORITY = 22; - - MplsIntent intent1; - MplsIntent intent2; - - Optional<MplsLabel> label1; - Optional<MplsLabel> label2; - - TrafficSelector selector; - TrafficTreatment treatment; - - @Before - public void mplsIntentTestSetUp() throws Exception { - - label1 = Optional.of(MplsLabel.mplsLabel(1)); - label2 = Optional.of(MplsLabel.mplsLabel(2)); - - selector = new IntentTestsMocks.MockSelector(); - treatment = new IntentTestsMocks.MockTreatment(); - - intent1 = MplsIntent.builder() - .appId(APP_ID) - .ingressLabel(label1) - .egressLabel(label2) - .ingressPoint(connectPoint("in", 1)) - .egressPoint(connectPoint("out", 1)) - .selector(selector) - .treatment(treatment) - .priority(PRIORITY) - .build(); - - intent2 = MplsIntent.builder() - .appId(APP_ID) - .ingressLabel(label1) - .egressLabel(label2) - .ingressPoint(connectPoint("in", 2)) - .egressPoint(connectPoint("out", 2)) - .selector(selector) - .treatment(treatment) - .priority(PRIORITY) - .build(); - } - - /** - * Checks that the MplsIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(MplsIntent.class); - } - - /** - * Checks the operation of equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup(intent1) - .addEqualityGroup(intent2) - .testEquals(); - } - - /** - * Checks that the MplsIntent objects are created correctly. - */ - @Test - public void testContents() { - assertThat(intent1.appId(), equalTo(APP_ID)); - assertThat(intent1.ingressLabel(), equalTo(label1)); - assertThat(intent1.egressLabel(), equalTo(label2)); - assertThat(intent1.ingressPoint(), equalTo(connectPoint("in", 1))); - assertThat(intent1.egressPoint(), equalTo(connectPoint("out", 1))); - assertThat(intent1.selector(), equalTo(intent2.selector())); - assertThat(intent1.treatment(), equalTo(intent2.treatment())); - assertThat(intent1.priority(), is(PRIORITY)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java deleted file mode 100644 index 64528cb9..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java +++ /dev/null @@ -1,113 +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.net.intent; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.MplsLabel; -import org.onosproject.net.Path; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.APP_ID; -import static org.onosproject.net.NetTestTools.createPath; - -/** - * Unit tests for the MplsPathIntent class. - */ -public class MplsPathIntentTest extends AbstractIntentTest { - - static final int PRIORITY = 777; - - MplsPathIntent intent1; - MplsPathIntent intent2; - Path defaultPath; - Optional<MplsLabel> label1; - Optional<MplsLabel> label2; - TrafficSelector selector; - TrafficTreatment treatment; - static final Key KEY1 = Key.of(5L, APP_ID); - - @Before - public void mplsPathIntentTestSetUp() { - defaultPath = createPath("a", "b", "c"); - selector = new IntentTestsMocks.MockSelector(); - treatment = new IntentTestsMocks.MockTreatment(); - - label1 = Optional.of(MplsLabel.mplsLabel(1)); - label2 = Optional.of(MplsLabel.mplsLabel(2)); - intent1 = MplsPathIntent.builder() - .appId(APP_ID) - .key(KEY1) - .ingressLabel(label1) - .egressLabel(label2) - .path(defaultPath) - .priority(PRIORITY) - .build(); - - intent2 = MplsPathIntent.builder() - .appId(APP_ID) - .ingressLabel(label1) - .egressLabel(label2) - .path(defaultPath) - .priority(PRIORITY) - .build(); - } - - - /** - * Checks that the MplsPathIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(MplsPathIntent.class); - } - - /** - * Checks the operation of equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup(intent1) - .addEqualityGroup(intent2) - .testEquals(); - } - - /** - * Checks that the MPLS path intent objects are created correctly. - */ - @Test - public void testContents() { - assertThat(intent1.appId(), equalTo(APP_ID)); - assertThat(intent1.ingressLabel(), equalTo(label1)); - assertThat(intent1.egressLabel(), equalTo(label2)); - assertThat(intent1.selector(), equalTo(intent2.selector())); - assertThat(intent1.treatment(), equalTo(intent2.treatment())); - assertThat(intent1.priority(), is(PRIORITY)); - assertThat(intent1.path(), is(defaultPath)); - assertThat(intent1.key(), equalTo(KEY1)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java deleted file mode 100644 index 00be3101..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java +++ /dev/null @@ -1,66 +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.net.intent; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -/** - * Suite of tests of the multi-to-single point intent descriptor. - */ -public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { - - /** - * Checks that the MultiPointToSinglePointIntent class is immutable. - */ - @Test - public void checkImmutability() { - assertThatClassIsImmutable(MultiPointToSinglePointIntent.class); - } - - @Test - public void basics() { - MultiPointToSinglePointIntent intent = createOne(); - assertEquals("incorrect id", APPID, intent.appId()); - assertEquals("incorrect match", MATCH, intent.selector()); - assertEquals("incorrect ingress", PS1, intent.ingressPoints()); - assertEquals("incorrect egress", P2, intent.egressPoint()); - } - - @Override - protected MultiPointToSinglePointIntent createOne() { - return MultiPointToSinglePointIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .ingressPoints(PS1) - .egressPoint(P2) - .build(); - } - - @Override - protected MultiPointToSinglePointIntent createAnother() { - return MultiPointToSinglePointIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .ingressPoints(PS2) - .egressPoint(P1) - .build(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/OpticalConnectivityIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/OpticalConnectivityIntentTest.java deleted file mode 100644 index 7df220c3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/OpticalConnectivityIntentTest.java +++ /dev/null @@ -1,35 +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.net.intent; - -import org.junit.Test; - -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -/** - * Unit tests for the OpticalConnectivityIntent class. - */ -public class OpticalConnectivityIntentTest { - - /** - * Checks that the HostToHostIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(OpticalConnectivityIntent.class); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java deleted file mode 100644 index 36e018a9..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java +++ /dev/null @@ -1,97 +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.net.intent; - -import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.OchSignalType; -import org.onosproject.net.Path; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.APP_ID; -import static org.onosproject.net.NetTestTools.connectPoint; -import static org.onosproject.net.NetTestTools.createLambda; -import static org.onosproject.net.NetTestTools.createPath; - -public class OpticalPathIntentTest extends AbstractIntentTest { - - static final int PRIORITY = 777; - - OpticalPathIntent intent1; - OpticalPathIntent intent2; - Path defaultPath; - - @Before - public void opticalPathIntentTestSetUp() { - defaultPath = createPath("a", "b", "c"); - intent1 = OpticalPathIntent.builder() - .appId(APP_ID) - .src(connectPoint("one", 1)) - .dst(connectPoint("two", 2)) - .path(defaultPath) - .lambda(createLambda()) - .signalType(OchSignalType.FIXED_GRID) - .priority(PRIORITY) - .build(); - - intent2 = OpticalPathIntent.builder() - .appId(APP_ID) - .src(connectPoint("two", 1)) - .dst(connectPoint("one", 2)) - .path(defaultPath) - .lambda(createLambda()) - .signalType(OchSignalType.FIXED_GRID) - .priority(PRIORITY) - .build(); - } - - /** - * Checks that the OpticalPathIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(OpticalPathIntent.class); - } - - /** - * Checks the operation of equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup(intent1) - .addEqualityGroup(intent2) - .testEquals(); - } - - /** - * Checks that the optical path intent objects are created correctly. - */ - @Test - public void testContents() { - assertThat(intent1.appId(), equalTo(APP_ID)); - assertThat(intent1.src(), Matchers.equalTo(connectPoint("one", 1))); - assertThat(intent1.dst(), Matchers.equalTo(connectPoint("two", 2))); - assertThat(intent1.priority(), is(PRIORITY)); - assertThat(intent1.path(), is(defaultPath)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PartitionServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PartitionServiceAdapter.java deleted file mode 100644 index 2a38cbb3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PartitionServiceAdapter.java +++ /dev/null @@ -1,43 +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.net.intent; - -import org.onosproject.cluster.NodeId; - -/** - * Testing adapter for the partition service. - */ -public class PartitionServiceAdapter implements PartitionService { - @Override - public boolean isMine(Key intentKey) { - return true; - } - - @Override - public NodeId getLeader(Key intentKey) { - return null; - } - - @Override - public void addListener(PartitionEventListener listener) { - - } - - @Override - public void removeListener(PartitionEventListener listener) { - - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java deleted file mode 100644 index 9e675347..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java +++ /dev/null @@ -1,117 +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.net.intent; - -import java.util.Arrays; -import java.util.Collections; - -import org.junit.Test; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.NetTestTools; -import org.onosproject.net.Path; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; - -import static org.junit.Assert.assertEquals; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; -import static org.onosproject.net.PortNumber.portNumber; - -public class PathIntentTest extends ConnectivityIntentTest { - // 111:11 --> 222:22 - private static final Path PATH1 = NetTestTools.createPath("111", "222"); - - // 111:11 --> 333:33 - private static final Path PATH2 = NetTestTools.createPath("222", "333"); - - private final ProviderId provider1 = new ProviderId("of", "1"); - private final DeviceId device1 = deviceId("1"); - private final DeviceId device2 = deviceId("2"); - private final PortNumber port1 = portNumber(1); - private final PortNumber port2 = portNumber(2); - private final PortNumber port3 = portNumber(3); - private final PortNumber port4 = portNumber(4); - private final ConnectPoint cp1 = new ConnectPoint(device1, port1); - private final ConnectPoint cp2 = new ConnectPoint(device1, port2); - private final ConnectPoint cp3 = new ConnectPoint(device2, port3); - private final ConnectPoint cp4 = new ConnectPoint(device2, port4); - private final DefaultLink link1 = new DefaultLink(provider1, cp1, cp2, DIRECT); - private final DefaultLink link2 = new DefaultLink(provider1, cp1, cp2, DIRECT); - private final double cost = 1; - - @Test - public void basics() { - PathIntent intent = createOne(); - assertEquals("incorrect id", APPID, intent.appId()); - assertEquals("incorrect match", MATCH, intent.selector()); - assertEquals("incorrect action", NOP, intent.treatment()); - assertEquals("incorrect path", PATH1, intent.path()); - assertEquals("incorrect key", KEY, intent.key()); - } - - @Override - protected PathIntent createOne() { - return PathIntent.builder() - .appId(APPID) - .key(KEY) - .selector(MATCH) - .treatment(NOP) - .path(PATH1) - .build(); - } - - @Override - protected PathIntent createAnother() { - return PathIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .path(PATH2) - .build(); - } - - /** - * Tests the constructor raises IllegalArgumentException when the same device is specified in - * source and destination of a link. - */ - @Test(expected = IllegalArgumentException.class) - public void testRaiseExceptionWhenSameDevices() { - PathIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .path(new DefaultPath(provider1, Collections.singletonList(link1), cost)) - .build(); - } - - /** - * Tests the constructor raises IllegalArgumentException when the different elements are specified - * in source element of the first link and destination element of the second link. - */ - @Test(expected = IllegalArgumentException.class) - public void testRaiseExceptionWhenDifferentDevice() { - PathIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .path(new DefaultPath(provider1, Arrays.asList(link1, link2), cost)) - .build(); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PointToPointIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PointToPointIntentTest.java deleted file mode 100644 index 46772f9f..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PointToPointIntentTest.java +++ /dev/null @@ -1,66 +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.net.intent; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; - -/** - * Suite of tests of the point-to-point intent descriptor. - */ -public class PointToPointIntentTest extends ConnectivityIntentTest { - - /** - * Checks that the MultiPointToSinglePointIntent class is immutable. - */ - @Test - public void checkImmutability() { - assertThatClassIsImmutableBaseClass(PointToPointIntent.class); - } - - @Test - public void basics() { - PointToPointIntent intent = createOne(); - assertEquals("incorrect id", APPID, intent.appId()); - assertEquals("incorrect match", MATCH, intent.selector()); - assertEquals("incorrect ingress", P1, intent.ingressPoint()); - assertEquals("incorrect egress", P2, intent.egressPoint()); - } - - @Override - protected PointToPointIntent createOne() { - return PointToPointIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .ingressPoint(P1) - .egressPoint(P2) - .build(); - } - - @Override - protected PointToPointIntent createAnother() { - return PointToPointIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .ingressPoint(P2) - .egressPoint(P1) - .build(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java deleted file mode 100644 index 18c6d7bc..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java +++ /dev/null @@ -1,66 +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.net.intent; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -/** - * Suite of tests of the single-to-multi point intent descriptor. - */ -public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { - - /** - * Checks that the SinglePointToMultiPointIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SinglePointToMultiPointIntent.class); - } - - @Test - public void basics() { - SinglePointToMultiPointIntent intent = createOne(); - assertEquals("incorrect id", APPID, intent.appId()); - assertEquals("incorrect match", MATCH, intent.selector()); - assertEquals("incorrect ingress", P1, intent.ingressPoint()); - assertEquals("incorrect egress", PS2, intent.egressPoints()); - } - - @Override - protected SinglePointToMultiPointIntent createOne() { - return SinglePointToMultiPointIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .ingressPoint(P1) - .egressPoints(PS2) - .build(); - } - - @Override - protected SinglePointToMultiPointIntent createAnother() { - return SinglePointToMultiPointIntent.builder() - .appId(APPID) - .selector(MATCH) - .treatment(NOP) - .ingressPoint(P2) - .egressPoints(PS1) - .build(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java deleted file mode 100644 index d949ee16..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java +++ /dev/null @@ -1,53 +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.net.intent; - -import org.onosproject.TestApplicationId; - -import java.util.Collections; - -/** - * An installable intent used in the unit test. - */ -public class TestInstallableIntent extends Intent { - - private final int value; - - /** - * Constructs an instance with the specified intent ID. - * - * @param value intent ID - */ - public TestInstallableIntent(int value) { // FIXME - super(new TestApplicationId("foo"), null, Collections.emptyList(), - Intent.DEFAULT_INTENT_PRIORITY); - this.value = value; - } - - /** - * Constructor for serializer. - */ - protected TestInstallableIntent() { - super(); - value = -1; - } - - @Override - public boolean isInstallable() { - return true; - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java deleted file mode 100644 index 857fc8b5..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java +++ /dev/null @@ -1,47 +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.net.intent; - -import org.onosproject.TestApplicationId; - -import java.util.Collections; - -/** - * An intent used in the unit test. - */ -public class TestIntent extends Intent { - - private final int value; - - /** - * Constructs an instance with the specified intent ID. - * - * @param value intent ID - */ - public TestIntent(int value) { // FIXME - super(new TestApplicationId("foo"), null, Collections.emptyList(), - Intent.DEFAULT_INTENT_PRIORITY); - this.value = value; - } - - /** - * Constructor for serializer. - */ - protected TestIntent() { - super(); - value = -1; - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestSubclassInstallableIntent.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestSubclassInstallableIntent.java deleted file mode 100644 index 82c14843..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestSubclassInstallableIntent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -/** - * An intent used in the unit test. - */ -public class TestSubclassInstallableIntent extends TestInstallableIntent { - /** - * Constructs an instance with the specified intent ID. - * - * @param id intent ID - */ - public TestSubclassInstallableIntent(int id) { //FIXME - super(id); - } - - /** - * Constructor for serializer. - */ - protected TestSubclassInstallableIntent() { - super(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestSubclassIntent.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestSubclassIntent.java deleted file mode 100644 index 44c81189..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestSubclassIntent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -/** - * An intent used in the unit test. - */ -public class TestSubclassIntent extends TestIntent { - /** - * Constructs an instance with the specified intent ID. - * - * @param id intent ID - */ - public TestSubclassIntent(int id) { //FIXME - super(id); - } - - /** - * Constructor for serializer. - */ - protected TestSubclassIntent() { - super(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestTools.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestTools.java deleted file mode 100644 index 80ae180d..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestTools.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -import static org.junit.Assert.fail; - -/** - * Set of test tools. - */ -public final class TestTools { - - // Disallow construction - private TestTools() { - } - - /** - * Utility method to pause the current thread for the specified number of - * milliseconds. - * - * @param ms number of milliseconds to pause - */ - public static void delay(int ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException e) { - fail("unexpected interrupt"); - } - } - - /** - * Periodically runs the given runnable, which should contain a series of - * test assertions until all the assertions succeed, in which case it will - * return, or until the the time expires, in which case it will throw the - * first failed assertion error. - * - * @param start start time, in millis since start of epoch from which the - * duration will be measured - * @param delay initial delay (in milliseconds) before the first assertion - * attempt - * @param step delay (in milliseconds) between successive assertion - * attempts - * @param duration number of milliseconds beyond the given start time, - * after which the failed assertions will be propagated and allowed - * to fail the test - * @param assertions runnable housing the test assertions - */ - public static void assertAfter(long start, int delay, int step, - int duration, Runnable assertions) { - delay(delay); - while (true) { - try { - assertions.run(); - break; - } catch (AssertionError e) { - if (System.currentTimeMillis() - start > duration) { - throw e; - } - } - delay(step); - } - } - - /** - * Periodically runs the given runnable, which should contain a series of - * test assertions until all the assertions succeed, in which case it will - * return, or until the the time expires, in which case it will throw the - * first failed assertion error. - * <p> - * The start of the period is the current time. - * - * @param delay initial delay (in milliseconds) before the first assertion - * attempt - * @param step delay (in milliseconds) between successive assertion - * attempts - * @param duration number of milliseconds beyond the current time time, - * after which the failed assertions will be propagated and allowed - * to fail the test - * @param assertions runnable housing the test assertions - */ - public static void assertAfter(int delay, int step, int duration, - Runnable assertions) { - assertAfter(System.currentTimeMillis(), delay, step, duration, - assertions); - } - - /** - * Periodically runs the given runnable, which should contain a series of - * test assertions until all the assertions succeed, in which case it will - * return, or until the the time expires, in which case it will throw the - * first failed assertion error. - * <p> - * The start of the period is the current time and the first assertion - * attempt is delayed by the value of {@code step} parameter. - * - * @param step delay (in milliseconds) between successive assertion - * attempts - * @param duration number of milliseconds beyond the current time time, - * after which the failed assertions will be propagated and allowed - * to fail the test - * @param assertions runnable housing the test assertions - */ - public static void assertAfter(int step, int duration, - Runnable assertions) { - assertAfter(step, step, duration, assertions); - } - - /** - * Periodically runs the given runnable, which should contain a series of - * test assertions until all the assertions succeed, in which case it will - * return, or until the the time expires, in which case it will throw the - * first failed assertion error. - * <p> - * The start of the period is the current time and each successive - * assertion attempt is delayed by at least 10 milliseconds unless the - * {@code duration} is less than that, in which case the one and only - * assertion is made after that delay. - * - * @param duration number of milliseconds beyond the current time, - * after which the failed assertions will be propagated and allowed - * to fail the test - * @param assertions runnable housing the test assertions - */ - public static void assertAfter(int duration, Runnable assertions) { - int step = Math.min(duration, Math.max(10, duration / 10)); - assertAfter(step, duration, assertions); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestableIntentService.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestableIntentService.java deleted file mode 100644 index 792c0ff8..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TestableIntentService.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2014 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.net.intent; - -import java.util.List; - -/** - * Abstraction of an extensible intent service enabled for unit tests. - */ -public interface TestableIntentService extends IntentService, IntentExtensionService { - - List<IntentException> getExceptions(); - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java deleted file mode 100644 index 0986216a..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java +++ /dev/null @@ -1,100 +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.net.intent; - -import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.APP_ID; -import static org.onosproject.net.NetTestTools.connectPoint; -/** - * Unit tests for the TwoWayP2PIntent class. - */ -public class TwoWayP2PIntentTest extends AbstractIntentTest { - - TrafficSelector selector; - TrafficTreatment treatment; - - TwoWayP2PIntent intent1; - TwoWayP2PIntent intent2; - - static final int PRIORITY = 12; - - @Before - public void twoWatP2PIntentTestSetUp() { - selector = new IntentTestsMocks.MockSelector(); - treatment = new IntentTestsMocks.MockTreatment(); - - intent1 = TwoWayP2PIntent.builder() - .appId(APP_ID) - .priority(PRIORITY) - .selector(selector) - .treatment(treatment) - .one(connectPoint("one", 1)) - .two(connectPoint("two", 2)) - .build(); - - intent2 = TwoWayP2PIntent.builder() - .appId(APP_ID) - .priority(PRIORITY) - .selector(selector) - .treatment(treatment) - .one(connectPoint("two", 2)) - .two(connectPoint("three", 2)) - .build(); - } - - /** - * Checks that the TwoWayP2PIntent class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(TwoWayP2PIntent.class); - } - - /** - * Checks the operation of equals(), hashCode() and toString() methods. - */ - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup(intent1) - .addEqualityGroup(intent2) - .testEquals(); - } - - /** - * Checks that the optical path ntent objects are created correctly. - */ - @Test - public void testContents() { - assertThat(intent1.appId(), equalTo(APP_ID)); - assertThat(intent1.one(), Matchers.equalTo(connectPoint("one", 1))); - assertThat(intent1.two(), Matchers.equalTo(connectPoint("two", 2))); - assertThat(intent1.priority(), is(PRIORITY)); - assertThat(intent1.selector(), is(selector)); - assertThat(intent1.treatment(), is(treatment)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java deleted file mode 100644 index b87dc12b..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2014 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.net.intent.constraint; - -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; -import static org.onosproject.net.PortNumber.portNumber; - -/** - * Test for link annotated value threshold. - */ -public class AnnotationConstraintTest { - - private static final ProviderId PID = new ProviderId("of", "foo"); - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final PortNumber PID1 = portNumber(1); - private static final PortNumber PID2 = portNumber(2); - private static final String KEY = "distance"; - private static final double VALUE = 100; - - private AnnotationConstraint sut; - private Link link; - private LinkResourceService linkResourceService; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build(); - - link = new DefaultLink(PID, cp(DID1, PID1), cp(DID2, PID2), DIRECT, annotations); - } - - /** - * Tests the specified annotated value is less than the threshold. - */ - @Test - public void testLessThanThreshold() { - double value = 120; - sut = new AnnotationConstraint(KEY, value); - - assertThat(sut.isValid(link, linkResourceService), is(true)); - assertThat(sut.cost(link, linkResourceService), is(closeTo(VALUE, 1.0e-6))); - } - - /** - * Tests the specified annotated value is more than the threshold. - */ - @Test - public void testMoreThanThreshold() { - double value = 80; - sut = new AnnotationConstraint(KEY, value); - - assertThat(sut.isValid(link, linkResourceService), is(false)); - assertThat(sut.cost(link, linkResourceService), is(lessThan(0.0))); - } - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(new AnnotationConstraint(KEY, 100), new AnnotationConstraint(KEY, 100)) - .addEqualityGroup(new AnnotationConstraint(KEY, 120)) - .addEqualityGroup(new AnnotationConstraint("latency", 100)) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java deleted file mode 100644 index d2e99400..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java +++ /dev/null @@ -1,131 +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.net.intent.constraint; - -import org.junit.Test; -import org.onlab.util.Bandwidth; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; - -/** - * Unit tests for Constraint objects. - */ -public class ConstraintObjectsTest { - - // Bandwidth Constraint - - private final Bandwidth bandwidth1 = Bandwidth.bps(100.0); - private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0); - private final Bandwidth bandwidth2 = Bandwidth.bps(200.0); - - final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1); - final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1); - final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2); - - /** - * Checks that the objects were created properly. - */ - @Test - public void testBandwidthConstraintCreation() { - assertThat(bandwidthConstraint1.bandwidth().bps(), is(equalTo(100.0))); - assertThat(bandwidthConstraintSameAs1.bandwidth().bps(), is(equalTo(100.0))); - assertThat(bandwidthConstraint2.bandwidth().bps(), is(equalTo(200.0))); - } - - /** - * Checks the correctness of the equals() method. - */ - @Test - public void testBandwidthConstraintEquals() { - new EqualsTester() - .addEqualityGroup(bandwidthConstraint1, bandwidthConstraintSameAs1) - .addEqualityGroup(bandwidthConstraint2) - .testEquals(); - } - - // Lambda Constraint - - final LambdaConstraint lambdaConstraint1 = - new LambdaConstraint(new IndexedLambda(100)); - final LambdaConstraint lambdaConstraintSameAs1 = - new LambdaConstraint(new IndexedLambda(100)); - final LambdaConstraint lambdaConstraint2 = - new LambdaConstraint(new IndexedLambda(200)); - - /** - * Checks that the objects were created properly. - */ - @Test - public void testLambdaConstraintCreation() { - assertThat(lambdaConstraint1.lambda().index(), is(equalTo(100L))); - assertThat(lambdaConstraintSameAs1.lambda().index(), is(equalTo(100L))); - assertThat(lambdaConstraint2.lambda().index(), is(equalTo(200L))); - } - - /** - * Checks the correctness of the equals() method. - */ - @Test - public void testLambdaConstraintEquals() { - new EqualsTester() - .addEqualityGroup(lambdaConstraint1, lambdaConstraintSameAs1) - .addEqualityGroup(lambdaConstraint2) - .testEquals(); - } - - // LinkType Constraint - - final LinkTypeConstraint linkTypeConstraint1 = - new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL); - final LinkTypeConstraint linkTypeConstraintSameAs1 = - new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL); - final LinkTypeConstraint linkTypeConstraint2 = - new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.DIRECT); - - /** - * Checks that the objects were created properly. - */ - @Test - public void testLinkTypeConstraintCreation() { - assertThat(linkTypeConstraint1.isInclusive(), is(true)); - assertThat(linkTypeConstraint1.types(), - contains(Link.Type.OPTICAL, Link.Type.TUNNEL)); - assertThat(linkTypeConstraintSameAs1.isInclusive(), is(true)); - assertThat(linkTypeConstraintSameAs1.types(), - contains(Link.Type.OPTICAL, Link.Type.TUNNEL)); - assertThat(linkTypeConstraint2.isInclusive(), is(true)); - assertThat(linkTypeConstraint2.types(), - contains(Link.Type.OPTICAL, Link.Type.DIRECT)); - } - - /** - * Checks the correctness of the equals() method. - */ - @Test - public void testLinkTypeConstraintEquals() { - new EqualsTester() - .addEqualityGroup(linkTypeConstraint1, linkTypeConstraintSameAs1) - .addEqualityGroup(linkTypeConstraint2) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java deleted file mode 100644 index bab17495..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2014 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.net.intent.constraint; - -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -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.resource.link.LinkResourceService; - -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.onosproject.net.AnnotationKeys.LATENCY; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; - -public class LatencyConstraintTest { - - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final DeviceId DID3 = deviceId("of:3"); - private static final PortNumber PN1 = PortNumber.portNumber(1); - private static final PortNumber PN2 = PortNumber.portNumber(2); - private static final PortNumber PN3 = PortNumber.portNumber(3); - private static final PortNumber PN4 = PortNumber.portNumber(4); - private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); - private static final String LATENCY1 = "3.0"; - private static final String LATENCY2 = "4.0"; - - private LatencyConstraint sut; - private LinkResourceService linkResourceService; - - private Path path; - private Link link1; - private Link link2; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build(); - Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build(); - - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1); - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2); - path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); - } - - /** - * Tests the path latency is less than the supplied constraint. - */ - @Test - public void testLessThanLatency() { - sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); - - assertThat(sut.validate(path, linkResourceService), is(true)); - } - - /** - * Tests the path latency is more than the supplied constraint. - */ - @Test - public void testMoreThanLatency() { - sut = new LatencyConstraint(Duration.of(3, ChronoUnit.MICROS)); - - assertThat(sut.validate(path, linkResourceService), is(false)); - } - - /** - * Tests the link latency is equal to "latency" annotated value. - */ - @Test - public void testCost() { - sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); - - assertThat(sut.cost(link1, linkResourceService), is(closeTo(Double.parseDouble(LATENCY1), 1.0e-6))); - assertThat(sut.cost(link2, linkResourceService), is(closeTo(Double.parseDouble(LATENCY2), 1.0e-6))); - } - - /** - * Tests equality of the instances. - */ - @Test - public void testEquality() { - LatencyConstraint c1 = new LatencyConstraint(Duration.of(1, ChronoUnit.SECONDS)); - LatencyConstraint c2 = new LatencyConstraint(Duration.of(1000, ChronoUnit.MILLIS)); - - LatencyConstraint c3 = new LatencyConstraint(Duration.of(2, ChronoUnit.SECONDS)); - LatencyConstraint c4 = new LatencyConstraint(Duration.of(2000, ChronoUnit.MILLIS)); - - new EqualsTester() - .addEqualityGroup(c1, c2) - .addEqualityGroup(c3, c4) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java deleted file mode 100644 index f02787f3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2014 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.net.intent.constraint; - -/** - * Test for constraint of intermediate nodes not passed. - */ -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Path; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import java.util.Arrays; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; - -public class ObstacleConstraintTest { - - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final DeviceId DID3 = deviceId("of:3"); - private static final DeviceId DID4 = deviceId("of:4"); - private static final PortNumber PN1 = PortNumber.portNumber(1); - private static final PortNumber PN2 = PortNumber.portNumber(2); - private static final PortNumber PN3 = PortNumber.portNumber(3); - private static final PortNumber PN4 = PortNumber.portNumber(4); - private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); - - private LinkResourceService linkResourceService; - - private Path path; - private DefaultLink link2; - private DefaultLink link1; - - private ObstacleConstraint sut; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); - path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); - } - - @Test - public void testEquality() { - ObstacleConstraint o1 = new ObstacleConstraint(DID1, DID2, DID3); - ObstacleConstraint o2 = new ObstacleConstraint(DID3, DID2, DID1); - ObstacleConstraint o3 = new ObstacleConstraint(DID1, DID2); - ObstacleConstraint o4 = new ObstacleConstraint(DID2, DID1); - - new EqualsTester() - .addEqualityGroup(o1, o2) - .addEqualityGroup(o3, o4) - .testEquals(); - } - - /** - * Tests the specified path avoids the specified obstacle. - */ - @Test - public void testPathNotThroughObstacles() { - sut = new ObstacleConstraint(DID4); - - assertThat(sut.validate(path, linkResourceService), is(true)); - } - - /** - * Test the specified path does not avoid the specified obstacle. - */ - @Test - public void testPathThroughObstacle() { - sut = new ObstacleConstraint(DID1); - - assertThat(sut.validate(path, linkResourceService), is(false)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java deleted file mode 100644 index f7e212a3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2014 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.net.intent.constraint; - -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Path; -import org.onosproject.net.PortNumber; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import java.util.Arrays; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; - -/** - * Test for constraint of intermediate elements. - */ -public class WaypointConstraintTest { - - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final DeviceId DID3 = deviceId("of:3"); - private static final DeviceId DID4 = deviceId("of:4"); - private static final PortNumber PN1 = PortNumber.portNumber(1); - private static final PortNumber PN2 = PortNumber.portNumber(2); - private static final PortNumber PN3 = PortNumber.portNumber(3); - private static final PortNumber PN4 = PortNumber.portNumber(4); - private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); - - private WaypointConstraint sut; - private LinkResourceService linkResourceService; - - private Path path; - private DefaultLink link2; - private DefaultLink link1; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); - path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); - } - - /** - * Tests that all of the specified waypoints are included in the specified path in order. - */ - @Test - public void testSatisfyWaypoints() { - sut = new WaypointConstraint(DID1, DID2, DID3); - - assertThat(sut.validate(path, linkResourceService), is(true)); - } - - /** - * Tests that the specified path does not includes the specified waypoint. - */ - @Test - public void testNotSatisfyWaypoint() { - sut = new WaypointConstraint(DID4); - - assertThat(sut.validate(path, linkResourceService), is(false)); - } - - @Test - public void testEquality() { - Constraint c1 = new WaypointConstraint(DID1, DID2); - Constraint c2 = new WaypointConstraint(DID1, DID2); - - Constraint c3 = new WaypointConstraint(DID2); - Constraint c4 = new WaypointConstraint(DID3); - - new EqualsTester() - .addEqualityGroup(c1, c2) - .addEqualityGroup(c3) - .addEqualityGroup(c4) - .testEquals(); - } -} |