Skip to content

Commit 627b0d5

Browse files
committed
fix for GRAILS-8769 ""No property found for name" exception on unit tests"
1 parent d6358f6 commit 627b0d5

File tree

9 files changed

+43
-16
lines changed

9 files changed

+43
-16
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ commonsCliVersion = "1.2"
2525
commonsCollectionsVersion = "3.2.1"
2626
commonsIOVersion = "2.1"
2727
commonsLangVersion = "2.6"
28-
datastoreVersion = "1.0.1.BUILD-SNAPSHOT"
28+
datastoreVersion = "1.0.2.BUILD-SNAPSHOT"
2929
gantVersion = "1.9.6"
3030
gdocEngineVersion = "1.0.1"
3131
groovyVersion = "1.8.6"
@@ -36,7 +36,7 @@ jansiVersion = "1.2.1"
3636
jlineVersion = "1.0"
3737
jnaVersion = "3.2.3"
3838
slf4jVersion = "1.6.2"
39-
springLoadedVersion = "1.0.4"
39+
springLoadedVersion = "1.0.2"
4040
springVersion = "3.1.0.RELEASE"
4141
springWebflowVersion= "2.0.8.RELEASE"
4242
hibernateVersion = "3.6.7.Final"

grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/resolve/GrailsCoreDependencies.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public Object doCall() {
191191
};
192192
registerDependencies(dependencyManager, compileTimeDependenciesMethod, commonsExcludingLoggingAndXmlApis, "commons-logging", "xml-apis", "commons-digester");
193193

194-
String datastoreMappingVersion = "1.0.1.BUILD-SNAPSHOT";
194+
String datastoreMappingVersion = "1.0.2.BUILD-SNAPSHOT";
195195
ModuleRevisionId[] compileDependencies = {
196196
ModuleRevisionId.newInstance("aopalliance", "aopalliance", "1.0"),
197197
ModuleRevisionId.newInstance("com.googlecode.concurrentlinkedhashmap", "concurrentlinkedhashmap-lru", "1.2_jdk5"),

grails-core/src/main/groovy/org/codehaus/groovy/grails/cli/agent/GrailsPluginManagerReloadPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public boolean shouldRerunStaticInitializer(String typename, Class<?> aClass, St
3636
public void reloadEvent(String typename, Class<?> aClass, String encodedTimestamp) {
3737
CachedIntrospectionResults.clearClassLoader(aClass.getClassLoader());
3838
ClassPropertyFetcher.clearClassPropertyFetcherCache();
39-
GrailsProjectWatcher.firePendingClassChangeEvents(aClass);
39+
if(GrailsProjectWatcher.isActive())
40+
GrailsProjectWatcher.firePendingClassChangeEvents(aClass);
4041
}
4142

4243
public static void register() {

grails-core/src/main/groovy/org/codehaus/groovy/grails/compiler/GrailsProjectWatcher.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public GrailsProjectWatcher(final GrailsProjectCompiler compiler, GrailsPluginMa
6767
}
6868
}
6969

70+
public void setPluginManager(GrailsPluginManager pluginManager) {
71+
this.pluginManager = pluginManager;
72+
initPluginWatchPatterns();
73+
}
74+
7075
public static MultipleCompilationErrorsException getCurrentCompilationError() {
7176
return currentCompilationError;
7277
}
@@ -150,6 +155,15 @@ public void onNew(File file) {
150155
}
151156
});
152157

158+
if(pluginManager != null) {
159+
initPluginWatchPatterns();
160+
}
161+
162+
163+
super.run();
164+
}
165+
166+
private void initPluginWatchPatterns() {
153167
GrailsPlugin[] allPlugins = pluginManager.getAllPlugins();
154168

155169
for (GrailsPlugin plugin : allPlugins) {
@@ -179,8 +193,6 @@ else if (watchPattern.getDirectory() != null) {
179193
}
180194
}
181195
}
182-
183-
super.run();
184196
}
185197

