What is Gosu?

Download Cheat Sheet PDF

Gosu is a pragmatic programming language designed to run on the Java Virtual Machine (JVM). It is object-oriented, statically typed, and features imperative type inference. Guidewire built Gosu to have first-class interaction with its data structures and rules engine.

Key Characteristics

  • 100% Java Compatible: You can call any Java library (like `java.util.Date`) natively from Gosu.
  • Type Inference: Use `var` instead of explicitly declaring types everywhere.
  • Properties: Getter and setter logic without the boilerplate (`claim.LossDate` instead of `claim.getLossDate()`).
  • Blocks (Closures): Powerful lambda-like expressions for collection manipulation.
  • Enhancements: Add functionality to classes at compile-time without subclassing.
// Variable declaration
var name = "John Doe" // Inferred as String
var age : int = 30    // Explicit type

// Collections and Blocks
var numbers = {1, 2, 3, 4, 5}
var evens = numbers.where( \n -> n % 2 == 0 )

print("Even numbers: " + evens)

Common Guidewire Patterns

1. Database Queries using gw.api.Query -

Direct SQL is almost never written in Gosu. Instead, the `Query` builder API is used to ensure type safety and handle table joins implicitly.

uses gw.api.database.Query
uses gw.api.database.Relop

// Find all Open Auto Claims
var q = Query.make(Claim)
q.compare(Claim#State, Relop.Equals, ClaimState.TC_OPEN)
q.compare(Claim#LossType, Relop.Equals, LossType.TC_AUTO)

var results = q.select()
for(claim in results) {
  print(claim.ClaimNumber)
}
2. Enhancements +

Enhancements (`.gsx` files) are heavily used to add helper methods to out-of-the-box Guidewire entities.

package ext.claim

enhancement ClaimExt : entity.Claim {
  
  // Adding a property to the Claim entity
  property get IsHighValue() : boolean {
    if(this.LossDate != null && this.TotalIncurred > 50000) {
      return true
    }
    return false
  }
}

GUnit Testing

GUnit is Gosu's equivalent to JUnit. It is standard practice to write GUnit tests for integrations, rules, and enhancement logic.

uses gw.testharness.TestBase

class HighValueClaimTest extends TestBase {
  function testHighValueLogic() {
    // Setup mock entity using GW builders (if available) or create in bundle
    gw.transaction.Transaction.runWithNewBundle( \bundle -> {
        var claim = new Claim(bundle)
        claim.TotalIncurred = 60000
        
        assertTrue("Claim should be high value", claim.IsHighValue)
    })
  }
}