import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.transportpce.common.InstanceIdentifiers;
-import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
+import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
import org.opendaylight.transportpce.test.AbstractTest;
+import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
@BeforeClass
public static void setUp() throws InterruptedException, ExecutionException {
TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
- TopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
+ TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
- TopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
- TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil());
+ TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
+ TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
+ TapiTopologyDataUtils.PORTMAPPING_FILE);
KeyedInstanceIdentifier<Node, NodeKey> muxAIID = InstanceIdentifier.create(Networks.class)
.child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.ReadTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
+import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
when(dataBroker.newReadOnlyTransaction())
.thenReturn(new ReadTransactionMock());
- GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER);
+ GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER);
TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataBroker);
ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.transportpce.common.InstanceIdentifiers;
-import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
+import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
import org.opendaylight.transportpce.test.AbstractTest;
+import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
endSignal = new CountDownLatch(1);
TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
- TopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
+ TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
- TopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
- TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil());
+ TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
+ TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
+ TapiTopologyDataUtils.PORTMAPPING_FILE);
LOG.info("setup done");
}
@Test
public void getTopologyDetailsForTransponder100GTopologyWhenSuccessful()
throws ExecutionException, InterruptedException {
- GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.TPDR_100G);
+ GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.TPDR_100G);
TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
result.addListener(new Runnable() {
@Test
public void getTopologyDetailsForOtnTopologyWithOtnLinksWhenSuccessful()
throws ExecutionException, InterruptedException {
- GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER);
+ GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER);
TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
result.addListener(new Runnable() {
--- /dev/null
+/*
+ * Copyright © 2020 Orange, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.tapi.utils;
+
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInputBuilder;
+
+public final class TapiTopologyDataUtils {
+ public static final String OPENROADM_TOPOLOGY_FILE = "src/test/resources/openroadm-topology.xml";
+ public static final String OTN_TOPOLOGY_FILE = "src/test/resources/otn-topology.xml";
+ public static final String PORTMAPPING_FILE = "src/test/resources/portmapping.xml";
+
+ public static GetTopologyDetailsInput buildGetTopologyDetailsInput(String topoName) {
+ GetTopologyDetailsInputBuilder builtInput = new GetTopologyDetailsInputBuilder();
+ builtInput.setTopologyIdOrName(topoName);
+ return builtInput.build();
+ }
+
+ private TapiTopologyDataUtils() {
+ }
+
+}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.transportpce.tapi.utils;
+package org.opendaylight.transportpce.test.utils;
import com.google.common.util.concurrent.FluentFuture;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.opendaylight.transportpce.test.converter.XMLDataObjectConverter;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.Network;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInputBuilder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public final class TopologyDataUtils {
private static final Logger LOG = LoggerFactory.getLogger(TopologyDataUtils.class);
- public static final String OPENROADM_TOPOLOGY_FILE = "src/test/resources/openroadm-topology.xml";
- public static final String OTN_TOPOLOGY_FILE = "src/test/resources/otn-topology.xml";
- public static final String PORTMAPPING_FILE = "src/test/resources/portmapping.xml";
-
- public static GetTopologyDetailsInput buildGetTopologyDetailsInput(String topoName) {
- GetTopologyDetailsInputBuilder builtInput = new GetTopologyDetailsInputBuilder();
- builtInput.setTopologyIdOrName(topoName);
- return builtInput.build();
- }
public static <T> void writeTopologyFromFileToDatastore(DataStoreContext dataStoreContextUtil, String file,
InstanceIdentifier ii) throws InterruptedException, ExecutionException {
File topoFile = new File(file);
if (topoFile.exists()) {
String fileName = topoFile.getName();
- InputStream targetStream;
- try {
- targetStream = new FileInputStream(topoFile);
+ try (InputStream targetStream = new FileInputStream(topoFile)) {
Optional<NormalizedNode<?, ?>> transformIntoNormalizedNode = XMLDataObjectConverter
.createWithDataStoreUtil(dataStoreContextUtil).transformIntoNormalizedNode(targetStream);
if (!transformIntoNormalizedNode.isPresent()) {
} else {
networks = (Networks) dataObject.get();
}
- } catch (FileNotFoundException e) {
- LOG.error("File not found : {} at {}", e.getMessage(), e.getLocalizedMessage());
+ } catch (IOException e) {
+ LOG.error("An error occured while reading file {}", file, e);
}
} else {
LOG.error("xml file {} not found at {}", topoFile.getName(), topoFile.getAbsolutePath());
}
+ if (networks == null) {
+ throw new IllegalStateException("Network is null cannot write it to datastore");
+ }
FluentFuture<? extends CommitInfo> commitFuture = writeTransaction(dataStoreContextUtil.getDataBroker(), ii,
networks.nonnullNetwork().values().stream().findFirst().get());
commitFuture.get();
return transaction.commit();
}
- public static void writePortmappingFromFileToDatastore(DataStoreContext dataStoreContextUtil)
+ public static void writePortmappingFromFileToDatastore(DataStoreContext dataStoreContextUtil, String file)
throws InterruptedException, ExecutionException {
Network result = null;
- File portmappingFile = new File(PORTMAPPING_FILE);
+ File portmappingFile = new File(file);
if (portmappingFile.exists()) {
String fileName = portmappingFile.getName();
- InputStream targetStream;
- try {
- targetStream = new FileInputStream(portmappingFile);
+ try (InputStream targetStream = new FileInputStream(portmappingFile)) {
Optional<NormalizedNode<?, ?>> transformIntoNormalizedNode = null;
transformIntoNormalizedNode = XMLDataObjectConverter.createWithDataStoreUtil(dataStoreContextUtil)
.transformIntoNormalizedNode(targetStream);
} else {
result = (Network) dataObject.get();
}
- } catch (FileNotFoundException e) {
- LOG.error("File not found : {} at {}", e.getMessage(), e.getLocalizedMessage());
+ } catch (IOException e) {
+ LOG.error("An error occured while reading file {}", file, e);
}
} else {
LOG.error("xml file {} not found at {}", portmappingFile.getName(), portmappingFile.getAbsolutePath());