Search in sources :

Example 11 with ViewConfigNode

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

the class ViewConfigTest method testMetaDataTreeWithRandomOrder.

@Test
public void testMetaDataTreeWithRandomOrder() {
    this.viewConfigExtension.addPageDefinition(Pages.Index.class);
    // simulates random processing-order
    this.viewConfigExtension.addPageDefinition(Pages.class);
    ViewConfigNode node = this.viewConfigExtension.findNode(Pages.Index.class);
    Assert.assertNotNull(node);
    Assert.assertNotNull(node.getParent());
    Assert.assertNotNull(node.getParent().getParent());
    Assert.assertNull(node.getParent().getParent().getParent());
    Assert.assertNotNull(node.getMetaData());
    Assert.assertEquals(0, node.getMetaData().size());
}
Also used : ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Test(org.junit.Test)

Example 12 with ViewConfigNode

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

the class ViewConfigTest method testCallbackExecutionPage.

@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();
    // the order in the result isn't guaranteed
    Set<String> expectedValues = new HashSet<String>();
    expectedValues.add("param1");
    expectedValues.add("param2");
    expectedValues.add(SimpleTestAccessDecisionVoter2.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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ViewConfigNode

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

the class ViewConfigTest method testMetaDataTree.

@Test
public void testMetaDataTree() {
    List<Class<? extends ViewConfig>> menuViewConfigClasses = new ArrayList<>();
    menuViewConfigClasses.add(Pages.Section1.Content1.class);
    menuViewConfigClasses.add(Pages.Section1.Content2.class);
    menuViewConfigClasses.add(Pages.Section2.Content1.class);
    menuViewConfigClasses.add(Pages.Section2.Content2.class);
    this.viewConfigExtension.addPageDefinition(Pages.Index.class);
    for (Class<? extends ViewConfig> menuViewConfigClass : menuViewConfigClasses) {
        this.viewConfigExtension.addPageDefinition(menuViewConfigClass);
    }
    ViewConfigNode node = this.viewConfigExtension.findNode(Pages.Index.class);
    Assert.assertNotNull(node.getMetaData());
    Assert.assertEquals(0, node.getMetaData().size());
    for (Class<? extends ViewConfig> menuViewConfigClass : menuViewConfigClasses) {
        node = this.viewConfigExtension.findNode(menuViewConfigClass);
        Assert.assertNotNull(node.getMetaData());
        Assert.assertEquals(1, node.getMetaData().size());
        Assert.assertEquals(TestMenuEntry.class, node.getMetaData().iterator().next().annotationType());
    }
}
Also used : ArrayList(java.util.ArrayList) ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Test(org.junit.Test)

Example 14 with ViewConfigNode

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

the class ViewConfigTest method testFolderOnlyMetaData.

@Test
public void testFolderOnlyMetaData() {
    this.viewConfigExtension.addPageDefinition(Pages.AdminArea.class);
    this.viewConfigExtension.addFolderDefinition(Pages.VipArea.class);
    ViewConfigNode node = this.viewConfigExtension.findNode(Pages.AdminArea.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(0, node.getMetaData().size());
    Assert.assertNotNull(node.getInheritedMetaData());
    Assert.assertEquals(0, node.getInheritedMetaData().size());
    node = this.viewConfigExtension.findNode(Pages.VipArea.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(1, node.getMetaData().size());
    Assert.assertEquals(Folder.class, node.getMetaData().iterator().next().annotationType());
    Assert.assertNotNull(node.getInheritedMetaData());
    Assert.assertEquals(0, node.getInheritedMetaData().size());
}
Also used : ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Test(org.junit.Test)

Example 15 with ViewConfigNode

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

the class ViewConfigTest method testMetaDataTree.

private void testMetaDataTree() {
    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(0, node.getMetaData().size());
    Assert.assertNotNull(node.getInheritedMetaData());
    Assert.assertEquals(1, node.getInheritedMetaData().size());
    Assert.assertNotNull(node.getCallbackDescriptors());
    Assert.assertEquals(0, node.getCallbackDescriptors().size());
}
Also used : ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode)

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