You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/10/06 12:21:17 UTC
svn commit: r1004970 - in
/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src:
main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/
test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/
test/java/org/apache/myfac...
Author: gpetracek
Date: Wed Oct 6 10:21:17 2010
New Revision: 1004970
URL: http://svn.apache.org/viewvc?rev=1004970&view=rev
Log:
[intermediate result] tests for EXTCDI-60 , EXTCDI-64 and EXTCDI-68
Added:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/InvalidMetaData.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter1.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter2.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean1.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean2.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean3.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithAccessDecisionVoters.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithSecurityErrorPages.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewController.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewMetaData.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData1.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData2.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/util/
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/util/ReflectionUtils.java
Modified:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java?rev=1004970&r1=1004969&r2=1004970&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigEntry.java Wed Oct 6 10:21:17 2010
@@ -103,6 +103,17 @@ public class ViewConfigEntry
return beanDefinition;
}
+ //we just need it for testing
+ protected final List<Class> getPageBeanClasses()
+ {
+ List<Class> result = new ArrayList<Class>();
+ for(PageBeanConfigEntry pageBeanConfigEntry : getPageBeanDefinitions())
+ {
+ result.add(pageBeanConfigEntry.getBeanClass());
+ }
+ return result;
+ }
+
public void invokeInitViewMethods()
{
for(PageBeanConfigEntry beanEntry : getPageBeanDefinitions())
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java?rev=1004970&r1=1004969&r2=1004970&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java Wed Oct 6 10:21:17 2010
@@ -114,7 +114,8 @@ public class ViewConfigExtension impleme
securedAnnotation = currentClass.getAnnotation(Secured.class);
Collections.addAll(foundVoters, securedAnnotation.value());
- if(!DefaultErrorView.class.getName().equals(securedAnnotation.errorView().getName()))
+ if(errorView == null &&
+ !DefaultErrorView.class.getName().equals(securedAnnotation.errorView().getName()))
{
errorView = securedAnnotation.errorView();
}
@@ -274,14 +275,14 @@ public class ViewConfigExtension impleme
{
ViewMetaData metaData = annotation.annotationType().getAnnotation(ViewMetaData.class);
- if(metaData.override())
- {
- blockedMetaDataTypes.add(annotation.annotationType());
- }
-
if(!blockedMetaDataTypes.contains(annotation.annotationType()))
{
result.add(annotation);
+
+ if(metaData.override())
+ {
+ blockedMetaDataTypes.add(annotation.annotationType());
+ }
}
}
}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/InvalidMetaData.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/InvalidMetaData.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/InvalidMetaData.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/InvalidMetaData.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.TYPE;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+@Documented
+
+//@ViewMetaData
+@interface InvalidMetaData
+{
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter1.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter1.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter1.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter1.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.security.AccessDecisionVoter;
+import org.apache.myfaces.extensions.cdi.core.api.security.SecurityViolation;
+
+import javax.interceptor.InvocationContext;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TestAccessDecisionVoter1 implements AccessDecisionVoter
+{
+ public void checkPermission(InvocationContext invocationContext, Set<SecurityViolation> violations)
+ {
+ //do nothing
+ }
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter2.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter2.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestAccessDecisionVoter2.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.security.AccessDecisionVoter;
+import org.apache.myfaces.extensions.cdi.core.api.security.SecurityViolation;
+
+import javax.interceptor.InvocationContext;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TestAccessDecisionVoter2 implements AccessDecisionVoter
+{
+ public void checkPermission(InvocationContext invocationContext, Set<SecurityViolation> violations)
+ {
+ //do nothing
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean1.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean1.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean1.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean1.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,26 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TestPageBean1
+{
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean2.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean2.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean2.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,26 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TestPageBean2
+{
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean3.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean3.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean3.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestPageBean3.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,26 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TestPageBean3
+{
+}
\ No newline at end of file
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java?rev=1004970&r1=1004969&r2=1004970&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java Wed Oct 6 10:21:17 2010
@@ -23,6 +23,11 @@ import static org.testng.Assert.*;
import org.apache.myfaces.extensions.cdi.jsf.impl.config.view.ViewConfigCache;
import org.apache.myfaces.extensions.cdi.jsf.impl.config.view.ViewConfigEntry;
import org.apache.myfaces.extensions.cdi.jsf.api.config.view.NavigationMode;
+import org.apache.myfaces.extensions.cdi.jsf.test.impl.util.ReflectionUtils;
+import static org.apache.myfaces.extensions.cdi.jsf.test.impl.util.ReflectionUtils.*;
+
+import java.util.List;
+import java.lang.reflect.Method;
/**
* @author Gerhard Petracek
@@ -37,6 +42,9 @@ public class ViewConfigTest
viewConfigExtension.addPageDefinition(SimpleView.class);
assertEquals(ViewConfigCache.getViewDefinition(SimpleView.class).getViewId(), "/simpleView.xhtml");
+
+ assertEquals(ViewConfigCache.getViewDefinition(SimpleView.class).getViewDefinitionClass(),
+ SimpleView.class);
}
@Test
@@ -151,4 +159,75 @@ public class ViewConfigTest
assertEquals(NavigationMode.FORWARD, viewConfigEntry.getNavigationMode());
}
+
+ @Test
+ public void testViewConfigWithAccessDecisionVoters()
+ {
+ viewConfigExtension.addPageDefinition(ViewConfigWithAccessDecisionVoters.Page1.class);
+ viewConfigExtension.addPageDefinition(ViewConfigWithAccessDecisionVoters.Page2.class);
+
+ ViewConfigEntry viewConfigEntry = ViewConfigCache.getViewDefinition(
+ ViewConfigWithAccessDecisionVoters.Page1.class);
+
+ assertEquals(viewConfigEntry.getAccessDecisionVoters().length, 1);
+
+ viewConfigEntry = ViewConfigCache.getViewDefinition(ViewConfigWithAccessDecisionVoters.Page2.class);
+
+ assertEquals(viewConfigEntry.getAccessDecisionVoters().length, 2);
+ assertTrue(viewConfigEntry.getAccessDecisionVoters()[0].equals(TestAccessDecisionVoter2.class));
+ assertTrue(viewConfigEntry.getAccessDecisionVoters()[1].equals(TestAccessDecisionVoter1.class));
+ }
+
+ @Test
+ public void testViewConfigWithSecurityErrorPages()
+ {
+ viewConfigExtension.addPageDefinition(ViewConfigWithSecurityErrorPages.Page1.class);
+ viewConfigExtension.addPageDefinition(ViewConfigWithSecurityErrorPages.Page2.class);
+
+ ViewConfigEntry viewConfigEntry = ViewConfigCache.getViewDefinition(
+ ViewConfigWithSecurityErrorPages.Page1.class);
+
+ assertEquals(viewConfigEntry.getErrorView(), SimpleView.class);
+
+ viewConfigEntry = ViewConfigCache.getViewDefinition(ViewConfigWithSecurityErrorPages.Page2.class);
+ assertEquals(viewConfigEntry.getErrorView(), SimpleViewWithManualName.class);
+ }
+
+ @Test
+ public void testViewConfigWithViewMetaData()
+ {
+ viewConfigExtension.addPageDefinition(ViewConfigWithViewMetaData.Page1.class);
+ viewConfigExtension.addPageDefinition(ViewConfigWithViewMetaData.Page2.class);
+
+ ViewConfigEntry viewConfigEntry = ViewConfigCache.getViewDefinition(
+ ViewConfigWithViewMetaData.Page1.class);
+
+ assertEquals(viewConfigEntry.getMetaData().size(), 2);
+
+ viewConfigEntry = ViewConfigCache.getViewDefinition(ViewConfigWithViewMetaData.Page2.class);
+ assertEquals(viewConfigEntry.getMetaData().size(), 3);
+ }
+
+ @Test
+ public void testViewConfigWithViewController()
+ {
+ viewConfigExtension.addPageDefinition(ViewConfigWithViewController.Page1.class);
+ viewConfigExtension.addPageDefinition(ViewConfigWithViewController.Page2.class);
+
+ ViewConfigEntry viewConfigEntry = ViewConfigCache.getViewDefinition(
+ ViewConfigWithViewController.Page1.class);
+
+ Method getPageBeanClassesMethod = ReflectionUtils.tryToGetMethod(ViewConfigEntry.class, "getPageBeanClasses");
+ List<Class> pageBeanClasses = (List<Class>) tryToInvokeMethod(viewConfigEntry, getPageBeanClassesMethod);
+ assertEquals(pageBeanClasses.size(), 1);
+ assertTrue(pageBeanClasses.contains(TestPageBean2.class));
+
+ viewConfigEntry = ViewConfigCache.getViewDefinition(ViewConfigWithViewController.Page2.class);
+
+ getPageBeanClassesMethod = ReflectionUtils.tryToGetMethod(ViewConfigEntry.class, "getPageBeanClasses");
+ pageBeanClasses = (List<Class>) tryToInvokeMethod(viewConfigEntry, getPageBeanClassesMethod);
+ assertEquals(pageBeanClasses.size(), 2);
+ assertTrue(pageBeanClasses.contains(TestPageBean2.class));
+ assertTrue(pageBeanClasses.contains(TestPageBean3.class));
+ }
}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithAccessDecisionVoters.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithAccessDecisionVoters.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithAccessDecisionVoters.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithAccessDecisionVoters.java Wed Oct 6 10:21:17 2010
@@ -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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewConfig;
+import org.apache.myfaces.extensions.cdi.core.api.security.Secured;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.Page;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Secured(TestAccessDecisionVoter1.class)
+abstract class ViewConfigWithAccessDecisionVoters implements ViewConfig
+{
+ @Page
+ public class Page1 extends ViewConfigWithAccessDecisionVoters
+ {
+ }
+
+ @Page
+ @Secured(TestAccessDecisionVoter2.class)
+ public class Page2 extends ViewConfigWithAccessDecisionVoters
+ {
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithSecurityErrorPages.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithSecurityErrorPages.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithSecurityErrorPages.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithSecurityErrorPages.java Wed Oct 6 10:21:17 2010
@@ -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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewConfig;
+import org.apache.myfaces.extensions.cdi.core.api.security.Secured;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.Page;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Secured(value = TestAccessDecisionVoter1.class, errorView = SimpleView.class)
+abstract class ViewConfigWithSecurityErrorPages implements ViewConfig
+{
+ @Page
+ public class Page1 extends ViewConfigWithSecurityErrorPages
+ {
+ }
+
+ @Page
+ @Secured(value = TestAccessDecisionVoter2.class, errorView = SimpleViewWithManualName.class)
+ public class Page2 extends ViewConfigWithSecurityErrorPages
+ {
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewController.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewController.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewController.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewController.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,45 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewConfig;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.Page;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.PageBean;
+
+/**
+ * @author Gerhard Petracek
+ */
+@PageBean(value = TestPageBean1.class) //won't get picked up!
+abstract class ViewConfigWithViewController implements ViewConfig
+{
+ @Page
+ @PageBean(TestPageBean2.class)
+ public class Page1 implements ViewConfig
+ {
+ }
+
+ @Page
+ @PageBean.List({
+ @PageBean(TestPageBean2.class),
+ @PageBean(TestPageBean3.class)
+ })
+ public class Page2 extends ViewConfigWithViewController
+ {
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewMetaData.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewMetaData.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewMetaData.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigWithViewMetaData.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,45 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewConfig;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.Page;
+
+/**
+ * @author Gerhard Petracek
+ */
+@ViewMetaData1
+@ViewMetaData2(level = 0)
+@InvalidMetaData
+abstract class ViewConfigWithViewMetaData implements ViewConfig
+{
+ @Page
+ @InvalidMetaData
+ public class Page1 extends ViewConfigWithViewMetaData
+ {
+ }
+
+ @Page
+ @ViewMetaData1
+ @ViewMetaData2(level = 1)
+ @InvalidMetaData
+ public class Page2 extends ViewConfigWithViewMetaData
+ {
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData1.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData1.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData1.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData1.java Wed Oct 6 10:21:17 2010
@@ -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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewMetaData;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.TYPE;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+@Documented
+
+@ViewMetaData
+@interface ViewMetaData1
+{
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData2.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData2.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewMetaData2.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.config.view;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewMetaData;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.TYPE;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+@Documented
+
+@ViewMetaData(override = true)
+@interface ViewMetaData2
+{
+ int level();
+}
\ No newline at end of file
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/util/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/util/ReflectionUtils.java?rev=1004970&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/util/ReflectionUtils.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/util/ReflectionUtils.java Wed Oct 6 10:21:17 2010
@@ -0,0 +1,197 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.test.impl.util;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ReflectionUtils
+{
+ private static final Logger LOGGER = Logger.getLogger(ReflectionUtils.class.getName());
+
+ public static Method tryToGetMethod(Class targetClass, String targetMethodName)
+ {
+ return tryToGetMethod(targetClass, targetMethodName, null);
+ }
+
+ public static Method tryToGetMethod(Class targetClass, String targetMethodName, Class... parameterTypes)
+ {
+ try
+ {
+ return getMethod(targetClass, targetMethodName, parameterTypes);
+ }
+ catch (Exception e)
+ {
+ //do nothing - it's just a try
+ return null;
+ }
+ }
+
+ public static Method getMethod(Class targetClass, String targetMethodName)
+ throws NoSuchMethodException
+ {
+ return getMethod(targetClass, targetMethodName, null);
+ }
+
+ public static Method getMethod(Class targetClass, String targetMethodName, Class... parameterTypes)
+ throws NoSuchMethodException
+ {
+ Class currentClass = targetClass;
+ Method targetMethod = null;
+
+ while (!Object.class.getName().equals(currentClass.getName()))
+ {
+ try
+ {
+ targetMethod = currentClass.getDeclaredMethod(targetMethodName, parameterTypes);
+ break;
+ }
+ catch (NoSuchMethodException e)
+ {
+ currentClass = currentClass.getSuperclass();
+ }
+ }
+
+ if(targetMethod == null)
+ {
+ for (Class currentInterface : targetClass.getInterfaces())
+ {
+ currentClass = currentInterface;
+
+ while (currentClass != null)
+ {
+ try
+ {
+ targetMethod = currentClass.getDeclaredMethod(targetMethodName, parameterTypes);
+ break;
+ }
+ catch (NoSuchMethodException e)
+ {
+ currentClass = currentClass.getSuperclass();
+ }
+ }
+ }
+ }
+
+ if(targetMethod != null)
+ {
+ return targetMethod;
+ }
+
+ throw new NoSuchMethodException("there is no method with the name '" + targetMethodName + "'" +
+ " class: " + targetClass.getName());
+ }
+
+ public static Object tryToInvokeMethod(Object target, Method method)
+ {
+ return tryToInvokeMethod(target, method, null);
+ }
+
+ public static Object tryToInvokeMethodOfClass(Class target, Method method)
+ {
+ return tryToInvokeMethodOfClass(target, method, null);
+ }
+
+ public static Object tryToInvokeMethodOfClass(Class target, Method method, Object[] args)
+ {
+ try
+ {
+ return invokeMethodOfClass(target, method, args);
+ }
+ catch (Exception e)
+ {
+ //do nothing - it's just a try
+ return null;
+ }
+ }
+
+ public static Object invokeMethodOfClass(Class target, Method method)
+ throws IllegalAccessException, InstantiationException, InvocationTargetException
+ {
+ return invokeMethod(target.newInstance(), method, null);
+ }
+
+ public static Object invokeMethodOfClass(Class target, Method method, Object... args)
+ throws IllegalAccessException, InstantiationException, InvocationTargetException
+ {
+ return invokeMethod(target.newInstance(), method, args);
+ }
+
+ public static Object tryToInvokeMethod(Object target, Method method, Object... args)
+ {
+ try
+ {
+ return invokeMethod(target, method, args);
+ }
+ catch (Exception e)
+ {
+ //do nothing - it's just a try
+ return null;
+ }
+ }
+
+ public static Object invokeMethod(Object target, Method method)
+ throws InvocationTargetException, IllegalAccessException
+ {
+ return invokeMethod(target, method, null);
+ }
+
+ public static Object invokeMethod(Object target, Method method, Object... args)
+ throws InvocationTargetException, IllegalAccessException
+ {
+ method.setAccessible(true);
+ return method.invoke(target, args);
+ }
+
+ private static Method tryToGetReadMethodManually(Class entity, String property)
+ {
+ property = property.substring(0, 1).toUpperCase() + property.substring(1);
+
+ try
+ {
+ //changed to official bean spec. due to caching there is no performance issue any more
+ return entity.getDeclaredMethod("is" + property);
+ }
+ catch (NoSuchMethodException e)
+ {
+ try
+ {
+ return entity.getDeclaredMethod("get" + property);
+ }
+ catch (NoSuchMethodException e1)
+ {
+ LOGGER.finest("method not found - class: " + entity.getName()
+ + " - methods: " + "get" + property + " " + "is" + property);
+
+ return null;
+ }
+ }
+ }
+}