Pavlin Radoslavov
Committed by Gerrit Code Review

Fix the SDN-IP unit tests after changing the Intent IDs to use

explicit ID assignment.

Change-Id: I50bc20188922193cfa47bf0ec324a69929744745
......@@ -36,12 +36,12 @@ import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.host.HostListener;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.host.InterfaceIpAddress;
import org.onlab.onos.net.intent.AbstractIntentTest;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentOperations;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.IntentState;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import org.onlab.onos.net.intent.AbstractIntentTest;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.sdnip.config.Interface;
import org.onlab.packet.Ethernet;
......
......@@ -30,11 +30,11 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.host.InterfaceIpAddress;
import org.onlab.onos.net.intent.AbstractIntentTest;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentOperations;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.onos.net.intent.AbstractIntentTest;
import org.onlab.onos.sdnip.bgp.BgpConstants;
import org.onlab.onos.sdnip.config.BgpPeer;
import org.onlab.onos.sdnip.config.BgpSpeaker;
......
......@@ -31,7 +31,6 @@ import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
......@@ -50,10 +49,12 @@ import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.host.HostListener;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.host.InterfaceIpAddress;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import org.onlab.onos.net.intent.AbstractIntentTest;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
import org.onlab.onos.sdnip.config.BgpPeer;
import org.onlab.onos.sdnip.config.Interface;
import org.onlab.onos.sdnip.config.SdnIpConfigService;
......@@ -232,7 +233,7 @@ public class RouterTest extends AbstractIntentTest {
/**
* This method tests adding a route entry.
*/
@Test @Ignore("needs fix from intents")
@Test
public void testProcessRouteAdd() throws TestUtilsException {
// Construct a route entry
RouteEntry routeEntry = new RouteEntry(
......@@ -260,7 +261,7 @@ public class RouterTest extends AbstractIntentTest {
// Set up test expectation
reset(intentService);
intentService.submit(intent);
intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
replay(intentService);
// Call the processRouteAdd() method in Router class
......@@ -272,8 +273,11 @@ public class RouterTest extends AbstractIntentTest {
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntry));
assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
intent);
Intent firstIntent =
intentSynchronizer.getRouteIntents().iterator().next();
IntentKey firstIntentKey = new IntentKey(firstIntent);
IntentKey intentKey = new IntentKey(intent);
assertTrue(firstIntentKey.equals(intentKey));
verify(intentService);
}
......@@ -282,7 +286,7 @@ public class RouterTest extends AbstractIntentTest {
*
* @throws TestUtilsException
*/
@Test @Ignore("needs fix from intents")
@Test
public void testRouteUpdate() throws TestUtilsException {
// Firstly add a route
testProcessRouteAdd();
......@@ -339,8 +343,8 @@ public class RouterTest extends AbstractIntentTest {
// Set up test expectation
reset(intentService);
intentService.withdraw(intent);
intentService.submit(intentNew);
intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
intentService.submit(TestIntentServiceHelper.eqExceptId(intentNew));
replay(intentService);
// Call the processRouteAdd() method in Router class
......@@ -352,15 +356,18 @@ public class RouterTest extends AbstractIntentTest {
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntryUpdate));
assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
intentNew);
Intent firstIntent =
intentSynchronizer.getRouteIntents().iterator().next();
IntentKey firstIntentKey = new IntentKey(firstIntent);
IntentKey intentNewKey = new IntentKey(intentNew);
assertTrue(firstIntentKey.equals(intentNewKey));
verify(intentService);
}
/**
* This method tests deleting a route entry.
*/
@Test @Ignore("needs fix from intents")
@Test
public void testProcessRouteDelete() throws TestUtilsException {
// Firstly add a route
testProcessRouteAdd();
......@@ -391,7 +398,7 @@ public class RouterTest extends AbstractIntentTest {
// Set up expectation
reset(intentService);
intentService.withdraw(intent);
intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
replay(intentService);
// Call route deleting method in Router class
......
......@@ -31,7 +31,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
......@@ -50,10 +49,12 @@ import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.host.InterfaceIpAddress;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import org.onlab.onos.net.intent.AbstractIntentTest;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
import org.onlab.onos.sdnip.Router.InternalHostListener;
import org.onlab.onos.sdnip.config.BgpPeer;
import org.onlab.onos.sdnip.config.Interface;
......@@ -194,7 +195,7 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
/**
* This method tests adding a route entry.
*/
@Test @Ignore("needs fix from intents")
@Test
public void testProcessRouteAdd() throws TestUtilsException {
// Construct a route entry
......@@ -213,7 +214,7 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
replay(hostService);
reset(intentService);
intentService.submit(intent);
intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
replay(intentService);
// Call the processRouteAdd() method in Router class
......@@ -234,8 +235,11 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntry));
assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
intent);
Intent firstIntent =
intentSynchronizer.getRouteIntents().iterator().next();
IntentKey firstIntentKey = new IntentKey(firstIntent);
IntentKey intentKey = new IntentKey(intent);
assertTrue(firstIntentKey.equals(intentKey));
verify(intentService);
verify(hostService);
......@@ -246,7 +250,7 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
*
* @throws TestUtilsException
*/
@Test @Ignore("needs fix from intents")
@Test
public void testRouteUpdate() throws TestUtilsException {
// Construct the existing route entry
......@@ -295,8 +299,8 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
replay(hostService);
reset(intentService);
intentService.withdraw(intent);
intentService.submit(intentNew);
intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
intentService.submit(TestIntentServiceHelper.eqExceptId(intentNew));
replay(intentService);
// Call the processRouteAdd() method in Router class
......@@ -317,8 +321,11 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
assertEquals(router.getRoutes().size(), 1);
assertTrue(router.getRoutes().contains(routeEntryUpdate));
assertEquals(intentSynchronizer.getRouteIntents().size(), 1);
assertEquals(intentSynchronizer.getRouteIntents().iterator().next(),
intentNew);
Intent firstIntent =
intentSynchronizer.getRouteIntents().iterator().next();
IntentKey firstIntentKey = new IntentKey(firstIntent);
IntentKey intentNewKey = new IntentKey(intentNew);
assertTrue(firstIntentKey.equals(intentNewKey));
verify(intentService);
verify(hostService);
}
......@@ -344,7 +351,7 @@ public class RouterTestWithAsyncArp extends AbstractIntentTest {
// Set up expectation
reset(intentService);
intentService.withdraw(intent);
intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
replay(intentService);
// Call route deleting method in Router class
......
......@@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
import org.easymock.IAnswer;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.onlab.junit.IntegrationTest;
......@@ -200,7 +199,7 @@ public class SdnIpTest extends AbstractIntentTest {
* @throws InterruptedException if interrupted while waiting on a latch
* @throws TestUtilsException if exceptions when using TestUtils
*/
@Test @Ignore("needs fix from intents")
@Test
public void testAddRoutes() throws InterruptedException, TestUtilsException {
int numRoutes = 100;
......@@ -220,7 +219,7 @@ public class SdnIpTest extends AbstractIntentTest {
MultiPointToSinglePointIntent intent = getIntentForUpdate(update,
generateMacAddress(nextHopAddress),
egressConnectPoint);
intentService.submit(intent);
intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
......@@ -262,7 +261,7 @@ public class SdnIpTest extends AbstractIntentTest {
* @throws InterruptedException if interrupted while waiting on a latch
* @throws TestUtilsException exceptions when using TestUtils
*/
@Test @Ignore("needs fix from intents")
@Test
public void testDeleteRoutes() throws InterruptedException, TestUtilsException {
int numRoutes = 100;
List<RouteUpdate> routeUpdates = generateRouteUpdates(numRoutes);
......@@ -281,7 +280,7 @@ public class SdnIpTest extends AbstractIntentTest {
MultiPointToSinglePointIntent intent = getIntentForUpdate(update,
generateMacAddress(nextHopAddress),
egressConnectPoint);
intentService.submit(intent);
intentService.submit(TestIntentServiceHelper.eqExceptId(intent));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
......@@ -289,7 +288,7 @@ public class SdnIpTest extends AbstractIntentTest {
return null;
}
}).once();
intentService.withdraw(intent);
intentService.withdraw(TestIntentServiceHelper.eqExceptId(intent));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
......
......@@ -5,10 +5,10 @@ import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.easymock.IArgumentMatcher;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentOperation;
import org.onlab.onos.net.intent.IntentOperations;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.onos.sdnip.IntentSynchronizer.IntentKey;
import static org.easymock.EasyMock.reportMatcher;
......@@ -24,6 +24,18 @@ public final class TestIntentServiceHelper {
}
/**
* Matcher method to set the expected intent to match against
* (ignoring the intent ID for the intent).
*
* @param intent the expected Intent
* @return the submitted Intent
*/
static Intent eqExceptId(Intent intent) {
reportMatcher(new IdAgnosticIntentMatcher(intent));
return intent;
}
/**
* Matcher method to set the expected intent operations to match against
* (ignoring the intent ID for each intent).
*
......@@ -35,18 +47,51 @@ public final class TestIntentServiceHelper {
return intentOperations;
}
/*
* EasyMock matcher that matches {@link Inten} but
* ignores the {@link IntentId} when matching.
* <p/>
* The normal intent equals method tests that the intent IDs are equal,
* however in these tests we can't know what the intent IDs will be in
* advance, so we can't set up expected intents with the correct IDs. Thus,
* the solution is to use an EasyMock matcher that verifies that all the
* value properties of the provided intent match the expected values, but
* ignores the intent ID when testing equality.
*/
private static final class IdAgnosticIntentMatcher implements
IArgumentMatcher {
private final Intent intent;
private String providedString;
/**
* Matcher method to set an expected point-to-point intent to match
* against (ignoring the intent ID).
* Constructor taking the expected intent to match against.
*
* @param intent the expected point-to-point intent
* @return the submitted point-to-point intent
* @param intent the expected intent
*/
private static PointToPointIntent eqExceptId(
PointToPointIntent intent) {
reportMatcher(new IdAgnosticPointToPointIntentMatcher(intent));
return intent;
public IdAgnosticIntentMatcher(Intent intent) {
this.intent = intent;
}
@Override
public void appendTo(StringBuffer strBuffer) {
strBuffer.append("IntentMatcher unable to match: "
+ providedString);
}
@Override
public boolean matches(Object object) {
if (!(object instanceof Intent)) {
return false;
}
Intent providedIntent = (Intent) object;
providedString = providedIntent.toString();
IntentKey thisIntentKey = new IntentKey(intent);
IntentKey providedIntentKey = new IntentKey(providedIntent);
return thisIntentKey.equals(providedIntentKey);
}
}
/*
......@@ -160,54 +205,4 @@ public final class TestIntentServiceHelper {
}
}
}
/*
* EasyMock matcher that matches {@link PointToPointIntent}s but
* ignores the {@link IntentId} when matching.
* <p/>
* The normal intent equals method tests that the intent IDs are equal,
* however in these tests we can't know what the intent IDs will be in
* advance, so we can't set up expected intents with the correct IDs. Thus,
* the solution is to use an EasyMock matcher that verifies that all the
* value properties of the provided intent match the expected values, but
* ignores the intent ID when testing equality.
*/
private static final class IdAgnosticPointToPointIntentMatcher implements
IArgumentMatcher {
private final PointToPointIntent intent;
private String providedIntentString;
/**
* Constructor taking the expected intent to match against.
*
* @param intent the expected intent
*/
public IdAgnosticPointToPointIntentMatcher(PointToPointIntent intent) {
this.intent = intent;
}
@Override
public void appendTo(StringBuffer strBuffer) {
strBuffer.append("PointToPointIntentMatcher unable to match: "
+ providedIntentString);
}
@Override
public boolean matches(Object object) {
if (!(object instanceof PointToPointIntent)) {
return false;
}
PointToPointIntent providedIntent = (PointToPointIntent) object;
providedIntentString = providedIntent.toString();
PointToPointIntent matchIntent =
new PointToPointIntent(providedIntent.appId(),
intent.selector(), intent.treatment(),
intent.ingressPoint(), intent.egressPoint());
return matchIntent.equals(providedIntent);
}
}
}
......