Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled test suite to run successfully with 'ant test' #45

Merged
merged 1 commit into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions framework/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,30 +280,37 @@
<param name="testAppPath" value="${basedir}/../samples-and-tests/just-test-cases"/>
<param name="play.user.language" value="-Duser.language=en"/>
<param name="play.user.country" value="-Duser.country=US"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="play-test">
<param name="testAppPath" value="${basedir}/../samples-and-tests/forum"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="play-test">
<param name="testAppPath" value="${basedir}/../samples-and-tests/zencontact"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="play-test">
<param name="testAppPath" value="${basedir}/../samples-and-tests/jobboard"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="play-test">
<param name="testAppPath" value="${basedir}/../samples-and-tests/yabe"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="play-test">
<param name="testAppPath" value="${basedir}/../samples-and-tests/nonstatic-app"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="play-test">
<param name="testAppPath" value="${basedir}/../samples-and-tests/fast-tag"/>
<param name="play.enhancement" value="-DenableAllEnhancers=true" />
</antcall>

<antcall target="test-success" />
Expand Down Expand Up @@ -337,6 +344,7 @@
<arg value="${testAppPath}"/>
<arg value="${play.user.language}" if:set="play.user.language"/>
<arg value="${play.user.country}" if:set="play.user.country"/>
<arg value="${play.enhancement}" if:set="play.enhancement"/>
</exec>
<available file="${testAppPath}/test-result/result.passed" property="${testAppPath}testPassed" />
<fail message="Last test has failed ! (Check results in file://${testAppPath}/test-result)">
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void init() {
}
ConfigurationSource source = null;
try {
Configurator.initialize(Play.classloader, new ConfigurationSource(new FileInputStream(log4jConf.getFile())));
Configurator.initialize(Play.classloader, new ConfigurationSource(log4jConf.openStream(), log4jConf, 0L));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
13 changes: 4 additions & 9 deletions framework/src/play/db/jpa/JPAPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,14 @@ public EntityManager em(String key) {
* Reads the configuration file and initialises required JPA EntityManagerFactories.
*/
@Override
public void onApplicationStart() {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig("org.hibernate.SQL");
loggerConfig.setLevel(Level.OFF);
ctx.updateLoggers();

public void onApplicationStart() {
Set<String> dBNames = Configuration.getDbNames();
for (String dbName : dBNames) {
Configuration dbConfig = new Configuration(dbName);

if (dbConfig.getProperty("jpa.debugSQL", "false").equals("true")) {
ctx = (LoggerContext) LogManager.getContext(false);
loggerConfig = ctx.getConfiguration().getLoggerConfig("org.hibernate.SQL");
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig("org.hibernate.SQL");
loggerConfig.setLevel(Level.ALL);
ctx.updateLoggers();
}
Expand Down
34 changes: 22 additions & 12 deletions framework/src/play/plugins/EnhancerPlugin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package play.plugins;

import java.util.ArrayList;
import java.util.List;

import play.PlayPlugin;
import play.classloading.ApplicationClasses.ApplicationClass;
import play.classloading.enhancers.ContinuationEnhancer;
Expand All @@ -11,28 +8,41 @@
import play.classloading.enhancers.LocalvariablesNamesEnhancer;
import play.classloading.enhancers.MailerEnhancer;
import play.classloading.enhancers.SigEnhancer;
import play.classloading.enhancers.PropertiesEnhancer;
import play.exceptions.UnexpectedException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Plugin used for core tasks
*/
public class EnhancerPlugin extends PlayPlugin {
protected Enhancer[] defaultEnhancers() {
return new Enhancer[] { new PropertiesEnhancer(), new ContinuationEnhancer(), new SigEnhancer(), new ControllersEnhancer(),
new MailerEnhancer(), new LocalvariablesNamesEnhancer() };
}

@Override
public void enhance(ApplicationClass applicationClass) {
List<Enhancer> enhancers = new ArrayList<Enhancer>(4);
if (applicationClass.name.startsWith("controllers.")) {
enhancers.add(new SigEnhancer());
enhancers.add(new ContinuationEnhancer());
enhancers.add(new ControllersEnhancer());
if (applicationClass.name.endsWith("Mailer")) {
if(System.getProperty("enableAllEnhancers")!=null){
enhancers = Arrays.asList(defaultEnhancers());
}else {
if (applicationClass.name.startsWith("controllers.")) {
enhancers.add(new SigEnhancer());
enhancers.add(new ContinuationEnhancer());
enhancers.add(new ControllersEnhancer());
if (applicationClass.name.endsWith("Mailer")) {
enhancers.add(new MailerEnhancer());
}
enhancers.add(new LocalvariablesNamesEnhancer());
} else if (applicationClass.name.endsWith("Mailer")) {
enhancers.add(new MailerEnhancer());
enhancers.add(new LocalvariablesNamesEnhancer());
}
enhancers.add(new LocalvariablesNamesEnhancer());
} else if (applicationClass.name.endsWith("Mailer")) {
enhancers.add(new MailerEnhancer());
enhancers.add(new LocalvariablesNamesEnhancer());
}

for (Enhancer enhancer : enhancers) {
try {
enhancer.enhanceThisClass(applicationClass);
Expand Down
135 changes: 70 additions & 65 deletions samples-and-tests/i-am-a-developer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,23 @@ def testLogLevelsAndLog4jConfig(self):
step('Writing log4j config file')

create(app, 'conf/log4j.xml')



insert(app, "conf/log4j.xml", 1, '<?xml version="1.0" encoding="UTF-8" ?>')
insert(app, "conf/log4j.xml", 2, '<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">')
insert(app, "conf/log4j.xml", 3, '<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">')
insert(app, "conf/log4j.xml", 4, ' <appender name="console" class="org.apache.log4j.ConsoleAppender">')
insert(app, "conf/log4j.xml", 5, ' <param name="Target" value="System.out"/>')
insert(app, "conf/log4j.xml", 6, ' <layout class="org.apache.log4j.PatternLayout">')
insert(app, "conf/log4j.xml", 7, ' <param name="ConversionPattern" value="%m%n"/>')
insert(app, "conf/log4j.xml", 8, ' </layout>')
insert(app, "conf/log4j.xml", 9, ' </appender>')
insert(app, "conf/log4j.xml", 10, ' <logger name="play">')
insert(app, "conf/log4j.xml", 11, ' <level value="debug"/>')
insert(app, "conf/log4j.xml", 12, ' </logger>')
insert(app, "conf/log4j.xml", 13, ' <root>')
insert(app, "conf/log4j.xml", 14, ' <priority value="info"/>')
insert(app, "conf/log4j.xml", 15, ' <appender-ref ref="console"/>')
insert(app, "conf/log4j.xml", 16, ' </root>')
insert(app, "conf/log4j.xml", 17, '</log4j:configuration>')
insert(app, "conf/log4j.xml", 2, '<Configuration status="INFO">')
insert(app, "conf/log4j.xml", 3, ' <Appenders>')
insert(app, "conf/log4j.xml", 4, ' <Console name="Console" target="SYSTEM_OUT">')
insert(app, "conf/log4j.xml", 5, ' <PatternLayout pattern="%m%n"/>')
insert(app, "conf/log4j.xml", 6, ' </Console>')
insert(app, "conf/log4j.xml", 7, ' </Appenders>')
insert(app, "conf/log4j.xml", 8, ' <Loggers>')
insert(app, "conf/log4j.xml", 9, ' <Root level="INFO">')
insert(app, "conf/log4j.xml", 10, ' <AppenderRef ref="Console"/>')
insert(app, "conf/log4j.xml", 11, ' </Root>')
insert(app, "conf/log4j.xml", 12, ' <Logger name="play" level="DEBUG"/>')
insert(app, "conf/log4j.xml", 13, ' </Loggers>')
insert(app, "conf/log4j.xml", 14, '</Configuration>')


# Run the newly created application
step('re-run our logger-application')
Expand Down Expand Up @@ -450,7 +449,7 @@ def testSimpleProjectCreation(self):
self.assert_(html.count('insert ";" to complete BlockStatements'))
self.assert_(html.count('In /app/controllers/Application.java (around line 13)'))
self.assert_(html.count(' render()'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Compilation error (In /app/controllers/Application.java around line 13)'))
self.assert_(waitFor(self.play, 'Syntax error, insert ";" to complete BlockStatements'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))
Expand All @@ -469,7 +468,7 @@ def testSimpleProjectCreation(self):
self.assert_(html.count('insert ";" to complete BlockStatements'))
self.assert_(html.count('In /app/controllers/Application.java (around line 13)'))
self.assert_(html.count(' render()'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Compilation error (In /app/controllers/Application.java around line 13)'))
self.assert_(waitFor(self.play, 'Syntax error, insert ";" to complete BlockStatements'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))
Expand All @@ -493,9 +492,16 @@ def testSimpleProjectCreation(self):
html = response.get_data()
self.assert_(html.count('Your application is ready !'))


step("stop play")
killPlay()
self.play.wait()

# Let's code hello world
step('Let\'s code hello world')
time.sleep(1)

self.play = callPlay(self, ['run', app])
self.assert_(waitFor(self.play, 'Listening for HTTP on port 9000'))

edit(app, 'app/controllers/Application.java', 12, ' public static void index(String name) {')
edit(app, 'app/controllers/Application.java', 13, ' render(name);')
Expand All @@ -513,11 +519,22 @@ def testSimpleProjectCreation(self):
html = response.get_data()
self.assert_(html.count('Hello Guillaume !!'))



step("stop play")
killPlay()
self.play.wait()

# Make a mistake in the template
step('Make a mistake in the template')
time.sleep(1)

edit(app, 'app/views/Application/index.html', 4, "Hello ${name !!")

self.play = callPlay(self, ['run', app])
self.assert_(waitFor(self.play, 'Listening for HTTP on port 9000'))


try:
response = browser.reload()
self.fail()
Expand All @@ -527,7 +544,7 @@ def testSimpleProjectCreation(self):
html = ''.join(error.readlines())
self.assert_(html.count('Template compilation error'))
self.assert_(html.count('In /app/views/Application/index.html (around line 4)'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Template compilation error (In /app/views/Application/index.html around line 4)'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))

Expand All @@ -543,7 +560,7 @@ def testSimpleProjectCreation(self):
html = ''.join(error.readlines())
self.assert_(html.count('Template compilation error'))
self.assert_(html.count('In /app/views/Application/index.html (around line 4)'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Template compilation error (In /app/views/Application/index.html around line 4)'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))

Expand All @@ -562,7 +579,7 @@ def testSimpleProjectCreation(self):
self.assert_(html.count('Template execution error '))
self.assert_(html.count('In /app/views/Application/index.html (around line 4)'))
self.assert_(html.count('Cannot get property \'name\' on null object'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Template execution error (In /app/views/Application/index.html around line 4)'))
self.assert_(waitFor(self.play, 'Execution error occurred in template /app/views/Application/index.html.'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))
Expand All @@ -582,7 +599,7 @@ def testSimpleProjectCreation(self):
self.assert_(html.count('Template execution error '))
self.assert_(html.count('In /app/views/Application/index.html (around line 4)'))
self.assert_(html.count('Cannot get property \'name\' on null object'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Template execution error (In /app/views/Application/index.html around line 4)'))
self.assert_(waitFor(self.play, 'Execution error occurred in template /app/views/Application/index.html.'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))
Expand All @@ -600,10 +617,23 @@ def testSimpleProjectCreation(self):
html = response.get_data()
self.assert_(html.count('Hello Guillaume !!'))

step("stop play")
killPlay()
self.play.wait()



# Make a Java runtime exception
step('Make a Java runtime exception')

insert(app, 'app/controllers/Application.java', 13, ' int a = 9/0;')


insert(app, 'app/controllers/Application.java', 13, ' int a = 9/0;')

self.play = callPlay(self, ['run', app])
self.assert_(waitFor(self.play, 'Listening for HTTP on port 9000'))


try:
response = browser.reload()
self.fail()
Expand All @@ -614,7 +644,7 @@ def testSimpleProjectCreation(self):
self.assert_(html.count('Execution exception'))
self.assert_(html.count('/ by zero'))
self.assert_(html.count('In /app/controllers/Application.java (around line 13)'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Execution exception (In /app/controllers/Application.java around line 13)'))
self.assert_(waitFor(self.play, 'ArithmeticException occurred : / by zero'))
self.assert_(waitFor(self.play, 'at controllers.Application.index(Application.java:13)'))
Expand All @@ -633,7 +663,7 @@ def testSimpleProjectCreation(self):
self.assert_(html.count('Execution exception'))
self.assert_(html.count('/ by zero'))
self.assert_(html.count('In /app/controllers/Application.java (around line 13)'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'ERROR'))
self.assert_(waitFor(self.play, 'Execution exception (In /app/controllers/Application.java around line 13)'))
self.assert_(waitFor(self.play, 'ArithmeticException occurred : / by zero'))
self.assert_(waitFor(self.play, 'at controllers.Application.index(Application.java:13)'))
Expand Down Expand Up @@ -717,7 +747,7 @@ def testSimpleProjectCreation(self):

# Correct the routes file
step('Correct the routes file')
time.sleep(1)


edit(app, 'conf/routes', 7, "GET /hello Hello2.hello")

Expand All @@ -734,48 +764,23 @@ def testSimpleProjectCreation(self):
html = response.get_data()
self.assert_(html.count('Hello'))



# Rename again
step('Rename again')
time.sleep(1)
#step("stop play")
#killPlay()
#self.play.wait()


step('Rename again & fix class name')

rename(app, 'app/controllers/Hello2.java', 'app/controllers/Hello3.java')
edit(app, 'conf/routes', 7, "GET /hello Hello3.hello")

try:
browser.reload()
self.fail()
except urllib2.HTTPError, error:
self.assert_(browser.viewing_html())
self.assert_(browser.title() == 'Application error')
html = ''.join(error.readlines())
self.assert_(html.count('Compilation error'))
self.assert_(html.count('/app/controllers/Hello3.java</strong> could not be compiled'))
self.assert_(html.count('The public type Hello2 must be defined in its own file'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'Compilation error (In /app/controllers/Hello3.java around line 3)'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))

# Refresh again
step('Refresh again')

try:
browser.reload()
self.fail()
except urllib2.HTTPError, error:
self.assert_(browser.viewing_html())
self.assert_(browser.title() == 'Application error')
html = ''.join(error.readlines())
self.assert_(html.count('Compilation error'))
self.assert_(html.count('/app/controllers/Hello3.java</strong> could not be compiled'))
self.assert_(html.count('The public type Hello2 must be defined in its own file'))
self.assert_(waitFor(self.play, 'ERROR ~'))
self.assert_(waitFor(self.play, 'Compilation error (In /app/controllers/Hello3.java around line 3)'))
self.assert_(waitFor(self.play, 'at Invocation.HTTP Request(Play!)'))

# Fix it
step('Fix it')

edit(app, 'app/controllers/Hello3.java', 3, "public class Hello3 extends Application {")

#self.play = callPlay(self, ['run', app])
#self.assert_(waitFor(self.play, 'Listening for HTTP on port 9000'))

browser.reload()
self.assert_(not browser.viewing_html())
html = response.get_data()
Expand Down
Loading