blob: eb7e2413edf271e1f147385b29bd096c0726dfb2 [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
Yuta HIGUCHI2e4a6d42017-08-25 10:51:40 -070030import static org.junit.Assert.fail;
Thomas Vachuska89534452017-07-28 10:20:12 -070031import static org.onosproject.yang.compiler.tool.YangCompilerManager.deSerializeDataModel;
32import static org.onosproject.yang.compiler.tool.YangCompilerManager.getYangNodes;
33import static org.onosproject.yang.compiler.tool.YangCompilerManager.processYangModel;
34
Sean Condond911af92017-07-19 18:05:27 +010035public class MockMicrosemiRegistrator extends MicrosemiModelRegistrator {
36 private static final String FS = File.separator;
37 private static final String PATH = System.getProperty("user.dir") +
38 FS + "buck-out" + FS + "gen" +
39 FS + "models" + FS + "microsemi" + FS + "onos-models-microsemi-schema" + FS;
40 private static final String SER_FILE_PATH = "yang" + FS + "resources" +
41 FS + "YangMetaData.ser";
42 private static final String META_PATH =
43 PATH.replace("drivers/microsemi", "")
44 + SER_FILE_PATH;
45
46 @Override
47 public void activate() {
48 modelRegistry = new DefaultYangModelRegistry();
49 List<YangNode> nodes = new ArrayList<>();
50 try {
Thomas Vachuska89534452017-07-28 10:20:12 -070051 nodes.addAll(getYangNodes(deSerializeDataModel(META_PATH)));
Sean Condond911af92017-07-19 18:05:27 +010052
Thomas Vachuska89534452017-07-28 10:20:12 -070053 model = processYangModel(META_PATH, nodes, "test", false);
Sean Condond911af92017-07-19 18:05:27 +010054 ModelRegistrationParam.Builder b =
55 DefaultModelRegistrationParam.builder().setYangModel(model);
56 b.setYangModel(model);
57
58 ModelRegistrationParam registrationParam = getAppInfo(b).setYangModel(model).build();
59 modelRegistry.registerModel(registrationParam);
60 } catch (IOException ioe) {
61 ioe.printStackTrace();
Yuta HIGUCHI2e4a6d42017-08-25 10:51:40 -070062 fail();
Sean Condond911af92017-07-19 18:05:27 +010063 }
64 }
65
66 public YangModelRegistry registry() {
67 return modelRegistry;
68 }
69}