Repository: deltaspike
Updated Branches:
  refs/heads/master 5a22110b7 -> 641abce69


DELTASPIKE-719 tests for multiple view-metadata stereotypes


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/641abce6
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/641abce6
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/641abce6

Branch: refs/heads/master
Commit: 641abce69d03104ed5ea336616cb103e5a9a13c6
Parents: 5a22110
Author: gpetracek <gpetra...@apache.org>
Authored: Thu Sep 18 23:10:12 2014 +0200
Committer: gpetracek <gpetra...@apache.org>
Committed: Thu Sep 18 23:18:20 2014 +0200

----------------------------------------------------------------------
 .../view/controller/uc005/PageBean005.java      |  32 +++
 .../config/view/controller/uc005/Pages.java     |  35 +++
 .../controller/uc005/SecuredStereotype1.java    |  39 +++
 .../controller/uc005/SecuredStereotype2.java    |  39 +++
 .../uc005/SimpleTestAccessDecisionVoter1.java   |  35 +++
 .../uc005/SimpleTestAccessDecisionVoter2.java   |  35 +++
 .../uc005/TestAccessDecisionVoter.java          |  29 +++
 .../view/controller/uc005/TestSecured.java      |  78 ++++++
 .../view/controller/uc005/ViewConfigTest.java   | 256 +++++++++++++++++++
 9 files changed, 578 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/PageBean005.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/PageBean005.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/PageBean005.java
