summaryrefslogtreecommitdiffstats
path: root/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java
blob: edd2acb630dad832249c6b22670d3d7df87f0996 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container.handler;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * @author Einar M R Rosenvinge
 */
public class ResponseTestCase {

    @Test
    public void requireThatCharsetParsingWorks() {
        assertEquals("utf-8", Response.charset("text/foobar").toString().toLowerCase());
        assertEquals("utf-8", Response.charset("adsf").toString().toLowerCase());
        assertEquals("utf-8", Response.charset("").toString().toLowerCase());
        assertEquals("utf-8", Response.charset(null).toString().toLowerCase());

        assertEquals("us-ascii", Response.charset("something; charset=US-ASCII").toString().toLowerCase());
        assertEquals("iso-8859-1", Response.charset("something; charset=iso-8859-1").toString().toLowerCase());

        assertEquals("utf-8", Response.charset("something; charset=").toString().toLowerCase());
        assertEquals("utf-8", Response.charset("something; charset=bananarama").toString().toLowerCase());
    }

    @Test
    public void testDefaultResponseBody() {
        Response res1 = new Response();
        Response res2 = new Response(new byte[0]);

        assertNotNull(res1.getBody());
        assertEquals(0, res1.getBody().length);
        assertNotNull(res2.getBody());
        assertEquals(0, res2.getBody().length);
    }
}