* 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());