</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
import org.slf4j.LoggerFactory;
@ThreadSafe
-public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry, NetconfNotificationListener, AutoCloseable {
+public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry,
+ NetconfNotificationListener, AutoCloseable {
public static final StreamNameType BASE_STREAM_NAME = new StreamNameType("NETCONF");
public static final Stream BASE_NETCONF_STREAM;
private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationManager.class);
- // TODO excessive synchronization provides thread safety but is most likely not optimal (combination of concurrent collections might improve performance)
- // And also calling callbacks from a synchronized block is dangerous since the listeners/publishers can block the whole notification processing
+ // TODO excessive synchronization provides thread safety but is most likely not optimal
+ // (combination of concurrent collections might improve performance)
+ // And also calling callbacks from a synchronized block is dangerous
+ // since the listeners/publishers can block the whole notification processing
@GuardedBy("this")
- private final Multimap<StreamNameType, GenericNotificationListenerReg> notificationListeners = HashMultimap.create();
+ private final Multimap<StreamNameType, GenericNotificationListenerReg> notificationListeners =
+ HashMultimap.create();
@GuardedBy("this")
private final Set<NetconfNotificationStreamListener> streamListeners = Sets.newHashSet();
}
@Override
- public synchronized NotificationListenerRegistration registerNotificationListener(final StreamNameType stream, final NetconfNotificationListener listener) {
+ public synchronized NotificationListenerRegistration registerNotificationListener(
+ final StreamNameType stream,
+ final NetconfNotificationListener listener) {
Preconditions.checkNotNull(stream);
Preconditions.checkNotNull(listener);
LOG.trace("Notification listener registered for stream: {}", stream);
- final GenericNotificationListenerReg genericNotificationListenerReg = new GenericNotificationListenerReg(listener) {
+ final GenericNotificationListenerReg genericNotificationListenerReg =
+ new GenericNotificationListenerReg(listener) {
@Override
public void close() {
synchronized (NetconfNotificationManager.this) {
}
@Override
- public synchronized NotificationRegistration registerStreamListener(final NetconfNotificationStreamListener listener) {
+ public synchronized NotificationRegistration registerStreamListener(
+ final NetconfNotificationStreamListener listener) {
streamListeners.add(listener);
// Notify about all already available
}
if (streamMetadata.containsKey(streamName)) {
- LOG.warn("Notification stream {} already registered as: {}. Will be reused", streamName, streamMetadata.get(streamName));
+ LOG.warn("Notification stream {} already registered as: {}. Will be reused", streamName,
+ streamMetadata.get(streamName));
} else {
streamMetadata.put(streamName, stream);
}
availableStreams.add(streamName);
- final GenericNotificationPublisherReg genericNotificationPublisherReg = new GenericNotificationPublisherReg(this, streamName) {
+ final GenericNotificationPublisherReg genericNotificationPublisherReg =
+ new GenericNotificationPublisherReg(this, streamName) {
@Override
public void close() {
synchronized (NetconfNotificationManager.this) {
return genericNotificationPublisherReg;
}
- private void unregisterNotificationPublisher(final StreamNameType streamName, final GenericNotificationPublisherReg genericNotificationPublisherReg) {
+ private void unregisterNotificationPublisher(
+ final StreamNameType streamName,
+ final GenericNotificationPublisherReg genericNotificationPublisherReg) {
availableStreams.remove(streamName);
notificationPublishers.remove(genericNotificationPublisherReg);
@Override
public BaseNotificationPublisherRegistration registerBaseNotificationPublisher() {
- final NotificationPublisherRegistration notificationPublisherRegistration = registerNotificationPublisher(BASE_NETCONF_STREAM);
+ final NotificationPublisherRegistration notificationPublisherRegistration =
+ registerNotificationPublisher(BASE_NETCONF_STREAM);
return new BaseNotificationPublisherReg(notificationPublisherRegistration);
}
private NetconfNotificationManager baseListener;
private final StreamNameType registeredStream;
- public GenericNotificationPublisherReg(final NetconfNotificationManager baseListener, final StreamNameType registeredStream) {
+ GenericNotificationPublisherReg(final NetconfNotificationManager baseListener,
+ final StreamNameType registeredStream) {
this.baseListener = baseListener;
this.registeredStream = registeredStream;
}
private final NotificationPublisherRegistration baseRegistration;
- public BaseNotificationPublisherReg(final NotificationPublisherRegistration baseRegistration) {
+ BaseNotificationPublisherReg(final NotificationPublisherRegistration baseRegistration) {
this.baseRegistration = baseRegistration;
}
@Override
public void onCapabilityChanged(final NetconfCapabilityChange capabilityChange) {
- baseRegistration.onNotification(BASE_STREAM_NAME, serializeNotification(capabilityChange, CAPABILITY_CHANGE_SCHEMA_PATH));
+ baseRegistration.onNotification(BASE_STREAM_NAME,
+ serializeNotification(capabilityChange, CAPABILITY_CHANGE_SCHEMA_PATH));
}
@Override
private class GenericNotificationListenerReg implements NotificationListenerRegistration {
private final NetconfNotificationListener listener;
- public GenericNotificationListenerReg(final NetconfNotificationListener listener) {
+ GenericNotificationListenerReg(final NetconfNotificationListener listener) {
this.listener = listener;
}
import org.w3c.dom.Element;
/**
- * Create subscription listens for create subscription requests and registers notification listeners into notification registry.
+ * Create subscription listens for create subscription requests
+ * and registers notification listeners into notification registry.
* Received notifications are sent to the client right away
*/
-public class CreateSubscription extends AbstractSingletonNetconfOperation implements SessionAwareNetconfOperation, AutoCloseable {
+public class CreateSubscription extends AbstractSingletonNetconfOperation
+ implements SessionAwareNetconfOperation, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(CreateSubscription.class);
private final List<NotificationListenerRegistration> subscriptions = Lists.newArrayList();
private NetconfSession netconfSession;
- public CreateSubscription(final String netconfSessionIdForReporting, final NetconfNotificationRegistry notifications) {
+ public CreateSubscription(final String netconfSessionIdForReporting,
+ final NetconfNotificationRegistry notifications) {
super(netconfSessionIdForReporting);
this.notifications = notifications;
}
@Override
- protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
+ protected Element handleWithNoSubsequentOperations(final Document document,
+ final XmlElement operationElement) throws DocumentedException {
operationElement.checkName(CREATE_SUBSCRIPTION);
operationElement.checkNamespace(CreateSubscriptionInput.QNAME.getNamespace().toString());
// FIXME reimplement using CODEC_REGISTRY and parse everything into generated class instance
final Optional<XmlElement> filter = operationElement.getOnlyChildElementWithSameNamespaceOptionally("filter");
// Replay not supported
- final Optional<XmlElement> startTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
+ final Optional<XmlElement> startTime =
+ operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
Preconditions.checkArgument(startTime.isPresent() == false, "StartTime element not yet supported");
// Stop time not supported
- final Optional<XmlElement> stopTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
+ final Optional<XmlElement> stopTime =
+ operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
Preconditions.checkArgument(stopTime.isPresent() == false, "StopTime element not yet supported");
final StreamNameType streamNameType = parseStreamIfPresent(operationElement);
Preconditions.checkNotNull(netconfSession);
// Premature streams are allowed (meaning listener can register even if no provider is available yet)
- if(notifications.isStreamAvailable(streamNameType) == false) {
- LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType, getNetconfSessionIdForReporting());
+ if (notifications.isStreamAvailable(streamNameType) == false) {
+ LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType,
+ getNetconfSessionIdForReporting());
}
- final NotificationListenerRegistration notificationListenerRegistration =
- notifications.registerNotificationListener(streamNameType, new NotificationSubscription(netconfSession, filter));
+ final NotificationListenerRegistration notificationListenerRegistration = notifications
+ .registerNotificationListener(streamNameType, new NotificationSubscription(netconfSession, filter));
subscriptions.add(notificationListenerRegistration);
return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
private static StreamNameType parseStreamIfPresent(final XmlElement operationElement) throws DocumentedException {
final Optional<XmlElement> stream = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stream");
- return stream.isPresent() ? new StreamNameType(stream.get().getTextContent()) : NetconfNotificationManager.BASE_STREAM_NAME;
+ return stream.isPresent() ? new StreamNameType(stream.get().getTextContent())
+ : NetconfNotificationManager.BASE_STREAM_NAME;
}
@Override
private final NetconfSession currentSession;
private final Optional<XmlElement> filter;
- public NotificationSubscription(final NetconfSession currentSession, final Optional<XmlElement> filter) {
+ NotificationSubscription(final NetconfSession currentSession, final Optional<XmlElement> filter) {
this.currentSession = currentSession;
this.filter = filter;
}
public void onNotification(final StreamNameType stream, final NetconfNotification notification) {
if (filter.isPresent()) {
try {
- final Optional<Document> filtered = SubtreeFilter.applySubtreeNotificationFilter(this.filter.get(), notification.getDocument());
+ final Optional<Document> filtered =
+ SubtreeFilter.applySubtreeNotificationFilter(this.filter.get(), notification.getDocument());
if (filtered.isPresent()) {
final Date eventTime = notification.getEventTime();
currentSession.sendMessage(new NetconfNotification(filtered.get(), eventTime));
public class Get extends AbstractNetconfOperation implements AutoCloseable {
private static final String GET = "get";
- private static final InstanceIdentifier<Netconf> NETCONF_SUBTREE_INSTANCE_IDENTIFIER = InstanceIdentifier.builder(Netconf.class).build();
+ private static final InstanceIdentifier<Netconf> NETCONF_SUBTREE_INSTANCE_IDENTIFIER =
+ InstanceIdentifier.builder(Netconf.class).build();
private final NetconfNotificationRegistry notificationRegistry;
}
@Override
- public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
+ protected Element handle(final Document document, final XmlElement message,
+ final NetconfOperationChainedExecution subsequentOperation)
+ throws DocumentedException {
+ throw new UnsupportedOperationException("Never gets called");
+ }
+
+ @Override
+ public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation)
+ throws DocumentedException {
final Document partialResponse = subsequentOperation.execute(requestMessage);
final Streams availableStreams = notificationRegistry.getNotificationPublishers();
- if(availableStreams.getStream().isEmpty() == false) {
+ if (availableStreams.getStream().isEmpty() == false) {
serializeStreamsSubtree(partialResponse, availableStreams);
}
return partialResponse;
}
- static void serializeStreamsSubtree(final Document partialResponse, final Streams availableStreams) throws DocumentedException {
+ static void serializeStreamsSubtree(final Document partialResponse, final Streams availableStreams)
+ throws DocumentedException {
final Netconf netconfSubtree = new NetconfBuilder().setStreams(availableStreams).build();
final NormalizedNode<?, ?> normalized = toNormalized(netconfSubtree);
final DOMResult result = new DOMResult(getPlaceholder(partialResponse));
try {
- NetconfUtil.writeNormalizedNode(normalized, result, SchemaPath.ROOT, NotificationsTransformUtil.NOTIFICATIONS_SCHEMA_CTX);
+ NetconfUtil.writeNormalizedNode(normalized, result, SchemaPath.ROOT,
+ NotificationsTransformUtil.NOTIFICATIONS_SCHEMA_CTX);
} catch (final XMLStreamException | IOException e) {
throw new IllegalStateException("Unable to serialize " + netconfSubtree, e);
}
private static Element getPlaceholder(final Document innerResult)
throws DocumentedException {
- final XmlElement rootElement = XmlElement.fromDomElementWithExpected(
- innerResult.getDocumentElement(), XmlMappingConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+ final XmlElement rootElement = XmlElement.fromDomElementWithExpected(innerResult.getDocumentElement(),
+ XmlMappingConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
return rootElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY).getDomElement();
}
private static NormalizedNode<?, ?> toNormalized(final Netconf netconfSubtree) {
- return NotificationsTransformUtil.CODEC_REGISTRY.toNormalizedNode(NETCONF_SUBTREE_INSTANCE_IDENTIFIER, netconfSubtree).getValue();
- }
-
- @Override
- protected Element handle(final Document document, final XmlElement message, final NetconfOperationChainedExecution subsequentOperation)
- throws DocumentedException {
- throw new UnsupportedOperationException("Never gets called");
+ return NotificationsTransformUtil.CODEC_REGISTRY
+ .toNormalizedNode(NETCONF_SUBTREE_INSTANCE_IDENTIFIER, netconfSubtree).getValue();
}
@Override
final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
moduleInfoBackedContext.addModuleInfos(Collections.singletonList($YangModuleInfoImpl.getInstance()));
- moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.$YangModuleInfoImpl.getInstance()));
+ moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params
+ .xml.ns.yang.ietf.netconf.notifications.rev120206.$YangModuleInfoImpl.getInstance()));
final Optional<SchemaContext> schemaContextOptional = moduleInfoBackedContext.tryToCreateSchemaContext();
Preconditions.checkState(schemaContextOptional.isPresent());
NOTIFICATIONS_SCHEMA_CTX = schemaContextOptional.get();
final JavassistUtils javassist = JavassistUtils.forClassPool(ClassPool.getDefault());
CODEC_REGISTRY = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(javassist));
- CODEC_REGISTRY.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(moduleInfoBackedContext, NOTIFICATIONS_SCHEMA_CTX));
+ CODEC_REGISTRY.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(moduleInfoBackedContext,
+ NOTIFICATIONS_SCHEMA_CTX));
}
private static RpcDefinition findCreateSubscriptionRpc() {
- return Iterables.getFirst(Collections2.filter(NOTIFICATIONS_SCHEMA_CTX.getOperations(), new Predicate<RpcDefinition>() {
- @Override
- public boolean apply(final RpcDefinition input) {
- return input.getQName().getLocalName().equals(CreateSubscription.CREATE_SUBSCRIPTION);
- }
- }), null);
+ return Iterables.getFirst(Collections2.filter(NOTIFICATIONS_SCHEMA_CTX.getOperations(),
+ new Predicate<RpcDefinition>() {
+ @Override
+ public boolean apply(final RpcDefinition input) {
+ return input.getQName().getLocalName().equals(CreateSubscription.CREATE_SUBSCRIPTION);
+ }
+ }), null);
}
/**
- * Transform base notification for capabilities into NetconfNotification
+ * Transform base notification for capabilities into NetconfNotification.
*/
public static NetconfNotification transform(final Notification notification, SchemaPath path) {
return transform(notification, Optional.<Date>absent(), path);
}
- public static NetconfNotification transform(final Notification notification, final Date eventTime, SchemaPath path) {
+ public static NetconfNotification transform(final Notification notification,
+ final Date eventTime, SchemaPath path) {
return transform(notification, Optional.fromNullable(eventTime), path);
}
- private static NetconfNotification transform(final Notification notification, final Optional<Date> eventTime, SchemaPath path) {
+ private static NetconfNotification transform(final Notification notification,
+ final Optional<Date> eventTime, SchemaPath path) {
final ContainerNode containerNode = CODEC_REGISTRY.toNormalizedNodeNotification(notification);
final DOMResult result = new DOMResult(XmlUtil.newDocument());
try {
NetconfUtil.writeNormalizedNode(containerNode, result, path, NOTIFICATIONS_SCHEMA_CTX);
- } catch (final XMLStreamException| IOException e) {
+ } catch (final XMLStreamException | IOException e) {
throw new IllegalStateException("Unable to serialize " + notification, e);
}
final Document node = (Document) result.getNode();
- return eventTime.isPresent() ?
- new NetconfNotification(node, eventTime.get()):
- new NetconfNotification(node);
+ return eventTime.isPresent() ? new NetconfNotification(node, eventTime.get()) : new NetconfNotification(node);
}
}
// Add properties to autowire with netconf-impl instance for cfg subsystem
final Dictionary<String, String> props = new Hashtable<>();
props.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_NOTIFICATION);
- netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
+ netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class,
+ netconfNotificationManager, new Hashtable<String, Object>());
final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
- private final Set<Capability> capabilities = Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
+ private final Set<Capability> capabilities =
+ Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
@Override
public Set<Capability> getCapabilities() {
public NetconfOperationService createService(final String netconfSessionIdForReporting) {
return new NetconfOperationService() {
- private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
+ private final CreateSubscription createSubscription =
+ new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
@Override
public Set<NetconfOperation> getNetconfOperations() {
final Dictionary<String, String> properties = new Hashtable<>();
properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
- operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
+ operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class,
+ netconfOperationServiceFactory, properties);
}
@Override
public void stop(final BundleContext context) throws Exception {
- if(netconfNotificationCollectorServiceRegistration != null) {
+ if (netconfNotificationCollectorServiceRegistration != null) {
netconfNotificationCollectorServiceRegistration.unregister();
netconfNotificationCollectorServiceRegistration = null;
}
)) {
try {
final Date apply = NetconfNotification.RFC3339_DATE_PARSER.apply(time);
- final Date parse = new SimpleDateFormat(RFC3339_DATE_FORMAT_WITH_MILLIS_BLUEPRINT).parse(iterator.next());
+ final Date parse =
+ new SimpleDateFormat(RFC3339_DATE_FORMAT_WITH_MILLIS_BLUEPRINT).parse(iterator.next());
assertEquals(parse.getTime(), apply.getTime());
// Testing that we're consistent from formatting to parsing.
final String dateString = NetconfNotification.RFC3339_DATE_FORMATTER.apply(apply);
final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
- final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
+ final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager
+ .registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
final NetconfCapabilityChange notification = capabilityChangedBuilder.build();
baseNotificationPublisherRegistration.onCapabilityChanged(notification);
public void testClose() throws Exception {
final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager();
- final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher();
+ final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration =
+ netconfNotificationManager.registerBaseNotificationPublisher();
final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
- netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
+ netconfNotificationManager
+ .registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener =
mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
public void testStreamListeners() throws Exception {
final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager();
- final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener = mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
+ final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener =
+ mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
doNothing().when(streamListener).onStreamRegistered(any(Stream.class));
doNothing().when(streamListener).onStreamUnregistered(any(StreamNameType.class));
public class CreateSubscriptionTest {
- private static final String CREATE_SUBSCRIPTION_XML = "<create-subscription\n" +
- "xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
- "<stream>TESTSTREAM</stream>" +
- "</create-subscription>";
+ private static final String CREATE_SUBSCRIPTION_XML = "<create-subscription\n"
+ + "xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\" "
+ + "xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + "<stream>TESTSTREAM</stream>"
+ + "</create-subscription>";
@Mock
private NetconfNotificationRegistry notificationRegistry;
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class));
- doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry).registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
+ doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry)
+ .registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
}
@Test
final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML);
final XmlElement operationElement = XmlElement.fromDomElement(e);
- final Element element = createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
+ final Element element =
+ createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
Assert.assertThat(XmlUtil.toString(element), CoreMatchers.containsString("ok"));
}
final Document response = getBlankResponse();
Get.serializeStreamsSubtree(response, streams);
NotificationsTransformUtilTest.compareXml(XmlUtil.toString(response),
- "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
- "<data>\n" +
- "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n" +
- "<streams>\n" +
- "<stream>\n" +
- "<name>base</name>\n" +
- "<description>description</description>\n" +
- "<replaySupport>false</replaySupport>\n" +
- "</stream>\n" +
- "</streams>\n" +
- "</netconf>\n" +
- "</data>\n" +
- "</rpc-reply>\n");
+ "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + "<data>\n"
+ + "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n"
+ + "<streams>\n"
+ + "<stream>\n"
+ + "<name>base</name>\n"
+ + "<description>description</description>\n"
+ + "<replaySupport>false</replaySupport>\n"
+ + "</stream>\n"
+ + "</streams>\n"
+ + "</netconf>\n"
+ + "</data>\n"
+ + "</rpc-reply>\n");
}
private static Document getBlankResponse() throws IOException, SAXException {
- return XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" +
- "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
- "<data>\n" +
- "</data>\n" +
- "</rpc-reply>");
+ return XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n"
+ + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + "<data>\n"
+ + "</data>\n"
+ + "</rpc-reply>");
}
}
\ No newline at end of file
public class NotificationsTransformUtilTest {
private static final Date DATE = new Date();
- private static final String innerNotification = "<netconf-capability-change xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-notifications\">" +
- "<deleted-capability>uri4</deleted-capability>" +
- "<deleted-capability>uri3</deleted-capability>" +
- "<added-capability>uri1</added-capability>" +
- "</netconf-capability-change>";
+ private static final String INNER_NOTIFICATION =
+ "<netconf-capability-change xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-notifications\">"
+ + "<deleted-capability>uri4</deleted-capability>"
+ + "<deleted-capability>uri3</deleted-capability>"
+ + "<added-capability>uri1</added-capability>"
+ + "</netconf-capability-change>";
- private static final String expectedNotification =
+ private static final String EXPECTED_NOTIFICATION =
"<notification xmlns=\"urn:ietf:params:netconf:capability:notification:1.0\">"
- + innerNotification
+ + INNER_NOTIFICATION
+ "<eventTime>"
- + NetconfNotification.RFC3339_DATE_FORMATTER.apply(DATE)
- + "</eventTime>" +
- "</notification>";
+ + NetconfNotification.RFC3339_DATE_FORMATTER.apply(DATE)
+ + "</eventTime>"
+ + "</notification>";
@Test
public void testTransform() throws Exception {
netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(new Uri("uri4"), new Uri("uri3")));
final NetconfCapabilityChange capabilityChange = netconfCapabilityChangeBuilder.build();
- final NetconfNotification transform = NotificationsTransformUtil.transform(capabilityChange, DATE, SchemaPath.create(true, NetconfCapabilityChange.QNAME));
+ final NetconfNotification transform = NotificationsTransformUtil.transform(capabilityChange, DATE,
+ SchemaPath.create(true, NetconfCapabilityChange.QNAME));
final String serialized = XmlUtil.toString(transform.getDocument());
- compareXml(expectedNotification, serialized);
+ compareXml(EXPECTED_NOTIFICATION, serialized);
}
static void compareXml(final String expected, final String actual) throws SAXException, IOException {
@Test
public void testTransformFromDOM() throws Exception {
- final NetconfNotification netconfNotification = new NetconfNotification(XmlUtil.readXmlToDocument(innerNotification), DATE);
+ final NetconfNotification netconfNotification =
+ new NetconfNotification(XmlUtil.readXmlToDocument(INNER_NOTIFICATION), DATE);
XMLUnit.setIgnoreWhitespace(true);
- compareXml(expectedNotification, netconfNotification.toString());
+ compareXml(EXPECTED_NOTIFICATION, netconfNotification.toString());
}
}
final ServiceRegistration operationaServiceRegistration = mock(ServiceRegistration.class);
// test registering services
- doReturn(netconfNotificationCollectorServiceRegistration).when(context).
- registerService(eq(NetconfNotificationCollector.class), any(NetconfNotificationManager.class), any());
- doReturn(operationaServiceRegistration).when(context).
- registerService(eq(NetconfOperationServiceFactory.class), any(NetconfOperationServiceFactory.class), any());
+ doReturn(netconfNotificationCollectorServiceRegistration).when(context)
+ .registerService(eq(NetconfNotificationCollector.class), any(NetconfNotificationManager.class), any());
+ doReturn(operationaServiceRegistration).when(context).registerService(eq(NetconfOperationServiceFactory.class),
+ any(NetconfOperationServiceFactory.class), any());
activator.start(context);
// test service factory argument requisites
final NetconfOperationServiceFactory serviceFactory = serviceFactoryArgumentCaptor.getValue();
- final Set<Capability> capabilities = Collections.singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
+ final Set<Capability> capabilities =
+ Collections.singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
- assertEquals(capabilities.iterator().next().getCapabilityUri(), serviceFactory.getCapabilities().iterator().next().getCapabilityUri());
- assertEquals(capabilities.iterator().next().getCapabilitySchema(), serviceFactory.getCapabilities().iterator().next().getCapabilitySchema());
- assertEquals(capabilities.iterator().next().getModuleNamespace(), serviceFactory.getCapabilities().iterator().next().getModuleNamespace());
- assertEquals(capabilities.iterator().next().getModuleName(), serviceFactory.getCapabilities().iterator().next().getModuleName());
+ assertEquals(capabilities.iterator().next()
+ .getCapabilityUri(), serviceFactory.getCapabilities().iterator().next().getCapabilityUri());
+ assertEquals(capabilities.iterator().next()
+ .getCapabilitySchema(), serviceFactory.getCapabilities().iterator().next().getCapabilitySchema());
+ assertEquals(capabilities.iterator().next()
+ .getModuleNamespace(), serviceFactory.getCapabilities().iterator().next().getModuleNamespace());
+ assertEquals(capabilities.iterator().next()
+ .getModuleName(), serviceFactory.getCapabilities().iterator().next().getModuleName());
final CapabilityListener listener = mock(CapabilityListener.class);
final NetconfOperationService netconfOperationService = serviceFactory.createService("id");
final Set<NetconfOperation> netconfOperations = netconfOperationService.getNetconfOperations();
- final CreateSubscription createSubscription = new CreateSubscription("id", activator.getNetconfNotificationManager());
+ final CreateSubscription createSubscription =
+ new CreateSubscription("id", activator.getNetconfNotificationManager());
netconfOperations.forEach(
- operation -> {
- if (operation instanceof CreateSubscription) {
- assertEquals(createSubscription.toString(), operation.toString());
- }
- if (operation instanceof Get) {
- assertEquals("id", ((Get) operation).getNetconfSessionIdForReporting());
- }
+ operation -> {
+ if (operation instanceof CreateSubscription) {
+ assertEquals(createSubscription.toString(), operation.toString());
}
+ if (operation instanceof Get) {
+ assertEquals("id", ((Get) operation).getNetconfSessionIdForReporting());
+ }
+ }
);
// test unregister after stop