Package com.google.sitebricks.acceptance

Source Code of com.google.sitebricks.acceptance.RestfuWebServiceWithCRUDAcceptanceTest

package com.google.sitebricks.acceptance;

import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.sitebricks.acceptance.util.AcceptanceTest;
import com.google.sitebricks.client.Web;
import com.google.sitebricks.client.WebResponse;
import com.google.sitebricks.client.transport.Json;
import com.google.sitebricks.conversion.Converter;
import com.google.sitebricks.conversion.ConverterRegistry;
import com.google.sitebricks.conversion.StandardTypeConverter;

import org.testng.annotations.Test;

import static com.google.sitebricks.example.RestfulWebServiceWithCRUD.BASE_SERVICE_PATH;
import static com.google.sitebricks.example.RestfulWebServiceWithCRUD.CREATE;
import static com.google.sitebricks.example.RestfulWebServiceWithCRUD.DELETE;
import static com.google.sitebricks.example.RestfulWebServiceWithCRUD.READ_COLLECTION;
import static com.google.sitebricks.example.RestfulWebServiceWithCRUD.READ_INDIVIDUAL;
import static com.google.sitebricks.example.RestfulWebServiceWithCRUD.UPDATE;

/**
* @author Jason van Zyl
*/
@Test(suiteName = AcceptanceTest.SUITE)
public class RestfuWebServiceWithCRUDAcceptanceTest {

  public void create() {
    String url = AcceptanceTest.baseUrl() + BASE_SERVICE_PATH;
    System.out.println("POST " + url);
    WebResponse response = createInjector()
        .getInstance(Web.class)
        .clientOf(url)
        .transports(String.class)
        .over(Json.class)
        .post("");

    assert CREATE.equals(response.toString()) : response.toString();
  }

  public void readCollection() {
    String url = AcceptanceTest.baseUrl() + BASE_SERVICE_PATH;
    System.out.println("GET " + url);
    WebResponse response = createInjector()
        .getInstance(Web.class)
        .clientOf(url)
        .transports(String.class)
        .over(Json.class)
        .get();

    assert READ_COLLECTION.equals(response.toString());
 

  public void readIndividual() {
    String url = AcceptanceTest.baseUrl() + BASE_SERVICE_PATH  + "/1";
    System.out.println("GET " + url);
    WebResponse response = createInjector()
        .getInstance(Web.class)
        .clientOf(url)
        .transports(String.class)
        .over(Json.class)
        .get();

    assert READ_INDIVIDUAL.equals(response.toString()) : response.toString();
 
 
  public void update() {
    String url = AcceptanceTest.baseUrl() + BASE_SERVICE_PATH  + "/1";
    System.out.println("PUT " + url);
    WebResponse response = createInjector()
        .getInstance(Web.class)
        .clientOf(url)
        .transports(String.class)
        .over(Json.class)
        .put("");

    assert UPDATE.equals(response.toString());
  }

  public void delete() {
    String url = AcceptanceTest.baseUrl() + BASE_SERVICE_PATH  + "/1";
    System.out.println("DELETE " + url);
    WebResponse response = createInjector()
        .getInstance(Web.class)
        .clientOf(url)
        .transports(String.class)
        .over(Json.class)
        .delete();

    assert DELETE.equals(response.toString());
  }
 

  private Injector createInjector() {
    return Guice.createInjector(new AbstractModule() {
        protected void configure() {
          bind(ConverterRegistry.class).toInstance(new StandardTypeConverter(
              ImmutableSet.<Converter>of()));
        }
      });
  }
}
TOP

Related Classes of com.google.sitebricks.acceptance.RestfuWebServiceWithCRUDAcceptanceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.