use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.
the class ViewConfigTest method testSimpleViewConfigWithViewControllerCallback.
@Test
public void testSimpleViewConfigWithViewControllerCallback() {
this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PostRenderView.class));
Assert.assertEquals(PageBean002.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PostRenderView.class).getCallbackMethods().keySet().iterator().next());
Assert.assertEquals("postRenderViewCallbackMethod", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PostRenderView.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
}
use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.
the class ViewConfigTest method testSimpleViewConfigWithViewControllerCallback.
@Test
public void testSimpleViewConfigWithViewControllerCallback() {
this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
this.viewConfigExtension.addIndirectlyInheritedMetaData(PageBean003.class);
ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, InitView.class));
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreViewAction.class));
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class));
Assert.assertNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PostRenderView.class));
Assert.assertEquals(PageBean003.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, InitView.class).getCallbackMethods().keySet().iterator().next());
Assert.assertEquals("callbackMethod1", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, InitView.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
Assert.assertEquals(PageBean003.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreViewAction.class).getCallbackMethods().keySet().iterator().next());
Assert.assertEquals("callbackMethod1", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreViewAction.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
Assert.assertEquals(PageBean003.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class).getCallbackMethods().keySet().iterator().next());
Assert.assertEquals("callbackMethod2", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
}
use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver in project deltaspike by apache.
the class ViewConfigTest method testSimpleViewConfigWithCallbacks.
@Test
public void testSimpleViewConfigWithCallbacks() {
this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, InitView.class));
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class));
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(TestSecured.class));
}
use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver 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());
}
Aggregations