use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.
the class PersistentFieldManagerImplTest method strategy_name_is_case_insensitive.
public void strategy_name_is_case_insensitive() {
String pageName = "foo.Bar";
String nestedId = "nested";
String fieldName = "field";
String strategyName = "FOO";
ComponentResources resources = mockComponentResources();
ComponentModel model = mockComponentModel();
PersistentFieldStrategy strat = newPersistentFieldStrategy();
Object value = new Object();
Map<String, PersistentFieldStrategy> strategies = newMap();
strategies.put("foo", strat);
train_getComponentModel(resources, model);
train_getFieldPersistenceStrategy(model, fieldName, strategyName);
train_getNestedId(resources, nestedId);
strat.postChange(pageName, nestedId, fieldName, value);
replay();
PersistentFieldManager manager = new PersistentFieldManagerImpl(null, strategies);
manager.postChange(pageName, resources, fieldName, value);
verify();
}
use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.
the class PersistentFieldManagerImplTest method post_change_with_unknown_strategy.
@Test
public void post_change_with_unknown_strategy() {
String fieldName = "field";
PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
ComponentResources resources = mockComponentResources();
ComponentModel model = mockComponentModel();
Map<String, PersistentFieldStrategy> strategies = newMap();
strategies.put("foo", strat1);
strategies.put("bar", strat2);
train_getComponentModel(resources, model);
train_getFieldPersistenceStrategy(model, fieldName, "braveheart");
replay();
PersistentFieldManager manager = new PersistentFieldManagerImpl(null, strategies);
try {
manager.postChange("foo.Bar", resources, fieldName, null);
unreachable();
} catch (UnknownValueException ex) {
assertEquals(ex.getMessage(), "'braveheart' is not a defined persistent strategy.");
assertListsEquals(ex.getAvailableValues().getValues(), "bar", "foo");
}
verify();
}
use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.
the class PageActivationContextCollectorImplTest method page_with_no_context.
@Test
public void page_with_no_context() {
String pageName = "mypage";
ComponentModel model = mockComponentModel();
ComponentModelSource modelSource = mockComponentModelSource();
RequestPageCache pageCache = mockRequestPageCache();
Page page = mockPage();
ComponentPageElement element = mockComponentPageElement();
expect(modelSource.getPageModel(pageName)).andReturn(model);
expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
train_get(pageCache, pageName, page);
train_getRootElement(page, element);
expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andReturn(false);
replay();
PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
Object[] actual = collector.collectPageActivationContext(pageName);
assertEquals(actual.length, 0);
}
use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.
the class DefaultInjectionProvider method provideInjection.
public boolean provideInjection(final PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
Class fieldType = classCache.forName(field.getTypeName());
Object injectionValue = masterObjectProvider.provide(fieldType, new AnnotationProvider() {
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return field.getAnnotation(annotationClass);
}
}, this.locator, false);
if (injectionValue != null) {
field.inject(injectionValue);
return true;
}
return false;
}
use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.
the class BindParameterWorker method identifyParameterName.
private String identifyParameterName(ComponentResources resources, String firstGuess, String... otherGuesses) {
ComponentModel model = resources.getContainerResources().getComponentModel();
List<String> guesses = CollectionFactory.newList();
guesses.add(firstGuess);
for (String name : otherGuesses) {
guesses.add(name);
}
for (String name : guesses) {
if (model.isFormalParameter(name))
return name;
if (isPublishedParameter(model, name))
return name;
}
String message = String.format("Containing component %s does not contain a formal parameter or a published parameter %s %s.", model.getComponentClassName(), guesses.size() == 1 ? "matching" : "matching any of", InternalUtils.joinSorted(guesses));
List<String> formalAndPublishedParameters = CollectionFactory.newList(model.getParameterNames());
formalAndPublishedParameters.addAll(getPublishedParameters(model));
throw new UnknownValueException(message, new AvailableValues("Formal and published parameters", formalAndPublishedParameters));
}
Aggregations