@@ -0,0 +1,2890 @@
+package org.workcraft.plugins.circuit;%0A%0Aimport java.io.IOException;%0Aimport java.net.URL;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.workcraft.Framework;%0Aimport org.workcraft.exceptions.DeserialisationException;%0Aimport org.workcraft.plugins.circuit.commands.CircuitToStgConversionCommand;%0Aimport org.workcraft.plugins.stg.SignalTransition.Type;%0Aimport org.workcraft.plugins.stg.Stg;%0Aimport org.workcraft.workspace.WorkspaceEntry;%0Aimport org.workcraft.workspace.WorkspaceUtils;%0A%0Apublic class CircuitConversionCommandsTests %7B%0A%0A    private static final String%5B%5D TEST_CIRCUIT_WORKS = %7B%0A        %22org/workcraft/plugins/circuit/buffer-tm.circuit.work%22,%0A        %22org/workcraft/plugins/circuit/celement-tm.circuit.work%22,%0A        %22org/workcraft/plugins/circuit/vme-tm.circuit.work%22,%0A    %7D;%0A%0A    @BeforeClass%0A    public static void initPlugins() %7B%0A        final Framework framework = Framework.getInstance();%0A        framework.initPlugins(false);%0A    %7D%0A%0A    @Test%0A    public void testPetriConversionCommands() throws IOException, DeserialisationException %7B%0A        final Framework framework = Framework.getInstance();%0A        final ClassLoader classLoader = ClassLoader.getSystemClassLoader();%0A        for (String testCircuitWork: TEST_CIRCUIT_WORKS) %7B%0A            URL srcUrl = classLoader.getResource(testCircuitWork);%0A%0A            WorkspaceEntry srcWe = framework.loadWork(srcUrl.getFile());%0A            Circuit srcCircuit = WorkspaceUtils.getAs(srcWe, Circuit.class);%0A%0A            Set%3CString%3E srcCircuitInputs = new HashSet%3C%3E();%0A            Set%3CString%3E srcCircuitOutputs = new HashSet%3C%3E();%0A            for (Contact port: srcCircuit.getPorts()) %7B%0A                if (port.isInput()) %7B%0A                    srcCircuitInputs.add(port.getName());%0A                %7D else %7B%0A                    srcCircuitOutputs.add(port.getName());%0A                %7D%0A            %7D%0A            int srcCircuitSignalCount = srcCircuitInputs.size();%0A            for (FunctionComponent component: srcCircuit.getFunctionComponents()) %7B%0A                if (!component.getIsZeroDelay()) %7B%0A                    srcCircuitSignalCount++;%0A                %7D%0A            %7D%0A%0A            CircuitToStgConversionCommand command = new CircuitToStgConversionCommand();%0A            WorkspaceEntry dstWe = command.execute(srcWe);%0A            Stg dstStg = WorkspaceUtils.getAs(dstWe, Stg.class);%0A%0A            int dstStgPlaceCount = dstStg.getPlaces().size();%0A            Set%3CString%3E dstStgInputs = dstStg.getSignalNames(Type.INPUT, null);%0A            Set%3CString%3E dstStgOutputs = dstStg.getSignalNames(Type.OUTPUT, null);%0A%0A            Assert.assertEquals(2 * srcCircuitSignalCount, dstStgPlaceCount);%0A            Assert.assertEquals(srcCircuitInputs, dstStgInputs);%0A            Assert.assertEquals(srcCircuitOutputs, dstStgOutputs);%0A        %7D%0A    %7D%0A%0A%7D%0A

Test conversion of Circuit to STG