mirror of https://github.com/jacekkow/keycloak-protocol-cas

github-actions
2024-04-17 58117a155fc1e445d252c654a543a841bc9d0674
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
package org.keycloak.protocol.cas;
 
import jakarta.ws.rs.core.*;
import org.junit.Test;
import org.keycloak.protocol.cas.utils.ContentTypeHelper;
 
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
 
public class ContentTypeHelperTest {
    @Test
    public void test() {
        assertEquals(MediaType.APPLICATION_XML_TYPE, get("").selectResponseType());
        assertEquals(MediaType.APPLICATION_JSON_TYPE, get("json").selectResponseType());
        assertEquals(MediaType.APPLICATION_XML_TYPE, get("xml").selectResponseType());
        assertEquals(MediaType.APPLICATION_JSON_TYPE, get("JSON").selectResponseType());
        assertEquals(MediaType.APPLICATION_XML_TYPE, get("XML").selectResponseType());
    }
 
    private ContentTypeHelper get(String format) {
        MultivaluedHashMap<String,String> queryParams = mock(MultivaluedHashMap.class);
        when(queryParams.getFirst(CASLoginProtocol.FORMAT_PARAM)).thenReturn(format);
        UriInfo uriInfo = mock(UriInfo.class);
        when(uriInfo.getQueryParameters()).thenReturn(queryParams);
        return new ContentTypeHelper(uriInfo);
    }
}