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.rev210310.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.YangInstanceIdentifier.PathArgument;
34 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class MappingUtilsImplTest extends AbstractTest {
39 private static final Logger LOG = LoggerFactory.getLogger(MappingUtilsImplTest.class);
40 private static MappingUtils mappingUtils;
43 public static void setUp() throws InterruptedException, ExecutionException, FileNotFoundException {
44 DataObjectConverter dataObjectConverter = JSONDataObjectConverter
45 .createWithDataStoreUtil(getDataStoreContextUtil());
46 try (Reader reader = new FileReader("src/test/resources/network.json", StandardCharsets.UTF_8)) {
47 NormalizedNode<? extends PathArgument, ?> normalizedNode = dataObjectConverter
48 .transformIntoNormalizedNode(reader).get();
49 Network network = (Network) getDataStoreContextUtil()
50 .getBindingDOMCodecServices().fromNormalizedNode(YangInstanceIdentifier
51 .of(Network.QNAME), normalizedNode).getValue();
52 WriteTransaction writeNetworkTransaction = getDataBroker().newWriteOnlyTransaction();
53 writeNetworkTransaction.put(LogicalDatastoreType.CONFIGURATION,
54 InstanceIdentifier.builder(Network.class).build(), network);
55 writeNetworkTransaction.commit().get();
56 } catch (IOException e) {
57 LOG.error("Cannot load network ", e);
58 fail("Cannot load network");
60 mappingUtils = new MappingUtilsImpl(getDataBroker());
64 public void getOpenRoadmVersionTest() throws ExecutionException, InterruptedException {
65 assertEquals("NodeInfo with ROADM-C1 as id should be 1.2.1 version",
66 StringConstants.OPENROADM_DEVICE_VERSION_1_2_1,
67 mappingUtils.getOpenRoadmVersion("ROADM-C1"));
68 assertEquals("NodeInfo with ROADM-A1 as id should be 2.2.1 version",
69 StringConstants.OPENROADM_DEVICE_VERSION_2_2_1,
70 mappingUtils.getOpenRoadmVersion("ROADM-A1"));
71 assertNull("NodeInfo with nodes3 as id should not exist", mappingUtils.getOpenRoadmVersion("nodes3"));
75 public void getMcCapabilitiesForNodeTest() {
76 assertEquals("Mc capabilities list size should be 2", 2,
77 mappingUtils.getMcCapabilitiesForNode("ROADM-A1").size());
78 assertTrue("Mc capabilities list size should be empty",
79 mappingUtils.getMcCapabilitiesForNode("ROADM-A2").isEmpty());