List of usage examples for java.io StringWriter getBuffer
public StringBuffer getBuffer()
From source file:com.vmware.gemfire.tools.pulse.tests.junit.ClusterSelectedRegionServiceTest.java
/** * * Tests that response is for same region * * Test method for {@link com.vmware.gemfire.tools.pulse.internal.service.ClusterSelectedRegionService#execute(javax.servlet.http.HttpServletRequest)}. * *///from ww w . j a va 2 s . com @Test public void testResponseNonExistentRegion() { System.out.println( "ClusterSelectedRegionServiceTest :: ------TESTCASE BEGIN : NON-EXISTENT REGION CHECK FOR CLUSTER REGIONS------"); if (httpclient != null) { try { HttpUriRequest pulseupdate = RequestBuilder.post().setUri(new URI(PULSE_UPDATE_URL)) .addParameter(PULSE_UPDATE_PARAM, PULSE_UPDATE_2_VALUE).build(); CloseableHttpResponse response = httpclient.execute(pulseupdate); try { HttpEntity entity = response.getEntity(); System.out.println("ClusterSelectedRegionServiceTest :: HTTP request status : " + response.getStatusLine()); BufferedReader respReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String sz = null; while ((sz = respReader.readLine()) != null) { pw.print(sz); } String jsonResp = sw.getBuffer().toString(); System.out.println("ClusterSelectedRegionServiceTest :: JSON response returned : " + jsonResp); EntityUtils.consume(entity); JSONObject jsonObj = new JSONObject(jsonResp); JSONObject clusterSelectedRegionObj = jsonObj.getJSONObject("ClusterSelectedRegion"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null response for ClusterSelectedRegion", clusterSelectedRegionObj); JSONObject jsonObjRegion = clusterSelectedRegionObj.getJSONObject("selectedRegion"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null response for selectedRegion", jsonObjRegion); Assert.assertTrue( "ClusterSelectedRegionServiceTest :: Server did not return error on non-existent region", jsonObjRegion.has("errorOnRegion")); } finally { response.close(); } } catch (Exception failed) { logException(failed); Assert.fail("Exception ! "); } } else { Assert.fail("ClusterSelectedRegionServiceTest :: No Http connection was established."); } System.out.println( "ClusterSelectedRegionServiceTest :: ------TESTCASE END : NON-EXISTENT REGION CHECK FOR CLUSTER REGIONS------\n"); }
From source file:com.vmware.gemfire.tools.pulse.tests.junit.ClusterSelectedRegionServiceTest.java
/** * * Tests that response is for same region * * Test method for {@link com.vmware.gemfire.tools.pulse.internal.service.ClusterSelectedRegionService#execute(javax.servlet.http.HttpServletRequest)}. * *//* www . ja v a2 s. c om*/ @Test public void testResponseRegionPathMatches() { System.out.println( "ClusterSelectedRegionServiceTest :: ------TESTCASE BEGIN : REGION PATH IN RESPONSE CHECK FOR CLUSTER REGIONS------"); if (httpclient != null) { try { HttpUriRequest pulseupdate = RequestBuilder.post().setUri(new URI(PULSE_UPDATE_URL)) .addParameter(PULSE_UPDATE_PARAM, PULSE_UPDATE_1_VALUE).build(); CloseableHttpResponse response = httpclient.execute(pulseupdate); try { HttpEntity entity = response.getEntity(); System.out.println("ClusterSelectedRegionServiceTest :: HTTP request status : " + response.getStatusLine()); BufferedReader respReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String sz = null; while ((sz = respReader.readLine()) != null) { pw.print(sz); } String jsonResp = sw.getBuffer().toString(); System.out.println("ClusterSelectedRegionServiceTest :: JSON response returned : " + jsonResp); EntityUtils.consume(entity); JSONObject jsonObj = new JSONObject(jsonResp); JSONObject clusterSelectedRegionObj = jsonObj.getJSONObject("ClusterSelectedRegion"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null response for ClusterSelectedRegion", clusterSelectedRegionObj); JSONObject jsonObjRegion = clusterSelectedRegionObj.getJSONObject("selectedRegion"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null response for selectedRegion", jsonObjRegion); Assert.assertTrue("ClusterSelectedRegionServiceTest :: Server did not return 'path' of region", jsonObjRegion.has("path")); String szPath = jsonObjRegion.getString("path"); Assert.assertEquals( "ClusterSelectedRegionServiceTest :: Server returned wrong region path. Expected region path = /GlobalVilage_2/GlobalVilage_9 , actual region path = " + szPath, szPath, "/GlobalVilage_2/GlobalVilage_9"); } finally { response.close(); } } catch (Exception failed) { logException(failed); Assert.fail("Exception ! "); } } else { Assert.fail("ClusterSelectedRegionServiceTest :: No Http connection was established."); } System.out.println( "ClusterSelectedRegionServiceTest :: ------TESTCASE END : REGION PATH IN RESPONSE CHECK FOR CLUSTER REGIONS------\n"); }
From source file:org.alfresco.bm.test.LifecycleController.java
/** * Stop all listeners/*from w w w. j a v a 2 s . c o m*/ */ private synchronized void stop() { if (!started) { // Someone jumped in ahead of us return; } // We have stopped no matter what started = false; StringBuffer sb = new StringBuffer(1024); sb.append("\nStopping ..."); if (logger.isDebugEnabled()) { logger.debug("Stopping components: " + name); } for (LifecycleListener listener : lifecycleListeners) { String listenerName = listener.getClass().getName(); if (logger.isDebugEnabled()) { logger.debug(" Stopping component: " + listenerName); } try { listener.stop(); if (logger.isDebugEnabled()) { logger.debug(" Stopped component: " + listenerName); } sb.append("\n Stopped component: " + listenerName); } catch (Exception e) { // Absorb the exception logger.error(" Failed to stop component: " + listenerName, e); sb.append("\n Failed to stop component: " + listenerName); StringWriter stackWriter = new StringWriter(1024); WriterOutputStream wos = new WriterOutputStream(stackWriter); PrintWriter pw = new PrintWriter(wos); try { e.printStackTrace(pw); } finally { try { pw.close(); } catch (Exception ee) { } } sb.append("\n").append(stackWriter.getBuffer().toString()); } } if (logger.isDebugEnabled()) { logger.debug("Stopped components: " + name); } log.append(sb.toString()); }
From source file:com.vmware.gemfire.tools.pulse.tests.junit.ClusterSelectedRegionServiceTest.java
/** * * Tests that service returns json object * * Test method for {@link com.vmware.gemfire.tools.pulse.internal.service.ClusterSelectedRegionService#execute(javax.servlet.http.HttpServletRequest)}. * *///from w w w . j ava 2 s . c o m @Test public void testResponseMemerberCount() { System.out.println( "ClusterSelectedRegionServiceTest :: ------TESTCASE BEGIN : MISMATCHED MEMBERCOUNT FOR REGION CHECK FOR CLUSTER REGIONS------"); if (httpclient != null) { try { HttpUriRequest pulseupdate = RequestBuilder.post().setUri(new URI(PULSE_UPDATE_URL)) .addParameter(PULSE_UPDATE_PARAM, PULSE_UPDATE_1_VALUE).build(); CloseableHttpResponse response = httpclient.execute(pulseupdate); try { HttpEntity entity = response.getEntity(); System.out.println("ClusterSelectedRegionServiceTest :: HTTP request status : " + response.getStatusLine()); BufferedReader respReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String sz = null; while ((sz = respReader.readLine()) != null) { pw.print(sz); } String jsonResp = sw.getBuffer().toString(); System.out.println("ClusterSelectedRegionServiceTest :: JSON response returned : " + jsonResp); EntityUtils.consume(entity); JSONObject jsonObj = new JSONObject(jsonResp); JSONObject clusterSelectedRegionObj = jsonObj.getJSONObject("ClusterSelectedRegion"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null ClusterSelectedRegion", clusterSelectedRegionObj); JSONObject jsonObjRegion = clusterSelectedRegionObj.getJSONObject("selectedRegion"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null for selectedRegion", jsonObjRegion); Assert.assertTrue( "ClusterSelectedRegionServiceTest :: Server did not return 'memberCount' of region", jsonObjRegion.has("memberCount")); int memberCount = jsonObjRegion.getInt("memberCount"); Assert.assertTrue( "ClusterSelectedRegionServiceTest :: Server did not return 'members' of region", jsonObjRegion.has("members")); JSONArray arrMembers = jsonObjRegion.getJSONArray("members"); Assert.assertNotNull( "ClusterSelectedRegionServiceTest :: Server returned null response in selectedRegion", arrMembers); int members = arrMembers.length(); Assert.assertEquals( "ClusterSelectedRegionServiceTest :: Server returned mismatched member count and region members", members, memberCount); } finally { response.close(); } } catch (Exception failed) { logException(failed); Assert.fail("Exception ! "); } } else { Assert.fail("ClusterSelectedRegionServiceTest :: No Http connection was established."); } System.out.println( "ClusterSelectedRegionServiceTest :: ------TESTCASE END : MISMATCHED MEMBERCOUNT FOR REGION CHECK FOR CLUSTER REGIONS------\n"); }
From source file:org.alfresco.bm.test.LifecycleController.java
/** * Start all listeners// w w w .j a v a 2 s. c o m */ private synchronized void start() { if (started) { // Someone jumped in ahead of us return; } // We start no matter what started = true; StringBuffer sb = new StringBuffer(1024); sb.append("\nStarting ..."); if (logger.isDebugEnabled()) { logger.debug("Starting components: " + name); } for (LifecycleListener listener : lifecycleListeners) { String listenerName = listener.getClass().getName(); if (logger.isDebugEnabled()) { logger.debug(" Starting component: " + listenerName); } try { listener.start(); if (logger.isDebugEnabled()) { logger.debug(" Started component: " + listenerName); } sb.append("\n Started component: " + listenerName); } catch (Exception e) { // Absorb the exception logger.error(" Failed to start component: " + listenerName, e); sb.append("\n Failed to start component: " + listenerName); StringWriter stackWriter = new StringWriter(1024); WriterOutputStream wos = new WriterOutputStream(stackWriter); PrintWriter pw = new PrintWriter(wos); try { e.printStackTrace(pw); } finally { try { pw.close(); } catch (Exception ee) { } } sb.append("\n").append(stackWriter.getBuffer().toString()); // Now respect the forceStart option if (!forceStart) { throw new RuntimeException("Component failed to start: " + listenerName, e); } } } if (logger.isDebugEnabled()) { logger.debug("Started components: " + name); } log.append(sb.toString()); }
From source file:com.vmware.gemfire.tools.pulse.tests.junit.ClusterSelectedRegionsMemberServiceTest.java
/** * Tests that service returns json object * *//*from w w w . j a v a 2s . c o m*/ @Test public void testResponseNotNull() { System.out.println( "ClusterSelectedRegionsMemberServiceTest :: ------TESTCASE BEGIN : NULL RESPONSE CHECK FOR CLUSTER REGION MEMBERS------"); if (httpclient != null) { try { HttpUriRequest pulseupdate = RequestBuilder.post().setUri(new URI(PULSE_UPDATE_URL)) .addParameter(PULSE_UPDATE_PARAM, PULSE_UPDATE_3_VALUE).build(); CloseableHttpResponse response = httpclient.execute(pulseupdate); try { HttpEntity entity = response.getEntity(); System.out.println("ClusterSelectedRegionsMemberServiceTest :: HTTP request status : " + response.getStatusLine()); BufferedReader respReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String sz = null; while ((sz = respReader.readLine()) != null) { pw.print(sz); } String jsonResp = sw.getBuffer().toString(); System.out.println( "ClusterSelectedRegionsMemberServiceTest :: JSON response returned : " + jsonResp); EntityUtils.consume(entity); JSONObject jsonObj = new JSONObject(jsonResp); Assert.assertNotNull( "ClusterSelectedRegionsMemberServiceTest :: Server returned null response for ClusterSelectedRegionsMember", jsonObj.getJSONObject("ClusterSelectedRegionsMember")); } finally { response.close(); } } catch (Exception failed) { logException(failed); Assert.fail("Exception ! "); } } else { Assert.fail("ClusterSelectedRegionsMemberServiceTest :: No Http connection was established."); } System.out.println( "ClusterSelectedRegionsMemberServiceTest :: ------TESTCASE END : NULL RESPONSE CHECK FOR CLUSTER REGION MEMBERS------"); }
From source file:com.netspective.sparx.navigate.NavigationControllerServletOptions.java
public String getHelp() { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(printWriter, 90, "com.netspective.sparx.navigate.CONTROLLER_SERVLET_OPTIONS Init Parameter", "Class: " + getClass().getName(), servletOptions, 3, 0, ""); return stringWriter.getBuffer().toString(); }
From source file:com.vmware.gemfire.tools.pulse.tests.junit.ClusterSelectedRegionsMemberServiceTest.java
/** * * Tests that response is for same logged in user * */// w w w .j a v a2 s .c o m @Test public void testResponseUsername() { System.out.println( "ClusterSelectedRegionsMemberServiceTest :: ------TESTCASE BEGIN : NULL USERNAME IN RESPONSE CHECK FOR CLUSTER REGION MEMBERS------"); if (httpclient != null) { try { HttpUriRequest pulseupdate = RequestBuilder.post().setUri(new URI(PULSE_UPDATE_URL)) .addParameter(PULSE_UPDATE_PARAM, PULSE_UPDATE_3_VALUE).build(); CloseableHttpResponse response = httpclient.execute(pulseupdate); try { HttpEntity entity = response.getEntity(); System.out.println("ClusterSelectedRegionsMemberServiceTest :: HTTP request status : " + response.getStatusLine()); BufferedReader respReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String sz = null; while ((sz = respReader.readLine()) != null) { pw.print(sz); } String jsonResp = sw.getBuffer().toString(); System.out.println( "ClusterSelectedRegionsMemberServiceTest :: JSON response returned : " + jsonResp); EntityUtils.consume(entity); JSONObject jsonObj = new JSONObject(jsonResp); JSONObject clusterSelectedRegionObj = jsonObj.getJSONObject("ClusterSelectedRegionsMember"); Assert.assertNotNull( "ClusterSelectedRegionsMemberServiceTest :: Server returned null response for ClusterSelectedRegionsMember", clusterSelectedRegionObj); Assert.assertTrue( "ClusterSelectedRegionsMemberServiceTest :: Server did not return 'userName' in request", clusterSelectedRegionObj.has("userName")); String szUser = clusterSelectedRegionObj.getString("userName"); Assert.assertEquals( "ClusterSelectedRegionsMemberServiceTest :: Server returned wrong user name. Expected was admin. Server returned = " + szUser, szUser, "admin"); } finally { response.close(); } } catch (Exception failed) { logException(failed); Assert.fail("Exception ! "); } } else { Assert.fail("ClusterSelectedRegionsMemberServiceTest :: No Http connection was established."); } System.out.println( "ClusterSelectedRegionsMemberServiceTest :: ------TESTCASE END : NULL USERNAME IN RESPONSE CHECK FOR CLUSTER REGION MEMBERS------"); }
From source file:com.vmware.gemfire.tools.pulse.tests.junit.ClusterSelectedRegionsMemberServiceTest.java
/** * * Tests that response is for same region * * *//* w w w . ja v a2s .c om*/ @Test public void testResponseNonExistentRegion() { System.out.println( "ClusterSelectedRegionsMemberServiceTest :: ------TESTCASE BEGIN : NON-EXISTENT REGION CHECK FOR CLUSTER REGION MEMBERS------"); if (httpclient != null) { try { System.out.println("Test for non-existent region : /Rubbish"); HttpUriRequest pulseupdate = RequestBuilder.post().setUri(new URI(PULSE_UPDATE_URL)) .addParameter(PULSE_UPDATE_PARAM, PULSE_UPDATE_4_VALUE).build(); CloseableHttpResponse response = httpclient.execute(pulseupdate); try { HttpEntity entity = response.getEntity(); System.out.println("ClusterSelectedRegionsMemberServiceTest :: HTTP request status : " + response.getStatusLine()); BufferedReader respReader = new BufferedReader(new InputStreamReader(entity.getContent())); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String sz = null; while ((sz = respReader.readLine()) != null) { pw.print(sz); } String jsonResp = sw.getBuffer().toString(); System.out.println( "ClusterSelectedRegionsMemberServiceTest :: JSON response returned : " + jsonResp); EntityUtils.consume(entity); JSONObject jsonObj = new JSONObject(jsonResp); JSONObject clusterSelectedRegionObj = jsonObj.getJSONObject("ClusterSelectedRegionsMember"); Assert.assertNotNull( "ClusterSelectedRegionsMemberServiceTest :: Server returned null for ClusterSelectedRegionsMember", clusterSelectedRegionObj); JSONObject jsonObjRegion = clusterSelectedRegionObj.getJSONObject("selectedRegionsMembers"); Assert.assertNotNull( "ClusterSelectedRegionsMemberServiceTest :: Server returned null for selectedRegionsMembers", jsonObjRegion); Assert.assertTrue( "ClusterSelectedRegionsMemberServiceTest :: Server did not return error on non-existent region", jsonObjRegion.has("errorOnRegion")); } finally { response.close(); } } catch (Exception failed) { logException(failed); Assert.fail("Exception ! "); } } else { Assert.fail("ClusterSelectedRegionsMemberServiceTest :: No Http connection was established."); } System.out.println( "ClusterSelectedRegionsMemberServiceTest :: ------TESTCASE END : NON-EXISTENT REGION CHECK FOR CLUSTER REGION MEMBERS------"); }
From source file:org.apache.mahout.utils.email.MailProcessorTest.java
@Test public void testStripQuoted() throws Exception { StringWriter writer = new StringWriter(); MailOptions options = new MailOptions(); options.setSeparator(":::"); options.setCharset(Charsets.UTF_8);/*from ww w .j a va2s . c o m*/ options.setPatternsToMatch(new Pattern[] { MailProcessor.SUBJECT_PREFIX }); options.setInput(new File(System.getProperty("user.dir"))); options.setIncludeBody(true); MailProcessor proc = new MailProcessor(options, "", writer); URL url = MailProcessorTest.class.getClassLoader().getResource("test.mbox"); File file = new File(url.toURI()); long count = proc.parseMboxLineByLine(file); assertEquals(7, count); assertTrue(writer.getBuffer().toString().contains("> Cocoon Cron Block Configurable Clustering")); writer = new StringWriter(); proc = new MailProcessor(options, "", writer); options.setStripQuotedText(true); count = proc.parseMboxLineByLine(file); assertEquals(7, count); assertFalse(writer.getBuffer().toString().contains("> Cocoon Cron Block Configurable Clustering")); }