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 | |
Sean Condon | cf2751f | 2017-11-28 17:29:30 +0000 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
Sean Condon | 1dbcd71 | 2017-10-19 12:09:21 +0100 | [diff] [blame] | 19 | import org.onosproject.models.microsemi.MicrosemiModelRegistrator; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 20 | import org.onosproject.yang.compiler.datamodel.YangNode; |
Ray Milkey | 8e2c339 | 2017-10-16 14:57:02 -0700 | [diff] [blame] | 21 | import org.onosproject.yang.compiler.tool.YangNodeInfo; |
Sean Condon | cf2751f | 2017-11-28 17:29:30 +0000 | [diff] [blame] | 22 | import org.onosproject.yang.model.YangModuleId; |
| 23 | import org.onosproject.yang.runtime.AppModuleInfo; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 24 | import org.onosproject.yang.runtime.DefaultModelRegistrationParam; |
| 25 | import org.onosproject.yang.runtime.ModelRegistrationParam; |
| 26 | import org.onosproject.yang.runtime.YangModelRegistry; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 27 | import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry; |
| 28 | |
| 29 | import java.io.File; |
| 30 | import java.io.IOException; |
| 31 | import java.util.ArrayList; |
Sean Condon | cf2751f | 2017-11-28 17:29:30 +0000 | [diff] [blame] | 32 | import java.util.HashMap; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 33 | import java.util.List; |
Sean Condon | cf2751f | 2017-11-28 17:29:30 +0000 | [diff] [blame] | 34 | import java.util.Map; |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 35 | |
Yuta HIGUCHI | 2e4a6d4 | 2017-08-25 10:51:40 -0700 | [diff] [blame] | 36 | import static org.junit.Assert.fail; |
Thomas Vachuska | 8953445 | 2017-07-28 10:20:12 -0700 | [diff] [blame] | 37 | import static org.onosproject.yang.compiler.tool.YangCompilerManager.deSerializeDataModel; |
| 38 | import static org.onosproject.yang.compiler.tool.YangCompilerManager.getYangNodes; |
| 39 | import static org.onosproject.yang.compiler.tool.YangCompilerManager.processYangModel; |
| 40 | |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 41 | public class MockMicrosemiRegistrator extends MicrosemiModelRegistrator { |
| 42 | private static final String FS = File.separator; |
| 43 | private static final String PATH = System.getProperty("user.dir") + |
| 44 | FS + "buck-out" + FS + "gen" + |
| 45 | FS + "models" + FS + "microsemi" + FS + "onos-models-microsemi-schema" + FS; |
| 46 | private static final String SER_FILE_PATH = "yang" + FS + "resources" + |
| 47 | FS + "YangMetaData.ser"; |
| 48 | private static final String META_PATH = |
Sean Condon | fa9c77d | 2018-02-28 09:03:00 +0000 | [diff] [blame] | 49 | PATH.replace("drivers/microsemi/ea1000", "") |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 50 | + SER_FILE_PATH; |
| 51 | |
| 52 | @Override |
| 53 | public void activate() { |
| 54 | modelRegistry = new DefaultYangModelRegistry(); |
Ray Milkey | 8e2c339 | 2017-10-16 14:57:02 -0700 | [diff] [blame] | 55 | List<YangNodeInfo> nodes = new ArrayList<>(); |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 56 | try { |
Ray Milkey | 8e2c339 | 2017-10-16 14:57:02 -0700 | [diff] [blame] | 57 | for (YangNode node : getYangNodes(deSerializeDataModel(META_PATH))) { |
| 58 | nodes.add(new YangNodeInfo(node, false)); |
| 59 | } |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 60 | |
Thomas Vachuska | 8953445 | 2017-07-28 10:20:12 -0700 | [diff] [blame] | 61 | model = processYangModel(META_PATH, nodes, "test", false); |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 62 | ModelRegistrationParam.Builder b = |
| 63 | DefaultModelRegistrationParam.builder().setYangModel(model); |
| 64 | b.setYangModel(model); |
| 65 | |
| 66 | ModelRegistrationParam registrationParam = getAppInfo(b).setYangModel(model).build(); |
| 67 | modelRegistry.registerModel(registrationParam); |
| 68 | } catch (IOException ioe) { |
| 69 | ioe.printStackTrace(); |
Yuta HIGUCHI | 2e4a6d4 | 2017-08-25 10:51:40 -0700 | [diff] [blame] | 70 | fail(); |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
Sean Condon | cf2751f | 2017-11-28 17:29:30 +0000 | [diff] [blame] | 74 | |
| 75 | public void addAppInfo(Map<YangModuleId, AppModuleInfo> map) { |
| 76 | Map<YangModuleId, AppModuleInfo> appInfoCopy = new HashMap<>(); |
| 77 | appInfoCopy.putAll(appInfo); |
| 78 | appInfoCopy.putAll(map); |
| 79 | appInfo = ImmutableMap.copyOf(appInfoCopy); |
| 80 | } |
| 81 | |
Sean Condon | d911af9 | 2017-07-19 18:05:27 +0100 | [diff] [blame] | 82 | public YangModelRegistry registry() { |
| 83 | return modelRegistry; |
| 84 | } |
| 85 | } |