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;
}
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations