public void assertContainsIgnoreCase(String searchIn, String searchFor) { if (new Str().containsIgnoreCase(searchIn, searchFor)) { return; } String msg = "<" + searchFor + "> not found in <" + searchIn + ">"; throw new AssertionFailedError(msg); }
String[] killArgs(boolean force) { List args = new ArrayList(); args.add(killCommand); if (force) { args.add("-9"); } args.add(pid); return str.toStringArray(args); }
/** * convienence method: * * @return shortClassName(obj.getClass()); */ public String shortClassName(Object obj) { return shortClassName(obj.getClass()); }
@Override protected void setUp() { str = new Str(); }
private boolean alreadyStarted(int port, String user, String pass) { new Str().classForName(Driver.class.getName()); Connection conn = null; String url = "jdbc:mysql://127.0.0.1:" + port + "/" + "?connectTimeout=150"; try { conn = DriverManager.getConnection(url, user, pass); return true; } catch (SQLException e) { if (e.getErrorCode() == MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR && throwOnBadPassword) { throw new SQLRuntimeException(e); } return false; } catch (Exception e) { return false; } finally { try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } } }
public void testGetAgentVersion() throws Exception { Map options = new HashMap(); options.put("foo", "bar"); MysqldResourceI mysqld = new MysqldResourceTestImpl(null, null, options, new HashMap()); SimpleMysqldDynamicMBean myBean = new SimpleMysqldDynamicMBean( new TestFactory(mysqld)); String verAttName = myBean.versionAttributeName(); String expected = "$Id: " + new Str().shortClassName(myBean); String beanVersion = (String) myBean.getAttribute(verAttName); new TestUtil().assertContainsIgnoreCase(beanVersion, expected); MBeanInfo info = myBean.getMBeanInfo(); MBeanAttributeInfo[] atts = info.getAttributes(); assertTrue(atts[0].isReadable()); assertTrue(atts[0].isWritable()); assertFalse(atts[0].isIs()); assertTrue(atts[1].isReadable()); assertTrue(atts[1].isWritable()); assertFalse(atts[1].isIs()); assertTrue(atts[2].isReadable()); assertFalse(atts[2].isWritable()); assertFalse(atts[2].isIs()); }
public void testContainsIgnoreCase() throws Exception { assertTrue(str.containsIgnoreCase("foobarbaz", "bar")); assertTrue(str.containsIgnoreCase("foobarbaz", "BAR")); assertTrue(str.containsIgnoreCase("fooBARbaz", "bar")); assertFalse(str.containsIgnoreCase("foobarbaz", "whiz")); }
public Map getOptionsFromHelp(String help) { String trimmed = trimToOptions(help); Map map = new LinkedHashMap(); String[] lines = utils.str().splitLines(trimmed); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.indexOf(' ') <= 0) { continue; } String key = line.substring(0, line.indexOf(' ')); String val = line.substring(key.length()).trim(); if (val.equals(NO_DEFAULT_VALUE)) { val = ""; } map.put(key, val); } map.remove("help"); map.remove("verbose"); return map; }
String trimToOptions(String help) { boolean success = false; try { int dividerPos = help.indexOf(DIVIDER); int start = dividerPos + DIVIDER.length(); int stop = help.indexOf(END_TEXT); if (dividerPos == -1) { throw new RuntimeException("Can not parse: <" + help + ">"); } help = help.substring(start, stop); help = help + System.getProperty("line.separator"); success = true; return help; } finally { if (!success) { StringBuffer msg = new StringBuffer(); msg.append("["); msg.append(classUtil.shortName(this)); msg.append("] parsing unseccessful:"); msg.append(str.newLine()); msg.append(help); err.println(msg); } } }
boolean canConnectToServer(int port, int milisecondsBeforeGivingUp) { int triesBeforeGivingUp = 1 + (milisecondsBeforeGivingUp / 1000) * 4; utils.str().classForName(Driver.class.getName()); Connection conn = null; String bogusUser = "Connector/MXJ"; String password = "Bogus Password"; String url = "jdbc:mysql://127.0.0.1:" + port + "/test" + "?connectTimeout=150"; for (int i = 0; i < triesBeforeGivingUp; i++) { try { conn = DriverManager.getConnection(url, bogusUser, password); return true; /* should never happen */ } catch (SQLException e) { if (e.getErrorCode() == MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR) { return true; } } finally { try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(err); } } utils.threads().pause(100); } return false; }
/** * returns the contentents of the collection as a string a collections with * "a", "b", null, and new Integer(1) would return: {[a][b][null][1]} */ public String toString(Collection strings) { return toString(strings, "[", "][", "]"); }
protected void setUp() { str = new Str(); }
public void testContainsIgnoreCase() throws Exception { assertTrue(str.containsIgnoreCase("foobarbaz", "bar")); assertTrue(str.containsIgnoreCase("foobarbaz", "BAR")); assertTrue(str.containsIgnoreCase("fooBARbaz", "bar")); assertFalse(str.containsIgnoreCase("foobarbaz", "whiz")); }
public Map getOptionsFromHelp(String help) { String trimmed = trimToOptions(help); Map map = new LinkedHashMap(); String[] lines = utils.str().splitLines(trimmed); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.indexOf(' ') <= 0) { continue; } String key = line.substring(0, line.indexOf(' ')); String val = line.substring(key.length()).trim(); if (val.equals(NO_DEFAULT_VALUE)) { val = ""; } map.put(key, val); } map.remove("help"); map.remove("verbose"); return map; }
utils.files().writeString(portFile, port + utils.str().newLine());
boolean canConnectToServer(int port, int milisecondsBeforeGivingUp) { int triesBeforeGivingUp = 1 + (milisecondsBeforeGivingUp / 1000) * 4; utils.str().classForName(Driver.class.getName()); Connection conn = null; String bogusUser = "Connector/MXJ";