mirror of
https://github.com/octoleo/plantuml-server.git
synced 2025-02-03 19:18:25 +00:00
Unit test of the proxy feature.
This commit is contained in:
parent
b924e99360
commit
225ef45c37
@ -14,11 +14,6 @@ if (encodedAttribute != null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
|
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
|
||||||
/*if (decodedAttribute == null) {
|
|
||||||
umltext = "Bob -> Alice : hello";
|
|
||||||
imgurl = host + contextRoot + "/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000";
|
|
||||||
} else { */
|
|
||||||
|
|
||||||
if (decodedAttribute != null) {
|
if (decodedAttribute != null) {
|
||||||
umltext = decodedAttribute.toString();
|
umltext = decodedAttribute.toString();
|
||||||
}
|
}
|
||||||
@ -70,7 +65,11 @@ if (decodedAttribute != null) {
|
|||||||
</p>
|
</p>
|
||||||
<% } //endif %>
|
<% } //endif %>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- This comment is used by the TestProxy class
|
||||||
|
@startuml
|
||||||
|
Bob -> Alice : hello
|
||||||
|
@enduml
|
||||||
|
-->
|
||||||
<%-- FOOTER
|
<%-- FOOTER
|
||||||
<%@ include file="util/footer.jspf" %> --%>
|
<%@ include file="util/footer.jspf" %> --%>
|
||||||
</body>
|
</body>
|
||||||
|
@ -10,6 +10,7 @@ public class AllTests extends TestSuite {
|
|||||||
//$JUnit-BEGIN$
|
//$JUnit-BEGIN$
|
||||||
suite.addTestSuite(TestForm.class);
|
suite.addTestSuite(TestForm.class);
|
||||||
suite.addTestSuite(TestImage.class);
|
suite.addTestSuite(TestImage.class);
|
||||||
|
suite.addTestSuite(TestProxy.class);
|
||||||
//$JUnit-END$
|
//$JUnit-END$
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
51
test/src/net/sourceforge/plantuml/servlet/TestProxy.java
Normal file
51
test/src/net/sourceforge/plantuml/servlet/TestProxy.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package net.sourceforge.plantuml.servlet;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import com.meterware.httpunit.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class TestProxy extends TestCase {
|
||||||
|
/**
|
||||||
|
* Verifies the proxified reception of the default Bob and Alice diagram
|
||||||
|
*/
|
||||||
|
public void testDefaultProxy() throws Exception {
|
||||||
|
WebConversation conversation = new WebConversation();
|
||||||
|
WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"proxy/"
|
||||||
|
+TestUtils.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( TestUtils.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 );
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user