<artifactId>mockito-configuration</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
private final NetconfMessage startExiMessage;
public NetconfClientSessionPreferences(final NetconfHelloMessage helloMessage,
- final NetconfMessage startExiMessage) {
+ final NetconfMessage startExiMessage) {
super(helloMessage);
this.startExiMessage = startExiMessage;
}
/**
+ * Getter for {@code NetconfMessage}.
+ *
* @return the startExiMessage
*/
public NetconfMessage getStartExiMessage() {
super(message);
}
- public NetconfDeserializerException(final String message, final Exception e) {
- super(message, e);
+ public NetconfDeserializerException(final String message, final Exception exception) {
+ super(message, exception);
}
}
super(message);
}
- public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
+ public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+ final ErrorSeverity errorSeverity) {
super(message, errorType, errorTag, errorSeverity);
}
- public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
+ public NetconfDocumentedException(final String message, final ErrorType errorType, final ErrorTag errorTag,
+ final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
super(message, errorType, errorTag, errorSeverity, errorInfo);
}
- public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
+ public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType,
+ final ErrorTag errorTag, final ErrorSeverity errorSeverity) {
super(message, cause, errorType, errorTag, errorSeverity);
}
- public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType, final ErrorTag errorTag, final ErrorSeverity errorSeverity, final Map<String, String> errorInfo) {
+ public NetconfDocumentedException(final String message, final Exception cause, final ErrorType errorType,
+ final ErrorTag errorTag, final ErrorSeverity errorSeverity,
+ final Map<String, String> errorInfo) {
super(message, cause, errorType, errorTag, errorSeverity, errorInfo);
}
- public NetconfDocumentedException(DocumentedException e) {
- super(e.getMessage(), (Exception) e.getCause(), e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo());
+ public NetconfDocumentedException(DocumentedException exception) {
+ super(exception.getMessage(), (Exception) exception.getCause(), exception.getErrorType(),
+ exception.getErrorTag(), exception.getErrorSeverity(), exception.getErrorInfo());
}
- public static NetconfDocumentedException fromXMLDocument( Document fromDoc) {
+ public static NetconfDocumentedException fromXMLDocument(Document fromDoc) {
return new NetconfDocumentedException(DocumentedException.fromXMLDocument(fromDoc));
}
}
package org.opendaylight.netconf.api;
/**
- * Session capable of exi communication according to http://tools.ietf.org/html/draft-varga-netconf-exi-capability-02
+ * Session capable of exi communication according to http://tools.ietf.org/html/draft-varga-netconf-exi-capability-02.
*/
public interface NetconfExiSession {
/**
- * Start exi communication with parameters included in start-exi message
+ * Start exi communication with parameters included in start-exi message.
+ *
* @param startExiMessage start exi message
*/
void startExiCommunication(NetconfMessage startExiMessage);
/**
- * Stop exi communication, initiated by stop-exi message
+ * Stop exi communication, initiated by stop-exi message.
*/
void stopExiCommunication();
}
private final long sessionId;
- public NetconfServerSessionPreferences(final NetconfHelloMessage helloMessage,
- long sessionId) {
+ public NetconfServerSessionPreferences(final NetconfHelloMessage helloMessage, long sessionId) {
super(helloMessage);
this.sessionId = sessionId;
}
import org.opendaylight.protocol.framework.SessionListener;
-public interface NetconfSessionListener<S extends NetconfSession> extends SessionListener<NetconfMessage, S, NetconfTerminationReason> {
+public interface NetconfSessionListener
+ <S extends NetconfSession> extends SessionListener<NetconfMessage, S, NetconfTerminationReason> {
}
}
/**
+ * Getter for {@code NetconfHelloMessage}.
+ *
* @return the helloMessage
*/
public NetconfHelloMessage getHelloMessage() {
import org.w3c.dom.Element;
/**
- * NetconfMessage that can carry additional header with session metadata. See {@link NetconfHelloMessageAdditionalHeader}
+ * NetconfMessage that can carry additional header with session metadata.
+ * See {@link NetconfHelloMessageAdditionalHeader}
*/
public final class NetconfHelloMessage extends NetconfMessage {
private final NetconfHelloMessageAdditionalHeader additionalHeader;
- public NetconfHelloMessage(Document doc, NetconfHelloMessageAdditionalHeader additionalHeader) throws NetconfDocumentedException {
+ public NetconfHelloMessage(Document doc, NetconfHelloMessageAdditionalHeader additionalHeader)
+ throws NetconfDocumentedException {
super(doc);
checkHelloMessage(doc);
this.additionalHeader = additionalHeader;
}
public Optional<NetconfHelloMessageAdditionalHeader> getAdditionalHeader() {
- return additionalHeader== null ? Optional.<NetconfHelloMessageAdditionalHeader>absent() : Optional.of(additionalHeader);
+ return additionalHeader == null ? Optional.<NetconfHelloMessageAdditionalHeader>absent()
+ : Optional.of(additionalHeader);
}
private static void checkHelloMessage(Document doc) {
}
public static NetconfHelloMessage createClientHello(Iterable<String> capabilities,
- Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) throws NetconfDocumentedException {
+ Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) throws NetconfDocumentedException {
Document doc = createHelloMessageDoc(capabilities);
return additionalHeaderOptional.isPresent() ? new NetconfHelloMessage(doc, additionalHeaderOptional.get())
: new NetconfHelloMessage(doc);
return doc;
}
- public static NetconfHelloMessage createServerHello(Set<String> capabilities, long sessionId) throws NetconfDocumentedException {
+ public static NetconfHelloMessage createServerHello(Set<String> capabilities, long sessionId)
+ throws NetconfDocumentedException {
Document doc = createHelloMessageDoc(capabilities);
Element sessionIdElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
XmlNetconfConstants.SESSION_ID);
XmlElement element = XmlElement.fromDomElement(document.getDocumentElement());
try {
// accept even if hello has no namespace
- return element.getName().equals(HELLO_TAG) &&
- (!element.hasNamespace() || element.getNamespace().equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+ return element.getName().equals(HELLO_TAG)
+ && (!element.hasNamespace()
+ || element.getNamespace().equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
} catch (DocumentedException e) {
// Cannot happen, since we check for hasNamespace
throw new IllegalStateException(e);
private final String transport;
private final String sessionIdentifier;
- public NetconfHelloMessageAdditionalHeader(String userName, String hostAddress, String port, String transport, String sessionIdentifier) {
+ public NetconfHelloMessageAdditionalHeader(String userName, String hostAddress, String port,
+ String transport, String sessionIdentifier) {
this.userName = userName;
this.hostAddress = hostAddress;
this.port = port;
}
/**
- * Format additional header into a string suitable as a prefix for netconf hello message
+ * Format additional header into a string suitable as a prefix for netconf hello message.
*/
public String toFormattedString() {
Preconditions.checkNotNull(userName);
private static final Pattern PATTERN = Pattern
.compile("\\[(?<username>[^;]+);(?<address>.+)[:/](?<port>[0-9]+);(?<transport>[a-z]+)[^\\]]+\\]");
private static final Pattern CUSTOM_HEADER_PATTERN = Pattern
- .compile("\\[(?<username>[^;]+);(?<address>.+)[:/](?<port>[0-9]+);(?<transport>[a-z]+);(?<sessionIdentifier>[a-z]+)[^\\]]+\\]");
+ .compile("\\[(?<username>[^;]+);"
+ + "(?<address>.+)[:/](?<port>[0-9]+);(?<transport>[a-z]+);(?<sessionIdentifier>[a-z]+)[^\\]]+\\]");
/**
- * Parse additional header from a formatted string
+ * Parse additional header from a formatted string.
*/
public static NetconfHelloMessageAdditionalHeader fromString(String additionalHeader) {
String additionalHeaderTrimmed = additionalHeader.trim();
Sessions getSessions();
/**
- * Returns session monitoring service session listener, which is used to notify monitoring service about state of session.
+ * Returns session monitoring service session listener, which is used to notify monitoring service about state of
+ * session.
+ *
* @return session listener
*/
SessionListener getSessionListener();
Capabilities getCapabilities();
/**
- * Allows push based capabilities information transfer. After the listener is registered, current state is pushed to the listener.
+ * Allows push based capabilities information transfer. After the listener is registered, current state is pushed
+ * to the listener.
+ *
* @param listener Monitoring listener
* @return listener registration
*/
/**
* Allows push based sessions information transfer.
+ *
* @param listener Monitoring listener
* @return listener registration
*/
interface CapabilitiesListener {
/**
- * Callback used to notify about a change in used capabilities
+ * Callback used to notify about a change in used capabilities.
+ *
* @param capabilities resulting capabilities
*/
void onCapabilitiesChanged(Capabilities capabilities);
/**
- * Callback used to notify about a change in used schemas
+ * Callback used to notify about a change in used schemas.
+ *
* @param schemas resulting schemas
*/
void onSchemasChanged(Schemas schemas);
interface SessionsListener {
/**
- * Callback used to notify about netconf session start
+ * Callback used to notify about netconf session start.
+ *
* @param session started session
*/
void onSessionStarted(Session session);
/**
- * Callback used to notify about netconf session end
+ * Callback used to notify about netconf session end.
+ *
* @param session ended session
*/
void onSessionEnded(Session session);
* Callback used to notify about activity in netconf session, like
* rpc or notification. It is triggered at regular time interval. Session parameter
* contains only sessions which state was changed.
+ *
* @param sessions updated sessions
*/
void onSessionsUpdated(Collection<Session> sessions);
}
/**
- * Returns session, where event occurred
+ * Returns session, where event occurred.
+ *
* @return session
*/
public NetconfManagementSession getSession() {
}
/**
- * Returns event type
+ * Returns event type.
+ *
* @return type
*/
public Type getType() {
}
/**
- * Session event type
+ * Session event type.
*/
public enum Type {
/**
- * Correct rpc message received
+ * Correct rpc message received.
*/
IN_RPC_SUCCESS,
/**
- * Incorrect rpc message received
+ * Incorrect rpc message received.
*/
IN_RPC_FAIL,
OUT_RPC_ERROR,
/**
- * Notification message sent
+ * Notification message sent.
*/
NOTIFICATION
}
public interface SessionListener {
/**
- * Callback used to notify about netconf session start
+ * Callback used to notify about netconf session start.
+ *
* @param session started session
*/
void onSessionUp(NetconfManagementSession session);
/**
- * Callback used to notify about netconf session end
+ * Callback used to notify about netconf session end.
+ *
* @param session ended session
*/
void onSessionDown(NetconfManagementSession session);
/**
* Callback used to notify about activity in netconf session, like
- * rpc or notification
+ * rpc or notification.
+ *
* @param event session event, contains session and type of event
*/
void onSessionEvent(SessionEvent event);
/**
* These constants mark operation service factories that are auto wired with netconf endpoint
- * for config subsystem
+ * for config subsystem.
*/
public final class NetconfConstants {
/*
public static final String NETCONF_MONITORING = "ietf-netconf-monitoring";
public static final String NETCONF_NOTIFICATION = "ietf-netconf-notifications";
- public static final Set<String> CONFIG_SERVICE_MARKERS = Sets.newHashSet(SERVICE_NAME, CONFIG_NETCONF_CONNECTOR, NETCONF_MONITORING, NETCONF_NOTIFICATION);
+ public static final Set<String> CONFIG_SERVICE_MARKERS = Sets.newHashSet(SERVICE_NAME, CONFIG_NETCONF_CONNECTOR,
+ NETCONF_MONITORING, NETCONF_NOTIFICATION);
}
public static final String GET = "get";
public static final String GET_CONFIG = "get-config";
- public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 = XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
+ public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 =
+ XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
public static final String URN_IETF_PARAMS_NETCONF_BASE_1_0 = "urn:ietf:params:netconf:base:1.0";
public static final String URN_IETF_PARAMS_NETCONF_BASE_1_1 = "urn:ietf:params:netconf:base:1.1";
public static final String URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0 = "urn:ietf:params:xml:ns:netconf:exi:1.0";
- public static final String URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0 = "urn:ietf:params:netconf:capability:notification:1.0";
+ public static final String URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0 =
+ "urn:ietf:params:netconf:capability:notification:1.0";
- public static final String URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0 = "urn:ietf:params:netconf:capability:exi:1.0";
- public static final String URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING = "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring";
+ public static final String URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0 =
+ "urn:ietf:params:netconf:capability:exi:1.0";
+ public static final String URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING =
+ "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring";
}
public void setUp() throws Exception {
final XPathFactory xPathfactory = XPathFactory.newInstance();
xpath = xPathfactory.newXPath();
- xpath.setNamespaceContext( new NamespaceContext() {
+ xpath.setNamespaceContext(new NamespaceContext() {
@Override
public Iterator<?> getPrefixes(final String namespaceURI) {
- return Collections.singletonList( "netconf" ).iterator();
+ return Collections.singletonList("netconf").iterator();
}
@Override
public String getNamespaceURI(final String prefix) {
return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
}
- } );
+ });
}
@Test
public void testToAndFromXMLDocument() throws XPathExpressionException {
final String errorMessage = "mock error message";
- DocumentedException ex = new NetconfDocumentedException( errorMessage, null,
+ DocumentedException ex = new NetconfDocumentedException(errorMessage, null,
DocumentedException.ErrorType.PROTOCOL,
DocumentedException.ErrorTag.DATA_EXISTS,
DocumentedException.ErrorSeverity.WARNING,
- ImmutableMap.of( "foo", "bar" ) );
+ ImmutableMap.of("foo", "bar"));
final Document doc = ex.toXMLDocument();
- assertNotNull( "Document is null", doc );
+ assertNotNull("Document is null", doc);
final Node rootNode = doc.getDocumentElement();
- assertEquals( "getNamespaceURI", "urn:ietf:params:xml:ns:netconf:base:1.0", rootNode.getNamespaceURI() );
- assertEquals( "getLocalName", "rpc-reply", rootNode.getLocalName() );
+ assertEquals("getNamespaceURI", "urn:ietf:params:xml:ns:netconf:base:1.0", rootNode.getNamespaceURI());
+ assertEquals("getLocalName", "rpc-reply", rootNode.getLocalName());
final Node rpcErrorNode = getNode("/netconf:rpc-reply/netconf:rpc-error", rootNode);
- assertNotNull( "rpc-error not found", rpcErrorNode );
+ assertNotNull("rpc-error not found", rpcErrorNode);
final Node errorTypeNode = getNode("netconf:error-type", rpcErrorNode);
- assertNotNull( "error-type not found", errorTypeNode );
+ assertNotNull("error-type not found", errorTypeNode);
assertEquals("error-type", DocumentedException.ErrorType.PROTOCOL.getTypeValue(),
- errorTypeNode.getTextContent() );
+ errorTypeNode.getTextContent());
final Node errorTagNode = getNode("netconf:error-tag", rpcErrorNode);
- assertNotNull( "error-tag not found", errorTagNode );
+ assertNotNull("error-tag not found", errorTagNode);
assertEquals("error-tag", DocumentedException.ErrorTag.DATA_EXISTS.getTagValue(),
- errorTagNode.getTextContent() );
+ errorTagNode.getTextContent());
final Node errorSeverityNode = getNode("netconf:error-severity", rpcErrorNode);
- assertNotNull( "error-severity not found", errorSeverityNode );
+ assertNotNull("error-severity not found", errorSeverityNode);
assertEquals("error-severity", DocumentedException.ErrorSeverity.WARNING.getSeverityValue(),
- errorSeverityNode.getTextContent() );
+ errorSeverityNode.getTextContent());
final Node errorInfoNode = getNode("netconf:error-info/netconf:foo", rpcErrorNode);
- assertNotNull( "foo not found", errorInfoNode );
- assertEquals( "foo", "bar", errorInfoNode.getTextContent() );
+ assertNotNull("foo not found", errorInfoNode);
+ assertEquals("foo", "bar", errorInfoNode.getTextContent());
final Node errorMsgNode = getNode("netconf:error-message", rpcErrorNode);
- assertNotNull( "error-message not found", errorMsgNode );
- assertEquals( "error-message", errorMessage, errorMsgNode.getTextContent() );
+ assertNotNull("error-message not found", errorMsgNode);
+ assertEquals("error-message", errorMessage, errorMsgNode.getTextContent());
// Test fromXMLDocument
- ex = DocumentedException.fromXMLDocument( doc );
+ ex = DocumentedException.fromXMLDocument(doc);
- assertNotNull( "NetconfDocumentedException is null", ex );
+ assertNotNull("NetconfDocumentedException is null", ex);
assertEquals("getErrorSeverity", DocumentedException.ErrorSeverity.WARNING, ex.getErrorSeverity());
assertEquals("getErrorTag", DocumentedException.ErrorTag.DATA_EXISTS, ex.getErrorTag());
assertEquals("getErrorType", DocumentedException.ErrorType.PROTOCOL, ex.getErrorType());
- assertEquals( "getLocalizedMessage", errorMessage, ex.getLocalizedMessage() );
- assertEquals( "getErrorInfo", ImmutableMap.of( "foo", "bar" ), ex.getErrorInfo() );
+ assertEquals("getLocalizedMessage", errorMessage, ex.getLocalizedMessage());
+ assertEquals("getErrorInfo", ImmutableMap.of("foo", "bar"), ex.getErrorInfo());
}
@SuppressWarnings("unchecked")
<T> T getNode(final String xpathExp, final Node node) throws XPathExpressionException {
- return (T)xpath.compile( xpathExp ).evaluate( node, XPathConstants.NODE );
+ return (T) xpath.compile(xpathExp).evaluate(node, XPathConstants.NODE);
}
}
@Test
public void testStaticConstructor() throws Exception {
- NetconfHelloMessageAdditionalHeader h = NetconfHelloMessageAdditionalHeader.fromString(customHeader);
- assertEquals(h.toString(), header.toString());
- assertEquals(h.toFormattedString(), header.toFormattedString());
+ NetconfHelloMessageAdditionalHeader header = NetconfHelloMessageAdditionalHeader.fromString(customHeader);
+ assertEquals(header.toString(), this.header.toString());
+ assertEquals(header.toFormattedString(), this.header.toFormattedString());
}
}
package org.opendaylight.netconf.api.messages;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@Test
public void testConstructor() throws NetconfDocumentedException {
- NetconfHelloMessageAdditionalHeader additionalHeader = new NetconfHelloMessageAdditionalHeader("name","host","1","transp","id");
+ NetconfHelloMessageAdditionalHeader additionalHeader = new NetconfHelloMessageAdditionalHeader("name",
+ "host", "1", "transp", "id");
NetconfHelloMessage message = NetconfHelloMessage.createClientHello(caps, Optional.of(additionalHeader));
assertTrue(NetconfHelloMessage.isHelloMessage(message));
assertEquals(Optional.of(additionalHeader), message.getAdditionalHeader());