diff --git a/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResource.java b/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResource.java index a9a173dfd..163f90b7a 100644 --- a/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResource.java +++ b/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResource.java @@ -46,9 +46,9 @@ @Api(tags = {CyRESTSwagger.CyRESTSwaggerConfig.COMMANDS_TAG}) @Singleton @Path("/v1/commands") -public class CommandResource implements PaxAppender, TaskObserver +public class CommandResource { - + @Inject @NotNull private AvailableCommands available; @@ -62,9 +62,7 @@ public class CommandResource implements PaxAppender, TaskObserver private SynchronousTaskManager taskManager; - private CustomFailureException taskException; - private MessageHandler messageHandler; - private boolean processingCommand = false; + @GET @Path("/") @@ -266,65 +264,31 @@ private final String executeCommand( } } - processingCommand = true; - messageHandler = handler; - taskException = null; - + + CommandResourceTaskObserver taskObserver = new CommandResourceTaskObserver(handler); + taskManager.execute(ceTaskFactory.createTaskIterator(namespace, - command, modifiedSettings, this), this); - - String messages = messageHandler.getMessages(); - processingCommand = false; - if (taskException != null) - throw taskException; - return messages; - } - - public void doAppend(PaxLoggingEvent event) { - // System.out.println(event.getLevel().toInt() + ": " + event.getMessage()); - // Get prefix - // Handle levels - if (!processingCommand) { - return; + command, modifiedSettings, taskObserver), taskObserver); + + synchronized (taskObserver) { + try{ + while (!taskObserver.isFinished()) { + System.out.println("Waiting for all tasks to finish at "+System.currentTimeMillis()); + taskObserver.wait(); + } + }catch(InterruptedException e){ + e.printStackTrace(); + } } - - PaxLevel level = event.getLevel(); - if (level.toInt() == 40000) - messageHandler.appendError(event.getMessage()); - else if (level.toInt() == 30000) - messageHandler.appendWarning(event.getMessage()); - else - messageHandler.appendMessage(event.getMessage()); - } - - ////////////////// For Observable Task ////////////////////////// + String messages = taskObserver.getMessageHandler().getMessages(); - @Override - public void taskFinished(ObservableTask t) { - final Object res = t.getResults(String.class); - if (res != null) - messageHandler.appendResult(res); + if (taskObserver.getTaskException() != null) + throw taskObserver.getTaskException(); + return messages; } - - @Override - public void allFinished(FinishStatus status) { - if (status.getType().equals(FinishStatus.Type.SUCCEEDED)) - messageHandler.appendMessage("Finished"); - else if (status.getType().equals(FinishStatus.Type.CANCELLED)) - messageHandler.appendWarning("Cancelled by user"); - else if (status.getType().equals(FinishStatus.Type.FAILED)) { - if (status.getException() != null) { - messageHandler.appendError("Failed: " - + status.getException().getMessage()); - taskException = new CustomFailureException("Failed: " - + status.getException().getMessage()); - } else { - messageHandler.appendError("Failed"); - taskException = new CustomFailureException(); - } - } - } + + private final String stripQuotes(final String quotedString) { String tqString = quotedString.trim(); @@ -344,14 +308,5 @@ public CustomNotFoundException(String message) { } } - public class CustomFailureException extends WebApplicationException { - public CustomFailureException() { - super(500); - } - - public CustomFailureException(String message) { - super(Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(message).type("text/plain").build()); - } - } + } diff --git a/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResourceTaskObserver.java b/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResourceTaskObserver.java new file mode 100644 index 000000000..a9cd29d96 --- /dev/null +++ b/src/main/java/org/cytoscape/rest/internal/commands/resources/CommandResourceTaskObserver.java @@ -0,0 +1,98 @@ +package org.cytoscape.rest.internal.commands.resources; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +import org.cytoscape.rest.internal.commands.handlers.MessageHandler; +import org.cytoscape.work.FinishStatus; +import org.cytoscape.work.ObservableTask; +import org.cytoscape.work.TaskObserver; +import org.ops4j.pax.logging.spi.PaxAppender; +import org.ops4j.pax.logging.spi.PaxLevel; +import org.ops4j.pax.logging.spi.PaxLoggingEvent; + +public class CommandResourceTaskObserver implements PaxAppender, TaskObserver { + + private CustomFailureException taskException; + public CustomFailureException getTaskException() { + return taskException; + } + + + + public MessageHandler getMessageHandler() { + return messageHandler; + } + + private MessageHandler messageHandler; + + private boolean finished; + + public CommandResourceTaskObserver (MessageHandler messageHandler) { + this.messageHandler = messageHandler; + finished = false; + } + + public boolean isFinished() { + return finished; + } + + + + @Override + public void taskFinished(ObservableTask t) { + final Object res = t.getResults(String.class); + if (res != null) + messageHandler.appendResult(res); + } + + + @Override + public void allFinished(FinishStatus status) { + if (status.getType().equals(FinishStatus.Type.SUCCEEDED)) + messageHandler.appendMessage("Finished"); + else if (status.getType().equals(FinishStatus.Type.CANCELLED)) + messageHandler.appendWarning("Cancelled by user"); + else if (status.getType().equals(FinishStatus.Type.FAILED)) { + if (status.getException() != null) { + messageHandler.appendError("Failed: " + + status.getException().getMessage()); + taskException = new CustomFailureException("Failed: " + + status.getException().getMessage()); + } else { + messageHandler.appendError("Failed"); + taskException = new CustomFailureException(); + } + } + synchronized(this) { + finished = true; + notify(); + } + } + + public class CustomFailureException extends WebApplicationException { + public CustomFailureException() { + super(500); + } + + public CustomFailureException(String message) { + super(Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(message).type("text/plain").build()); + } + } + + public void doAppend(PaxLoggingEvent event) { + // System.out.println(event.getLevel().toInt() + ": " + event.getMessage()); + // Get prefix + // Handle levels + + + PaxLevel level = event.getLevel(); + if (level.toInt() == 40000) + messageHandler.appendError(event.getMessage()); + else if (level.toInt() == 30000) + messageHandler.appendWarning(event.getMessage()); + else + messageHandler.appendMessage(event.getMessage()); + } +} diff --git a/src/test/java/org/cytoscape/rest/service/BasicResourceTest.java b/src/test/java/org/cytoscape/rest/service/BasicResourceTest.java index f8904a265..7d3d05634 100644 --- a/src/test/java/org/cytoscape/rest/service/BasicResourceTest.java +++ b/src/test/java/org/cytoscape/rest/service/BasicResourceTest.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.cytoscape.application.CyApplicationManager; import org.cytoscape.application.NetworkViewRenderer; @@ -131,7 +133,6 @@ import org.cytoscape.work.TaskIterator; import org.cytoscape.work.TaskMonitor; import org.cytoscape.work.TaskObserver; - import org.cytoscape.work.util.BoundedDouble; import org.cytoscape.work.util.ListSingleSelection; import org.glassfish.grizzly.http.server.HttpServer; @@ -161,9 +162,9 @@ public class BasicResourceTest extends JerseyTest { CyGroup cyGroup; CyNode cyGroupNode; - + protected CyRootNetworkManager rootNetworkManager; - + protected CyNetwork network; protected CyNetworkView view; @@ -176,26 +177,26 @@ public class BasicResourceTest extends JerseyTest { protected TaskFactoryManager tfManager; protected InputStreamTaskFactory inputStreamCXTaskFactory; - + protected CyNetworkReader inputStreamCXNetworkReader; - + protected CyNetworkManager networkManager = nts.getNetworkManager(); protected LoadNetworkURLTaskFactory loadNetworkURLTaskFactory; - + protected RenderingEngine renderingEngine; - + protected SaveSessionAsTaskFactory saveSessionAsTaskFactory; protected OpenSessionTaskFactory openSessionTaskFactory; protected NewSessionTaskFactory newSessionTaskFactory; protected SelectFirstNeighborsTaskFactory selectFirstNeighborsTaskFactory; protected GraphicsWriterManager graphicsWriterManager; - + protected ExportNetworkViewTaskFactory exportNetworkViewTaskFactory; - + protected PresentationWriterFactory presentationWriterFactory; - + protected MappingFactoryManager mappingFactoryManager = new MappingFactoryManager(); protected final String DUMMY_NAMESPACE = "dummyNamespace"; @@ -204,11 +205,19 @@ public class BasicResourceTest extends JerseyTest { protected final String DUMMY_ARGUMENT_DESCRIPTION = "dummyArgumentDescription"; protected final Class DUMMY_ARGUMENT_CLASS = int.class; protected final boolean DUMMY_ARGUMENT_REQUIRED = false; + + protected final String DUMMY_MULTI_TASK_COMMAND = "dummyMultiTaskCommand"; + protected boolean multiTaskAComplete = false; + protected boolean multiTaskBComplete = false; + protected final String DUMMY_APPEND_TASK_COMMAND = "dummyAppendTaskCommand"; + protected boolean appendTaskAComplete = false; + protected boolean appendTaskBComplete = false; + protected CyRESTSwagger cyRESTSwagger; - + protected final String cyRESTPort = "1234"; - + protected final String logLocation = "dummyLogLocation"; protected interface DummyCyWriter extends CyWriter @@ -217,7 +226,7 @@ protected interface DummyCyWriter extends CyWriter public ListSingleSelection getUnits(); public void setHeight(Double height); } - + public BasicResourceTest() { CyLayoutAlgorithm def = mock(CyLayoutAlgorithm.class); Object context = new Object(); @@ -254,18 +263,18 @@ public BasicResourceTest() { tfManager = mock(TaskFactoryManager.class); inputStreamCXTaskFactory = mock(InputStreamTaskFactory.class); - + TaskIterator inputStreamTaskIterator = new TaskIterator(); - + // Start Mocks for CX URL Reading inputStreamCXNetworkReader = mock(CyNetworkReader.class); - + CyRootNetwork cyRootNetwork = mock(CyRootNetwork.class);//, withSettings().extraInterfaces(CySubNetwork.class)); CySubNetwork cySubNetwork = mock(CySubNetwork.class); - + when(inputStreamCXNetworkReader.buildCyNetworkView(cyRootNetwork)).thenReturn(mock(CyNetworkView.class)); when(inputStreamCXNetworkReader.buildCyNetworkView(cySubNetwork)).thenReturn(mock(CyNetworkView.class)); - + when(cyRootNetwork.getSUID()).thenReturn(1l); when(cySubNetwork.getSUID()).thenReturn(2l); when(cyRootNetwork.getDefaultNetworkTable()).thenReturn(mock(CyTable.class)); @@ -277,13 +286,13 @@ public BasicResourceTest() { when(cySubNetwork.getRow(cySubNetwork)).thenReturn(cyRow); CyNetwork[] inputStreamNetworks = new CyNetwork[]{cySubNetwork, cyRootNetwork}; when(inputStreamCXNetworkReader.getNetworks()).thenReturn(inputStreamNetworks); - + inputStreamTaskIterator.append(inputStreamCXNetworkReader); - + when(inputStreamCXTaskFactory.createTaskIterator(any(InputStream.class), eq("cx file"))).thenReturn(inputStreamTaskIterator); when(tfManager.getInputStreamTaskFactory(eq("cytoscapeCxNetworkReaderFactory"))).thenReturn(inputStreamCXTaskFactory); // End Mocks for CX URL Reading - + VisualMappingManager vmm = mock(VisualMappingManager.class); Set styles = new HashSet(); VisualStyle mockStyle = mock(VisualStyle.class); @@ -304,10 +313,10 @@ public BasicResourceTest() { CyNetworkViewWriterFactory cytoscapeJsWriterFactory = mock(CyNetworkViewWriterFactory.class); when(cytoscapeJsWriterFactory.createWriter(any(OutputStream.class), any(CyNetworkView.class))).thenReturn(mock(CyWriter.class)); - + ServiceTracker cytoscapeJsWriterFactoryTracker = mock(ServiceTracker.class); when(cytoscapeJsWriterFactoryTracker.getService()).thenReturn(cytoscapeJsWriterFactory); - + WriterListener writerListsner = mock(WriterListener.class); TaskMonitor headlessTaskMonitor = new HeadlessTaskMonitor(); @@ -326,43 +335,43 @@ public BasicResourceTest() { CyGroupManager groupManager = mock(CyGroupManager.class); loadNetworkURLTaskFactory = mock(LoadNetworkURLTaskFactory.class); CyNetworkReader cyNetworkReader = mock(CyNetworkReader.class); - + when(cyNetworkReader.getNetworks()).thenReturn(new CyNetwork[]{network}); when(loadNetworkURLTaskFactory.loadCyNetworks((java.net.URL) anyObject())).thenReturn(new TaskIterator(cyNetworkReader)); - + CyProperty cyPropertyServiceRef = mock(CyProperty.class); NewNetworkSelectedNodesAndEdgesTaskFactory networkSelectedNodesAndEdgesTaskFactory = mock(NewNetworkSelectedNodesAndEdgesTaskFactory.class); EdgeListReaderFactory edgeListReaderFactory = mock(EdgeListReaderFactory.class); - + InputStreamTaskFactory cytoscapeJsReaderFactory = mock(InputStreamTaskFactory.class); when(cytoscapeJsReaderFactory.createTaskIterator((InputStream)anyObject(), (String)anyObject())).thenReturn(new TaskIterator(cyNetworkReader)); ServiceTracker cytoscapeJsReaderFactoryTracker = mock(ServiceTracker.class); when(cytoscapeJsReaderFactoryTracker.getService()).thenReturn(cytoscapeJsReaderFactory); - + CyTableFactory tableFactory = mock(CyTableFactory.class); NetworkTaskFactory fitContentTaskFactory = mock(NetworkTaskFactory.class); TaskIterator fitTaskIterator = new TaskIterator(); fitTaskIterator.append(mock(Task.class)); - + when(fitContentTaskFactory.createTaskIterator(any(CyNetwork.class))).thenReturn(fitTaskIterator); - + EdgeBundler edgeBundler = mock(EdgeBundler.class); NetworkTaskFactory edgeBundlerTaskFactory = mock(NetworkTaskFactory.class); TaskIterator edgeBundlerTaskIterator = new TaskIterator(); edgeBundlerTaskIterator.append(mock(Task.class)); when(edgeBundlerTaskFactory.createTaskIterator(any(CyNetwork.class))).thenReturn(edgeBundlerTaskIterator); when(edgeBundler.getBundlerTF()).thenReturn(edgeBundlerTaskFactory); - + RenderingEngineManager renderingEngineManager = mock(RenderingEngineManager.class); - + renderingEngine = mock(RenderingEngine.class); when(renderingEngine.getRendererId()).thenReturn("org.cytoscape.ding"); Collection> renderingEngines = new ArrayList>(); renderingEngines.add(renderingEngine); - + when(renderingEngineManager.getRenderingEngines(anyObject())).thenReturn(renderingEngines); - - + + CySessionManager sessionManager = mock(CySessionManager.class); when(sessionManager.getCurrentSessionFileName()).thenReturn("testSession"); @@ -374,48 +383,51 @@ public BasicResourceTest() { newSessionTaskFactory = mock(NewSessionTaskFactory.class); when(newSessionTaskFactory.createTaskIterator(true)).thenReturn(new TaskIterator(mockTask)); CySwingApplication desktop = mock(CySwingApplication.class); - + NetworkTaskFactory lodNetworkTaskFactory = mock(NetworkTaskFactory.class); TaskIterator lodTaskIterator = new TaskIterator(); lodTaskIterator.append(mock(Task.class)); when(lodNetworkTaskFactory.createTaskIterator(null)).thenReturn(lodTaskIterator); - + LevelOfDetails lodTF = mock(LevelOfDetails.class); when(lodTF.getLodTF()).thenReturn(lodNetworkTaskFactory); - + selectFirstNeighborsTaskFactory = mock(SelectFirstNeighborsTaskFactory.class); graphicsWriterManager = mock(GraphicsWriterManager.class); - + presentationWriterFactory = mock(PresentationWriterFactory.class); - + DummyCyWriter cyWriter = mock(DummyCyWriter.class); BoundedDouble boundedDouble = new BoundedDouble(0d,1d,10d, true, true); - + ListSingleSelection listSingleSelection = new ListSingleSelection(); - + when(cyWriter.getUnits()).thenReturn(listSingleSelection); when(cyWriter.getZoom()).thenReturn(boundedDouble); - + when(presentationWriterFactory.createWriter(anyObject(), anyObject())).thenReturn(cyWriter); - + when(graphicsWriterManager.getFactory(anyString())).thenReturn(presentationWriterFactory); - + exportNetworkViewTaskFactory = mock(ExportNetworkViewTaskFactory.class); TaskIterator exportTaskIterator = new TaskIterator(); when(exportNetworkViewTaskFactory.createTaskIterator(any(CyNetworkView.class), any(File.class))).thenReturn(exportTaskIterator); final AvailableCommands available = mock(AvailableCommands.class); - + final List dummynameSpaces = new ArrayList(); dummynameSpaces.add(DUMMY_NAMESPACE); - + + final List dummyCommands = new ArrayList(); dummyCommands.add(DUMMY_COMMAND); - + dummyCommands.add(DUMMY_MULTI_TASK_COMMAND); + dummyCommands.add(DUMMY_APPEND_TASK_COMMAND); + final List dummyArguments = new ArrayList(); dummyArguments.add(DUMMY_ARGUMENT_NAME); - + when(available.getNamespaces()).thenReturn(dummynameSpaces); when(available.getCommands(eq(DUMMY_NAMESPACE))).thenReturn(dummyCommands); when(available.getArguments(DUMMY_NAMESPACE, DUMMY_COMMAND)).thenReturn(dummyArguments); @@ -424,39 +436,145 @@ public BasicResourceTest() { when(available.getArgDescription(DUMMY_NAMESPACE, DUMMY_COMMAND, DUMMY_ARGUMENT_NAME)).thenReturn(DUMMY_ARGUMENT_DESCRIPTION); when(available.getArgRequired(DUMMY_NAMESPACE, DUMMY_COMMAND, DUMMY_ARGUMENT_NAME)).thenReturn(false); + //No arguments for multi-task command and append task command + when(available.getArguments(DUMMY_NAMESPACE, DUMMY_MULTI_TASK_COMMAND)).thenReturn(new ArrayList()); + when(available.getArguments(DUMMY_NAMESPACE, DUMMY_APPEND_TASK_COMMAND)).thenReturn(new ArrayList()); + final CommandExecutorTaskFactory ceTaskFactory = mock(CommandExecutorTaskFactory.class); TaskIterator dummyTaskIterator = new TaskIterator(); - ObservableTask dummyJsonTask = mock(ObservableTask.class); - - //when(dummyJsonTask.) + ObservableTask dummyTask = mock(ObservableTask.class); + dummyTaskIterator.append(dummyTask); + when(dummyTask.getResults(String.class)).thenReturn("Dummy string"); when(ceTaskFactory.createTaskIterator(eq(DUMMY_NAMESPACE), eq(DUMMY_COMMAND), any(Map.class), any(TaskObserver.class))).thenReturn(dummyTaskIterator); + + TaskIterator dummyMultiTaskIterator = new TaskIterator(); + ObservableTask dummyMultiTaskA = mock(ObservableTask.class); + ObservableTask dummyMultiTaskB = mock(ObservableTask.class); + dummyMultiTaskIterator.append(dummyMultiTaskA); + dummyMultiTaskIterator.append(dummyMultiTaskB); + + try { + doAnswer(new Answer() { + public Void answer(InvocationOnMock invocation) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + System.err.println("Thread interrupt"); + } + multiTaskAComplete = true; + return null; + } + }).when(dummyMultiTaskA).run(any()); + } catch (Exception e1) { + e1.printStackTrace(); + } + + try { + doAnswer(new Answer() { + public Void answer(InvocationOnMock invocation) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + System.err.println("Thread interrupt"); + } + multiTaskBComplete = true; + return null; + } + }).when(dummyMultiTaskB).run(any()); + } catch (Exception e1) { + e1.printStackTrace(); + } + + when(dummyMultiTaskA.getResults(String.class)).thenReturn("Dummy string A"); + when(ceTaskFactory.createTaskIterator(eq(DUMMY_NAMESPACE), eq(DUMMY_MULTI_TASK_COMMAND), any(Map.class), any(TaskObserver.class))).thenReturn(dummyMultiTaskIterator); + + final TaskIterator dummyAppendTaskIterator = new TaskIterator(); + ObservableTask dummyAppendTaskA = mock(ObservableTask.class); + ObservableTask dummyAppendTaskB = mock(ObservableTask.class); + dummyAppendTaskIterator.append(dummyAppendTaskA); + try { + doAnswer(new Answer() { + public Void answer(InvocationOnMock invocation) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + System.err.println("Thread interrupt"); + } + dummyAppendTaskIterator.insertTasksAfter(dummyAppendTaskA, dummyAppendTaskB); + appendTaskAComplete = true; + return null; + } + }).when(dummyAppendTaskA).run(any()); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + doAnswer(new Answer() { + public Void answer(InvocationOnMock invocation) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + System.err.println("Thread interrupt"); + } + appendTaskBComplete = true; + return null; + } + }).when(dummyAppendTaskB).run(any()); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + when(ceTaskFactory.createTaskIterator(eq(DUMMY_NAMESPACE), eq(DUMMY_APPEND_TASK_COMMAND), any(Map.class), any(TaskObserver.class))).thenReturn(dummyAppendTaskIterator); + final SynchronousTaskManager synchronousTaskManager = mock(SynchronousTaskManager.class); doAnswer(new Answer() { public Void answer(InvocationOnMock invocation) { - Object[] args = invocation.getArguments(); - if (args[1] instanceof TaskObserver) { - //TODO make this execute closer to how Commands are actually executed. - ((TaskObserver) args[1]).taskFinished(dummyJsonTask); - ((TaskObserver) args[1]).allFinished(FinishStatus.getSucceeded()); - } + final ExecutorService service = Executors.newSingleThreadExecutor(); + service.submit(()-> { + Object[] args = invocation.getArguments(); + + TaskIterator taskIterator = (TaskIterator) args[0]; + TaskObserver observer = (TaskObserver) args[1]; + // System.out.println("SyncTaskManager.execute"); + + Task task = null; + try { + while (taskIterator.hasNext()) { + task = taskIterator.next(); + + task.run(mock(TaskMonitor.class)); + + if (task instanceof ObservableTask && observer != null) { + observer.taskFinished((ObservableTask)task); + } + } + if (observer != null) observer.allFinished(FinishStatus.getSucceeded()); + + } catch (Exception exception) { + if (observer != null && task != null) observer.allFinished(FinishStatus.newFailed(task, exception)); + } + }); return null; } }).when(synchronousTaskManager).execute(any(TaskIterator.class), any(TaskObserver.class));final CyNetworkViewWriterFactoryManager viewWriterFactoryManager = new CyNetworkViewWriterFactoryManager(); BundleResourceProvider bundleResourceProvider = mock(BundleResourceProvider.class); - + try { when(bundleResourceProvider.getResourceInputStream("dummyResourcePath")).thenReturn(new ByteArrayInputStream("test data".getBytes())); } catch (IOException e) { fail(); } - + final String cyRESTPort = this.cyRESTPort; - + final String logLocation = this.logLocation; - + this.binder = new CoreServiceModule(networkManager, viewManager, netFactory, tfManager, cyApplicationManager, vmm, cytoscapeJsWriterFactoryTracker, cytoscapeJsReaderFactoryTracker, layouts, writerListsner, @@ -479,7 +597,7 @@ private VisualStyle initStyle() throws Exception { lexicon = new DVisualLexicon(cgManager); final CyEventHelper eventHelper = mock(CyEventHelper.class); - + final CyServiceRegistrar cyServiceRegistrar = mock(CyServiceRegistrar.class); when(cyServiceRegistrar.getService(CyEventHelper.class)).thenReturn(mock(CyEventHelper.class)); passthroughFactory = new PassthroughMappingFactory(cyServiceRegistrar); @@ -751,9 +869,9 @@ public void start() { resourceClasses.add(UIResource.class); resourceClasses.add(CollectionResource.class); resourceClasses.add(CommandResource.class); - + resourceClasses.add(SwaggerUIResource.class); - + resourceClasses.add(CyRESTCommandSwagger.class); final ResourceConfig rc = new ResourceConfig(); diff --git a/src/test/java/org/cytoscape/rest/service/CommandResourceTest.java b/src/test/java/org/cytoscape/rest/service/CommandResourceTest.java index 0984c9813..9e19039ae 100644 --- a/src/test/java/org/cytoscape/rest/service/CommandResourceTest.java +++ b/src/test/java/org/cytoscape/rest/service/CommandResourceTest.java @@ -1,7 +1,9 @@ package org.cytoscape.rest.service; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import javax.ws.rs.core.Application; import javax.ws.rs.core.Response; @@ -33,4 +35,36 @@ public void testCommand() throws Exception { assertEquals(200, response.getStatus()); } + + @Test + public void testMultiTaskCommand() throws Exception { + + assertFalse(multiTaskAComplete); + assertFalse(multiTaskBComplete); + Response response = target("/v1/commands/dummyNamespace/dummyMultiTaskCommand").request().get(); + assertNotNull(response); + + final String body = response.readEntity(String.class); + System.out.println(body); + + assertEquals(200, response.getStatus()); + assertTrue(multiTaskAComplete); + assertTrue(multiTaskBComplete); + } + + @Test + public void testAppendTaskCommand() throws Exception { + + assertFalse(appendTaskAComplete); + assertFalse(appendTaskBComplete); + Response response = target("/v1/commands/dummyNamespace/dummyAppendTaskCommand").request().get(); + assertNotNull(response); + + final String body = response.readEntity(String.class); + System.out.println(body); + + assertEquals(200, response.getStatus()); + assertTrue(appendTaskAComplete); + assertTrue(appendTaskBComplete); + } }