Permalink
Browse files

fix for GRAILS-8769 ""No property found for name" exception on unit t…

…ests"
  • Loading branch information...
1 parent 01faebd commit 6f9a901a6477498e141626b394198fa90490eb65 @graemerocher graemerocher committed Feb 14, 2012
View
@@ -22,7 +22,7 @@ commonsCliVersion = "1.2"
commonsCollectionsVersion = "3.2.1"
commonsIOVersion = "2.1"
commonsLangVersion = "2.6"
-datastoreVersion = "1.0.1.BUILD-SNAPSHOT"
+datastoreVersion = "1.0.2.BUILD-SNAPSHOT"
gantVersion = "1.9.6"
gdocEngineVersion = "1.0.1"
groovyVersion = "1.8.6"
@@ -33,7 +33,7 @@ jansiVersion = "1.2.1"
jlineVersion = "1.0"
jnaVersion = "3.2.3"
slf4jVersion = "1.6.2"
-springLoadedVersion = "1.0.4"
+springLoadedVersion = "1.0.2"
springVersion = "3.1.0.RELEASE"
springWebflowVersion= "2.0.8.RELEASE"
hibernateVersion = "3.6.8.Final"
@@ -180,7 +180,7 @@ public Object doCall() {
};
registerDependencies(dependencyManager, compileTimeDependenciesMethod, commonsExcludingLoggingAndXmlApis, "commons-logging", "xml-apis", "commons-digester");
- String datastoreMappingVersion = "1.0.1.BUILD-SNAPSHOT";
+ String datastoreMappingVersion = "1.0.2.BUILD-SNAPSHOT";
ModuleRevisionId[] compileDependencies = {
ModuleRevisionId.newInstance("aopalliance", "aopalliance", "1.0"),
ModuleRevisionId.newInstance("com.googlecode.concurrentlinkedhashmap", "concurrentlinkedhashmap-lru", "1.2_jdk5"),
@@ -36,7 +36,8 @@ public boolean shouldRerunStaticInitializer(String typename, Class<?> aClass, St
public void reloadEvent(String typename, Class<?> aClass, String encodedTimestamp) {
CachedIntrospectionResults.clearClassLoader(aClass.getClassLoader());
ClassPropertyFetcher.clearClassPropertyFetcherCache();
- GrailsProjectWatcher.firePendingClassChangeEvents(aClass);
+ if(GrailsProjectWatcher.isActive())
+ GrailsProjectWatcher.firePendingClassChangeEvents(aClass);
}
public static void register() {
@@ -67,6 +67,11 @@ public GrailsProjectWatcher(final GrailsProjectCompiler compiler, GrailsPluginMa
}
}
+ public void setPluginManager(GrailsPluginManager pluginManager) {
+ this.pluginManager = pluginManager;
+ initPluginWatchPatterns();
+ }
+
public static MultipleCompilationErrorsException getCurrentCompilationError() {
return currentCompilationError;
}
@@ -150,6 +155,15 @@ public void onNew(File file) {
}
});
+ if(pluginManager != null) {
+ initPluginWatchPatterns();
+ }
+
+
+ super.run();
+ }
+
+ private void initPluginWatchPatterns() {
GrailsPlugin[] allPlugins = pluginManager.getAllPlugins();
for (GrailsPlugin plugin : allPlugins) {
@@ -179,8 +193,6 @@ else if (watchPattern.getDirectory() != null) {
}
}
}
-
- super.run();
}
private void reloadPlugin(File file) {
@@ -192,6 +204,7 @@ private void reloadPlugin(File file) {
}
private void informPluginManager(final File file, boolean isNew) {
+ if(pluginManager == null) return;
if (!isSourceFile(file) || isNew) {
try {
pluginManager.informOfFileChange(file);
@@ -45,6 +45,7 @@ import org.codehaus.groovy.grails.validation.ConstrainedProperty
import org.grails.datastore.gorm.validation.constraints.UniqueConstraint
import org.grails.datastore.gorm.validation.constraints.UniqueConstraintFactory
import org.junit.AfterClass
+import org.grails.datastore.mapping.reflect.ClassPropertyFetcher
/**
* <p>A mixin that can be applied to JUnit or Spock tests to add testing support
@@ -80,6 +81,7 @@ class DomainClassUnitTestMixin extends GrailsUnitTestMixin {
@BeforeClass
static void initializeDatastoreImplementation() {
+ ClassPropertyFetcher.clearCache()
if (applicationContext == null) {
super.initGrailsApplication()
}
@@ -99,6 +101,7 @@ class DomainClassUnitTestMixin extends GrailsUnitTestMixin {
@AfterClass
static void cleanupDatastore() {
+ ClassPropertyFetcher.clearCache()
ConstrainedProperty.removeConstraint("unique")
}
@@ -110,7 +113,8 @@ class DomainClassUnitTestMixin extends GrailsUnitTestMixin {
@After
void shutdownDatastoreImplementation() {
currentSession?.disconnect()
- DatastoreUtils.unbindSession(currentSession)
+ if(currentSession != null)
+ DatastoreUtils.unbindSession(currentSession)
simpleDatastore.clearData()
}
@@ -44,6 +44,7 @@ import org.springframework.context.support.StaticMessageSource
import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager
import org.springframework.context.MessageSource
import org.codehaus.groovy.grails.cli.support.MetaClassRegistryCleaner
+import org.springframework.beans.CachedIntrospectionResults
/**
* A base unit testing mixin that watches for MetaClass changes and unbinds them on tear down.
@@ -75,6 +76,8 @@ class GrailsUnitTestMixin {
@BeforeClass
static void initGrailsApplication() {
+ ClassPropertyFetcher.clearClassPropertyFetcherCache()
+ CachedIntrospectionResults.clearClassLoader(GrailsUnitTestMixin.class.classLoader)
registerMetaClassRegistryWatcher()
if (applicationContext == null) {
ExpandoMetaClass.enableGlobally()
@@ -107,7 +110,6 @@ class GrailsUnitTestMixin {
@After
void resetGrailsApplication() {
- grailsApplication?.clear()
MockUtils.TEST_INSTANCES.clear()
ClassPropertyFetcher.clearClassPropertyFetcherCache()
cleanupModifiedMetaClasses()
@@ -203,7 +203,10 @@ runServer = { Map args ->
* want changes to artifacts automatically detected and loaded.
*/
target(startPluginScanner: "Starts the plugin manager's scanner that detects changes to artifacts.") {
- new GrailsProjectWatcher(projectCompiler, pluginManager).start()
+ if(GrailsProjectWatcher.isReloadingAgentPresent() && !GrailsProjectWatcher.isActive()) {
+ projectWatcher = new GrailsProjectWatcher(projectCompiler, pluginManager)
+ projectWatcher.start()
+ }
}
target(stopPluginScanner: "Stops the plugin manager's scanner that detects changes to artifacts.") {
@@ -60,6 +60,7 @@ GrailsPluginUtils.pluginBuildSettings = pluginSettings
// Other useful properties.
grailsApp = null
+projectWatcher = null
isPluginProject = baseFile.listFiles().find { it.name.endsWith("GrailsPlugin.groovy") }
View
@@ -108,6 +108,7 @@ ant.taskdef (name: 'testc', classname:'org.codehaus.groovy.grails.test.compiler.
createTestReports = true
testsFailed = false
+projectWatcher = null
target(allTests: "Runs the project's tests.") {
def dependencies = [compile,startLogging, packagePlugins]
@@ -131,6 +132,10 @@ target(allTests: "Runs the project's tests.") {
event("TestPhasesStart", [phasesToRun])
+ if (InteractiveMode.current && GrailsProjectWatcher.isReloadingAgentPresent()) {
+ startPluginScanner()
+ }
+
// Handle pre 1.2 style testing configuration
def convertedPhases = [:]
phasesToRun.each { phaseName ->
@@ -332,16 +337,14 @@ integrationTestPhasePreparation = {
if (app.parentContext == null) {
app.applicationContext = appCtx
}
+
+ if(projectWatcher) {
+ projectWatcher.pluginManager = pluginManager
+ }
initPersistenceContext()
- if (InteractiveMode.current || GrailsProjectWatcher.isReloadingAgentPresent()) {
- // if interactive mode is running start the project change watcher
- if (!GrailsProjectWatcher.isActive()) {
- def watcher = new GrailsProjectWatcher(projectCompiler, pluginManager)
- watcher.start()
- }
- }
+
GrailsConfigUtils.configureServletContextAttributes(appCtx.servletContext, app, pluginManager, appCtx)
GrailsConfigUtils.executeGrailsBootstraps(app, appCtx, appCtx.servletContext)
}

0 comments on commit 6f9a901

Please sign in to comment.