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)));
}
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);
}
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();
}
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);
}
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));
}
Aggregations