Skip to content

Commit bda36ea

Browse files
committed
Inject serverPort property into all tests since the default is now a random port
1 parent 39b2387 commit bda36ea

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/IntegrationTestMixinTransformation.groovy

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ class IntegrationTestMixinTransformation implements ASTTransformation {
134134
def webIntegrationTestAnnotation = new AnnotationNode(WEB_INTEGRATION_TEST_CLASS_NODE)
135135
webIntegrationTestAnnotation.addMember("randomPort", new ConstantExpression(Boolean.TRUE))
136136
classNode.addAnnotation(webIntegrationTestAnnotation)
137+
138+
if(classNode.getProperty("serverPort") == null) {
139+
140+
def serverPortField = new FieldNode("serverPort", Modifier.PROTECTED, ClassHelper.Integer_TYPE, classNode, new ConstantExpression(8080))
141+
def valueAnnotation = new AnnotationNode(ClassHelper.make(Value))
142+
valueAnnotation.setMember("value", new ConstantExpression('${local.server.port}'))
143+
serverPortField.addAnnotation(valueAnnotation)
144+
145+
classNode.addProperty(new PropertyNode(serverPortField, Modifier.PUBLIC, null, null ))
146+
}
137147
}
138148
} else {
139149
classNode.addAnnotation(new AnnotationNode(INTEGRATION_TEST_CLASS_NODE))
@@ -166,7 +176,7 @@ class IntegrationTestMixinTransformation implements ASTTransformation {
166176
args.addExpression(new ConstantExpression("geb.build.baseUrl"))
167177
args.addExpression(new GStringExpression('http://localhost:${port}', [new ConstantExpression("http://localhost:"), new ConstantExpression("")], [new VariableExpression(param)] as List<Expression>))
168178
setterBody.addStatement(new ExpressionStatement(new MethodCallExpression(systemClassExpression, "setProperty", args)))
169-
def method = new MethodNode("setPort", Modifier.PUBLIC, ClassHelper.VOID_TYPE, [param] as Parameter[], null, setterBody)
179+
def method = new MethodNode("setGebPort", Modifier.PUBLIC, ClassHelper.VOID_TYPE, [param] as Parameter[], null, setterBody)
170180
def valueAnnotation = new AnnotationNode(ClassHelper.make(Value))
171181
valueAnnotation.setMember("value", new ConstantExpression('${local.server.port}'))
172182
method.addAnnotation(valueAnnotation)

0 commit comments

Comments
 (0)