use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class TemplateParserImplTest method just_HTML.
@Test
public void just_HTML() {
Resource resource = getResource("justHTML.tml");
ComponentTemplate template = getParser().parseTemplate(resource);
assertSame(template.getResource(), resource);
assertFalse(template.usesStrictMixinParameters());
List<TemplateToken> tokens = template.getTokens();
// They add up quick ...
assertEquals(tokens.size(), 20);
StartElementToken t0 = get(tokens, 0);
// Spot check a few things ...
assertEquals(t0.name, "html");
assertEquals(t0.namespaceURI, "");
checkLine(t0, 1);
TextToken t1 = get(tokens, 1);
// Concerned this may not work cross platform.
assertEquals(t1.text, "\n ");
StartElementToken t2 = get(tokens, 2);
assertEquals(t2.name, "head");
checkLine(t2, 2);
TextToken t5 = get(tokens, 5);
assertEquals(t5.text, "title");
checkLine(t5, 3);
get(tokens, 6);
StartElementToken t12 = get(tokens, 12);
assertEquals(t12.name, "p");
AttributeToken t13 = get(tokens, 13);
assertEquals(t13.name, "class");
assertEquals(t13.value, "important");
assertEquals(t13.namespaceURI, "");
TextToken t14 = get(tokens, 14);
// Simplify the text, converting consecutive whitespace to just a single space.
assertEquals(t14.text.replaceAll("\\s+", " ").trim(), "Tapestry rocks! Line 2");
// Line number is the *start* line of the whole text block.
checkLine(t14, 6);
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class PropertyOverridesImplTest method block_found.
@Test
public void block_found() {
Messages messages = mockMessages();
ComponentResources resources = mockInternalComponentResources();
Block block = mockBlock();
String name = "alfred";
train_getContainerMessages(resources, messages);
train_getBlockParameter(resources, name, block);
replay();
PropertyOverrides po = new PropertyOverridesImpl(resources);
assertSame(po.getOverrideBlock(name), block);
verify();
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class CheckMethodAdapter method visitMaxs.
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
checkVisitCodeCalled();
checkVisitMaxsNotCalled();
visitMaxCalled = true;
for (Label l : referencedLabels) {
if (labelInsnIndices.get(l) == null) {
throw new IllegalStateException("Undefined label used");
}
}
for (int i = 0; i < handlers.size(); i += 2) {
Integer startInsnIndex = labelInsnIndices.get(handlers.get(i));
Integer endInsnIndex = labelInsnIndices.get(handlers.get(i + 1));
if (startInsnIndex == null || endInsnIndex == null) {
throw new IllegalStateException("Undefined try catch block labels");
}
if (endInsnIndex.intValue() <= startInsnIndex.intValue()) {
throw new IllegalStateException("Emty try catch block handler range");
}
}
checkUnsignedShort(maxStack, "Invalid max stack");
checkUnsignedShort(maxLocals, "Invalid max locals");
super.visitMaxs(maxStack, maxLocals);
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class ModuleImpl method findOrCreate.
/**
* Locates the service proxy for a particular service (from the service definition).
*
* @param def defines the service
* @param eagerLoadProxies collection into which proxies for eager loaded services are added (or null)
* @return the service proxy
*/
private Object findOrCreate(final ServiceDef3 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies) {
final String key = def.getServiceId();
final Invokable create = new Invokable() {
@Override
public Object invoke() {
// In a race condition, two threads may try to create the same service simulatenously.
// The second will block until after the first creates the service.
Object result = services.get(key);
if (result == null) {
result = create(def, eagerLoadProxies);
services.put(key, result);
}
return result;
}
};
Invokable find = new Invokable() {
@Override
public Object invoke() {
Object result = services.get(key);
if (result == null)
result = BARRIER.withWrite(create);
return result;
}
};
return BARRIER.withRead(find);
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class BlockImplTest method body_pushed_to_queue_backwards.
@Test
public void body_pushed_to_queue_backwards() {
BlockImpl block = new BlockImpl(null, null);
RenderQueue queue = mockRenderQueue();
MarkupWriter writer = mockMarkupWriter();
RenderCommand element1 = mockRenderCommand();
RenderCommand element2 = mockRenderCommand();
getMocksControl().checkOrder(true);
queue.push(element2);
queue.push(element1);
replay();
block.addToBody(element1);
block.addToBody(element2);
block.render(writer, queue);
verify();
}
Aggregations