Search in sources :

Example 1 with MockCodecContext

use of org.onosproject.codec.impl.MockCodecContext in project onos by opennetworkinglab.

the class VirtualHostCodecTest method testEncode.

@Test
public void testEncode() {
    MockCodecContext context = new MockCodecContext();
    NetworkId networkId = NetworkId.networkId(TEST_NETWORK_ID);
    HostId id = NetTestTools.hid(TEST_HOST_ID);
    MacAddress mac = MacAddress.valueOf(TEST_MAC_ADDRESS);
    VlanId vlan = VlanId.vlanId(TEST_VLAN_ID);
    HostLocation location = new HostLocation(CONNECT_POINT, 0L);
    Set<IpAddress> ips = ImmutableSet.of(IpAddress.valueOf(TEST_IP1), IpAddress.valueOf(TEST_IP2));
    VirtualHost host = new DefaultVirtualHost(networkId, id, mac, vlan, location, ips);
    JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
    ObjectNode node = codec.encode(host, context);
    assertThat(node.get(VirtualHostCodec.NETWORK_ID).asLong(), is(TEST_NETWORK_ID));
    assertThat(node.get(VirtualHostCodec.HOST_ID).asText(), is(TEST_HOST_ID));
    assertThat(node.get(VirtualHostCodec.MAC_ADDRESS).asText(), is(TEST_MAC_ADDRESS));
    assertThat(node.get(VirtualHostCodec.VLAN).asInt(), is((int) TEST_VLAN_ID));
    assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("elementId").asText(), is(location.deviceId().toString()));
    assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("port").asLong(), is(location.port().toLong()));
    JsonNode jsonIps = node.get(VirtualHostCodec.IP_ADDRESSES);
    assertThat(jsonIps, notNullValue());
    assertThat(jsonIps.isArray(), is(true));
    assertThat(jsonIps.size(), is(ips.size()));
    IntStream.of(0, 1).forEach(index -> assertThat(jsonIps.get(index).asText(), isOneOf(TEST_IP1, TEST_IP2)));
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) MockCodecContext(org.onosproject.codec.impl.MockCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) HostId(org.onosproject.net.HostId) MacAddress(org.onlab.packet.MacAddress) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Example 2 with MockCodecContext

use of org.onosproject.codec.impl.MockCodecContext in project onos by opennetworkinglab.

the class KubevirtRouterCodecTest method setUp.

@Before
public void setUp() {
    context = new MockCodecContext();
    kubevirtRouterCodec = new KubevirtRouterCodec();
    assertThat(kubevirtRouterCodec, notNullValue());
    expect(mockCoreService.registerApplication(REST_APP_ID)).andReturn(APP_ID).anyTimes();
    replay(mockCoreService);
    context.registerService(CoreService.class, mockCoreService);
}
Also used : MockCodecContext(org.onosproject.codec.impl.MockCodecContext) Before(org.junit.Before)

Example 3 with MockCodecContext

use of org.onosproject.codec.impl.MockCodecContext in project trellis-control by opennetworkinglab.

the class DropPolicyCodecTest method setUp.

@Before
public void setUp() throws Exception {
    context = new MockCodecContext();
    codec = new DropPolicyCodec();
    dropPolicy = new DropPolicy();
}
Also used : MockCodecContext(org.onosproject.codec.impl.MockCodecContext) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Before(org.junit.Before)

Example 4 with MockCodecContext

use of org.onosproject.codec.impl.MockCodecContext in project onos by opennetworkinglab.

the class KubevirtFloatingIpCodecTest method setUp.

@Before
public void setUp() {
    context = new MockCodecContext();
    kubevirtFloatingIpCodec = new KubevirtFloatingIpCodec();
    assertThat(kubevirtFloatingIpCodec, notNullValue());
    expect(mockCoreService.registerApplication(REST_APP_ID)).andReturn(APP_ID).anyTimes();
    replay(mockCoreService);
    context.registerService(CoreService.class, mockCoreService);
}
Also used : MockCodecContext(org.onosproject.codec.impl.MockCodecContext) Before(org.junit.Before)

Example 5 with MockCodecContext

use of org.onosproject.codec.impl.MockCodecContext in project onos by opennetworkinglab.

the class VirtualHostCodecTest method testDecode.

@Test
public void testDecode() throws IOException {
    MockCodecContext context = new MockCodecContext();
    InputStream jsonStream = VirtualHostCodecTest.class.getResourceAsStream("VirtualHost.json");
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat(json, notNullValue());
    JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
    VirtualHost virtualHost = codec.decode((ObjectNode) json, context);
    assertThat(virtualHost, notNullValue());
    assertThat(virtualHost.networkId().id(), is(TEST_NETWORK_ID));
    assertThat(virtualHost.id().toString(), is(NetTestTools.hid(TEST_MAC_ADDRESS + "/12").toString()));
    assertThat(virtualHost.mac().toString(), is(TEST_MAC_ADDRESS));
    assertThat(virtualHost.vlan().id(), is((short) TEST_VLAN_ID));
    assertThat(virtualHost.location().deviceId(), is(CONNECT_POINT.deviceId()));
    assertThat(virtualHost.location().port().toLong(), is(CONNECT_POINT.port().toLong()));
    assertThat(virtualHost.ipAddresses().contains(IpAddress.valueOf(TEST_IP1)), is(true));
    assertThat(virtualHost.ipAddresses().contains(IpAddress.valueOf(TEST_IP2)), is(true));
}
Also used : MockCodecContext(org.onosproject.codec.impl.MockCodecContext) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) Test(org.junit.Test)

Aggregations

MockCodecContext (org.onosproject.codec.impl.MockCodecContext)8 Before (org.junit.Before)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Test (org.junit.Test)2 DefaultVirtualHost (org.onosproject.incubator.net.virtual.DefaultVirtualHost)2 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 VlanId (org.onlab.packet.VlanId)1 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)1 DeviceId (org.onosproject.net.DeviceId)1 HostId (org.onosproject.net.HostId)1 HostLocation (org.onosproject.net.HostLocation)1 DropPolicy (org.onosproject.segmentrouting.policy.api.DropPolicy)1 RedirectPolicy (org.onosproject.segmentrouting.policy.api.RedirectPolicy)1 TrafficMatch (org.onosproject.segmentrouting.policy.api.TrafficMatch)1 TrafficMatchPriority (org.onosproject.segmentrouting.policy.api.TrafficMatchPriority)1