Honeynode test tool
[transportpce.git] / tests / honeynode / honeynode-plugin-impl / src / test / java / io / fd / honeycomb / transportpce / device / test / CreateDeviceFromXMLFileTest.java
1 /*
2  * Copyright (c) 2018 Orange and/or its affiliates.
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 io.fd.honeycomb.transportpce.device.test;
17
18 import io.fd.honeycomb.transportpce.device.tools.DefaultDeviceFactory;
19 import io.fd.honeycomb.transportpce.test.common.DataStoreContext;
20 import io.fd.honeycomb.transportpce.test.common.DataStoreContextImpl;
21
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.Collection;
25
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.Parameterized;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Test to create {@link OrgOpenroadmDevice} object
36  * from xml file or String using Yangtools
37  *
38  * @author Martial COULIBALY ( martial.coulibaly@gfi.com ) on behalf of Orange
39  */
40 @RunWith(Parameterized.class)
41 public class CreateDeviceFromXMLFileTest {
42     private static final Logger LOG = LoggerFactory.getLogger(CreateDeviceFromXMLFileTest.class);
43     private static final String DEVICE_OPER_IN = "src/main/resources/honeycomb-minimal-resources/config/device/sample-config-ROADM.xml";
44     private String xml;
45
46
47     public CreateDeviceFromXMLFileTest(String xmlData) {
48         this.xml = xmlData;
49     }
50
51     @Parameterized.Parameters
52     public static Collection<Object[]> stringXML() {
53         return Arrays.asList(new Object[][]{
54             {DeviceOperToConfig.getDeviceFromXML(DeviceOperToConfig.operToConfig())}
55 //                {DeviceOperToConfig.operToConfig()}
56
57         });
58     }
59
60     /**
61      * This test  create instance of
62      * {@link OrgOpenroadmDevice} with String xml
63      * from {@link DeviceOperToConfig#operToConfig()}
64      * function as parameters.
65      *
66      * @throws NullPointerException
67      */
68     @Test
69     public void createDeviceFromString() throws NullPointerException {
70         OrgOpenroadmDevice result = null;
71         LOG.info("Parameterized string is : {}", xml);
72         DataStoreContext dataStoreContextUtil = new DataStoreContextImpl();
73         DefaultDeviceFactory defaultDeviceFactory = new DefaultDeviceFactory();
74         result = defaultDeviceFactory.createDefaultDevice(dataStoreContextUtil,xml);
75         if (result != null) {
76             LOG.info("result info : {}", result.getInfo().getNodeId());
77             Assert.assertEquals("ROADMA", result.getInfo().getNodeId());
78         }
79         LOG.info("Test Succeed");
80     }
81
82
83     /**
84      * This test create Device from File
85      * located at {@link CreateDeviceFromXMLFileTest#DEVICE_OPER_IN}.
86      *
87      * @throws NullPointerException
88      */
89     @Test
90     public void createDeviceFromFile() throws NullPointerException{
91         LOG.info("test createDeviceFromFile ...");
92         OrgOpenroadmDevice result = null;
93         result = null;
94         File device_data = new File(DEVICE_OPER_IN);
95         DataStoreContext dataStoreContextUtil = new DataStoreContextImpl();
96         DefaultDeviceFactory defaultDeviceFactory = new DefaultDeviceFactory();
97         result = defaultDeviceFactory.createDefaultDevice(dataStoreContextUtil,device_data);
98         if (result != null) {
99             LOG.info("result info : {}", result.getInfo().getNodeId());
100             Assert.assertEquals("ROADMA", result.getInfo().getNodeId());
101         }
102         LOG.info("Test Succeed");
103     }
104 }