X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-monitoring%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fmonitoring%2Fxml%2FJaxBSerializerTest.java;h=e19febf1a7d4a89a757d26dee7ecfc5ea60036ec;hb=refs%2Fchanges%2F13%2F23413%2F26;hp=d0d587fb84263c02ef99cb0727de1d4c81b28223;hpb=e90bec01888e6b2a2503d21de25f3a674d607163;p=controller.git diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java index d0d587fb84..e19febf1a7 100644 --- a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java @@ -1,22 +1,27 @@ /* -* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. -* -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0 which accompanies this distribution, -* and is available at http://www.eclipse.org/legal/epl-v10.html -*/ + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.netconf.monitoring.xml; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import com.google.common.base.Optional; import com.google.common.collect.Lists; +import java.util.Set; import org.hamcrest.CoreMatchers; import org.junit.Test; +import org.opendaylight.controller.config.util.capability.Capability; +import org.opendaylight.controller.config.util.xml.XmlUtil; +import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.monitoring.xml.model.NetconfState; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.DomainName; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Host; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; @@ -25,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfSsh; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Transport; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang; +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.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; @@ -38,10 +44,25 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types. public class JaxBSerializerTest { @Test - public void testName() throws Exception { + public void testSerialization() throws Exception { final NetconfMonitoringService service = new NetconfMonitoringService() { + @Override + public void onCapabilitiesChanged(Set added, Set removed) { + + } + + @Override + public void onSessionUp(final NetconfManagementSession session) { + + } + + @Override + public void onSessionDown(final NetconfManagementSession session) { + + } + @Override public Sessions getSessions() { return new SessionsBuilder().setSession(Lists.newArrayList(getMockSession(NetconfTcp.class), getMockSession(NetconfSsh.class))).build(); @@ -51,31 +72,51 @@ public class JaxBSerializerTest { public Schemas getSchemas() { return new SchemasBuilder().setSchema(Lists.newArrayList(getMockSchema("id", "v1", Yang.class), getMockSchema("id2", "", Yang.class))).build(); } + + @Override + public String getSchemaForCapability(final String moduleName, final Optional revision) { + return null; + } + + @Override + public Capabilities getCapabilities() { + return null; + } + + @Override + public AutoCloseable registerListener(final MonitoringListener listener) { + return new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + } }; final NetconfState model = new NetconfState(service); - final String xml = XmlUtil.toString(new JaxBSerializer().toXml(model)); + final String xml = XmlUtil.toString(new JaxBSerializer().toXml(model)).replaceAll("\\s", ""); assertThat(xml, CoreMatchers.containsString( - "\n" + - "yang\n" + - "id\n" + - "NETCONF\n" + - "localhost\n" + - "v1\n" + - "\n")); + "" + + "yang" + + "id" + + "NETCONF" + + "localhost" + + "v1" + + "")); assertThat(xml, CoreMatchers.containsString( - "\n" + - "1\n" + - "0\n" + - "0\n" + - "loginTime\n" + - "0\n" + - "0\n" + - "client\n" + - "address/port\n" + - "ncme:netconf-tcp\n" + - "username\n" + + "" + + "1" + + "0" + + "0" + + "2010-10-10T12:32:32Z" + + "0" + + "0" + + "client" + + "192.168.1.1" + + "ncme:netconf-tcp" + + "username" + "")); } @@ -96,8 +137,8 @@ public class JaxBSerializerTest { final Session1 mockedSession1 = mock(Session1.class); doReturn("client").when(mockedSession1).getSessionIdentifier(); doReturn(1L).when(mocked).getSessionId(); - doReturn(new DateAndTime("loginTime")).when(mocked).getLoginTime(); - doReturn(new Host(new DomainName("address/port"))).when(mocked).getSourceHost(); + doReturn(new DateAndTime("2010-10-10T12:32:32Z")).when(mocked).getLoginTime(); + doReturn(new Host(new DomainName("192.168.1.1"))).when(mocked).getSourceHost(); doReturn(new ZeroBasedCounter32(0L)).when(mocked).getInBadRpcs(); doReturn(new ZeroBasedCounter32(0L)).when(mocked).getInRpcs(); doReturn(new ZeroBasedCounter32(0L)).when(mocked).getOutNotifications();