1 Groovy for Java developers and testers How Java developers and testers could use Groovy to...

38
1 Groovy for Java developers and testers How Java developers and testers could use Groovy to increase their efficiency AUGUST 6, 2015

Transcript of 1 Groovy for Java developers and testers How Java developers and testers could use Groovy to...

1

Groovy for Java developers and testers

How Java developers and testers could use Groovy to increase their efficiency

AUGUST 6, 2015

2

• Life Science Department, Saint-Petersburg, Russia

[email protected]

Mikhail Denisov

Demo project: https://git.epam.com/mikhail_denisov/itweek2015-groovy

3

WHY GROOVY?

Smooth Java integration. Runs on the JVM, 100% compatible with Java bytecode1

Concise, familiar and easy to learn syntax (“syntactic sugar”)3

Dynamic language, with static-typing and static compilation capabilities4

GDK - the extension to the JDK5

Metaprogramming (Builders, DSL), functional programming, scripting6

Supported by many systems and frameworks2

4

AstraZeneca SOA Factory project

• Over 20 web-services (DB and AD interaction)• Service Bus proxy for each service• 4 environments: dev, test, preprod, prod• 3 regions: Emea, America, Asia

20 * 2 * 3 * 4 = 480 endpoints

SOA Factory project

5

GROOVY BY EXAMPLES

Working with database and files1

HTML, JSON and XML parsing2

JSON and XML generation3

Working with SOAP-service4

Groovlets5

Advanced Groovy6

6

Maven POM.xml configuration with Groovy-Eclipse-Compiler

http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html

7

GROOVY BASICS: variables and collections

8

GROOVY BASICS: closures and GDK

9

GROOVY BASICS: objects and classes

10

Working with database and files

Case: update database with data from file

11

GROOVY TESTS: interface implementation with Map

12

HTML parsing with RegExp

13

JSON parsing with JsonSlurper, GPath expressions

14

JSON parsing with JsonSlurper, GPath expressions

15

XML parsing: Google News RSS

16

GROOVY METAPROGRAMMING: working with metaClass

17

GROOVY METAPROGRAMMING: expanding Java classes

18

GROOVY METAPROGRAMMING: missing method interception

19

XML GENERATION: class MarkupBuilder

20

XML GENERATION: class MarkupBuilder

21

JSON GENERATION: class JsonBuilder

22

SOAP Web Service interaction with WSLite

SOAP WebService “Magic Square”

WSDL: http://www.cs.fsu.edu/~engelen/magic.wsdl

Add WSLite to pom.xml

23

SOAP Web Service interaction with WSLite

24

SOAP Web Service: service MagicSquare.groovy

25

SOAP Web Service: test MagicSquareTest.groovy

26

Groovlet: display results as HTML page

web.xml – add groovy.servlet.GroovyServlet

27

Groovlet: display results as HTML page

Create script src/main/webapp/scripts/magic1.groovy

Build application, run it in the servlet containerBrowse the link http://localhost:8080/itweek2015-groovy/scripts/magic1.groovyResult would be like this

28

Groovlet: scripts/magic2.groovy - params, <form>, <table>

application, context

javax.servlet.ServletContext

session javax.servlet.HttpSessionrequest javax.servlet.HttpServletresponse javax.servlet.HttpResponseout response.getWriter()

Groovlet implicit objects:

29

Groovlet: add parameters and HTML markup: result s

30

Groovlet: script/magic3.groovy - add CSS

31

Groovlet: scripts/magic3.groovy - result

32

SOAFactory PROJECT UTILS

33

SOAFactory PROJECT UTILS

34

ADVANCED GROOVY: DSL

How many lines are needed to run it as a DSL script?

please show the square_root of 1024

35

ADVANCED GROOVY: DSL

36

ADVANCED GROOVY: GPars

Case: we have to collect data from many independent sources (collect all jokes about Chuck)

37

ADVANCED GROOVY: GPars

38

Groovy for Java developers and testersQ & A

AUGUST 6, 2015