/** * Test run control api cli client * * @throws Exception */ @Test public void testRunControlApiCliClient() throws Exception { File propertiesFile = File.createTempFile("testApiCliClnt", null); Properties props = new Properties(); props.put("thrift_host", HOST); props.put("thrift_port", PORT + ""); FileOutputStream fos = new FileOutputStream(propertiesFile); props.store(fos, ""); fos.close(); ConsoleReader reader = Mockito.mock(ConsoleReader.class); Mockito.doReturn("disconnect; quit").when(reader).readLine(Mockito.any(String.class)); ControlApiCliThriftClient cli = Mockito.spy(new ControlApiCliThriftClient()); Mockito.doReturn(reader).when(cli).createReader(); int result = cli.process(new String[] {"\\/\\/\\", "----"}); Assert.assertEquals(1, result); result = cli.process(new String[] {"-c", "fake"}); Assert.assertEquals(2, result); result = cli.process(new String[] {"-c", propertiesFile.getAbsolutePath()}); Assert.assertEquals(-1, result); TestCluster.stop(); result = cli.process(new String[] {"-c", propertiesFile.getAbsolutePath()}); Assert.assertEquals(1, result); propertiesFile.delete(); }
/** * Before test. * * @throws Exception the exception */ @Before public void beforeTest() throws Exception { MongoDataLoader.loadData(); TestCluster.checkStarted(controlService); }
/** * After. * * @throws Exception the exception */ @AfterClass public static void after() throws Exception { TestCluster.stop(); MongoDBTestRunner.tearDown(); }