public void testShortName() { assertEquals("String", new ClassUtil().shortName(String.class)); } }
public void testTrimOptionsErrorMsg() { ByteArrayOutputStream out = new ByteArrayOutputStream(); HelpOptionsParser parser = new HelpOptionsParser(new PrintStream(out), new Threads(), new ClassUtil(), new Str()); Exception expected = null; try { parser.trimToOptions("bogus"); } catch (Exception e) { expected = e; } assertNotNull(expected); String errMsg = new String(out.toByteArray()); assertTrue(errMsg.indexOf("bogus") >= 0); } }
public void testOptionParser() throws Exception { String resourceVersionDir = MysqldResourceI.DEFAULT_VERSION.replaceAll( "\\.", "-"); assertEquals("4-1-13", resourceVersionDir); String sampleHelp = resourceVersionDir + "/com/mysql/management/MySQL_Help.txt"; ClassLoader cl = getClass().getClassLoader(); InputStream is = cl.getResourceAsStream(sampleHelp); String help = new Streams().readString(is); is.close(); HelpOptionsParser parser = new HelpOptionsParser(System.err, new Threads(), new ClassUtil(), new Str()); Map parsed = parser.parseHelp(help); assertEquals("/usr/local/mysql/", parsed.get(MysqldResourceI.BASEDIR)); assertEquals("TRUE", parsed.get("bdb")); // assertEquals("(No default value)", parsed.get("time-format")); assertEquals("", parsed.get("time-format")); }
/** * This constructor is useful for tests which need to have "stub" or "mock" * implementations of the underlying MySQL resource. This constructor is not * included int the MBeanInfo. */ protected SimpleMysqldDynamicMBean(MysqldResourceI mysqldResource) { this.mysqldResource = mysqldResource; this.classUtil = new ClassUtil(); this.notesInfos = new MBeanNotificationInfo[0]; this.mBeanOperationInfoList = new ArrayList(); this.startMysqldOp = newVoidMBeanOperation(START_METHOD, "Start MySQL"); this.stopOp = newVoidMBeanOperation(STOP_METHOD, "Stop MySQL"); getMBeanOperationInfoList().add(startMysqldOp); initAttributes(); initConstructors(); }
public MysqldResource(File baseDir, PrintStream out, PrintStream err) { this(baseDir, out, err, new FileUtil(), new Shell.Factory(), new Streams(), new Threads(), new Str(), new ClassUtil()); }
protected void setUp() { super.setUp(); testUtil = new TestUtil(); threads = new Threads(); fileUtil = new TestFileUtil(); shellFactory = new Shell.Factory(); streams = new Streams(); str = new Str(); classUtil = new ClassUtil(); mysqldResource = new MysqldResource(fileUtil.nullFile(), System.out, System.err, fileUtil, shellFactory, streams, threads, str, classUtil); mysqldResource.setKillDelay(10000); File baseDir = mysqldResource.getBaseDir(); fileUtil.deleteTree(baseDir); if (baseDir.exists()) { warn("residual files"); } }
public void testGetAgentVersion() throws Exception { Map options = new HashMap(); options.put("foo", "bar"); MysqldResourceI mysqld = new MysqldResourceTestImpl(options); SimpleMysqldDynamicMBean myBean = new SimpleMysqldDynamicMBean(mysqld); String verAttName = myBean.versionAttributeName(); String expected = "$Id: " + new ClassUtil().shortName(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()); }