diff --git a/src/main/java/com/github/khalidzahra/TopologyAPI.java b/src/main/java/com/github/khalidzahra/TopologyAPI.java index c62d214..e6c56c7 100644 --- a/src/main/java/com/github/khalidzahra/TopologyAPI.java +++ b/src/main/java/com/github/khalidzahra/TopologyAPI.java @@ -52,7 +52,8 @@ public boolean writeJSON(String topologyID, String filePath) { /** * Queries all topologies currently stored in memory * - * @return Returns a List of Topology containing all loaded topologies. Returns an empty list if no topologies are found. + * @return Returns a List of Topology containing all loaded topologies. + * Returns an empty list if no topologies are found. */ public List queryTopologies() { return topologyRegistry.getTopologyList(); @@ -60,13 +61,14 @@ public List queryTopologies() { /** * Finds topology with specified topology ID + * * @param topologyID String variable containing the topology ID * @return Returns Topology object with specified topology ID */ public Topology findTopology(String topologyID) { return topologyRegistry.getTopologyList() .stream() - .filter(topology -> topology.getId().equals(topologyID)) + .filter(topology -> topology.getTopologyId().equals(topologyID)) .findAny() .orElse(null); } @@ -85,7 +87,8 @@ public boolean deleteTopology(String topologyID) { * Queries the devices connected within a topology * * @param topologyID String variable containing the topology ID - * @return Returns a List of Device containing all connected devices. Returns an empty list if no devices are found. + * @return Returns a List of Device containing all connected devices. + * Returns an empty list if no devices are found. */ public List queryDevices(String topologyID) { Topology topology = topologyRegistry.findTopology(topologyID); @@ -97,7 +100,8 @@ public List queryDevices(String topologyID) { * * @param topologyID String variable containing the topology ID * @param netlistNodeID String variable containing the node ID - * @return Returns a List of Device containing all connected devices. Returns an empty list if no devices are found. + * @return Returns a List of Device containing all connected devices. + * Returns an empty list if no devices are found. */ public List queryDevicesWithNetlistNode(String topologyID, String netlistNodeID) { Topology topology = topologyRegistry.findTopology(topologyID); diff --git a/src/main/java/com/github/khalidzahra/internal/device/Device.java b/src/main/java/com/github/khalidzahra/internal/device/Device.java index 885f165..57aaab7 100644 --- a/src/main/java/com/github/khalidzahra/internal/device/Device.java +++ b/src/main/java/com/github/khalidzahra/internal/device/Device.java @@ -3,28 +3,29 @@ import com.github.khalidzahra.internal.util.JsonKeyUtil; import com.google.gson.annotations.SerializedName; -import java.util.HashMap; +import java.util.Map; /** * Created by Khalid on 9/28/21. */ public class Device { - @SerializedName(value = JsonKeyUtil.DEVICE_TYPE_KEY) - private DeviceType deviceType; - private String id; + @SerializedName(JsonKeyUtil.DEVICE_TYPE_KEY) + private final DeviceType deviceType; + @SerializedName("id") + private final String deviceId; @SerializedName(value = JsonKeyUtil.DEVICE_PROPERTIES_KEY, alternate = {JsonKeyUtil.DEVICE_PROPERTIES_RESISTANCE_KEY, JsonKeyUtil.DEVICE_PROPERTIES_CAPACITANCE_KEY, JsonKeyUtil.DEVICE_PROPERTIES_INDUCTANCE_KEY, JsonKeyUtil.DEVICE_PROPERTIES_TRANSISTOR_KEY}) - private DeviceProperties deviceProperties; - @SerializedName(value = JsonKeyUtil.DEVICE_NETLIST_KEY) - private HashMap netList; + private final DeviceProperties deviceProperties; + @SerializedName(JsonKeyUtil.DEVICE_NETLIST_KEY) + private final Map netList; - public Device(DeviceType deviceType, String id, DeviceProperties deviceProperties, HashMap netList) { + public Device(DeviceType deviceType, String deviceId, DeviceProperties deviceProperties, Map netList) { this.deviceType = deviceType; - this.id = id; + this.deviceId = deviceId; this.deviceProperties = deviceProperties; this.netList = netList; } @@ -33,15 +34,15 @@ public DeviceType getDeviceType() { return deviceType; } - public String getId() { - return id; + public String getDeviceId() { + return deviceId; } public DeviceProperties getDeviceProperties() { return deviceProperties; } - public HashMap getNetList() { + public Map getNetList() { return netList; } } diff --git a/src/main/java/com/github/khalidzahra/internal/device/DeviceProperties.java b/src/main/java/com/github/khalidzahra/internal/device/DeviceProperties.java index 06d9707..822a282 100644 --- a/src/main/java/com/github/khalidzahra/internal/device/DeviceProperties.java +++ b/src/main/java/com/github/khalidzahra/internal/device/DeviceProperties.java @@ -7,11 +7,18 @@ */ public class DeviceProperties { - private double min, max; + private double min; + private double max; @SerializedName("default") private double defaultValue; + public DeviceProperties(double min, double max, double defaultValue) { + this.min = min; + this.max = max; + this.defaultValue = defaultValue; + } + public double getMin() { return min; } diff --git a/src/main/java/com/github/khalidzahra/internal/topology/Topology.java b/src/main/java/com/github/khalidzahra/internal/topology/Topology.java index f1f1380..52698f8 100644 --- a/src/main/java/com/github/khalidzahra/internal/topology/Topology.java +++ b/src/main/java/com/github/khalidzahra/internal/topology/Topology.java @@ -11,17 +11,18 @@ */ public class Topology { - private String id; + @SerializedName("id") + private final String topologyId; @SerializedName("components") - private List devices; + private final List devices; - public Topology(String id) { - this.id = id; + public Topology(String topologyId) { + this.topologyId = topologyId; this.devices = new ArrayList<>(); } - public Topology(String id, List deviceList) { - this.id = id; + public Topology(String topologyId, List deviceList) { + this.topologyId = topologyId; this.devices = deviceList; } @@ -42,8 +43,8 @@ public void addDevice(Device device) { devices.add(device); } - public String getId() { - return id; + public String getTopologyId() { + return topologyId; } public List getDevices() { diff --git a/src/main/java/com/github/khalidzahra/internal/topology/TopologyRegistry.java b/src/main/java/com/github/khalidzahra/internal/topology/TopologyRegistry.java index d57cfbd..0a6cd3c 100644 --- a/src/main/java/com/github/khalidzahra/internal/topology/TopologyRegistry.java +++ b/src/main/java/com/github/khalidzahra/internal/topology/TopologyRegistry.java @@ -1,6 +1,6 @@ package com.github.khalidzahra.internal.topology; -import com.github.khalidzahra.internal.util.json.GsonHandler; +import com.github.khalidzahra.internal.util.json.GsonUtil; import java.util.ArrayList; import java.util.List; @@ -18,53 +18,64 @@ public TopologyRegistry() { /** * Loads the topology from the specified file and adds it to topologyList. + * * @param filePath String variable containing path to the JSON file * @return Returns true if the topology is successfully loaded and registered */ public boolean loadAndRegisterTopology(String filePath) { - Topology topology = GsonHandler.loadTopology(filePath); + Topology topology = GsonUtil.loadTopology(filePath); return registerTopology(topology); } /** * Writes the specified topology to the specified file + * * @param topologyID String variable containing the topology ID - * @param filePath String variable containing path to the JSON file + * @param filePath String variable containing path to the JSON file * @return Returns true if the topology is successfully found and saved */ public boolean saveTopology(String topologyID, String filePath) { Topology topology = findTopology(topologyID); - if (topology == null) return false; - return GsonHandler.saveTopology(filePath, topology); + if (topology == null) { + return false; + } + return GsonUtil.saveTopology(filePath, topology); } /** * Adds the topology to topologyList + * * @param topology Topology object to be registered * @return Returns true if the topology is successfully registered */ public boolean registerTopology(Topology topology) { - if (topology == null) return false; + if (topology == null) { + return false; + } return topologyList.add(topology); } /** * Finds the topology matching the specified ID + * * @param topologyID String variable containing the topology ID * @return Returns Topology object matching the specified ID. Returns null if no object matching the ID is found. */ public Topology findTopology(String topologyID) { - return topologyList.stream().filter(topology -> topology.getId().equals(topologyID)).findAny().orElse(null); + return topologyList.stream().filter(topology -> topology.getTopologyId().equals(topologyID)).findAny().orElse(null); } /** * Unloads the topology from memory + * * @param topologyID String variable containing the topology ID * @return Returns true if topology is successfully found and unloaded. */ public boolean deregisterTopology(String topologyID) { Topology topology = findTopology(topologyID); - if (topology == null) return false; + if (topology == null) { + return false; + } return topologyList.remove(topology); } diff --git a/src/main/java/com/github/khalidzahra/internal/util/json/DeviceSerializer.java b/src/main/java/com/github/khalidzahra/internal/util/json/DeviceSerializer.java index 2c4f180..a225043 100644 --- a/src/main/java/com/github/khalidzahra/internal/util/json/DeviceSerializer.java +++ b/src/main/java/com/github/khalidzahra/internal/util/json/DeviceSerializer.java @@ -21,7 +21,7 @@ public class DeviceSerializer implements JsonSerializer { public JsonElement serialize(Device device, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(JsonKeyUtil.DEVICE_TYPE_KEY, device.getDeviceType().toString().toLowerCase(Locale.ROOT)); - jsonObject.addProperty("id", device.getId()); + jsonObject.addProperty("id", device.getDeviceId()); jsonObject.add(device.getDeviceType().getSerializedPropertyName(), jsonSerializationContext.serialize(device.getDeviceProperties())); jsonObject.add(JsonKeyUtil.DEVICE_NETLIST_KEY, jsonSerializationContext.serialize(device.getNetList())); diff --git a/src/main/java/com/github/khalidzahra/internal/util/json/GsonHandler.java b/src/main/java/com/github/khalidzahra/internal/util/json/GsonUtil.java similarity index 79% rename from src/main/java/com/github/khalidzahra/internal/util/json/GsonHandler.java rename to src/main/java/com/github/khalidzahra/internal/util/json/GsonUtil.java index fafe06d..b84312d 100644 --- a/src/main/java/com/github/khalidzahra/internal/util/json/GsonHandler.java +++ b/src/main/java/com/github/khalidzahra/internal/util/json/GsonUtil.java @@ -6,16 +6,18 @@ import com.google.gson.GsonBuilder; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; /** * Created by Khalid on 9/28/21. */ -public class GsonHandler { +public class GsonUtil { /** * GsonBuilder object that will be used throughout project */ - private static final Gson gson = new GsonBuilder() + private static final Gson GSON_OBJECT = new GsonBuilder() .registerTypeAdapter(Device.class, new DeviceSerializer()) .setPrettyPrinting().create(); @@ -27,10 +29,9 @@ public class GsonHandler { */ public static Topology loadTopology(String filePath) { Topology topology; - try { - BufferedReader reader = new BufferedReader(new FileReader(filePath)); + try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath))) { topology = getGson().fromJson(reader, Topology.class); - } catch (FileNotFoundException e) { + } catch (IOException e) { return null; } return topology; @@ -44,7 +45,7 @@ public static Topology loadTopology(String filePath) { * @return Returns true if save was successful */ public static boolean saveTopology(String filePath, Topology topology) { - try (FileWriter writer = new FileWriter(filePath)) { + try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath))) { getGson().toJson(topology, writer); } catch (IOException e) { return false; @@ -53,6 +54,6 @@ public static boolean saveTopology(String filePath, Topology topology) { } public static Gson getGson() { - return gson; + return GSON_OBJECT; } } diff --git a/src/test/java/com/github/khalidzahra/TopologyAPITest.java b/src/test/java/com/github/khalidzahra/TopologyAPITest.java index c7d555e..41be4d4 100644 --- a/src/test/java/com/github/khalidzahra/TopologyAPITest.java +++ b/src/test/java/com/github/khalidzahra/TopologyAPITest.java @@ -4,9 +4,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; import junit.framework.TestCase; +import org.junit.Test; -import java.io.FileNotFoundException; -import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -17,103 +18,111 @@ public class TopologyAPITest extends TestCase { private final Path resourceDirectory = Paths.get("src", "test", "resources"); + private final Path top1Path = Paths.get(resourceDirectory.toAbsolutePath() + "/topology1.json"); + private final Path top2Path = Paths.get(resourceDirectory.toAbsolutePath() + "/topology2.json"); + @Test public void testReadJSON() { TopologyAPI topologyAPI = new TopologyAPI(); - assertTrue(topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json")); - assertFalse(topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology-tests.json")); - assertFalse(topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology.json")); - assertTrue(topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json")); + assertTrue("Should return true", topologyAPI.readJSON(top1Path.toAbsolutePath().toString())); + assertFalse("Should return false", topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology-tests.json")); + assertFalse("Should return false", topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology.json")); + assertTrue("Should return true", topologyAPI.readJSON(top2Path.toAbsolutePath().toString())); } + @Test public void testWriteJSON() { TopologyAPI topologyAPI = new TopologyAPI(); // check return values of api methods - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json"); - assertTrue(topologyAPI.writeJSON("top1", resourceDirectory.toAbsolutePath() + "/topology1-test.json")); - assertFalse(topologyAPI.writeJSON("top2", resourceDirectory.toAbsolutePath() + "/topology1.json")); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json"); - assertTrue(topologyAPI.writeJSON("top2", resourceDirectory.toAbsolutePath() + "/topology2-test.json")); - assertFalse(topologyAPI.writeJSON("top3", resourceDirectory.toAbsolutePath() + "/topology2.json")); + topologyAPI.readJSON(top1Path.toAbsolutePath().toString()); + assertTrue("Should return true", topologyAPI.writeJSON("top1", resourceDirectory.toAbsolutePath() + "/topology1-test.json")); + assertFalse("Should return false", topologyAPI.writeJSON("top2", top1Path.toAbsolutePath().toString())); + topologyAPI.readJSON(top2Path.toAbsolutePath().toString()); + assertTrue("Should return true", topologyAPI.writeJSON("top2", resourceDirectory.toAbsolutePath() + "/topology2-test.json")); + assertFalse("Should return false", topologyAPI.writeJSON("top3", top2Path.toAbsolutePath().toString())); // check if data is being saved correctly try { - JsonElement top1 = JsonParser.parseReader(new FileReader(resourceDirectory.toAbsolutePath() + "/topology1.json")); - JsonElement top1Test = JsonParser.parseReader(new FileReader(resourceDirectory.toAbsolutePath() + "/topology1-test.json")); - JsonElement top2 = JsonParser.parseReader(new FileReader(resourceDirectory.toAbsolutePath() + "/topology2.json")); - JsonElement top2Test = JsonParser.parseReader(new FileReader(resourceDirectory.toAbsolutePath() + "/topology2-test.json")); - assertEquals(top1, top1Test); - assertEquals(top2, top2Test); - } catch (FileNotFoundException e) { - e.printStackTrace(); + JsonElement top1 = JsonParser.parseReader(Files.newBufferedReader(top1Path)); + JsonElement top1Test = JsonParser.parseReader(Files.newBufferedReader(Paths.get(resourceDirectory.toAbsolutePath() + "/topology1-test.json"))); + JsonElement top2 = JsonParser.parseReader(Files.newBufferedReader(Paths.get(top2Path.toAbsolutePath().toString()))); + JsonElement top2Test = JsonParser.parseReader(Files.newBufferedReader(Paths.get(resourceDirectory.toAbsolutePath() + "/topology2-test.json"))); + assertEquals("Should hold the same data", top1, top1Test); + assertEquals("Should hold the same data", top2, top2Test); + } catch (IOException ignored) { } } + @Test public void testQueryTopologies() { TopologyAPI topologyAPI = new TopologyAPI(); - assertEquals(topologyAPI.queryTopologies().size(), 0); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json"); - assertEquals(topologyAPI.queryTopologies().size(), 1); - assertEquals(topologyAPI.queryTopologies().get(0).getId(), "top1"); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json"); - assertEquals(topologyAPI.queryTopologies().size(), 2); - assertEquals(topologyAPI.queryTopologies().get(1).getId(), "top2"); + assertEquals("Should have 0 elements", 0, topologyAPI.queryTopologies().size()); + topologyAPI.readJSON(top1Path.toAbsolutePath().toString()); + assertEquals("Should have 1 element", 1, topologyAPI.queryTopologies().size()); + assertEquals("Should have the id 'top1'", "top1", topologyAPI.queryTopologies().get(0).getTopologyId()); + topologyAPI.readJSON(top2Path.toAbsolutePath().toString()); + assertEquals("Should have 2 elements", 2, topologyAPI.queryTopologies().size()); + assertEquals("Should have the id 'top2'", "top2", topologyAPI.queryTopologies().get(1).getTopologyId()); } + @Test public void testDeleteTopology() { TopologyAPI topologyAPI = new TopologyAPI(); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json"); - assertEquals(topologyAPI.queryTopologies().size(), 1); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json"); - assertEquals(topologyAPI.queryTopologies().size(), 2); - assertFalse(topologyAPI.deleteTopology("top3")); - assertTrue(topologyAPI.deleteTopology("top1")); - assertEquals(topologyAPI.queryTopologies().size(), 1); - assertTrue(topologyAPI.deleteTopology("top2")); - assertEquals(topologyAPI.queryTopologies().size(), 0); + topologyAPI.readJSON(top1Path.toAbsolutePath().toString()); + assertEquals("Should have 1 element", 1, topologyAPI.queryTopologies().size()); + topologyAPI.readJSON(top2Path.toAbsolutePath().toString()); + assertEquals("Should have 2 elements", 2, topologyAPI.queryTopologies().size()); + assertFalse("Should return false", topologyAPI.deleteTopology("top3")); + assertTrue("Should return true", topologyAPI.deleteTopology("top1")); + assertEquals("Should have 1 element", 1, topologyAPI.queryTopologies().size()); + assertTrue("Should return true", topologyAPI.deleteTopology("top2")); + assertEquals("Should have 0 elements", 0, topologyAPI.queryTopologies().size()); } + @Test public void testQueryDevices() { TopologyAPI topologyAPI = new TopologyAPI(); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json"); - assertEquals(topologyAPI.queryDevices("top1").size(), 2); - topologyAPI.queryDevices("top1").forEach(device -> assertTrue(device.getDeviceType() == DeviceType.RESISTOR || device.getDeviceType() == DeviceType.NMOS)); - topologyAPI.queryDevices("top1").forEach(device -> assertFalse(device.getDeviceType() == DeviceType.CAPACITOR || device.getDeviceType() == DeviceType.PMOS)); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json"); - assertEquals(topologyAPI.queryDevices("top2").size(), 2); - topologyAPI.queryDevices("top2").forEach(device -> assertTrue(device.getDeviceType() == DeviceType.CAPACITOR || device.getDeviceType() == DeviceType.PMOS)); - topologyAPI.queryDevices("top2").forEach(device -> assertFalse(device.getDeviceType() == DeviceType.RESISTOR || device.getDeviceType() == DeviceType.NMOS)); + topologyAPI.readJSON(top1Path.toAbsolutePath().toString()); + assertEquals("Should have 2 elements", 2, topologyAPI.queryDevices("top1").size()); + topologyAPI.queryDevices("top1").forEach(device -> assertTrue("Should return true", device.getDeviceType() == DeviceType.RESISTOR || device.getDeviceType() == DeviceType.NMOS)); + topologyAPI.queryDevices("top1").forEach(device -> assertFalse("Should return false", device.getDeviceType() == DeviceType.CAPACITOR || device.getDeviceType() == DeviceType.PMOS)); + topologyAPI.readJSON(top2Path.toAbsolutePath().toString()); + assertEquals("Should have 2 elements", 2, topologyAPI.queryDevices("top2").size()); + topologyAPI.queryDevices("top2").forEach(device -> assertTrue("Should return true", device.getDeviceType() == DeviceType.CAPACITOR || device.getDeviceType() == DeviceType.PMOS)); + topologyAPI.queryDevices("top2").forEach(device -> assertFalse("Should return false", device.getDeviceType() == DeviceType.RESISTOR || device.getDeviceType() == DeviceType.NMOS)); } + @Test public void testQueryDevicesWithNetlistNode() { TopologyAPI topologyAPI = new TopologyAPI(); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json"); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top1", "n1").size(), 2); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top1", "vdd").size(), 1); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top1", "vdd").get(0).getDeviceType(), DeviceType.RESISTOR); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top1", "vss").size(), 1); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top1", "vss").get(0).getDeviceType(), DeviceType.NMOS); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json"); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top2", "n1").size(), 2); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top2", "vdd").size(), 1); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top2", "vdd").get(0).getDeviceType(), DeviceType.CAPACITOR); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top2", "vss").size(), 1); - assertEquals(topologyAPI.queryDevicesWithNetlistNode("top2", "vss").get(0).getDeviceType(), DeviceType.PMOS); + topologyAPI.readJSON(top1Path.toAbsolutePath().toString()); + assertEquals("Should have 2 elements", 2, topologyAPI.queryDevicesWithNetlistNode("top1", "n1").size()); + assertEquals("Should have 1 element", 1, topologyAPI.queryDevicesWithNetlistNode("top1", "vdd").size()); + assertEquals("Should have a device type of RESISTOR", DeviceType.RESISTOR, topologyAPI.queryDevicesWithNetlistNode("top1", "vdd").get(0).getDeviceType()); + assertEquals("Should have 1 element", 1, topologyAPI.queryDevicesWithNetlistNode("top1", "vss").size()); + assertEquals("Should have a device type of NMOS", DeviceType.NMOS, topologyAPI.queryDevicesWithNetlistNode("top1", "vss").get(0).getDeviceType()); + topologyAPI.readJSON(top2Path.toAbsolutePath().toString()); + assertEquals("Should have 2 elements", 2, topologyAPI.queryDevicesWithNetlistNode("top2", "n1").size()); + assertEquals("Should have 1 element", 1, topologyAPI.queryDevicesWithNetlistNode("top2", "vdd").size()); + assertEquals("Should have a device type of CAPACITOR", DeviceType.CAPACITOR, topologyAPI.queryDevicesWithNetlistNode("top2", "vdd").get(0).getDeviceType()); + assertEquals("Should have 1 element", 1, topologyAPI.queryDevicesWithNetlistNode("top2", "vss").size()); + assertEquals("Should have a device type of PMOS", DeviceType.PMOS, topologyAPI.queryDevicesWithNetlistNode("top2", "vss").get(0).getDeviceType()); } + @Test public void testFindTopology() { TopologyAPI topologyAPI = new TopologyAPI(); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json"); - assertNotNull(topologyAPI.findTopology("top1")); - assertEquals(topologyAPI.findTopology("top1").getId(), "top1"); - topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json"); - assertNotNull(topologyAPI.findTopology("top2")); - assertEquals(topologyAPI.findTopology("top2").getId(), "top2"); - assertNull(topologyAPI.findTopology("top3")); - assertNull(topologyAPI.findTopology("top4")); + topologyAPI.readJSON(top1Path.toAbsolutePath().toString()); + assertNotNull("Should not be null", topologyAPI.findTopology("top1")); + assertEquals("Should have an id of 'top1'", "top1", topologyAPI.findTopology("top1").getTopologyId()); + topologyAPI.readJSON(top2Path.toAbsolutePath().toString()); + assertNotNull("Should not be null", topologyAPI.findTopology("top2")); + assertEquals("Should have an id of 'top2'", "top2", topologyAPI.findTopology("top2").getTopologyId()); + assertNull("Should be null", topologyAPI.findTopology("top3")); + assertNull("Should be null", topologyAPI.findTopology("top4")); topologyAPI.deleteTopology("top1"); - assertNull(topologyAPI.findTopology("top1")); + assertNull("Should be null", topologyAPI.findTopology("top1")); topologyAPI.deleteTopology("top2"); - assertNull(topologyAPI.findTopology("top2")); + assertNull("Should be null", topologyAPI.findTopology("top2")); } } \ No newline at end of file