/*
# Licensed Materials - Property of IBM
# Copyright IBM Corp. 2015  
 */
package com.ibm.streamsx.topology.test.python;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Map;

import org.junit.Before;

import com.ibm.streamsx.topology.Topology;
import com.ibm.streamsx.topology.context.StreamsContext.Type;
import com.ibm.streamsx.topology.spl.SPL;
import com.ibm.streamsx.topology.test.TestTopology;

/**
 * Test publish/subscribe. These tests just use publish/subscribe
 * within a single job, but the expected use case is across jobs.
 *
 */
abstract class PublishSubscribePython extends TestTopology {

    @Before
    public void checkIsDistributed() {
        assumeTrue(getTesterType() == Type.DISTRIBUTED_TESTER);
    }
    
    Path genPythonToolkit(String module) throws IOException, InterruptedException {
    	
    	Path pubsub = Paths.get(getTestRoot().getAbsolutePath(), "python", "pubsub");
    	System.err.println("Pubsub:" + pubsub);
    	
    	
    	Path pyTk = Files.createTempDirectory("pytk").toAbsolutePath();
    	
    	System.err.println("PKTK:" + pyTk);
    	
    	Path pyPackages = Paths.get(System.getProperty("topology.toolkit.release"),
    			"opt", "python", "packages").toAbsolutePath();

      String pythonversion = System.getProperty("topology.test.python"); 
    	    	
		ProcessBuilder pb = new ProcessBuilder(pythonversion, module, pyTk.toAbsolutePath().toString());		
		pb.redirectOutput(Redirect.INHERIT);
		pb.redirectError(Redirect.INHERIT);
		
    	Map<String, String> env = pb.environment();
    	env.put("PYTHONPATH", pyPackages.toString());
		
		pb.directory(pubsub.toFile());
		Process proc = pb.start();
		
		assertEquals(0, proc.waitFor());
    	
    	return pyTk;
    }
    
    public void includePythonApp(Topology topology, String module, String composite) throws Exception {
    	Path pyTk = genPythonToolkit(module);
    	    	    	
    	SPL.addToolkit(topology, pyTk.toFile());
    	
    	SPL.invokeOperator(topology, "MainPy", composite,
    			Collections.emptyList(), Collections.emptyList(),
    			Collections.emptyMap());
    }
}

@@ -1145,65 +1145,14 @@
 %22);%0A
-    %09System.err.println(%22Pubsub:%22 + pubsub);%0A    %09%0A
     %09%0A
+
     
@@ -1226,55 +1226,8 @@
   %09%0A
-    %09System.err.println(%22PKTK:%22 + pyTk);%0A    %09%0A
     
@@ -1358,16 +1358,18 @@
 ath();%0A%0A
+  
       St

Remove System.err debug msgs