PageRenderTime 517ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/sitebricks-acceptance-tests/src/test/java/com/google/sitebricks/acceptance/RestfuWebServiceWithSubpaths2AcceptanceTest.java

http://github.com/dhanji/sitebricks
Java | 167 lines | 118 code | 24 blank | 25 comment | 0 complexity | 2c49579f3175ea4e6ee7de055bc76300 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.google.sitebricks.acceptance;
  2. import com.google.common.collect.ImmutableSet;
  3. import com.google.inject.AbstractModule;
  4. import com.google.inject.Guice;
  5. import com.google.inject.Injector;
  6. import com.google.sitebricks.acceptance.util.AcceptanceTest;
  7. import com.google.sitebricks.client.Web;
  8. import com.google.sitebricks.client.WebResponse;
  9. import com.google.sitebricks.client.transport.Json;
  10. import com.google.sitebricks.conversion.Converter;
  11. import com.google.sitebricks.conversion.ConverterRegistry;
  12. import com.google.sitebricks.conversion.StandardTypeConverter;
  13. import com.google.sitebricks.example.RestfulWebServiceWithSubpaths2;
  14. import org.testng.annotations.Test;
  15. import static com.google.sitebricks.example.RestfulWebServiceWithSubpaths2.TOPLEVEL;
  16. /**
  17. * @author Dhanji R. Prasanna (dhanji@gmail.com)
  18. */
  19. @Test(suiteName = AcceptanceTest.SUITE)
  20. public class RestfuWebServiceWithSubpaths2AcceptanceTest {
  21. public void shouldServiceTopLevelDynamicPath() {
  22. WebResponse response = createInjector()
  23. .getInstance(Web.class)
  24. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/" + TOPLEVEL)
  25. .transports(String.class)
  26. .over(Json.class)
  27. .get();
  28. assert TOPLEVEL.equals(response.toString());
  29. }
  30. public void shouldServiceFirstLevelStaticPath() {
  31. WebResponse response = createInjector()
  32. .getInstance(Web.class)
  33. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/subpath1")
  34. .transports(String.class)
  35. .over(Json.class)
  36. .post("");
  37. assert RestfulWebServiceWithSubpaths2.PATH_1.equals(response.toString()) : response.toString();
  38. }
  39. public void shouldServiceSameFirstLevelStaticPathWithPutMethod() {
  40. WebResponse response = createInjector()
  41. .getInstance(Web.class)
  42. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/subpath1")
  43. .transports(String.class)
  44. .over(Json.class)
  45. .put("");
  46. assert RestfulWebServiceWithSubpaths2.PATH_1_PUT.equals(response.toString())
  47. : response.toString();
  48. }
  49. public void shouldServiceSameFirstLevelStaticPathWithDeleteMethod() {
  50. WebResponse response = createInjector()
  51. .getInstance(Web.class)
  52. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/subpath1")
  53. .transports(String.class)
  54. .over(Json.class)
  55. .delete();
  56. assert RestfulWebServiceWithSubpaths2.PATH_1_DELETE.equals(response.toString())
  57. : response.toString();
  58. }
  59. public void shouldServiceTwoLevelDynamicPath() {
  60. WebResponse response = createInjector()
  61. .getInstance(Web.class)
  62. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk")
  63. .transports(String.class)
  64. .over(Json.class)
  65. .post("");
  66. assert "junk_more_junk".equals(response.toString()) : response.toString();
  67. }
  68. public void shouldServiceTwoLevelDynamicPathWithDeleteMethod() {
  69. WebResponse response = createInjector()
  70. .getInstance(Web.class)
  71. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk")
  72. .transports(String.class)
  73. .over(Json.class)
  74. .delete();
  75. assert "delete:junk_more_junk".equals(response.toString()) : response.toString();
  76. }
  77. public void shouldServiceThreeLevelDynamicPathWithDeleteMethod() {
  78. WebResponse response = createInjector()
  79. .getInstance(Web.class)
  80. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk/most_junk")
  81. .transports(String.class)
  82. .over(Json.class)
  83. .delete();
  84. assert "delete:junk_more_junk_most_junk".equals(response.toString()) : response.toString();
  85. }
  86. public void shouldServiceThreeLevelDynamicPathWithPutMethod() {
  87. WebResponse response = createInjector()
  88. .getInstance(Web.class)
  89. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk/most_junk")
  90. .transports(String.class)
  91. .over(Json.class)
  92. .put("");
  93. assert "put:junk_more_junk_most_junk".equals(response.toString()) : response.toString();
  94. }
  95. public void shouldServiceThreeLevelDynamicPathWithPostMethod() {
  96. WebResponse response = createInjector()
  97. .getInstance(Web.class)
  98. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk/most_junk")
  99. .transports(String.class)
  100. .over(Json.class)
  101. .post("");
  102. assert "post:junk_more_junk_most_junk".equals(response.toString()) : response.toString();
  103. }
  104. public void shouldServiceThreeLevelDynamicPathWithGetMethod() {
  105. WebResponse response = createInjector()
  106. .getInstance(Web.class)
  107. .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk/most_junk")
  108. .transports(String.class)
  109. .over(Json.class)
  110. .get();
  111. assert "get:junk_more_junk_most_junk".equals(response.toString()) : response.toString();
  112. }
  113. private Injector createInjector() {
  114. return Guice.createInjector(new AbstractModule() {
  115. protected void configure() {
  116. bind(ConverterRegistry.class).toInstance(new StandardTypeConverter(
  117. ImmutableSet.<Converter>of()));
  118. }
  119. });
  120. }
  121. //
  122. // public void shouldService4LevelMixedPathWithGetMethod() {
  123. // WebResponse response = createInjector()
  124. // .getInstance(Web.class)
  125. // .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk/most_junk/4l")
  126. // .transports(String.class)
  127. // .over(Json.class)
  128. // .get();
  129. //
  130. // assert "4l:get:junk_more_junk_most_junk".equals(response.toString()) : response.toString();
  131. // }
  132. //
  133. // public void shouldService4LevelMixedPathWithPostMethod() {
  134. // WebResponse response = createInjector()
  135. // .getInstance(Web.class)
  136. // .clientOf(AcceptanceTest.baseUrl() + "/superpath2/junk/more_junk/most_junk/4l")
  137. // .transports(String.class)
  138. // .over(Json.class)
  139. // .post("");
  140. //
  141. // assert "4l:post:junk_more_junk_most_junk".equals(response.toString()) : response.toString();
  142. // }
  143. }