improved integration test in examples/securityRealm: made integration test protocol-agnostic
improved integration test in examples/securityRealm: made integration test protocol-agnostic

package org.akhikhl.examples.gretty.hellogretty

import geb.spock.GebReportingSpec

class RequestResponseIT extends GebReportingSpec {

  private static String baseURI

  void setupSpec() {
    baseURI = System.getProperty('gretty.preferredBaseURI')
  }

  def 'should reject invalid credentials'() {
  when:
    go baseURI
  then: 'base URI should redirect to login page'
    $('h1.login-title').text() == 'Log in'
  when:
    $('form.form-signin input[name=j_username]').value('abc')
    $('form.form-signin input[name=j_password]').value('def')
    $('form.form-signin button[type=submit]').click()
  then: 'login should fail'
    $('h1.login-title').text() == 'Login failed'
  }

  def 'should accept valid credentials'() {
  when:
    go baseURI
  then: 'base URI should redirect to login page'
    $('h1.login-title').text() == 'Log in'
  when:
    $('form.form-signin input[name=j_username]').value('test')
    $('form.form-signin input[name=j_password]').value('test123')
    $('form.form-signin button[type=submit]').click()
  then: 'login should succeed'
    $('h1').text() == 'Hello, world!'
    $('p', 0).text() == 'This is static HTML page.'
  when:
    $('a[href=dynamic]').click()
  then: 'should navigate to dynamic page'
    $('h1').text() == 'Hello, world!'
    $('p', 0).text() == 'This is dynamic HTML page generated by servlet.'
  }
}

package org.akhikhl.examples.gretty.hellogretty

import geb.spock.GebReportingSpec

class RequestResponseIT extends GebReportingSpec {

  private static String baseURI

  void setupSpec() {
    baseURI = System.getProperty('gretty.baseURI')
  }

  def 'should reject invalid credentials'() {
  when:
    go baseURI
  then: 'base URI should redirect to login page'
    $('h1.login-title').text() == 'Log in'
  when:
    $('form.form-signin input[name=j_username]').value('abc')
    $('form.form-signin input[name=j_password]').value('def')
    $('form.form-signin button[type=submit]').click()
  then: 'login should fail'
    $('h1.login-title').text() == 'Login failed'
  }

  def 'should accept valid credentials'() {
  when:
    go baseURI
  then: 'base URI should redirect to login page'
    $('h1.login-title').text() == 'Log in'
  when:
    $('form.form-signin input[name=j_username]').value('test')
    $('form.form-signin input[name=j_password]').value('test123')
    $('form.form-signin button[type=submit]').click()
  then: 'login should succeed'
    $('h1').text() == 'Hello, world!'
    $('p', 0).text() == 'This is static HTML page.'
  when:
    $('a[href=dynamic]').click()
  then: 'should navigate to dynamic page'
    $('h1').text() == 'Hello, world!'
    $('p', 0).text() == 'This is dynamic HTML page generated by servlet.'
  }
}
