That's great.  I think I have it working now.  Below is my build file.
 Please let me know if I've overcomplicated things.

I assume I need to make sure that jettyRun is a daemon thread, and I added a
task to shut down the server.

Thanks again for all your help,

Ken

apply plugin:'war'
apply plugin:'jetty'
apply plugin:'groovy'

repositories {
mavenCentral()
}

configurations {
    integrationTestCompile {
        extendsFrom testCompile
    }
    integrationTestRuntime {
        extendsFrom integrationTestCompile, testRuntime
    }
}

sourceSets {
   main {
     java { srcDirs = [] }
     groovy { srcDir 'src' }
   }
   test {
     java { srcDirs = [] }
     groovy { srcDir 'tests' }
   }
integrationTest {
 java { srcDirs = [] }
groovy { srcDir 'integrationTests' }
compileClasspath = sourceSets.main.classes +
 sourceSets.test.classes + configurations.integrationTestCompile
        runtimeClasspath = classes +
         compileClasspath + configurations.integrationTestRuntime
 }
}

webAppDirName = 'WebContent'
stopKey = 'foo'
stopPort = 9451

gradle.taskGraph.whenReady {graph ->
    if (graph.hasTask(integrationTest)) {
        [jettyRun, jettyRunWar]*.daemon = true
    }
}

task integrationTest(type: Test, dependsOn: jettyRun) {
    testClassesDir = sourceSets.integrationTest.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
}

task shutDownServer(dependsOn: integrationTest) {
 jettyStop.execute()
}

build.dependsOn shutDownServer

def spockVersion = '0.4-groovy-1.7'

dependencies {
   groovy group:'org.codehaus.groovy', name:'groovy-all', version:'1.7.4'
   compile 'org.apache.httpcomponents:httpclient:4.0.2'
   providedCompile 'javax.servlet:servlet-api:2.5'
   testCompile 'junit:junit:4.8.1'
   testCompile group:'org.spockframework', name:'spock-core',
version:spockVersion
}


On Sun, Sep 12, 2010 at 5:52 PM, Rene Groeschke <[email protected]> wrote:

>  Hi Ken,
>
> Am 12.09.10 23:09, schrieb Kenneth Kousen:
> > Hi all,
> >
> > I've been playing around with some basic servlets (wow, how 1997, right?)
> to
> > simulate how RESTful web services work.
> >
> > When testing SOAP-based web services, JDK 1.6 includes an
> Endpoint.publish()
> > command that lets me start a tiny server in a regular Java app, and then
> in
> > Gradle I can start that in my tests.  When I test JAX-RS web services,
> > Jersey comes with an embeddable server called Grizzly, which lets me do
> > something similar.  I've been wondering, though, if the JDK or Gradle
> > included any way to do the same approach with basic servlets.
> >
> > One of the Gradle examples shows how to define a task that depends on
> > jettyRun.  Calling that task builds a URL and accesses it.   That works,
> but
> > the problem is that I have to embed all my testing code inside my Gradle
> > task.  Plus the results don't show up as part of my overall test cases.
> You could use an additional sourceSet for those integration tests. have
> a look at http://bit.ly/9jEDAr
> If you configure the according test task to be dependent on jettyRun you
> can test your rest api using the gradle jetty plugin.
>
> regards,
> René
>
>
>
> --
> ------------------------------------
> Rene Groeschke
>
> [email protected]
> http://www.breskeby.com
> http://twitter.com/breskeby
> ------------------------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


-- 
Kenneth A. Kousen
President
Kousen IT, Inc.

Email: [email protected]
Site: http://www.kousenit.com
Blog: http://kousenit.wordpress.com
Twitter: @kenkousen

Reply via email to