Project fully mavenized with functionality exceeding previous Ant build.xml implemented (except deployment to servlet container, which can be easily added).

Improved unit tests to be independent of externally running servlet container, now every test runs its own embedded jetty server (and stops it afterward).

Removed all eclipse artifacts (.project, .classpath, .settings, etc.) and added to .gitignore to be independent of development environment (can be autogenerated by maven, or better yet use m2eclipse).

Removed embedded dependency jars since they are handled automatically by maven.
This commit is contained in:
Pablo Lalloni
2011-11-02 19:11:52 -03:00
parent 4f80244a2b
commit 89c4d91b41
45 changed files with 202 additions and 259 deletions

View File

@@ -0,0 +1,54 @@
package net.sourceforge.plantuml.servlet;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
public class TestProxy extends WebappTestCase {
/**
* Verifies the proxified reception of the default Bob and Alice diagram
*/
public void testDefaultProxy() throws Exception {
WebConversation conversation = new WebConversation();
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());
// Get the image and verify its size (~1533 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);
}
imageStream.close();
responseStream.close();
byte[] inMemoryImage = imageStream.toByteArray();
int diagramLen = inMemoryImage.length;
assertTrue( diagramLen > 1500);
assertTrue( diagramLen < 1600);
}
/**
* Verifies that the HTTP header of a diagram incites the browser to cache it.
*/
public void testInvalidUrl() throws Exception {
WebConversation conversation = new WebConversation();
// Try to proxify an invalid address
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/invalidURL");
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());
WebForm forms[] = response.getForms();
assertEquals( 2, forms.length );
}
}