186198
private void reloadPlugin(File file) {
@@ -192,6 +204,7 @@ private void reloadPlugin(File file) {
192204
}
193205

194206
private void informPluginManager(final File file, boolean isNew) {
207+
if(pluginManager == null) return;
195208
if (!isSourceFile(file) || isNew) {
196209
try {
197210
pluginManager.informOfFileChange(file);

grails-plugin-testing/src/main/groovy/grails/test/mixin/domain/DomainClassUnitTestMixin.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import org.codehaus.groovy.grails.validation.ConstrainedProperty
4545
import org.grails.datastore.gorm.validation.constraints.UniqueConstraint
4646
import org.grails.datastore.gorm.validation.constraints.UniqueConstraintFactory
4747
import org.junit.AfterClass
48+
import org.grails.datastore.mapping.reflect.ClassPropertyFetcher
4849

4950
/**
5051
* <p>A mixin that can be applied to JUnit or Spock tests to add testing support
@@ -80,6 +81,7 @@ class DomainClassUnitTestMixin extends GrailsUnitTestMixin {
8081

8182
@BeforeClass
8283
static void initializeDatastoreImplementation() {
84+
ClassPropertyFetcher.clearCache()
8385
if (applicationContext == null) {
8486
super.initGrailsApplication()
8587
}
@@ -99,6 +101,7 @@ class DomainClassUnitTestMixin extends GrailsUnitTestMixin {
99101

100102
@AfterClass
101103
static void cleanupDatastore() {
104+
ClassPropertyFetcher.clearCache()
102105
ConstrainedProperty.removeConstraint("unique")
103106
}
104107

@@ -110,7 +113,8 @@ class DomainClassUnitTestMixin extends GrailsUnitTestMixin {
110113
@After
111114
void shutdownDatastoreImplementation() {
112115
currentSession?.disconnect()
113-
DatastoreUtils.unbindSession(currentSession)
116+
if(currentSession != null)
117+
DatastoreUtils.unbindSession(currentSession)
114118
simpleDatastore.clearData()
115119
}
116120

grails-plugin-testing/src/main/groovy/grails/test/mixin/support/GrailsUnitTestMixin.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.springframework.context.support.StaticMessageSource
4444
import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager
4545
import org.springframework.context.MessageSource
4646
import org.codehaus.groovy.grails.cli.support.MetaClassRegistryCleaner
47+
import org.springframework.beans.CachedIntrospectionResults
4748

4849
/**
4950
* A base unit testing mixin that watches for MetaClass changes and unbinds them on tear down.
@@ -75,6 +76,8 @@ class GrailsUnitTestMixin {
7576

7677
@BeforeClass
7778
static void initGrailsApplication() {
79+
ClassPropertyFetcher.clearClassPropertyFetcherCache()
80+
CachedIntrospectionResults.clearClassLoader(GrailsUnitTestMixin.class.classLoader)
7881
registerMetaClassRegistryWatcher()
7982
if (applicationContext == null) {
8083
ExpandoMetaClass.enableGlobally()
@@ -107,7 +110,6 @@ class GrailsUnitTestMixin {
107110

108111
@After
109112
void resetGrailsApplication() {
110-
grailsApplication?.clear()
111113
MockUtils.TEST_INSTANCES.clear()
112114
ClassPropertyFetcher.clearClassPropertyFetcherCache()
113115
cleanupModifiedMetaClasses()

scripts/_GrailsRun.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ runServer = { Map args ->
203203
* want changes to artifacts automatically detected and loaded.
204204
*/
205205
target(startPluginScanner: "Starts the plugin manager's scanner that detects changes to artifacts.") {
206-
new GrailsProjectWatcher(projectCompiler, pluginManager).start()
206+
if(GrailsProjectWatcher.isReloadingAgentPresent() && !GrailsProjectWatcher.isActive()) {
207+
projectWatcher = new GrailsProjectWatcher(projectCompiler, pluginManager)
208+
projectWatcher.start()
209+
}
207210
}
208211

209212
target(stopPluginScanner: "Stops the plugin manager's scanner that detects changes to artifacts.") {

scripts/_GrailsSettings.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ GrailsPluginUtils.pluginBuildSettings = pluginSettings
6060

6161
// Other useful properties.
6262
grailsApp = null
63+
projectWatcher = null
6364

6465
isPluginProject = baseFile.listFiles().find { it.name.endsWith("GrailsPlugin.groovy") }
6566

scripts/_GrailsTest.groovy

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ ant.taskdef (name: 'testc', classname:'org.codehaus.groovy.grails.test.compiler.
108108
createTestReports = true
109109

110110
testsFailed = false
111+
projectWatcher = null
111112

112113
target(allTests: "Runs the project's tests.") {
113114
def dependencies = [compile,startLogging, packagePlugins]
@@ -131,6 +132,10 @@ target(allTests: "Runs the project's tests.") {
131132

132133
event("TestPhasesStart", [phasesToRun])
133134

135+
if (InteractiveMode.current && GrailsProjectWatcher.isReloadingAgentPresent()) {
136+
startPluginScanner()
137+
}
138+
134139
// Handle pre 1.2 style testing configuration
135140
def convertedPhases = [:]
136141
phasesToRun.each { phaseName ->
@@ -332,16 +337,14 @@ integrationTestPhasePreparation = {
332337
if (app.parentContext == null) {
333338
app.applicationContext = appCtx
334339
}
340+
341+
if(projectWatcher) {
342+
projectWatcher.pluginManager = pluginManager
343+
}
335344

336345
initPersistenceContext()
337346

338-
if (InteractiveMode.current || GrailsProjectWatcher.isReloadingAgentPresent()) {
339-
// if interactive mode is running start the project change watcher
340-
if (!GrailsProjectWatcher.isActive()) {
341-
def watcher = new GrailsProjectWatcher(projectCompiler, pluginManager)
342-
watcher.start()
343-
}
344-
}
347+
345348
GrailsConfigUtils.configureServletContextAttributes(appCtx.servletContext, app, pluginManager, appCtx)
346349
GrailsConfigUtils.executeGrailsBootstraps(app, appCtx, appCtx.servletContext)
347350
}

0 commit comments

Comments
 (0)