update junit test classes and there dependencies
This commit is contained in:
@@ -1,28 +1,31 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import com.meterware.httpunit.GetMethodWebRequest;
|
||||
import com.meterware.httpunit.PostMethodWebRequest;
|
||||
import com.meterware.httpunit.WebConversation;
|
||||
import com.meterware.httpunit.WebRequest;
|
||||
import com.meterware.httpunit.WebResponse;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class TestSVG extends WebappTestCase {
|
||||
|
||||
/**
|
||||
* Verifies the generation of the SVG for the Bob -> Alice sample
|
||||
*/
|
||||
public void testSimpleSequenceDiagram() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/" + TestUtils.SEQBOB);
|
||||
WebResponse response = conversation.getResource(request);
|
||||
public void testSimpleSequenceDiagram() throws IOException {
|
||||
final URL url = new URL(getServerUrl() + "/svg/" + TestUtils.SEQBOB);
|
||||
final URLConnection conn = url.openConnection();
|
||||
// Analyze response
|
||||
// Verifies the Content-Type header
|
||||
assertEquals("Response content type is not SVG", "image/svg+xml", response.getContentType());
|
||||
assertEquals(
|
||||
"Response content type is not SVG",
|
||||
"image/svg+xml",
|
||||
conn.getContentType().toLowerCase()
|
||||
);
|
||||
// Get the content and verify its size
|
||||
String diagram = response.getText();
|
||||
String diagram = getContentText(conn);
|
||||
int diagramLen = diagram.length();
|
||||
assertTrue(diagramLen > 1000);
|
||||
assertTrue(diagramLen < 3000);
|
||||
@@ -31,24 +34,31 @@ public class TestSVG extends WebappTestCase {
|
||||
/**
|
||||
* Verifies the generation of the SVG for the Bob -> Alice sample
|
||||
*/
|
||||
public void testPostedSequenceDiagram() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
PostMethodWebRequest request = new PostMethodWebRequest(
|
||||
getServerUrl() + "svg/",
|
||||
new ByteArrayInputStream("@startuml\nBob -> Alice\n@enduml".getBytes(Charset.defaultCharset())),
|
||||
"text/plain");
|
||||
|
||||
WebResponse response = conversation.getResource(request);
|
||||
|
||||
assertEquals(200, response.getResponseCode());
|
||||
|
||||
public void testPostedSequenceDiagram() throws IOException {
|
||||
final URL url = new URL(getServerUrl() + "/svg");
|
||||
final HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setRequestProperty("Content-type", "text/plain");
|
||||
try (final OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream())) {
|
||||
writer.write("@startuml\nBob -> Alice\n@enduml");
|
||||
writer.flush();
|
||||
}
|
||||
// Analyze response
|
||||
// HTTP response 200
|
||||
assertEquals(
|
||||
"Bad HTTP status received",
|
||||
200,
|
||||
conn.getResponseCode()
|
||||
);
|
||||
// Verifies the Content-Type header
|
||||
assertEquals("Response content type is not SVG", "image/svg+xml", response.getContentType());
|
||||
assertEquals(
|
||||
"Response content type is not SVG",
|
||||
"image/svg+xml",
|
||||
conn.getContentType().toLowerCase()
|
||||
);
|
||||
// Get the content and verify its size
|
||||
|
||||
String diagram = response.getText();
|
||||
|
||||
String diagram = getContentText(conn.getInputStream());
|
||||
int diagramLen = diagram.length();
|
||||
assertTrue(diagramLen > 1000);
|
||||
assertTrue(diagramLen < 3000);
|
||||
@@ -57,40 +67,51 @@ public class TestSVG extends WebappTestCase {
|
||||
/**
|
||||
* Verifies the generation of the SVG for the Bob -> Alice sample
|
||||
*/
|
||||
public void testPostedInvalidSequenceDiagram() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
PostMethodWebRequest request = new PostMethodWebRequest(
|
||||
getServerUrl() + "svg/",
|
||||
new ByteArrayInputStream("@startuml\n[Bob\n@enduml".getBytes(Charset.defaultCharset())),
|
||||
"text/plain");
|
||||
|
||||
WebResponse response = conversation.getResource(request);
|
||||
|
||||
assertEquals(400, response.getResponseCode());
|
||||
public void testPostedInvalidSequenceDiagram() throws IOException {
|
||||
final URL url = new URL(getServerUrl() + "/svg");
|
||||
final HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setRequestProperty("Content-type", "text/plain");
|
||||
try (final OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream())) {
|
||||
writer.write("@startuml\n[Bob\n@enduml");
|
||||
writer.flush();
|
||||
}
|
||||
// Analyze response
|
||||
// HTTP response 400
|
||||
assertEquals(
|
||||
"Bad HTTP status received",
|
||||
400,
|
||||
conn.getResponseCode()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the content of the SVG
|
||||
*/
|
||||
public void testSequenceDiagramContent() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
WebRequest request = new GetMethodWebRequest(getServerUrl() + "svg/" + TestUtils.SEQBOB);
|
||||
WebResponse response = conversation.getResource(request);
|
||||
public void testSequenceDiagramContent() throws IOException {
|
||||
final URL url = new URL(getServerUrl() + "/svg/" + TestUtils.SEQBOB);
|
||||
// Analyze response
|
||||
// Get the data contained in the XML
|
||||
Scanner s = new Scanner(response.getInputStream()).useDelimiter("(<([^<>]+)>)+");
|
||||
String token;
|
||||
int bobCounter = 0, aliceCounter = 0;
|
||||
while (s.hasNext()) {
|
||||
token = s.next();
|
||||
if (token.startsWith("Bob")) {
|
||||
bobCounter++;
|
||||
}
|
||||
if (token.startsWith("Alice")) {
|
||||
aliceCounter++;
|
||||
try (
|
||||
final InputStream responseStream = url.openStream();
|
||||
final Scanner scanner = new Scanner(responseStream).useDelimiter("(<([^<>]+)>)+")
|
||||
) {
|
||||
String token;
|
||||
int bobCounter = 0;
|
||||
int aliceCounter = 0;
|
||||
while (scanner.hasNext()) {
|
||||
token = scanner.next();
|
||||
if (token.startsWith("Bob")) {
|
||||
bobCounter++;
|
||||
}
|
||||
if (token.startsWith("Alice")) {
|
||||
aliceCounter++;
|
||||
}
|
||||
}
|
||||
assertTrue(bobCounter == 2);
|
||||
assertTrue(aliceCounter == 2);
|
||||
}
|
||||
assertTrue(bobCounter == 2);
|
||||
assertTrue(aliceCounter == 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user