Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestUtil.java =================================================================== RCS file: /usr/local/cvsroot/TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestUtil.java,v diff -u -r1.2 -r1.3 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestUtil.java 17 Sep 2006 06:09:25 -0000 1.2 +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestUtil.java 13 Jan 2014 08:47:10 -0000 1.3 @@ -37,100 +37,91 @@ import com.allaire.wddx.WddxSerializer; /** - * @version - * - *

- * View Source - *

- * - * @author Fei Yang + * @author Fei Yang, Marcin Cieslak */ public class TestUtil { + private static final Logger log = Logger.getLogger(TestUtil.class); + protected static final char NAME_SEPERATOR = '_'; - private static final Logger log = Logger.getLogger(TestUtil.class); - - private static String machineName; + private static String machineName; - protected static final char NAME_SEPERATOR = '_'; + public static String buildName(String testName, String simpleName) { + return TestUtil.getMachineName() + TestUtil.NAME_SEPERATOR + testName + TestUtil.NAME_SEPERATOR + simpleName; + } - public static String getMachineName() { - try { - if (machineName == null) - return machineName = InetAddress.getLocalHost().getHostName(); - else - return machineName; - } catch (UnknownHostException e) { - return "UnknownHost"; - } + public static String buildName(String testName, String simpleName, int maxLength) { + return TestUtil.truncate(TestUtil.buildName(TestUtil.truncate(testName, 1, true), simpleName), maxLength, true); + } - } + public static Object deserialize(String wddxPacket) throws WddxDeserializationException { - public static String serialize(Object data) throws IOException { - WddxSerializer tempws = new WddxSerializer(); - StringWriter tempsw = new StringWriter(); - tempws.serialize(data, tempsw); - return tempsw.toString(); - } + TestUtil.log.debug("WDDX packet from the server:" + wddxPacket); - public static Object deserialize(String wddxPacket) throws WddxDeserializationException { - - log.debug("WDDX packet from the server:"+wddxPacket); - - // Create an input source (org.xml.sax.InputSource) bound to the packet - InputSource tempSource = new InputSource(new StringReader(wddxPacket)); + // Create an input source (org.xml.sax.InputSource) bound to the packet + InputSource tempSource = new InputSource(new StringReader(wddxPacket)); - // Create a WDDX deserializer (com.allaire.wddx.WddxDeserializer) - WddxDeserializer tempDeserializer = new WddxDeserializer("org.apache.xerces.parsers.SAXParser"); + // Create a WDDX deserializer (com.allaire.wddx.WddxDeserializer) + WddxDeserializer tempDeserializer = new WddxDeserializer("org.apache.xerces.parsers.SAXParser"); - // Deserialize the WDDX packet - Object result; - try { - result = tempDeserializer.deserialize(tempSource); - log.debug("Object deserialized from the WDDX packet:"+result); - } catch (IOException e) { - throw new WddxDeserializationException(e); - } - - return result; + // Deserialize the WDDX packet + Object result; + try { + result = tempDeserializer.deserialize(tempSource); + TestUtil.log.debug("Object deserialized from the WDDX packet:" + result); + } catch (IOException e) { + throw new WddxDeserializationException(e); } - public static String buildName(String testName, String simpleName) { - return TestUtil.getMachineName() + NAME_SEPERATOR + testName + NAME_SEPERATOR + simpleName; - } + return result; + } - public static String buildName(String testName, String simpleName, int maxLength) { - return truncate(buildName(truncate(testName,1,true),simpleName), maxLength, true); + public static String extractString(String text, String startFlag, char endFlag) { + String target = null; + try { + int index = text.indexOf(startFlag); + if (index != -1) { + int startIndex = index + startFlag.length(); + int endIndex = text.indexOf(endFlag, startIndex); + target = text.substring(startIndex, endIndex); + } + } catch (IndexOutOfBoundsException e) { + TestUtil.log.error("Index out of bounds. StartFlag: " + startFlag + ", endFlag: " + endFlag + ", text: " + + text); } + return target; + } - private static String truncate(String name, int length, boolean leftToRight) { - if(name.length()<=length) - return name; - if(leftToRight) - return name.substring(name.length()-length); - else - return name.substring(0,length); - } + public static int generateRandomNumber(int length) { + return new Random().nextInt(length); + } - public static String extractString(String text, String startFlag, char endFlag){ - String target = null; - try{ - int index = text.indexOf(startFlag); - if(index!=-1){ - int startIndex = index + startFlag.length(); - int endIndex = text.indexOf(endFlag, startIndex); - target = text.substring(startIndex, endIndex); - } - }catch(IndexOutOfBoundsException e){ - log.debug(e.getMessage()); - log.debug("startFlag: "+startFlag+" endFlag: "+endFlag); - log.debug(text); - } - return target; + public static String getMachineName() { + try { + if (TestUtil.machineName == null) { + return TestUtil.machineName = InetAddress.getLocalHost().getHostName(); + } else { + return TestUtil.machineName; + } + } catch (UnknownHostException e) { + return "UnknownHost"; } + } - public static int generateRandomIndex(int length){ - return new Random().nextInt(length); - } - + public static String serialize(Object data) throws IOException { + WddxSerializer tempws = new WddxSerializer(); + StringWriter tempsw = new StringWriter(); + tempws.serialize(data, tempsw); + return tempsw.toString(); + } + private static String truncate(String name, int length, boolean leftToRight) { + if (name.length() <= length) { + return name; + } + if (leftToRight) { + return name.substring(name.length() - length); + } else { + return name.substring(0, length); + } + } } \ No newline at end of file