[java-identity-provider COMMIT] /trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNam...
noreply at shibboleth.net
noreply at shibboleth.net
Thu Mar 12 06:15:05 EDT 2015
Author: rdw
Date: Thu Mar 12 06:15:03 2015
New Revision: 7407
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=7407&view=rev
Log:
IDP-635 Add HttpServletRequest /default language sensitive constructor. Leave old server base constructor in place pending tests
Modified:
trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameFunctionTest.java
Modified: trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameFunctionTest.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameFunctionTest.java?rev=7407&r1=7406&r2=7407&view=diff
==============================================================================
--- trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameFunctionTest.java (original)
+++ trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameFunctionTest.java Thu Mar 12 06:15:03 2015
@@ -17,13 +17,19 @@
package net.shibboleth.idp.consent.logic;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+
import net.shibboleth.idp.attribute.IdPAttribute;
+import org.springframework.mock.web.MockHttpServletRequest;
import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Function;
@@ -32,8 +38,10 @@
* test for {@link AttributeDisplayNameFunction}.
*/
public class AttributeDisplayNameFunctionTest {
+
+ private IdPAttribute testAttribute;
- private IdPAttribute constructAttribute() {
+ @BeforeClass public void constructAttribute() {
final IdPAttribute attr = new IdPAttribute("What");
final Map<Locale, String> names = new HashMap<>(3);
@@ -49,12 +57,41 @@
attr.setDisplayNames(names);
attr.setDisplayDescriptions(descriptions);
- return attr;
+ testAttribute = attr;
+ }
+
+ private HttpServletRequest getMockRequest(String... languages) {
+
+ final MockHttpServletRequest request = new MockHttpServletRequest();
+ final List<Locale> locales = new ArrayList<>(languages.length);
+ for (String language: languages) {
+ locales.add(new Locale(language));
+ }
+ request.setPreferredLocales(locales);
+ return request;
}
@Test public void testServerLocale() {
+ @SuppressWarnings("deprecation")
Function<IdPAttribute, String> func = new AttributeDisplayNameFunction(new Locale("fr"));
- Assert.assertEquals(func.apply(constructAttribute()), "FR locale Name");
+ Assert.assertEquals(func.apply(testAttribute), "FR locale Name");
}
+
+ @Test public void testHttpOnly() {
+ Function<IdPAttribute, String> func = new AttributeDisplayNameFunction(getMockRequest("fr", "de", "en"), null);
+ Assert.assertEquals(func.apply(testAttribute), "FR locale Name");
+
+ func = new AttributeDisplayNameFunction(getMockRequest("pt", "es"), null);
+ Assert.assertEquals(func.apply(testAttribute), testAttribute.getId());
+ }
+
+ @Test public void testWithDefault() {
+ Function<IdPAttribute, String> func = new AttributeDisplayNameFunction(getMockRequest("fr", "de", "en"), "en,fr,de");
+ Assert.assertEquals(func.apply(testAttribute), "FR locale Name");
+
+ func = new AttributeDisplayNameFunction(getMockRequest("pt", "es"), "en,fr,de");
+ Assert.assertEquals(func.apply(testAttribute), "EN locale Name");
+ }
+
}
More information about the commits
mailing list