- private static void addDummyNamespaceToAllNodes(final NodeWrapper<?> wrappedNode) throws URISyntaxException {
- wrappedNode.setNamespace(new URI(""));
- if (wrappedNode instanceof CompositeNodeWrapper) {
- for (final NodeWrapper<?> childNodeWrapper : ((CompositeNodeWrapper) wrappedNode).getValues()) {
- addDummyNamespaceToAllNodes(childNodeWrapper);
- }
- }
- }
-
- private static void prepareMocksForRestconf(final Set<Module> modules, final RestconfImpl restconf) {
- final ControllerContext controllerContext = ControllerContext.getInstance();
- final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
-
- controllerContext.setSchemas(TestUtils.loadSchemaContext(modules));
-
- when(mockedBrokerFacade.commitConfigurationDataPut(any(YangInstanceIdentifier.class), any(NormalizedNode.class)))
- .thenReturn(mock(CheckedFuture.class));
-
- restconf.setControllerContext(controllerContext);
- restconf.setBroker(mockedBrokerFacade);
- }
-
- public static Node<?> readInputToCnSn(final String path, final boolean dummyNamespaces,
- final MessageBodyReader<Node<?>> reader) throws WebApplicationException {
-
- final InputStream inputStream = TestUtils.class.getResourceAsStream(path);
- try {
- final Node<?> node = reader.readFrom(null, null, null, null, null, inputStream);
- assertTrue(node instanceof CompositeNodeWrapper);
- if (dummyNamespaces) {
- try {
- TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) node);
- return ((CompositeNodeWrapper) node).unwrap();
- } catch (final URISyntaxException e) {
- LOG.error(e.getMessage());
- assertTrue(e.getMessage(), false);
- }
- }
- return node;
- } catch (final IOException e) {
- LOG.error(e.getMessage());
- assertTrue(e.getMessage(), false);
- }
- return null;
- }
-
-// public static Node<?> readInputToCnSnNew(String path, MessageBodyReader<Node<?>> reader) throws WebApplicationException {
-// InputStream inputStream = TestUtils.class.getResourceAsStream(path);
-// try {
-// return reader.readFrom(null, null, null, null, null, inputStream);
-// } catch (IOException e) {
-// LOG.error(e.getMessage());
-// assertTrue(e.getMessage(), false);
-// }
-// return null;
-// }
-
- public static Node<?> readInputToCnSn(final String path, final MessageBodyReader<Node<?>> reader) {
- return readInputToCnSn(path, false, reader);
- }
-
- public static String writeCompNodeWithSchemaContextToOutput(final Node<?> node, final Set<Module> modules,
- final DataSchemaNode dataSchemaNode, final MessageBodyWriter<StructuredData> messageBodyWriter) throws IOException,
- WebApplicationException {
-
- assertNotNull(dataSchemaNode);
- assertNotNull("Composite node can't be null", node);
- final ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
-
- ControllerContext.getInstance().setSchemas(loadSchemaContext(modules));
-
- assertTrue(node instanceof CompositeNode);
- messageBodyWriter.writeTo(new StructuredData((CompositeNode)node, dataSchemaNode, null), null, null, null, null,
- null, byteArrayOS);
-
- return byteArrayOS.toString();
- }
-