blob: 45679a3e13ffd5024efb8f4fa0c89c1459dcc687 [file] [log] [blame]
Sean Condond911af92017-07-19 18:05:27 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Sean Condond911af92017-07-19 18:05:27 +01003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.yang;
17
18import org.onosproject.drivers.microsemi.yang.MicrosemiModelRegistrator;
19import org.onosproject.yang.compiler.datamodel.YangNode;
Sean Condond911af92017-07-19 18:05:27 +010020import org.onosproject.yang.runtime.DefaultModelRegistrationParam;
21import org.onosproject.yang.runtime.ModelRegistrationParam;
22import org.onosproject.yang.runtime.YangModelRegistry;
Sean Condond911af92017-07-19 18:05:27 +010023import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
24
25import java.io.File;
26import java.io.IOException;
27import java.util.ArrayList;
28import java.util.List;
29
Thomas Vachuska89534452017-07-28 10:20:12 -070030import static org.onosproject.yang.compiler.tool.YangCompilerManager.deSerializeDataModel;
31import static org.onosproject.yang.compiler.tool.YangCompilerManager.getYangNodes;
32import static org.onosproject.yang.compiler.tool.YangCompilerManager.processYangModel;
33
Sean Condond911af92017-07-19 18:05:27 +010034public class MockMicrosemiRegistrator extends MicrosemiModelRegistrator {
35 private static final String FS = File.separator;
36 private static final String PATH = System.getProperty("user.dir") +
37 FS + "buck-out" + FS + "gen" +
38 FS + "models" + FS + "microsemi" + FS + "onos-models-microsemi-schema" + FS;
39 private static final String SER_FILE_PATH = "yang" + FS + "resources" +
40 FS + "YangMetaData.ser";
41 private static final String META_PATH =
42 PATH.replace("drivers/microsemi", "")
43 + SER_FILE_PATH;
44
45 @Override
46 public void activate() {
47 modelRegistry = new DefaultYangModelRegistry();
48 List<YangNode> nodes = new ArrayList<>();
49 try {
Thomas Vachuska89534452017-07-28 10:20:12 -070050 nodes.addAll(getYangNodes(deSerializeDataModel(META_PATH)));
Sean Condond911af92017-07-19 18:05:27 +010051
Thomas Vachuska89534452017-07-28 10:20:12 -070052 model = processYangModel(META_PATH, nodes, "test", false);
Sean Condond911af92017-07-19 18:05:27 +010053 ModelRegistrationParam.Builder b =
54 DefaultModelRegistrationParam.builder().setYangModel(model);
55 b.setYangModel(model);
56
57 ModelRegistrationParam registrationParam = getAppInfo(b).setYangModel(model).build();
58 modelRegistry.registerModel(registrationParam);
59 } catch (IOException ioe) {
60 ioe.printStackTrace();
61 }
62 }
63
64 public YangModelRegistry registry() {
65 return modelRegistry;
66 }
67}