2 * Copyright © 2020 Orange. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.common.mapping;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import java.io.FileNotFoundException;
17 import java.io.FileReader;
18 import java.io.IOException;
19 import java.io.Reader;
20 import java.nio.charset.StandardCharsets;
21 import java.util.concurrent.ExecutionException;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.opendaylight.mdsal.binding.api.WriteTransaction;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.transportpce.common.StringConstants;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.transportpce.test.converter.DataObjectConverter;
29 import org.opendaylight.transportpce.test.converter.JSONDataObjectConverter;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.Network;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class MappingUtilsImplTest extends AbstractTest {
38 private static final Logger LOG = LoggerFactory.getLogger(MappingUtilsImplTest.class);
39 private static MappingUtils mappingUtils;
42 public static void setUp() throws InterruptedException, ExecutionException, FileNotFoundException {
43 DataObjectConverter dataObjectConverter = JSONDataObjectConverter
44 .createWithDataStoreUtil(getDataStoreContextUtil());
45 try (Reader reader = new FileReader("src/test/resources/network.json", StandardCharsets.UTF_8)) {
46 NormalizedNode normalizedNode = dataObjectConverter
47 .transformIntoNormalizedNode(reader).get();
48 Network network = (Network) getDataStoreContextUtil()
49 .getBindingDOMCodecServices().fromNormalizedNode(YangInstanceIdentifier
50 .of(Network.QNAME), normalizedNode).getValue();
51 WriteTransaction writeNetworkTransaction = getDataBroker().newWriteOnlyTransaction();
52 writeNetworkTransaction.put(LogicalDatastoreType.CONFIGURATION,
53 InstanceIdentifier.builder(Network.class).build(), network);
54 writeNetworkTransaction.commit().get();
55 } catch (IOException e) {
56 LOG.error("Cannot load network ", e);
57 fail("Cannot load network");
59 mappingUtils = new MappingUtilsImpl(getDataBroker());
63 public void getOpenRoadmVersionTest() throws ExecutionException, InterruptedException {
64 assertEquals("NodeInfo with ROADM-C1 as id should be 1.2.1 version",
65 StringConstants.OPENROADM_DEVICE_VERSION_1_2_1,
66 mappingUtils.getOpenRoadmVersion("ROADM-C1"));
67 assertEquals("NodeInfo with ROADM-A1 as id should be 2.2.1 version",
68 StringConstants.OPENROADM_DEVICE_VERSION_2_2_1,
69 mappingUtils.getOpenRoadmVersion("ROADM-A1"));
70 assertNull("NodeInfo with nodes3 as id should not exist", mappingUtils.getOpenRoadmVersion("nodes3"));
74 public void getMcCapabilitiesForNodeTest() {
75 assertEquals("Mc capabilities list size should be 2", 2,
76 mappingUtils.getMcCapabilitiesForNode("ROADM-A1").size());
77 assertTrue("Mc capabilities list size should be empty",
78 mappingUtils.getMcCapabilitiesForNode("ROADM-A2").isEmpty());