Grails/Groovyによる開発事例紹介

8,059 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
8,059
On SlideShare
0
From Embeds
0
Number of Embeds
6,562
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Grails/Groovyによる開発事例紹介

  1. 1. 2011 9 23
  2. 2. 2011 9 23
  3. 3. 2011 9 23
  4. 4. JSR241 • Groovyis an agile, dynamic programming language for the Java Virtual Machine. • Groovyincludes features found in Python, Ruby, and Smalltalk, but uses syntax similar to the Java programming language.2011 9 23
  5. 5. HelloWorld.java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }2011 9 23
  6. 6. HelloWorld.groovy public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } Java2011 9 23
  7. 7. HelloWorld.groovy println "Hello, World!"2011 9 23
  8. 8. Grails2011 9 23
  9. 9. 2011 9 23
  10. 10. 2011 9 23
  11. 11. G*Magazine2011 9 23
  12. 12. G*Magazine Vol.32011 9 23
  13. 13. 2011 9 23
  14. 14. 2011 9 23
  15. 15. 2011 9 23
  16. 16. 2011 9 23
  17. 17. 2011 9 23
  18. 18. 2011 9 23
  19. 19. 2011 9 23
  20. 20. 2011 9 23
  21. 21. 2011 9 23
  22. 22. 2011 9 23
  23. 23. 2011 9 23
  24. 24. 2011 9 23
  25. 25. 2011 9 23
  26. 26. 2011 9 23
  27. 27. 2011 9 23
  28. 28. class Book { String title String isbn static constraints = { title blank:false isbn blank:false, unique:true } }2011 9 23
  29. 29. class Book { static mapWith = mongo String title String isbn static constraints = { title blank:false isbn blank:false, unique:true } }2011 9 23
  30. 30. 2011 9 23
  31. 31. 2011 9 23
  32. 32. 2011 9 23
  33. 33. 2011 9 23
  34. 34. 2011 9 23
  35. 35. 2011 9 23
  36. 36. class FolderService { void rename(Long id, String newName) { def folder = Folder.get(id) folder.name = newName folder.save() } List<Folder> findAll() { Folder.findAll() } }2011 9 23
  37. 37. class FolderService { @PreAuthorize("hasPermission(#id, sample.Folder, admin)") void rename(Long id, String newName) { def folder = Folder.get(id) folder.name = newName folder.save() } @PostFilter("hasPermission(filterObject, read)") List<Folder> findAll() { Folder.findAll() } }2011 9 23
  38. 38. 2011 9 23
  39. 39. 2011 9 23
  40. 40. import spock.lang.* class HelloSpock extends Specification { def " "() { expect: name.size() == length where: name | length "Spock" | 5 "Kirk" | 4 "Scotty" | 6 } }2011 9 23
  41. 41. @Test public void test() { assert 1 + 1 * 2 == 4 } // Assertion failed: assert 1 + 1 * 2 == 4 | | | 3 2 false2011 9 23
  42. 42. 2011 9 23
  43. 43. class LoginSpec extends GebSpec { def () { when: to login at { title == Login } and: / $(input[name="username"]).value username $(input[name="password"]).value password $(input[name="login_button"]).click() then: at { title == Welcome } } }2011 9 23
  44. 44. class LoginPage { static at = { title == Login} static content = { username { $(input[name="username"]) } password { $(input[name="password"]) } loginButton { $(input[name="login_button"]) } } }2011 9 23
  45. 45. class LoginSpec extends GebSpec { def () { given: to LoginPage when: / username = username password = password loginButton.click() then: at TopPage } }2011 9 23
  46. 46. class LoginSpec extends GebSpec { def () { given: new User(username:user, password:pass).save() to LoginPage when: username = username password = password loginButton.click() then: at TopPage } }2011 9 23
  47. 47. class LoginSpec extends GebSpec { def () { given: fixtureLoader.load { user User, username:user, password:pass admin User, username:admin, password:pass } to LoginPage when: username = username password = password loginButton.click() then: at TopPage } }2011 9 23
  48. 48. 2011 9 23
  49. 49. 2011 9 23
  50. 50. 2011 9 23
  51. 51. 2011 9 23
  52. 52. 2011 9 23
  53. 53. 2011 9 23
  54. 54. 2011 9 23

×