Search in sources :

Example 26 with ViewConfigNode

use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.

the class ViewConfigExtension method addIndirectlyInheritedMetaData.

protected void addIndirectlyInheritedMetaData(Class configClass, Set<Annotation> annotations) {
    for (Annotation annotation : annotations) {
        InlineViewMetaData inlineViewMetaData = annotation.annotationType().getAnnotation(InlineViewMetaData.class);
        if (inlineViewMetaData != null) {
            Class<? extends TargetViewConfigProvider> targetViewConfigProviderClass = inlineViewMetaData.targetViewConfigProvider();
            TargetViewConfigProvider targetViewConfigProvider = ClassUtils.tryToInstantiateClass(targetViewConfigProviderClass);
            for (Class<? extends ViewConfig> viewConfigRef : targetViewConfigProvider.getTarget(annotation)) {
                ViewConfigNode viewConfigNode = findNode(viewConfigRef);
                if (viewConfigNode == null) {
                    addPageDefinition(viewConfigRef);
                    viewConfigNode = findNode(viewConfigRef);
                    if (viewConfigNode == null) {
                        throw new IllegalStateException("No node created for: " + viewConfigRef);
                    }
                }
                Class<? extends InlineMetaDataTransformer> inlineNodeTransformerClass = inlineViewMetaData.inlineMetaDataTransformer();
                if (!InlineMetaDataTransformer.class.equals(inlineNodeTransformerClass)) {
                    InlineMetaDataTransformer inlineMetaDataTransformer = ClassUtils.tryToInstantiateClass(inlineNodeTransformerClass);
                    viewConfigNode.getInheritedMetaData().add(inlineMetaDataTransformer.convertToViewMetaData(annotation, configClass));
                } else // no custom transformer registered -> add the annotation itself
                {
                    viewConfigNode.getInheritedMetaData().add(annotation);
                }
            }
            break;
        }
    }
}
Also used : InlineMetaDataTransformer(org.apache.deltaspike.core.spi.config.view.InlineMetaDataTransformer) InlineViewMetaData(org.apache.deltaspike.core.api.config.view.metadata.InlineViewMetaData) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) TargetViewConfigProvider(org.apache.deltaspike.core.spi.config.view.TargetViewConfigProvider) Annotation(java.lang.annotation.Annotation)

Example 27 with ViewConfigNode

use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.

the class ViewConfigTest method testSimpleMetaDataTreeWithViewControllerCallback.

@Test
public void testSimpleMetaDataTreeWithViewControllerCallback() {
    this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
    ViewConfigNode node = this.viewConfigExtension.findNode(SimplePageConfig.class);
    Assert.assertNotNull(node);
    Assert.assertNotNull(node.getParent());
    Assert.assertNull(node.getParent().getParent());
    Assert.assertNotNull(node.getChildren());
    Assert.assertEquals(0, node.getChildren().size());
    Assert.assertNotNull(node.getMetaData());
    Assert.assertEquals(1, node.getMetaData().size());
    Assert.assertNotNull(node.getInheritedMetaData());
    Assert.assertEquals(0, node.getInheritedMetaData().size());
    Assert.assertNotNull(node.getCallbackDescriptors());
    // TODO related to the discussion about #getInheritedMetaData (see TODOs in other use-cases)
    Assert.assertEquals(0, node.getCallbackDescriptors().size());
}
Also used : ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Test(org.junit.Test)

Example 28 with ViewConfigNode

use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.

the class ViewConfigTest method testCallbackExecution.

@Test
public void testCallbackExecution() {
    this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
    final SimpleTestAccessDecisionVoter testInstance = new SimpleTestAccessDecisionVoter();
    ViewConfigNode node = this.viewConfigExtension.findNode(SimplePageConfig.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[] { SimpleTestAccessDecisionVoter.class }, DefaultCallback.class) {

                @Override
                protected Object getTargetObject(Class targetType) {
                    return testInstance;
                }
            });
        }
    });
    ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
    ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.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(2, callbackResult.iterator().next().size());
    Iterator<String> resultIterator = callbackResult.iterator().next().iterator();
    // the order in the result isn't guaranteed
    Set<String> expectedValues = new HashSet<String>();
    expectedValues.add("param1");
    expectedValues.add("param2");
    while (resultIterator.hasNext()) {
        String currentValue = resultIterator.next();
        if (!expectedValues.remove(currentValue)) {
            Assert.fail("value '" + currentValue + "' not found in the result");
        }
    }
    Assert.assertTrue(expectedValues.isEmpty());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CallbackDescriptor(org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) CallbackDescriptor(org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigDescriptor(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor) ViewConfigResolver(org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with ViewConfigNode

use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.

the class ViewConfigTest method testCallbackExecutionFolder.

@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();
    // the order in the result isn't guaranteed
    Set<String> expectedValues = new CopyOnWriteArraySet<String>();
    expectedValues.add("param1");
    expectedValues.add("param2");
    expectedValues.add(SimpleTestAccessDecisionVoter1.class.getName());
    while (resultIterator.hasNext()) {
        String currentValue = resultIterator.next();
        if (!expectedValues.remove(currentValue)) {
            Assert.fail("value '" + currentValue + "' not found in the result");
        }
    }
    Assert.assertTrue(expectedValues.isEmpty());
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Test(org.junit.Test)

Example 30 with ViewConfigNode

use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.

the class ViewConfigTest method testMetaDataTreeWithStereotypeViewMetaData.

@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());
}
Also used : ArrayList(java.util.ArrayList) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Aggregations

ViewConfigNode (org.apache.deltaspike.core.spi.config.view.ViewConfigNode)31 Test (org.junit.Test)24 Annotation (java.lang.annotation.Annotation)7 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)3 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 View (org.apache.deltaspike.jsf.api.config.view.View)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 CallbackDescriptor (org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor)1 InlineViewMetaData (org.apache.deltaspike.core.api.config.view.metadata.InlineViewMetaData)1 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)1 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)1 InlineMetaDataTransformer (org.apache.deltaspike.core.spi.config.view.InlineMetaDataTransformer)1 TargetViewConfigProvider (org.apache.deltaspike.core.spi.config.view.TargetViewConfigProvider)1