PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

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

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