blob: 111ec8aac1123985b93e1248db3541adf5588645 [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
Sean Condon1dbcd712017-10-19 12:09:21 +010018import org.onosproject.models.microsemi.MicrosemiModelRegistrator;
Sean Condond911af92017-07-19 18:05:27 +010019import org.onosproject.yang.compiler.datamodel.YangNode;
Ray Milkey8e2c3392017-10-16 14:57:02 -070020import org.onosproject.yang.compiler.tool.YangNodeInfo;
Sean Condond911af92017-07-19 18:05:27 +010021import org.onosproject.yang.runtime.DefaultModelRegistrationParam;
22import org.onosproject.yang.runtime.ModelRegistrationParam;
23import org.onosproject.yang.runtime.YangModelRegistry;
Sean Condond911af92017-07-19 18:05:27 +010024import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
25
26import java.io.File;
27import java.io.IOException;
28import java.util.ArrayList;
29import java.util.List;
30
Yuta HIGUCHI2e4a6d42017-08-25 10:51:40 -070031import static org.junit.Assert.fail;
Thomas Vachuska89534452017-07-28 10:20:12 -070032import static org.onosproject.yang.compiler.tool.YangCompilerManager.deSerializeDataModel;
33import static org.onosproject.yang.compiler.tool.YangCompilerManager.getYangNodes;
34import static org.onosproject.yang.compiler.tool.YangCompilerManager.processYangModel;
35
Sean Condond911af92017-07-19 18:05:27 +010036public class MockMicrosemiRegistrator extends MicrosemiModelRegistrator {
37 private static final String FS = File.separator;
38 private static final String PATH = System.getProperty("user.dir") +
39 FS + "buck-out" + FS + "gen" +
40 FS + "models" + FS + "microsemi" + FS + "onos-models-microsemi-schema" + FS;
41 private static final String SER_FILE_PATH = "yang" + FS + "resources" +
42 FS + "YangMetaData.ser";
43 private static final String META_PATH =
44 PATH.replace("drivers/microsemi", "")
45 + SER_FILE_PATH;
46
47 @Override
48 public void activate() {
49 modelRegistry = new DefaultYangModelRegistry();
Ray Milkey8e2c3392017-10-16 14:57:02 -070050 List<YangNodeInfo> nodes = new ArrayList<>();
Sean Condond911af92017-07-19 18:05:27 +010051 try {
Ray Milkey8e2c3392017-10-16 14:57:02 -070052 for (YangNode node : getYangNodes(deSerializeDataModel(META_PATH))) {
53 nodes.add(new YangNodeInfo(node, false));
54 }
Sean Condond911af92017-07-19 18:05:27 +010055
Thomas Vachuska89534452017-07-28 10:20:12 -070056 model = processYangModel(META_PATH, nodes, "test", false);
Sean Condond911af92017-07-19 18:05:27 +010057 ModelRegistrationParam.Builder b =
58 DefaultModelRegistrationParam.builder().setYangModel(model);
59 b.setYangModel(model);
60
61 ModelRegistrationParam registrationParam = getAppInfo(b).setYangModel(model).build();
62 modelRegistry.registerModel(registrationParam);
63 } catch (IOException ioe) {
64 ioe.printStackTrace();
Yuta HIGUCHI2e4a6d42017-08-25 10:51:40 -070065 fail();
Sean Condond911af92017-07-19 18:05:27 +010066 }
67 }
68
69 public YangModelRegistry registry() {
70 return modelRegistry;
71 }
72}