deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-658 improved @Stereotype support for @ViewMetaData
Date Fri, 04 Jul 2014 13:02:57 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 2302c3d34 -> 8006d52c6


DELTASPIKE-658 improved @Stereotype support for @ViewMetaData


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

Branch: refs/heads/master
Commit: 8006d52c6e43d5c7e87ae78f398a7a4e74db8e68
Parents: 2302c3d
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Jul 4 14:40:32 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Jul 4 14:58:33 2014 +0200

----------------------------------------------------------------------
 .../DefaultViewConfigInheritanceStrategy.java   |   3 +-
 .../view/navigation/syntax/uc010/MyView.java    |  48 +++++
 .../view/navigation/syntax/uc010/Pages.java     |  41 +++++
 .../navigation/syntax/uc010/ViewConfigTest.java | 173 +++++++++++++++++++
 4 files changed, 264 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8006d52c/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
index 486c294..77e4a0a 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
@@ -106,7 +106,8 @@ public class DefaultViewConfigInheritanceStrategy implements ViewConfigInheritan
         {
             metaDataList.add(currentAnnotation);
         }
-        else if (annotationClass.isAnnotationPresent(Stereotype.class))
+
+        if (annotationClass.isAnnotationPresent(Stereotype.class))
         {
             for (Annotation inheritedViaStereotype : annotationClass.getAnnotations())
             {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8006d52c/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/MyView.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/MyView.java
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/MyView.java
new file mode 100644
index 0000000..1865d60
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/MyView.java
@@ -0,0 +1,48 @@
+/*
+ * 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.navigation.syntax.uc010;
+
+import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData;
+import org.apache.deltaspike.jsf.api.config.view.View;
+
+import javax.enterprise.inject.Stereotype;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.deltaspike.jsf.api.config.view.View.NavigationMode.REDIRECT;
+
+/**
+ * Custom meta-data
+ */
+
+@ViewMetaData
+//don't use @Inherited
+@Target({TYPE})
+@Retention(RUNTIME)
+@Documented
+
+@Stereotype
+@View(navigation = REDIRECT)
+@interface MyView
+{
+    String description();
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8006d52c/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/Pages.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/Pages.java
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/Pages.java
new file mode 100644
index 0000000..149d4f6
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/Pages.java
@@ -0,0 +1,41 @@
+/*
+ * 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.navigation.syntax.uc010;
+
+import org.apache.deltaspike.core.api.config.view.ViewConfig;
+import org.apache.deltaspike.jsf.api.config.view.View;
+
+import static org.apache.deltaspike.jsf.api.config.view.View.ViewParameterMode.INCLUDE;
+
+interface Pages
+{
+    @MyView(description = "public content")
+    interface Public extends ViewConfig
+    {
+        class Index implements Public
+        {
+        }
+    }
+
+    @MyView(description = "landing page")
+    @View(viewParams = INCLUDE)
+    class Home implements ViewConfig
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8006d52c/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/ViewConfigTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/ViewConfigTest.java
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/ViewConfigTest.java
new file mode 100644
index 0000000..3142fdc
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc010/ViewConfigTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.navigation.syntax.uc010;
+
+import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor;
+import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver;
+import org.apache.deltaspike.core.spi.config.view.ViewConfigNode;
+import org.apache.deltaspike.jsf.api.config.view.View;
+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;
+
+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 testMetaDataTreeWithStereotypeMetaData()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.Home.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
+
+        ViewConfigNode node = this.viewConfigExtension.findNode(Pages.Home.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(0, node.getChildren().size());
+
+        Assert.assertNotNull(node.getMetaData());
+        Assert.assertEquals(2, node.getMetaData().size());
+
+        Assert.assertEquals(2, node.getMetaData().size());
+
+        boolean facesRedirectAnnotationFound = false;
+        boolean viewAnnotationFound = false;
+
+        for (Annotation metaData : node.getMetaData())
+        {
+            if (MyView.class.isAssignableFrom(metaData.annotationType()))
+            {
+                facesRedirectAnnotationFound = true;
+            }
+            else if (View.class.isAssignableFrom(metaData.annotationType()))
+            {
+                viewAnnotationFound = true;
+            }
+        }
+
+        Assert.assertTrue(facesRedirectAnnotationFound);
+        Assert.assertTrue(viewAnnotationFound);
+
+        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.Public.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());
+        Assert.assertEquals(MyView.class, node.getMetaData().iterator().next().annotationType());
+
+        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.Public.Index.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(0, node.getMetaData().size());
+
+        Assert.assertNotNull(node.getInheritedMetaData());
+        Assert.assertEquals(0, node.getInheritedMetaData().size());
+
+        Assert.assertNotNull(node.getCallbackDescriptors());
+        Assert.assertEquals(0, node.getCallbackDescriptors().size());
+    }
+
+    @Test
+    public void testViewConfigWithStereotypeMetaData()
+    {
+        this.viewConfigExtension.addPageDefinition(Pages.Home.class);
+        this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
+
+        ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
+
+
+        ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Home.class);
+
+        Assert.assertNotNull(viewConfigDescriptor);
+        Assert.assertNotNull(viewConfigDescriptor.getMetaData());
+        Assert.assertEquals(2, viewConfigDescriptor.getMetaData().size());
+        Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
+        Assert.assertEquals(1, viewConfigDescriptor.getMetaData(MyView.class).size());
+        Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
+        Assert.assertEquals(View.ViewParameterMode.INCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
+        Assert.assertEquals("landing page", viewConfigDescriptor.getMetaData(MyView.class).iterator().next().description());
+
+
+        viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Public.Index.class);
+
+        Assert.assertNotNull(viewConfigDescriptor);
+        Assert.assertNotNull(viewConfigDescriptor.getMetaData());
+        Assert.assertEquals(2, viewConfigDescriptor.getMetaData().size());
+        Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
+        Assert.assertEquals(1, viewConfigDescriptor.getMetaData(MyView.class).size());
+        Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
+        Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
+        Assert.assertEquals("public content", viewConfigDescriptor.getMetaData(MyView.class).iterator().next().description());
+    }
+}


Mime
View raw message