Do not rely on union char[] values 52/73952/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Jul 2018 18:47:21 +0000 (20:47 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Jul 2018 19:08:46 +0000 (21:08 +0200)
This removes the dependency on synthetic getValue() and the union
constructor for JMX.

Change-Id: I46eaa2922e8cc83505a3198a9b29561f8ab1b32a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/controller/config/yang/netconf/mdsal/notification/SessionNotificationProducerTest.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/NetconfServerSessionTest.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfCapabilityMonitoringServiceTest.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfSessionMonitoringServiceTest.java

index aa83c680ff8f4ebdc63af1b89961e0ae6d2296e3..5a647b4a6f4916e1acfb96e605e69567e0093134 100644 (file)
@@ -23,12 +23,13 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.SessionBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
@@ -74,8 +75,7 @@ public class SessionNotificationProducerTest {
     @Test
     public void testOnDataChangedSessionCreated() throws Exception {
         final Session session = createSession(1);
-        final DataTreeModification<Session> treeChange = getTreeModification(session, DataObjectModification
-                .ModificationType.WRITE);
+        final DataTreeModification<Session> treeChange = getTreeModification(session, ModificationType.WRITE);
         publisher.onDataTreeChanged(Collections.singleton(treeChange));
         ArgumentCaptor<NetconfSessionStart> captor = ArgumentCaptor.forClass(NetconfSessionStart.class);
         verify(registration).onSessionStarted(captor.capture());
@@ -93,7 +93,7 @@ public class SessionNotificationProducerTest {
         final Session sessionAfter = createSessionWithInRpcCount(1, 1);
         doReturn(sessionBefore).when(changeObject).getDataBefore();
         doReturn(sessionAfter).when(changeObject).getDataAfter();
-        doReturn(DataObjectModification.ModificationType.WRITE).when(changeObject).getModificationType();
+        doReturn(ModificationType.WRITE).when(changeObject).getModificationType();
         doReturn(changeObject).when(treeChange).getRootNode();
         publisher.onDataTreeChanged(Collections.singleton(treeChange));
         //session didn't start, only stats changed. No notification should be produced
@@ -104,8 +104,7 @@ public class SessionNotificationProducerTest {
     @Test
     public void testOnDataChangedSessionDeleted() throws Exception {
         final Session session = createSession(1);
-        final DataTreeModification<Session> data = getTreeModification(session, DataObjectModification
-                .ModificationType.DELETE);
+        final DataTreeModification<Session> data = getTreeModification(session, ModificationType.DELETE);
         publisher.onDataTreeChanged(Collections.singleton(data));
         ArgumentCaptor<NetconfSessionEnd> captor = ArgumentCaptor.forClass(NetconfSessionEnd.class);
         verify(registration).onSessionEnded(captor.capture());
@@ -115,22 +114,21 @@ public class SessionNotificationProducerTest {
         Assert.assertEquals(session.getUsername(), value.getUsername());
     }
 
-    private Session createSession(long id) {
+    private static Session createSession(long id) {
         return createSessionWithInRpcCount(id, 0);
     }
 
-    private Session createSessionWithInRpcCount(long id, long inRpc) {
+    private static Session createSessionWithInRpcCount(long id, long inRpc) {
         return new SessionBuilder()
                 .setSessionId(id)
-                .setSourceHost(new Host("0.0.0.0".toCharArray()))
+                .setSourceHost(HostBuilder.getDefaultInstance("0.0.0.0"))
                 .setUsername("user")
                 .setInRpcs(new ZeroBasedCounter32(inRpc))
                 .build();
     }
 
     @SuppressWarnings("unchecked")
-    private DataTreeModification<Session> getTreeModification(Session session, DataObjectModification
-            .ModificationType type) {
+    private static DataTreeModification<Session> getTreeModification(Session session, ModificationType type) {
         final DataTreeModification<Session> treeChange = mock(DataTreeModification.class);
         final DataObjectModification<Session> changeObject = mock(DataObjectModification.class);
         switch (type) {
index 6e4408643680c39c21ef1a3c224aaa19ae8ba856..6e3dc9e153d64c7079ab336aa4c6d2911223a766 100644 (file)
@@ -138,7 +138,7 @@ public class NetconfServerSessionTest {
         final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         final Session managementSession = tcpSession.toManagementSession();
-        Assert.assertEquals(new String(managementSession.getSourceHost().getValue()), HOST);
+        Assert.assertEquals(HOST, managementSession.getSourceHost().getIpAddress().getIpv4Address().getValue());
         Assert.assertEquals(managementSession.getUsername(), USER);
         Assert.assertEquals(managementSession.getSessionId().toString(), SESSION_ID);
         Assert.assertEquals(managementSession.getTransport(), NetconfTcp.class);
@@ -152,6 +152,7 @@ public class NetconfServerSessionTest {
         final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         tcpSession.toManagementSession();
+        tcpSession.close();
     }
 
     @Test
@@ -162,7 +163,7 @@ public class NetconfServerSessionTest {
         final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         final Session managementSession = tcpSession.toManagementSession();
-        Assert.assertEquals(new String(managementSession.getSourceHost().getValue()), "::1");
+        Assert.assertEquals("::1", managementSession.getSourceHost().getIpAddress().getIpv6Address().getValue());
         Assert.assertEquals(managementSession.getUsername(), USER);
         Assert.assertEquals(managementSession.getSessionId().toString(), SESSION_ID);
         Assert.assertEquals(managementSession.getTransport(), NetconfSsh.class);
index 54d3cb3b7c7246f75dae6baef7194779d78d457b..73ef36ef15128e0c8a4fc7c2162442c171004430 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.netconf.api.monitoring.NetconfManagementSession;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder;
@@ -60,7 +60,7 @@ public class NetconfCapabilityMonitoringServiceTest {
     private YangModuleCapability moduleCapability2;
     private static final Session SESSION = new SessionBuilder()
             .setSessionId(1L)
-            .setSourceHost(new Host("0.0.0.0".toCharArray()))
+            .setSourceHost(HostBuilder.getDefaultInstance("0.0.0.0"))
             .setUsername("admin")
             .build();
     private int capabilitiesSize;
index 860aa36e8b85a4bb06ea16bf17742bacbb70dd53..ae8ee0e6280ef90db9a4d048e84106fb20dac9d3 100644 (file)
@@ -32,7 +32,7 @@ import org.opendaylight.netconf.api.monitoring.NetconfManagementSession;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.netconf.api.monitoring.SessionEvent;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.SessionBuilder;
 
@@ -40,12 +40,12 @@ public class NetconfSessionMonitoringServiceTest {
 
     private static final Session SESSION_1 = new SessionBuilder()
             .setSessionId(1L)
-            .setSourceHost(new Host("0.0.0.0".toCharArray()))
+            .setSourceHost(HostBuilder.getDefaultInstance("0.0.0.0"))
             .setUsername("admin")
             .build();
     private static final Session SESSION_2 = new SessionBuilder()
             .setSessionId(2L)
-            .setSourceHost(new Host("0.0.0.0".toCharArray()))
+            .setSourceHost(HostBuilder.getDefaultInstance("0.0.0.0"))
             .setUsername("admin")
             .build();