Search in sources :

Example 16 with MockIntent

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"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with MockIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with MockIntent

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()));
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) NetworkResource(org.onosproject.net.NetworkResource) List(java.util.List) ArrayList(java.util.ArrayList) FlowRule(org.onosproject.net.flow.FlowRule) WebTarget(javax.ws.rs.client.WebTarget) FlowEntry(org.onosproject.net.flow.FlowEntry) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 19 with MockIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 20 with MockIntent

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());
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)34 Test (org.junit.Test)32 Intent (org.onosproject.net.intent.Intent)28 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)16 PathIntent (org.onosproject.net.intent.PathIntent)16 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)12 IntentData (org.onosproject.net.intent.IntentData)12 IntentEvent (org.onosproject.net.intent.IntentEvent)12 IntentStoreDelegate (org.onosproject.net.intent.IntentStoreDelegate)12 Timestamp (org.onosproject.store.Timestamp)8 SystemClockTimestamp (org.onosproject.store.trivial.SystemClockTimestamp)8 WebTarget (javax.ws.rs.client.WebTarget)6 NetworkResource (org.onosproject.net.NetworkResource)6 ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)6 HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)6 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)6 JsonObject (com.eclipsesource.json.JsonObject)5 HashSet (java.util.HashSet)5 Ignore (org.junit.Ignore)5 Before (org.junit.Before)2