use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsMiniSummary.
@Test
public void testIntentsMiniSummary() {
final Intent intent1 = new MockIntent(1L, Collections.emptyList());
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final Intent intent2 = new MockIntent(2L, resources);
intents.add(intent1);
intents.add(intent2);
final WebTarget wt = target();
replay(mockIntentService);
final String response = wt.path("intents/minisummary").request().get(String.class);
assertThat(response, containsString("{\"All\":{"));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(2));
assertThat(result.names().get(0), containsString("All"));
JsonObject jsonIntents = (JsonObject) result.get("All");
assertThat(jsonIntents, notNullValue());
assertThat(jsonIntents.get("total").toString(), containsString("2"));
jsonIntents = (JsonObject) result.get("Mock");
assertThat(jsonIntents, notNullValue());
assertThat(jsonIntents.get("installed").toString(), containsString("2"));
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsSingle.
/**
* Tests the result of a rest api GET for a single intent.
*/
@Test
public void testIntentsSingle() {
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final Intent intent = new MockIntent(3L, resources);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0", APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0x0", APP_ID))).andReturn(null).anyTimes();
replay(mockIntentService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/" + APP_ID.name() + "/0").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesIntent(intent, true));
// Test get using numeric value
final String responseNumeric = wt.path("intents/" + APP_ID.name() + "/0x0").request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric, matchesIntent(intent, true));
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testRelatedFlowsForIntents.
/**
* Tests the result of a rest api GET for related flows for single intent.
*/
@Test
public void testRelatedFlowsForIntents() {
List<FlowEntry> flowEntries = new ArrayList<>();
flowEntries.add(flow1);
flowEntries.add(flow2);
List<List<FlowEntry>> paths = new ArrayList<>();
paths.add(flowEntries);
List<FlowRule> flowRules = new ArrayList<>();
flowRules.add(flowRule1);
flowRules.add(flowRule2);
FlowRuleIntent flowRuleIntent = new FlowRuleIntent(APP_ID, null, flowRules, new HashSet<NetworkResource>(), PathIntent.ProtectionType.PRIMARY, null);
Intent intent = new MockIntent(3L);
installableIntents.add(flowRuleIntent);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0", APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0x0", APP_ID))).andReturn(null).anyTimes();
expect(mockIntentService.getInstallableIntents(intent.key())).andReturn(installableIntents).anyTimes();
replay(mockIntentService);
expect(mockFlowService.getFlowEntries(deviceId1)).andReturn(flowEntries).anyTimes();
replay(mockFlowService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID.id())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/relatedflows/" + APP_ID.name() + "/0").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesRelatedFlowEntries(paths, APP_ID.name()));
// Test get using numeric value
final String responseNumeric = wt.path("intents/relatedflows/" + APP_ID.name() + "/0x0").request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric, matchesRelatedFlowEntries(paths, APP_ID.name()));
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentInstallables.
/**
* Tests the result of a rest api GET for intent installables.
*/
@Test
public void testIntentInstallables() {
Link link1 = DefaultLink.builder().type(Link.Type.DIRECT).providerId(ProviderId.NONE).src(connectPoint1).dst(connectPoint2).build();
Link link2 = DefaultLink.builder().type(Link.Type.DIRECT).providerId(ProviderId.NONE).src(connectPoint3).dst(connectPoint4).build();
Set<NetworkResource> resources = new HashSet<>();
resources.add(link1);
resources.add(link2);
FlowRuleIntent flowRuleIntent = new FlowRuleIntent(APP_ID, null, new ArrayList<>(), resources, PathIntent.ProtectionType.PRIMARY, null);
Intent intent = new MockIntent(MockIntent.nextId());
Long intentId = intent.id().id();
installableIntents.add(flowRuleIntent);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(intentId, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(intentId.toString(), APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(intentId, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(Long.toHexString(intentId), APP_ID))).andReturn(null).anyTimes();
expect(mockIntentService.getInstallableIntents(intent.key())).andReturn(installableIntents).anyTimes();
replay(mockIntentService);
replay(mockFlowService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID.id())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/installables/" + APP_ID.name() + "/" + intentId).request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result.get(INSTALLABLES).asArray(), hasIntent(flowRuleIntent, false));
// Test get using numeric value
final String responseNumeric = wt.path("intents/installables/" + APP_ID.name() + "/" + Long.toHexString(intentId)).request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric.get(INSTALLABLES).asArray(), hasIntent(flowRuleIntent, false));
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentCleanupTest method skipPoll.
/**
* Only submit one of two intents because one is too new.
*/
@Test
public void skipPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(CORRUPT);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, null);
store.addPending(data);
Intent intent2 = new MockIntent(2L);
Timestamp version = new SystemClockTimestamp(1L);
data = new IntentData(intent2, INSTALL_REQ, version);
store.addPending(data);
cleanup.run();
assertEquals("Expect number of submits incorrect", 1, service.submitCounter());
}
Aggregations