2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.binding.test.bugfix;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder;
19 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
21 public class UnionSerializationTest extends AbstractDataServiceTest {
23 public static final String PREFIX_STRING = "192.168.0.1/32";
27 public void testPrefixSerialization() throws Exception {
29 Ipv4Prefix ipv4prefix = new Ipv4Prefix(PREFIX_STRING);
30 IpPrefix ipPrefix = new IpPrefix(ipv4prefix);
31 Prefix prefix = new PrefixBuilder().setPrefix(ipPrefix).build();
33 CompositeNode serialized = testContext.getBindingToDomMappingService().toDataDom(prefix);
34 assertNotNull(serialized);
35 assertNotNull(serialized.getFirstSimpleByName(Prefix.QNAME));
36 assertEquals(PREFIX_STRING, serialized.getFirstSimpleByName(Prefix.QNAME).getValue());
38 Prefix deserialized = (Prefix) testContext.getBindingToDomMappingService().dataObjectFromDataDom(Prefix.class, serialized);
39 assertNotNull(deserialized);
40 assertNotNull(deserialized.getPrefix());
41 assertNotNull(deserialized.getPrefix().getIpv4Prefix());
42 assertEquals(PREFIX_STRING, deserialized.getPrefix().getIpv4Prefix().getValue());