/*
* For every language we should get the same content and contentMap template code
*/
String contentEXT=Config.getStringProperty("VELOCITY_CONTENT_EXTENSION");
VelocityEngine engine = VelocityUtil.getEngine();
SimpleNode contentTester = engine.getRuntimeServices().parse(new StringReader("code:$code"), "tester1");
contentTester.init(null, null);
InvocationHandler dotInvocationHandler = new DotInvocationHandler(new HashMap());
DotRequestProxy requestProxy = (DotRequestProxy) Proxy
.newProxyInstance(DotRequestProxy.class.getClassLoader(),
new Class[] { DotRequestProxy.class },
dotInvocationHandler);
DotResponseProxy responseProxy = (DotResponseProxy) Proxy
.newProxyInstance(DotResponseProxy.class.getClassLoader(),
new Class[] { DotResponseProxy.class },
dotInvocationHandler);
requestProxy.setAttribute(WebKeys.HTMLPAGE_LANGUAGE, "1");
requestProxy.setAttribute(com.liferay.portal.util.WebKeys.USER,APILocator.getUserAPI().getSystemUser());
Template teng1 = engine.getTemplate("/live/"+w.getIdentifier()+"_1."+contentEXT);
Template tesp1 = engine.getTemplate("/live/"+w.getIdentifier()+"_2."+contentEXT);
Context ctx = VelocityUtil.getWebContext(requestProxy, responseProxy);
StringWriter writer=new StringWriter();
teng1.merge(ctx, writer);
contentTester.render(new InternalContextAdapterImpl(ctx), writer);
assertEquals("code:Initial code",writer.toString());
ctx = VelocityUtil.getWebContext(requestProxy, responseProxy);
writer=new StringWriter();
tesp1.merge(ctx, writer);
contentTester.render(new InternalContextAdapterImpl(ctx), writer);
assertEquals("code:Initial code",writer.toString());
Contentlet w2=contentletAPI.checkout(w.getInode(), user, false);
w2.setStringProperty("code", "Modified Code to make templates different");
w2 = contentletAPI.checkin(w2, user, false);
contentletAPI.publish(w2, user, false);
contentletAPI.isInodeIndexed(w2.getInode(),true);
// now if everything have been cleared correctly those should match again
Template teng3 = engine.getTemplate("/live/"+w.getIdentifier()+"_1."+contentEXT);
Template tesp3 = engine.getTemplate("/live/"+w.getIdentifier()+"_2."+contentEXT);
ctx = VelocityUtil.getWebContext(requestProxy, responseProxy);
writer=new StringWriter();
teng3.merge(ctx, writer);
contentTester.render(new InternalContextAdapterImpl(ctx), writer);
assertEquals("code:Modified Code to make templates different",writer.toString());
ctx = VelocityUtil.getWebContext(requestProxy, responseProxy);
writer=new StringWriter();
tesp3.merge(ctx, writer);
contentTester.render(new InternalContextAdapterImpl(ctx), writer);
assertEquals("code:Modified Code to make templates different",writer.toString());
// clean up
APILocator.getVersionableAPI().removeLive(w2);
contentletAPI.archive(w2, user, false);