01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.markup.html.link;
18:
19: import org.apache.wicket.WicketTestCase;
20: import org.apache.wicket.protocol.http.MockServletContext;
21: import org.slf4j.Logger;
22: import org.slf4j.LoggerFactory;
23:
24: /**
25: * Tests DownloadLink
26: *
27: * @author <a href="mailto:jbq@apache.org">Jean-Baptiste Quenot</a>
28: */
29: public class DownloadLinkTest extends WicketTestCase {
30: private static final String APPLICATION_X_CUSTOM = "application/x-custom";
31: private static final Logger log = LoggerFactory
32: .getLogger(DownloadLinkTest.class);
33:
34: /**
35: * Construct.
36: *
37: * @param name
38: */
39: public DownloadLinkTest(String name) {
40: super (name);
41: }
42:
43: /**
44: * Tests custom type download.
45: */
46: public void testCustomTypeDownloadLink() {
47: tester.startPage(DownloadPage.class);
48: ((MockServletContext) tester.getApplication()
49: .getServletContext()).addMimeType("custom",
50: APPLICATION_X_CUSTOM);
51: tester.clickLink(DownloadPage.CUSTOM_DOWNLOAD_LINK);
52: log.debug("Content-Type: "
53: + tester.getContentTypeFromResponseHeader());
54: assertTrue(tester.getContentTypeFromResponseHeader()
55: .startsWith(APPLICATION_X_CUSTOM));
56: }
57:
58: /**
59: * Tests pdf download.
60: */
61: public void testPdfDownloadLink() {
62: tester.startPage(DownloadPage.class);
63: tester.clickLink(DownloadPage.PDF_DOWNLOAD_LINK);
64: assertTrue(tester.getContentTypeFromResponseHeader()
65: .startsWith("application/pdf"));
66: assertEquals(DownloadPage.HELLO_WORLD.length(), tester
67: .getContentLengthFromResponseHeader());
68: }
69:
70: /**
71: * Tests text download.
72: */
73: public void testTextDownloadLink() {
74: tester.startPage(DownloadPage.class);
75: tester.clickLink(DownloadPage.TEXT_DOWNLOAD_LINK);
76: assertTrue(tester.getContentTypeFromResponseHeader()
77: .startsWith("text/plain"));
78: assertTrue(tester.getContentDispositionFromResponseHeader()
79: .startsWith("attachment; filename="));
80: assertEquals(0, tester.getContentLengthFromResponseHeader());
81: }
82: }
|