Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.yang; |
| 17 | |
| 18 | import org.onosproject.drivers.microsemi.yang.MicrosemiModelRegistrator; |
| 19 | import org.onosproject.yang.compiler.datamodel.YangNode; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 20 | import org.onosproject.yang.runtime.DefaultModelRegistrationParam; |
| 21 | import org.onosproject.yang.runtime.ModelRegistrationParam; |
| 22 | import org.onosproject.yang.runtime.YangModelRegistry; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 23 | import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry; |
| 24 | |
| 25 | import java.io.File; |
| 26 | import java.io.IOException; |
| 27 | import java.util.ArrayList; |
| 28 | import java.util.List; |
| 29 | |
Thomas Vachuska | 8953445 | 2017-07-28 10:20:12 -0700 | [diff] [blame] | 30 | import static org.onosproject.yang.compiler.tool.YangCompilerManager.deSerializeDataModel; |
| 31 | import static org.onosproject.yang.compiler.tool.YangCompilerManager.getYangNodes; |
| 32 | import static org.onosproject.yang.compiler.tool.YangCompilerManager.processYangModel; |
| 33 | |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 34 | public 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 Vachuska | 8953445 | 2017-07-28 10:20:12 -0700 | [diff] [blame] | 50 | nodes.addAll(getYangNodes(deSerializeDataModel(META_PATH))); |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 51 | |
Thomas Vachuska | 8953445 | 2017-07-28 10:20:12 -0700 | [diff] [blame] | 52 | model = processYangModel(META_PATH, nodes, "test", false); |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 53 | 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 | } |