new file mode 100644
index 0000000..3cb466e
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/PageBean005.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.controller.PreRenderView;
+
+import javax.enterprise.inject.Model;
+
+@Model
+public class PageBean005
+{
+    @PreRenderView
+    protected void preRenderViewCallbackMethod()
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/Pages.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/Pages.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/Pages.java
new file mode 100644
index 0000000..e0c49a9
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/Pages.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.ViewConfig;
+import org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef;
+
+public interface Pages extends ViewConfig
+{
+    @SecuredStereotype1
+    interface Secure extends Pages
+    {
+        @SecuredStereotype2
+        @ViewControllerRef(PageBean005.class)
+        class Settings implements Secure
+        {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype1.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype1.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype1.java
new file mode 100644
index 0000000..fc554a8
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype1.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData;
+
+import javax.enterprise.inject.Stereotype;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(RUNTIME)
+@Target(TYPE)
+
+@ViewMetaData
+@Stereotype
+
+@TestSecured(SimpleTestAccessDecisionVoter1.class)
+public @interface SecuredStereotype1
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype2.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype2.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype2.java
new file mode 100644
index 0000000..c241452
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SecuredStereotype2.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData;
+
+import javax.enterprise.inject.Stereotype;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(RUNTIME)
+@Target(TYPE)
+
+@ViewMetaData
+@Stereotype
+
+@TestSecured(SimpleTestAccessDecisionVoter2.class)
+public @interface SecuredStereotype2
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter1.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter1.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter1.java
new file mode 100644
index 0000000..e52c265
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter1.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class SimpleTestAccessDecisionVoter1 implements TestAccessDecisionVoter
+{
+    @Override
+    public Set<String> checkPermission(String param1, String param2)
+    {
+        Set<String> result = new HashSet<String>();
+        result.add(param1);
+        result.add(param2);
+        result.add(getClass().getName());
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter2.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter2.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter2.java
new file mode 100644
index 0000000..bdefd2d
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/SimpleTestAccessDecisionVoter2.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class SimpleTestAccessDecisionVoter2 implements TestAccessDecisionVoter
+{
+    @Override
+    public Set<String> checkPermission(String param1, String param2)
+    {
+        Set<String> result = new HashSet<String>();
+        result.add(param1);
+        result.add(param2);
+        result.add(getClass().getName());
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestAccessDecisionVoter.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestAccessDecisionVoter.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestAccessDecisionVoter.java
new file mode 100644
index 0000000..1917ffe
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestAccessDecisionVoter.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.metadata.DefaultCallback;
+
+import java.util.Set;
+
+public interface TestAccessDecisionVoter
+{
+    @DefaultCallback
+    Set<String> checkPermission(String param1, String param2);
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestSecured.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestSecured.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestSecured.java
new file mode 100644
index 0000000..fd50aae
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/TestSecured.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor;
+import org.apache.deltaspike.core.api.config.view.metadata.DefaultCallback;
+import 
org.apache.deltaspike.core.api.config.view.metadata.ExecutableCallbackDescriptor;
+import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData;
+import org.apache.deltaspike.core.spi.config.view.ConfigPreProcessor;
+import org.apache.deltaspike.core.spi.config.view.ViewConfigNode;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.util.List;
+import java.util.Set;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target( TYPE )
+@Retention(RUNTIME)
+@Documented
+
+@ViewMetaData(preProcessor = TestSecured.AnnotationPreProcessor.class)
+public @interface TestSecured
+{
+    Class<? extends TestAccessDecisionVoter>[] value();
+
+    class AnnotationPreProcessor implements ConfigPreProcessor<TestSecured>
+    {
+        //for a real implementation see e.g.:
+        //org.apache.deltaspike.security.api.authorization.Secured
+        
//org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef
+        @Override
+        public TestSecured beforeAddToConfig(TestSecured metaData, 
ViewConfigNode viewConfigNode)
+        {
+            List<CallbackDescriptor> descriptors = 
viewConfigNode.getCallbackDescriptors(TestSecured.class);
+
+            if (descriptors.isEmpty()) //just for testing different 
constellations - usually not needed!
+            {
+                descriptors.add(new Descriptor(metaData.value(), 
DefaultCallback.class));
+            }
+            return metaData; //no change needed
+        }
+    }
+
+    //can be used from outside to get a typed result
+    static class Descriptor extends ExecutableCallbackDescriptor<Set<String>>
+    {
+        public Descriptor(Class[] beanClasses, Class<? extends Annotation> 
callbackMarker)
+        {
+            super(beanClasses, callbackMarker);
+        }
+
+        public List<Set<String>> execute(String param1, String param2)
+        {
+            return super.execute(param1, param2);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/641abce6/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/ViewConfigTest.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/ViewConfigTest.java
 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/ViewConfigTest.java
new file mode 100644
index 0000000..21e4896
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/controller/uc005/ViewConfigTest.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jsf.impl.config.view.controller.uc005;
+
+import org.apache.deltaspike.core.api.config.view.controller.InitView;
+import org.apache.deltaspike.core.api.config.view.controller.PreRenderView;
+import org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef;
+import org.apache.deltaspike.core.api.config.view.metadata.*;
+import org.apache.deltaspike.core.spi.config.view.ViewConfigNode;
+import org.apache.deltaspike.jsf.impl.config.view.ViewConfigExtension;
+import org.apache.deltaspike.jsf.impl.config.view.ViewConfigResolverProducer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Tests for view-configs
+ */
+public class ViewConfigTest
+{
+    private ViewConfigExtension viewConfigExtension;
+
+    private ViewConfigResolverProducer viewConfigResolverProducer;
+
+    @Before
+    public void before()
+    {
+        this.viewConfigExtension = new ViewConfigExtension();
+        this.viewConfigResolverProducer = new 
ViewConfigResolverProducer(this.viewConfigExtension);
+    }
+
+    @After
+    public void after()
+    {
+        this.viewConfigExtension.freeViewConfigCache(null);
+    }
+
+    @Test
+    public void testMetaDataTreeWithStereotypeViewMetaData()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Secure.class);
+        
this.viewConfigExtension.addPageDefinition(Pages.Secure.Settings.class);
+
+        ViewConfigNode node = this.viewConfigExtension.findNode(Pages.class);
+
+        Assert.assertNotNull(node);
+        Assert.assertNotNull(node.getParent());
+        Assert.assertNull(node.getParent().getParent());
+
+        Assert.assertNotNull(node.getChildren());
+        Assert.assertEquals(1, node.getChildren().size());
+
+        Assert.assertNotNull(node.getMetaData());
+        Assert.assertEquals(0, node.getMetaData().size());
+
+        Assert.assertNotNull(node.getInheritedMetaData());
+        Assert.assertEquals(0, node.getInheritedMetaData().size());
+
+        Assert.assertNotNull(node.getCallbackDescriptors());
+        Assert.assertEquals(0, node.getCallbackDescriptors().size());
+
+
+        node = this.viewConfigExtension.findNode(Pages.Secure.class);
+
+        Assert.assertNotNull(node);
+        Assert.assertNotNull(node.getParent());
+        Assert.assertNotNull(node.getParent().getParent());
+        Assert.assertNull(node.getParent().getParent().getParent());
+
+        Assert.assertNotNull(node.getChildren());
+        Assert.assertEquals(1, node.getChildren().size());
+
+        Assert.assertNotNull(node.getMetaData());
+        Assert.assertEquals(1, node.getMetaData().size());
+
+        Iterator<Annotation> metaDataIterator = node.getMetaData().iterator();
+        List<Class<? extends Annotation>> possibleMetaDataTypes = new 
ArrayList<Class<? extends Annotation>>();
+        possibleMetaDataTypes.add(SecuredStereotype1.class);
+        Class<? extends Annotation> foundMetaData = 
metaDataIterator.next().annotationType();
+        possibleMetaDataTypes.remove(foundMetaData);
+
+        Assert.assertTrue(possibleMetaDataTypes.isEmpty());
+
+        Assert.assertNotNull(node.getInheritedMetaData());
+        Assert.assertEquals(0, node.getInheritedMetaData().size());
+
+        Assert.assertNotNull(node.getCallbackDescriptors());
+        Assert.assertEquals(0, node.getCallbackDescriptors().size());
+
+
+        node = this.viewConfigExtension.findNode(Pages.Secure.Settings.class);
+
+        Assert.assertNotNull(node);
+        Assert.assertNotNull(node.getParent());
+        Assert.assertNotNull(node.getParent().getParent());
+        Assert.assertNotNull(node.getParent().getParent().getParent());
+        
Assert.assertNull(node.getParent().getParent().getParent().getParent());
+
+        Assert.assertNotNull(node.getChildren());
+        Assert.assertEquals(0, node.getChildren().size());
+
+        Assert.assertNotNull(node.getMetaData());
+        Assert.assertEquals(2, node.getMetaData().size());
+
+        metaDataIterator = node.getMetaData().iterator();
+        possibleMetaDataTypes = new ArrayList<Class<? extends Annotation>>();
+        possibleMetaDataTypes.add(ViewControllerRef.class);
+        possibleMetaDataTypes.add(SecuredStereotype2.class);
+        foundMetaData = metaDataIterator.next().annotationType();
+        possibleMetaDataTypes.remove(foundMetaData);
+        foundMetaData = metaDataIterator.next().annotationType();
+        possibleMetaDataTypes.remove(foundMetaData);
+
+        Assert.assertTrue(possibleMetaDataTypes.isEmpty());
+
+        Assert.assertNotNull(node.getInheritedMetaData());
+        Assert.assertEquals(0, node.getInheritedMetaData().size());
+
+        Assert.assertNotNull(node.getCallbackDescriptors());
+        Assert.assertEquals(0, node.getCallbackDescriptors().size());
+    }
+
+    @Test
+    public void testBaseViewConfigWithStereotypeViewMetaData()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Secure.class);
+
+        ViewConfigResolver viewConfigResolver = 
this.viewConfigResolverProducer.createViewConfigResolver();
+        ConfigDescriptor configDescriptor = 
viewConfigResolver.getConfigDescriptor(Pages.Secure.class);
+
+        Assert.assertNotNull(configDescriptor);
+        
Assert.assertNotNull(configDescriptor.getCallbackDescriptor(TestSecured.class));
+        
Assert.assertNotNull(configDescriptor.getCallbackDescriptor(TestSecured.class).getCallbackMethods());
+        
Assert.assertFalse(configDescriptor.getCallbackDescriptor(TestSecured.class).getCallbackMethods().isEmpty());
+        
Assert.assertNotNull(configDescriptor.getCallbackDescriptor(TestSecured.class).getCallbackMethods().get(SimpleTestAccessDecisionVoter1.class));
+    }
+
+    @Test
+    public void testViewConfigWithStereotypeViewMetaData()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Secure.class);
+        
this.viewConfigExtension.addPageDefinition(Pages.Secure.Settings.class);
+
+        ViewConfigResolver viewConfigResolver = 
this.viewConfigResolverProducer.createViewConfigResolver();
+        ViewConfigDescriptor viewConfigDescriptor = 
viewConfigResolver.getViewConfigDescriptor(Pages.Secure.Settings.class);
+
+        Assert.assertNotNull(viewConfigDescriptor);
+        
Assert.assertNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class,
 InitView.class));
+        
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class,
 PreRenderView.class));
+        
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class));
+        
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class).getCallbackMethods());
+        
Assert.assertFalse(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class).getCallbackMethods().isEmpty());
+        
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class).getCallbackMethods().get(SimpleTestAccessDecisionVoter2.class));
+    }
+
+    @Test
+    public void testCallbackExecutionFolder()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Secure.class);
+
+        final SimpleTestAccessDecisionVoter1 testInstance1 = new 
SimpleTestAccessDecisionVoter1();
+
+        ViewConfigNode node = 
this.viewConfigExtension.findNode(Pages.Secure.class);
+        //add it to avoid in-container test for this simple constellation - 
usually not needed!
+        node.getCallbackDescriptors().put(TestSecured.class, new 
ArrayList<CallbackDescriptor>() {{
+            add(new TestSecured.Descriptor(new Class[] 
{SimpleTestAccessDecisionVoter1.class}, DefaultCallback.class) {
+                @Override
+                protected Object getTargetObject(Class targetType)
+                {
+                    return testInstance1;
+                }
+            });
+        }});
+
+        ViewConfigResolver viewConfigResolver = 
this.viewConfigResolverProducer.createViewConfigResolver();
+        ConfigDescriptor configDescriptor = 
viewConfigResolver.getConfigDescriptor(Pages.Secure.class);
+
+        Assert.assertNotNull(configDescriptor);
+        
Assert.assertNotNull(configDescriptor.getCallbackDescriptor(TestSecured.class));
+        List<Set<String> /*return type of one callback*/> callbackResult =
+                
((TestSecured.Descriptor)configDescriptor.getExecutableCallbackDescriptor(TestSecured.class,
 TestSecured.Descriptor.class))
