Move NetconfMessage into netconf.api.messages
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / rpc / SimulatedCreateSubscription.java
index fc7e99a31d3cf0b72cb56b05e872a3b20f79b882..764cd061bcdb3042143f4252dfc7f940f05fcf0e 100644 (file)
@@ -5,20 +5,17 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.test.tool.rpc;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import java.io.File;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -26,45 +23,45 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlRootElement;
-import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.messages.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.impl.NetconfServerSession;
-import org.opendaylight.netconf.impl.mapping.operations.DefaultNetconfOperation;
-import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
+import org.opendaylight.netconf.server.NetconfServerSession;
+import org.opendaylight.netconf.server.api.operations.AbstractLastNetconfOperation;
+import org.opendaylight.netconf.server.mapping.operations.DefaultNetconfOperation;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
 public class SimulatedCreateSubscription extends AbstractLastNetconfOperation implements DefaultNetconfOperation {
-
     private final Map<Notification, NetconfMessage> notifications;
+
     private NetconfServerSession session;
     private ScheduledExecutorService scheduledExecutorService;
 
-    public SimulatedCreateSubscription(final String id, final Optional<File> notificationsFile) {
-        super(id);
+    public SimulatedCreateSubscription(final SessionIdType sessionId, final Optional<File> notificationsFile) {
+        super(sessionId);
 
         final Optional<Notifications> notifs;
-
         if (notificationsFile.isPresent()) {
-            notifs = Optional.of(loadNotifications(notificationsFile.get()));
+            notifs = Optional.of(loadNotifications(notificationsFile.orElseThrow()));
             scheduledExecutorService = Executors.newScheduledThreadPool(1);
         } else {
-            notifs = Optional.absent();
+            notifs = Optional.empty();
         }
 
         if (notifs.isPresent()) {
-            final Collection<Notification> toCopy = notifs.get().getNotificationList();
+            final List<Notification> toCopy = notifs.orElseThrow().getNotificationList();
             final Map<Notification, NetconfMessage> preparedMessages = Maps.newHashMapWithExpectedSize(toCopy.size());
             for (final Notification notification : toCopy) {
                 final NetconfMessage parsedNotification = parseNetconfNotification(notification.getContent());
                 preparedMessages.put(notification, parsedNotification);
             }
-            this.notifications = preparedMessages;
+            notifications = preparedMessages;
         } else {
-            this.notifications = Collections.emptyMap();
+            notifications = Map.of();
         }
     }
 
@@ -103,7 +100,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
                 }, delayAggregator, TimeUnit.SECONDS);
             }
         }
-        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());
+        return document.createElement(XmlNetconfConstants.OK);
     }
 
     private static NetconfMessage parseNetconfNotification(String content) {
@@ -123,7 +120,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
 
     @Override
     public void setNetconfSession(final NetconfServerSession newSession) {
-        this.session = newSession;
+        session = newSession;
     }
 
     @XmlRootElement(name = "notifications")
@@ -138,7 +135,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
 
         @Override
         public String toString() {
-            final StringBuffer sb = new StringBuffer("Notifications{");
+            final StringBuilder sb = new StringBuilder("Notifications{");
             sb.append("notificationList=").append(notificationList);
             sb.append('}');
             return sb.toString();
@@ -170,7 +167,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im
 
         @Override
         public String toString() {
-            final StringBuffer sb = new StringBuffer("Notification{");
+            final StringBuilder sb = new StringBuilder("Notification{");
             sb.append("delayInSeconds=").append(delayInSeconds);
             sb.append(", times=").append(times);
             sb.append(", content='").append(content).append('\'');