import static org.mockito.Mockito.when;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.io.FileNotFoundException;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.netconf.sal.rest.api.Draft02;
import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
+import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.SchemaAwareBuilders;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
*/
public class RestconfImplTest {
- private static SchemaContext schemaContext;
+ private static EffectiveModelContext schemaContext;
private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
@BeforeClass
public static void init() throws FileNotFoundException, ReactorException {
- schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
- final Set<Module> allModules = schemaContext.getModules();
- assertNotNull(allModules);
+ schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs", "/modules/restconf-module-testing");
+ }
+
+ @AfterClass
+ public static void cleanUp() {
+ WebSocketServer.destroyInstance(); // NETCONF-604
}
@Test
final MapEntryNode payload = mock(MapEntryNode.class);
final NodeIdentifierWithPredicates nodeIdWithPred =
- new NodeIdentifierWithPredicates(keyDef, keyDef, al2.toArray());
+ NodeIdentifierWithPredicates.of(keyDef, keyDef, al2.toArray());
when(payload.getIdentifier()).thenReturn(nodeIdWithPred);
final List<QName> keyDefinitions = new ArrayList<>();
final DOMRpcService rpcService = mock(DOMRpcService.class);
doReturn(Optional.of(rpcService)).when(mount).getService(DOMRpcService.class);
doReturn(immediateFluentFuture(mock(DOMRpcResult.class))).when(rpcService)
- .invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+ .invokeRpc(any(QName.class), any(NormalizedNode.class));
this.restconfImpl.invokeRpc("randomId", ctx, uriInfo);
this.restconfImpl.invokeRpc("ietf-netconf", ctx, uriInfo);
- verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), isNull());
+ verify(rpcService, times(2)).invokeRpc(any(QName.class), any());
}
/**
"2014-01-14", "create-notification-stream")).when(schemaNode).getQName();
doReturn(null).when(iiCtx).getMountPoint();
- final Set<DataContainerChild<?, ?>> children = new HashSet<>();
- final DataContainerChild<?, ?> child = mock(DataContainerChild.class,
+ final Set<DataContainerChild> children = new HashSet<>();
+ final DataContainerChild child = mock(DataContainerChild.class,
Mockito.withSettings().extraInterfaces(LeafSetNode.class));
final LeafSetEntryNode entryNode = mock(LeafSetEntryNode.class);
- when(entryNode.getValue()).thenReturn("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)toastDone");
- when(((LeafSetNode) child).getValue()).thenReturn(Sets.newHashSet(entryNode));
+ when(entryNode.body()).thenReturn("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)toastDone");
+ when(((LeafSetNode) child).body()).thenReturn(Sets.newHashSet(entryNode));
children.add(child);
- final NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class,
+ final NormalizedNode normalizedNode = mock(NormalizedNode.class,
Mockito.withSettings().extraInterfaces(ContainerNode.class));
doReturn(normalizedNode).when(payload).getData();
- doReturn(children).when(normalizedNode).getValue();
+ doReturn(children).when(normalizedNode).body();
// register notification
final NormalizedNodeContext context = this.restconfImpl
assertNotNull(context);
}
+ /**
+ * Tests stream entry node.
+ */
+ @Test
+ public void toStreamEntryNodeTest() {
+ final Module restconfModule = this.controllerContext.getRestconfModule();
+ final DataSchemaNode streamSchemaNode = this.controllerContext
+ .getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
+ final ListSchemaNode listStreamSchemaNode = (ListSchemaNode) streamSchemaNode;
+ final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamNodeValues =
+ SchemaAwareBuilders.mapEntryBuilder(listStreamSchemaNode);
+ List<DataSchemaNode> instanceDataChildrenByName =
+ ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "name");
+ final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ streamNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) nameSchemaNode)
+ .withValue("")
+ .build());
+
+ instanceDataChildrenByName =
+ ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "description");
+ final DataSchemaNode descriptionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ streamNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) nameSchemaNode)
+ .withValue("DESCRIPTION_PLACEHOLDER")
+ .build());
+
+ instanceDataChildrenByName =
+ ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "replay-support");
+ final DataSchemaNode replaySupportSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ streamNodeValues.withChild(
+ SchemaAwareBuilders.leafBuilder((LeafSchemaNode) replaySupportSchemaNode).withValue(Boolean.TRUE).build());
+
+ instanceDataChildrenByName =
+ ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "replay-log-creation-time");
+ final DataSchemaNode replayLogCreationTimeSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ streamNodeValues.withChild(
+ SchemaAwareBuilders.leafBuilder((LeafSchemaNode) replayLogCreationTimeSchemaNode).withValue("").build());
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "events");
+ final DataSchemaNode eventsSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ streamNodeValues.withChild(
+ SchemaAwareBuilders.leafBuilder((LeafSchemaNode) eventsSchemaNode).withValue(Empty.getInstance()).build());
+ assertNotNull(streamNodeValues.build());
+ }
+
/**
* Subscribe for notification stream of toaster module.
*/