Test of the HTTP header added.
This commit is contained in:
@@ -5,6 +5,9 @@ import com.meterware.httpunit.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class TestImage extends TestCase {
|
||||
/**
|
||||
@@ -16,7 +19,7 @@ public class TestImage extends TestCase {
|
||||
WebResponse response = conversation.getResource( request);
|
||||
// Analyze response
|
||||
// Verifies the Content-Type header
|
||||
assertEquals( "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();
|
||||
@@ -32,4 +35,25 @@ public class TestImage extends TestCase {
|
||||
assertTrue( diagramLen > 10000);
|
||||
assertTrue( diagramLen < 20000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the HTTP header of a diagram incites the browser to cache it.
|
||||
*/
|
||||
public void testDiagramHttpHeader() throws Exception {
|
||||
WebConversation conversation = new WebConversation();
|
||||
// Bob -> Alice : hello
|
||||
WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
|
||||
WebResponse response = conversation.getResource( request);
|
||||
// Analyze response
|
||||
// Verifies the Content-Type header
|
||||
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"));
|
||||
// Verifies the availability of the Last-Modified entry in the response header
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user