- static String convertCompositeNodeDataAndYangToJson(CompositeNode compositeNode, String yangPath, String outputPath) {
- String jsonResult = null;
- Set<Module> modules = null;
-
- try {
- modules = TestUtils.loadModules(ToJsonBasicDataTypesTest.class.getResource(yangPath).getPath());
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- assertNotNull("modules can't be null.", modules);
-
- assertNotNull("Composite node can't be null", compositeNode);
-
- StructuredDataToJsonProvider structuredDataToJsonProvider = StructuredDataToJsonProvider.INSTANCE;
- for (Module module : modules) {
- ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
- for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
- StructuredData structuredData = new StructuredData(compositeNode, dataSchemaNode);
- try {
- structuredDataToJsonProvider.writeTo(structuredData, null, null, null, null, null, byteArrayOS);
- } catch (WebApplicationException | IOException e) {
- e.printStackTrace();
- }
- assertFalse(
- "Returning JSON string can't be empty for node " + dataSchemaNode.getQName().getLocalName(),
- byteArrayOS.toString().isEmpty());
- }
- jsonResult = byteArrayOS.toString();
- try {
- outputToFile(byteArrayOS, outputPath);
- } catch (IOException e) {
- System.out.println("Output file wasn't cloased sucessfuly.");
- }
-
- }
- return jsonResult;
- }
-
- static CompositeNode loadCompositeNode(String xmlDataPath) {
- InputStream xmlStream = ToJsonBasicDataTypesTest.class.getResourceAsStream(xmlDataPath);
- CompositeNode compositeNode = null;
- try {
- compositeNode = TestUtils.loadCompositeNode(xmlStream);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- return compositeNode;
- }
+ /**
+ *
+ * Fill missing data (namespaces) and build correct data type in
+ * {@code compositeNode} according to {@code dataSchemaNode}. The method
+ * {@link RestconfImpl#createConfigurationData createConfigurationData} is
+ * used because it contains calling of method {code normalizeNode}
+ */
+ public static void normalizeCompositeNode(CompositeNode compositeNode, Set<Module> modules, String schemaNodePath) {
+ RestconfImpl restconf = RestconfImpl.getInstance();
+ ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext(modules));