From 33e5bcd2d66aeb6c47dbfb16df2ded8f42bf961f Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Mon, 04 Mar 2024 13:29:27 +0000 Subject: [PATCH] Fix ContentTypeHelperTest --- src/test/java/org/keycloak/protocol/cas/ContentTypeHelperTest.java | 28 ++++++++++++++-------------- pom.xml | 6 ++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 8048947..6cd3cfb 100644 --- a/pom.xml +++ b/pom.xml @@ -113,6 +113,12 @@ <version>2.9.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>5.11.0</version> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/src/test/java/org/keycloak/protocol/cas/ContentTypeHelperTest.java b/src/test/java/org/keycloak/protocol/cas/ContentTypeHelperTest.java index 826213f..bdd024a 100644 --- a/src/test/java/org/keycloak/protocol/cas/ContentTypeHelperTest.java +++ b/src/test/java/org/keycloak/protocol/cas/ContentTypeHelperTest.java @@ -1,27 +1,27 @@ package org.keycloak.protocol.cas; -import jakarta.ws.rs.core.HttpHeaders; -import jakarta.ws.rs.core.MediaType; -import org.jboss.resteasy.mock.MockHttpRequest; -import org.jboss.resteasy.mock.MockHttpResponse; -import org.jboss.resteasy.specimpl.RequestImpl; +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() throws Exception { - assertEquals(MediaType.APPLICATION_XML_TYPE, get("http://example.com/").selectResponseType()); - assertEquals(MediaType.APPLICATION_JSON_TYPE, get("http://example.com/?format=json").selectResponseType()); - assertEquals(MediaType.APPLICATION_XML_TYPE, get("http://example.com/?format=xml").selectResponseType()); - assertEquals(MediaType.APPLICATION_JSON_TYPE, get("http://example.com/?format=JSON").selectResponseType()); - assertEquals(MediaType.APPLICATION_XML_TYPE, get("http://example.com/?format=XML").selectResponseType()); + 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 uri) throws Exception { - MockHttpRequest req = MockHttpRequest.get(uri); - return new ContentTypeHelper(req.getUri()); + 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); } } -- Gitblit v1.9.1