1 package org.objectweb.celtix.testutil.common; 2 3 import java.util.logging.Logger ; 4 5 import junit.framework.Assert; 6 7 public abstract class AbstractTestServerBase extends Assert { 8 9 14 protected abstract void run(); 15 16 protected Logger getLog() { 17 String loggerName = this.getClass().getName(); 18 return Logger.getLogger(loggerName); 19 } 20 21 22 public void startInProcess() throws Exception { 23 System.out.println("running server in-process"); 24 run(); 25 System.out.println("signal ready"); 26 ready(); 27 } 28 29 public boolean stopInProcess() throws Exception { 30 boolean ret = true; 31 if (verify(getLog())) { 32 System.out.println("server passed"); 33 } else { 34 ret = false; 35 } 36 return ret; 37 } 38 39 public void start() { 40 try { 41 System.out.println("running server"); 42 run(); 43 System.out.println("signal ready"); 44 ready(); 45 46 System.in.read(); 50 System.out.println("stopping bus"); 51 tearDown(); 52 } catch (Throwable ex) { 53 ex.printStackTrace(); 54 startFailed(); 55 } finally { 56 if (verify(getLog())) { 57 System.out.println("server passed"); 58 } else { 59 System.out.println(ServerLauncher.SERVER_FAILED); 60 } 61 System.out.println("server stopped"); 62 System.exit(0); 63 } 64 } 65 66 public void setUp() throws Exception { 67 } 69 70 public void tearDown() throws Exception { 71 } 73 74 protected void ready() { 75 System.out.println("server ready"); 76 } 77 78 protected void startFailed() { 79 System.out.println(ServerLauncher.SERVER_FAILED); 80 System.exit(-1); 81 } 82 83 89 protected boolean verify(Logger l) { 90 return true; 91 } 92 } 93 | Popular Tags |