[java-identity-provider COMMIT] /trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolve...

noreply at shibboleth.net noreply at shibboleth.net
Mon Mar 25 07:52:47 EDT 2013


Author: rdw
Date: Mon Mar 25 07:52:47 2013
New Revision: 4357

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4357&view=rev
Log:
IDP-275 Add test to collect existing Attribute.

Modified:
    trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeTest.java

Modified: trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeTest.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeTest.java?rev=4357&r1=4356&r2=4357&view=diff
==============================================================================
--- trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeTest.java (original)
+++ trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeTest.java Mon Mar 25 07:52:47 2013
@@ -51,11 +51,21 @@
     /** Simple result. */
     private static final String SIMPLE_VALUE = "simple";
 
-    /** A simple script to set a constant value. */
+    /**
+     * A simple script to set a constant value.
+     */
     private static final String TEST_SIMPLE_SCRIPT =
             "importPackage(Packages.net.shibboleth.idp.attribute.resolver.impl.ad);\n" + TEST_ATTRIBUTE_NAME
                     + " = res = new JscriptAttribute(\"" + TEST_ATTRIBUTE_NAME + "\");\n" + TEST_ATTRIBUTE_NAME
                     + ".addValue(\"" + SIMPLE_VALUE + "\");\n";
+
+    private static final String TEST_SIMPLE_SCRIPT_USING_PREDEF_ATTRIBUTE =
+            "importPackage(Packages.net.shibboleth.idp.attribute.resolver.impl.ad);importPackage(Packages.net.shibboleth.idp.attribute);\n"
+                    + "tmp = "
+                    + TEST_ATTRIBUTE_NAME
+                    + ".getValues(); val = new StringAttributeValue(\""
+                    + SIMPLE_VALUE
+                    + "\");tmp.add(val);" + TEST_ATTRIBUTE_NAME + ".setValues(tmp);";
 
     /** A simple script to set a value based on input values. */
     private static final String TEST_ATTRIBUTES_SCRIPT =
@@ -75,11 +85,9 @@
                     + "claz = clazloader.loadClass(\"net.shibboleth.idp.attribute.resolver.AttributeResolutionContext\");\n"
                     + "parent = requestContext.getParent();\n" + "child = parent.getSubcontext(claz);\n"
                     + TEST_ATTRIBUTE_NAME + ".addValue(child);\n";
-    
+
     private static final String TEST_FAIL_SCRIPT =
-            "importPackage(Packages.net.shibboleth.idp.attribute.resolver.impl.ad);\n"
-                    + " flibby.nonexistant();";
-
+            "importPackage(Packages.net.shibboleth.idp.attribute.resolver.impl.ad);\n" + " flibby.nonexistant();";
 
     /**
      * Test resolution of an simple script (statically generated data).
@@ -88,8 +96,7 @@
      * @throws ComponentInitializationException only if the test will fail
      * @throws ScriptException
      */
-    @Test public void testSimple() throws ResolutionException, ComponentInitializationException,
-            ScriptException {
+    @Test public void testSimple() throws ResolutionException, ComponentInitializationException, ScriptException {
 
         final Attribute test = new Attribute(TEST_ATTRIBUTE_NAME);
 
@@ -101,7 +108,7 @@
         attr.setScript(new EvaluableScript(SCRIPT_LANGUAGE, TEST_SIMPLE_SCRIPT));
         attr.initialize();
         Assert.assertNotNull(attr.getScript());
-        
+
         final Attribute val = attr.doAttributeDefinitionResolve(new AttributeResolutionContext()).get();
         final Set<AttributeValue> results = val.getValues();
 
@@ -110,8 +117,28 @@
         Assert.assertEquals(results.iterator().next().getValue(), SIMPLE_VALUE, "Scripted result contains known value");
     }
 
-    @Test public void testFails() throws ResolutionException, ComponentInitializationException,
-            ScriptException {
+    @Test public void testSimpleWithPredef() throws ResolutionException, ComponentInitializationException, ScriptException {
+
+        final Attribute test = new Attribute(TEST_ATTRIBUTE_NAME);
+
+        test.getValues().add(new StringAttributeValue(SIMPLE_VALUE));
+
+        final ScriptedAttributeDefinition attr = new ScriptedAttributeDefinition();
+        Assert.assertNull(attr.getScript());
+        attr.setId(TEST_ATTRIBUTE_NAME);
+        attr.setScript(new EvaluableScript(SCRIPT_LANGUAGE, TEST_SIMPLE_SCRIPT_USING_PREDEF_ATTRIBUTE));
+        attr.initialize();
+        Assert.assertNotNull(attr.getScript());
+
+        final Attribute val = attr.doAttributeDefinitionResolve(new AttributeResolutionContext()).get();
+        final Set<AttributeValue> results = val.getValues();
+
+        Assert.assertTrue(test.equals(val), "Scripted result is the same as bases");
+        Assert.assertEquals(results.size(), 1, "Scripted result value count");

[... 26 lines stripped ...]


More information about the commits mailing list