[TASK] Full coding style clean up

This commit is contained in:
Maxime Sinclair
2013-07-10 17:07:24 +02:00
parent ded3a5578a
commit ce168633ad
14 changed files with 130 additions and 137 deletions

View File

@@ -7,13 +7,13 @@ public class AllTests extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
//$JUnit-BEGIN$
// $JUnit-BEGIN$
suite.addTestSuite(TestForm.class);
suite.addTestSuite(TestImage.class);
suite.addTestSuite(TestAsciiArt.class);
suite.addTestSuite(TestSVG.class);
suite.addTestSuite(TestProxy.class);
//$JUnit-END$
// $JUnit-END$
return suite;
}

View File

@@ -1,6 +1,5 @@
package net.sourceforge.plantuml.servlet;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;

View File

@@ -8,23 +8,22 @@ import com.meterware.httpunit.WebResponse;
public class TestForm extends WebappTestCase {
/**
* Verifies that the welcome page has exactly two form
* with the Bob --> Alice sample
*/
/**
* Verifies that the welcome page has exactly two form with the Bob --> Alice sample
*/
public void testWelcomePage() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request );
WebResponse response = TestUtils.tryGetResponse(conversation, request);
// Analyze response
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
assertEquals( "url", forms[1].getParameterNames()[0] );
assertTrue( forms[1].getParameterValue("url").endsWith("/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"));
WebForm forms[] = response.getForms();
assertEquals(2, forms.length);
assertEquals("url", forms[1].getParameterNames()[0]);
assertTrue(forms[1].getParameterValue("url").endsWith("/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"));
// Ensure the generated image is present
assertEquals( 1, response.getImages().length);
assertEquals(1, response.getImages().length);
}
}
/**
* Verifies that the version image is generated
@@ -33,19 +32,19 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation();
// Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request );
WebResponse response = TestUtils.tryGetResponse(conversation, request);
WebForm formUMLText = response.getForms()[0];
formUMLText.setParameter("text", "version");
response = formUMLText.submit();
// Analyze response
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
assertEquals(2, forms.length);
// Ensure the Text field is correct
assertEquals( "version", forms[0].getParameterValue("text"));
assertEquals("version", forms[0].getParameterValue("text"));
// Ensure the URL field is correct
assertTrue( forms[1].getParameterValue("url").endsWith("/img/AqijAixCpmC0"));
assertTrue(forms[1].getParameterValue("url").endsWith("/img/AqijAixCpmC0"));
// Ensure the image is present
assertEquals( 1, response.getImages().length);
assertEquals(1, response.getImages().length);
}
/**
@@ -55,19 +54,19 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation();
// Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request );
WebResponse response = TestUtils.tryGetResponse(conversation, request);
WebForm formUMLText = response.getForms()[0];
formUMLText.setParameter("text", "");
response = formUMLText.submit();
// Analyze response
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
assertEquals(2, forms.length);
// Ensure the Text field is empty
assertNull( forms[0].getParameterValue("text"));
assertNull(forms[0].getParameterValue("text"));
// Ensure the URL field is empty
assertTrue( forms[1].getParameterValue("url").isEmpty());
assertTrue(forms[1].getParameterValue("url").isEmpty());
// Ensure there is no image
assertEquals( 0, response.getImages().length);
assertEquals(0, response.getImages().length);
}
/**
@@ -77,19 +76,19 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation();
// Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request );
WebResponse response = TestUtils.tryGetResponse(conversation, request);
WebForm formUrl = response.getForms()[1];
formUrl.setParameter("url", "");
response = formUrl.submit();
// Analyze response
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
assertEquals(2, forms.length);
// Ensure the Text field is empty
assertNull( forms[0].getParameterValue("text"));
assertNull(forms[0].getParameterValue("text"));
// Ensure the URL field is empty
assertTrue( forms[1].getParameterValue("url").isEmpty());
assertTrue(forms[1].getParameterValue("url").isEmpty());
// Ensure there is no image
assertEquals( 0, response.getImages().length);
assertEquals(0, response.getImages().length);
}
/**
@@ -99,19 +98,19 @@ public class TestForm extends WebappTestCase {
WebConversation conversation = new WebConversation();
// Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = TestUtils.tryGetResponse(conversation, request );
WebResponse response = TestUtils.tryGetResponse(conversation, request);
WebForm formDitaaText = response.getForms()[0];
formDitaaText.setParameter("text", "@startditaa \n*--> \n@endditaa");
response = formDitaaText.submit();
// Analyze response
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
assertEquals(2, forms.length);
// Ensure the Text field is correct
assertTrue( forms[0].getParameterValue("text").startsWith( "@startditaa"));
assertTrue(forms[0].getParameterValue("text").startsWith("@startditaa"));
// Ensure the URL field is correct
assertTrue( forms[1].getParameterValue("url").endsWith("/img/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00"));
assertTrue(forms[1].getParameterValue("url").endsWith("/img/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00"));
// Ensure the image is present
assertEquals( 1, response.getImages().length);
assertEquals(1, response.getImages().length);
}
}

View File

@@ -18,23 +18,23 @@ public class TestImage extends WebappTestCase {
public void testVersionImage() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/AqijAixCpmC0");
WebResponse response = conversation.getResource( request);
WebResponse response = conversation.getResource(request);
// Analyze response
// Verifies the Content-Type header
assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
assertEquals("Response content type is not PNG", "image/png", response.getContentType());
// Get the image and verify its size
InputStream responseStream = response.getInputStream();
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while( ( n = responseStream.read( buf)) != -1) {
imageStream.write( buf, 0, n);
while ((n = responseStream.read(buf)) != -1) {
imageStream.write(buf, 0, n);
}
imageStream.close();
byte[] inMemoryImage = imageStream.toByteArray();
int diagramLen = inMemoryImage.length;
assertTrue( diagramLen > 10000);
assertTrue( diagramLen < 20000);
assertTrue(diagramLen > 10000);
assertTrue(diagramLen < 20000);
responseStream.close();
}
@@ -45,21 +45,21 @@ public class TestImage extends WebappTestCase {
WebConversation conversation = new WebConversation();
// Bob -> Alice : hello
WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
WebResponse response = conversation.getResource( request);
WebResponse response = conversation.getResource(request);
// Analyze response
// Verifies the Content-Type header
assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
assertEquals("Response content type is not PNG", "image/png", response.getContentType());
// Verifies the availability of the Expires entry in the response header
assertNotNull( response.getHeaderField( "Expires"));
assertNotNull(response.getHeaderField("Expires"));
// Verifies the availability of the Last-Modified entry in the response header
assertNotNull( response.getHeaderField( "Last-Modified"));
assertNotNull(response.getHeaderField("Last-Modified"));
// Verifies the Last-Modified value is in the past
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZ", Locale.ENGLISH);
Date lastModified = format.parse( response.getHeaderField( "Last-Modified"));
assertTrue( "Last-Modified is not in the past", lastModified.before( new Date()));
Date lastModified = format.parse(response.getHeaderField("Last-Modified"));
assertTrue("Last-Modified is not in the past", lastModified.before(new Date()));
// Consume the response
InputStream responseStream = response.getInputStream();
while( responseStream.read() != -1) {
while (responseStream.read() != -1) {
; // Do nothing
}
}

View File

@@ -15,41 +15,39 @@ public class TestProxy extends WebappTestCase {
*/
public void testDefaultProxy() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/"
+ getServerUrl() + "welcome");
WebResponse response = conversation.getResource( request);
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/" + getServerUrl() + "welcome");
WebResponse response = conversation.getResource(request);
// Analyze response
// Verifies the Content-Type header
//assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
// assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
// Get the image and verify its size (~2000 bytes)
InputStream responseStream = response.getInputStream();
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while( ( n = responseStream.read( buf)) != -1) {
imageStream.write( buf, 0, n);
while ((n = responseStream.read(buf)) != -1) {
imageStream.write(buf, 0, n);
}
imageStream.close();
responseStream.close();
byte[] inMemoryImage = imageStream.toByteArray();
int diagramLen = inMemoryImage.length;
assertTrue( diagramLen > 1500);
assertTrue( diagramLen < 2500);
assertTrue(diagramLen > 1500);
assertTrue(diagramLen < 2500);
}
public void testProxyWithFormat() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/svg/"
+ getServerUrl() + "welcome");
WebResponse response = conversation.getResource( request);
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/svg/" + getServerUrl() + "welcome");
WebResponse response = conversation.getResource(request);
// Analyze response
// Verifies the Content-Type header
// TODO assertEquals( "Response content type is not SVG", "image/svg+xml", response.getContentType());
// Get the content and verify its size
String diagram = response.getText();
int diagramLen = diagram.length();
assertTrue( diagramLen > 1000);
assertTrue( diagramLen < 3000);
assertTrue(diagramLen > 1000);
assertTrue(diagramLen < 3000);
}
/**
@@ -59,11 +57,11 @@ public class TestProxy extends WebappTestCase {
WebConversation conversation = new WebConversation();
// Try to proxify an invalid address
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/invalidURL");
WebResponse response = conversation.getResource( request);
WebResponse response = conversation.getResource(request);
// Analyze response, it must be the empty form
// Verifies the Content-Type header
assertEquals( "Response content type is not HTML", "text/html", response.getContentType());
assertEquals("Response content type is not HTML", "text/html", response.getContentType());
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
assertEquals(2, forms.length);
}
}

View File

@@ -8,33 +8,34 @@ import com.meterware.httpunit.*;
public class TestUtils {
/**
* Return the URL of the PlantUMLServlet, deployed on the testing web server
* in the following form http://server/contextroot/
* Note the trailing slash (/)
* Return the URL of the PlantUMLServlet, deployed on the testing web server in the following form
* http://server/contextroot/ Note the trailing slash (/)
*
* @return the URL
*/
public static String getServerUrl() {
public static String getServerUrl() {
return "http://localhost/plantuml/";
}
/**
* Try getting a response for the given Conversation and Request
* show an error message if a 404 error appears
* @param conversation - the conversation to use
/**
* Try getting a response for the given Conversation and Request show an error message if a 404 error appears
*
* @param conversation
* - the conversation to use
* @param request
* @return the response
* @throws an Exception if getting the response fails
* @throws an
* Exception if getting the response fails
*/
public static WebResponse tryGetResponse(WebConversation conversation, WebRequest request) throws Exception {
WebResponse response=null;
public static WebResponse tryGetResponse(WebConversation conversation, WebRequest request) throws Exception {
WebResponse response = null;
try {
response = conversation.getResponse( request );
response = conversation.getResponse(request);
} catch (HttpNotFoundException nfe) {
System.err.println("The URL '"+request.getURL()+"' is not active any more");
System.err.println("The URL '" + request.getURL() + "' is not active any more");
throw nfe;
}
return response;
}
}