Skip to content

Commit

Permalink
test: add missing groovy tests (#9000)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo authored Mar 23, 2023
1 parent 17e288a commit f503fd3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions test-suite-groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
testRuntimeOnly libs.bcpkix

testImplementation libs.managed.reactor
testImplementation(libs.awaitility)
}

//compileTestGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005']
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.micronaut.docs.expressions

import io.micronaut.context.BeanContext
import io.micronaut.inject.BeanDefinition
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class AnnotationContextExampleSpec extends Specification {
@Shared
@AutoCleanup
BeanContext beanContext = BeanContext.run()
void "testAnnotationContextEvaluation"() {
given:
BeanDefinition<Example> beanDefinition = beanContext.getBeanDefinition(Example)
String val = beanDefinition.stringValue(CustomAnnotation).orElse(null)

expect:
"first valuesecond value" == val
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ExampleJob {

@Scheduled(
fixedRate = "1s",
condition = "#{!jobControl.paused}") // <1>
condition = '#{!jobControl.paused}') // <1>
void run(ExampleJobControl jobControl) {
System.out.println("Job Running")
this.jobRan = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.micronaut.docs.expressions

import io.micronaut.context.ApplicationContext
import spock.lang.AutoCleanup
import spock.lang.Shared;
import spock.lang.Specification

import static java.util.concurrent.TimeUnit.SECONDS
import static org.awaitility.Awaitility.await

class ExampleJobSpec extends Specification {
@Shared
@AutoCleanup
ApplicationContext ctx = ApplicationContext.run()

void testJobCondition(){
given:
ExampleJob exampleJob = ctx.getBean(ExampleJob)
ExampleJobControl jobControl = ctx.getBean(ExampleJobControl)

expect:
jobControl.isPaused()
!exampleJob.hasJobRun()

when:
Thread.sleep(5000)

then:
!exampleJob.hasJobRun()

when:
jobControl.unpause()

then:
await().atMost(3, SECONDS).until(exampleJob::hasJobRun)

and:
exampleJob.hasJobRun()
}
}

0 comments on commit f503fd3

Please sign in to comment.