+                        .execute("param1", "param2");
+        Assert.assertNotNull(callbackResult);
+        Assert.assertEquals(1, callbackResult.size());
+        Assert.assertEquals(3, callbackResult.iterator().next().size());
+        Iterator<String> resultIterator = 
callbackResult.iterator().next().iterator();
+        Assert.assertEquals("param1", resultIterator.next());
+        Assert.assertEquals("param2", resultIterator.next());
+        Assert.assertEquals(SimpleTestAccessDecisionVoter1.class.getName(), 
resultIterator.next());
+    }
+
+    @Test
+    public void testCallbackExecutionPage()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Secure.class);
+        
this.viewConfigExtension.addPageDefinition(Pages.Secure.Settings.class);
+
+        final SimpleTestAccessDecisionVoter2 testInstance2 = new 
SimpleTestAccessDecisionVoter2();
+
+        ViewConfigNode node = 
this.viewConfigExtension.findNode(Pages.Secure.Settings.class);
+        //add it to avoid in-container test for this simple constellation - 
usually not needed!
+        node.getCallbackDescriptors().put(TestSecured.class, new 
ArrayList<CallbackDescriptor>() {{
+            add(new TestSecured.Descriptor(new Class[] 
{SimpleTestAccessDecisionVoter2.class}, DefaultCallback.class) {
+                @Override
+                protected Object getTargetObject(Class targetType)
+                {
+                    return testInstance2;
+                }
+            });
+        }});
+
+        ViewConfigResolver viewConfigResolver = 
this.viewConfigResolverProducer.createViewConfigResolver();
+        ViewConfigDescriptor viewConfigDescriptor = 
viewConfigResolver.getViewConfigDescriptor(Pages.Secure.Settings.class);
+
+        Assert.assertNotNull(viewConfigDescriptor);
+        
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class));
+        List<Set<String> /*return type of one callback*/> callbackResult =
+            
viewConfigDescriptor.getExecutableCallbackDescriptor(TestSecured.class, 
TestSecured.Descriptor.class)
+                .execute("param1", "param2");
+        Assert.assertNotNull(callbackResult);
+        Assert.assertEquals(1, callbackResult.size());
+        Assert.assertEquals(3, callbackResult.iterator().next().size());
+        Iterator<String> resultIterator = 
callbackResult.iterator().next().iterator();
+        Assert.assertEquals("param1", resultIterator.next());
+        Assert.assertEquals("param2", resultIterator.next());
+        Assert.assertEquals(SimpleTestAccessDecisionVoter2.class.getName(), 
resultIterator.next());
+    }
+}

Reply via email to