Package solysombra

Source Code of solysombra.AllTest

package solysombra;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import solysombra.client.MashupService;
import solysombra.client.MashupServiceAsync;
import solysombra.shared.domain.wwo.Forecast;
import solysombra.shared.places.Places;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.maps.gwt.client.GoogleMap;
import com.google.maps.gwt.client.LatLng;
import com.google.maps.gwt.client.MapOptions;
import com.google.maps.gwt.client.MapTypeId;

import static org.junit.Assert.*;

public class AllTest {

  final MashupServiceAsync mashupService = GWT.create(MashupService.class);
  final Double latitud = 37.356286486920844,longitud = -5.98174581323663;
  final Integer mes=12,dia=12,hora=5;
  final String uriPlaces="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=LAT,LON&radius=500&types=types&sensor=false&key=KEY";
  final String uriWWO="http://api.worldweatheronline.com/free/v1/weather.ashx?key=KEY&q=LAT,LON&fx=no&format=json";
  final String uriHS="http://api.worldweatheronline.com/free/v1/weather.ashx?key=KEY&q=LAT,LON&fx=no&format=json";
 
  Integer resPlaces;
  String[] resHSolar;
  Integer resGmaps;
  String salida;

 
  boolean resultado;
  static Integer contador;

  @Before
  public void setUp() throws Exception {
    contador=0;
    resultado=false;
    resPlaces=0;
    resHSolar=null;
    resGmaps=0;
  }
 
  @After
  public void tearDown() throws Exception {
  }

 
  @Test(timeout=10)
  void googlePlacesTest(){
    contador++;
    assertNotNull("GooglePlacesTest: 'Latitud is null' ", latitud);
    assertNotNull("GooglePlacesTest: 'Longitud is null' ", longitud);
   
    mashupService.getPlaces(latitud, longitud, "cafe", "", new AsyncCallback<Places>() {

      @Override
          public void onFailure(Throwable caught) {
        salida="Servicio GooglePlaces failed";
        resultado= false;
      }

      @Override
          public void onSuccess(Places result) {
        salida="Servicio GooglePlaces successful";
        resultado= true;
        resPlaces=result.getResults().size();
       

          }
        });
 
   
    System.out.println("-----------------------------------------");
    System.out.println("ID: PRUEBA_"+contador);
    System.out.println("DESCRIPCI�N: Prueba para la detecci�n de errores al implementar consultas en GooglePlaces usando servicios RESTful");
    System.out.println("ENTRADA: Se hace uso de la librer�a 'resteasy.jar' para invocar al servicio usando la URI "+uriPlaces+" desde nuestra aplicaci�n GWT");
    System.out.println("SALIDA ESPERADA: Servicio GooglePlaces successful");
    System.out.println("RESULTADO: "+resultado);;
    System.out.println("-----------------------------------------");
   
    assertTrue(salida,resultado=true && resPlaces==4);
   
  }
 
  @Test(timeout=10)
  void wwoTest(){
   
    contador++;
    assertNotNull("WheatherWorldTest: 'Latitud is null' ", latitud);
    assertNotNull("WheatherWorldTest: 'Longitud is null' ", longitud);
    mashupService.getWWOForecast(latitud,longitud, new AsyncCallback<Forecast>() {

          @Override
          public void onFailure(Throwable caught) {
            salida="Servicio WWOForecast failed";
            resultado= false;
          }

          @Override
          public void onSuccess(Forecast result) {
            salida="Servicio WWOForecast successful";
            resultado= true;

          }
        });
   
   
    System.out.println("-----------------------------------------");
    System.out.println("ID: PRUEBA_"+contador);
    System.out.println("DESCRIPCI�N: Prueba para la detecci�n de errores al implementar consultas en WorldWheather usando servicios RESTful");
    System.out.println("ENTRADA: Se hace uso de la librer�a 'resteasy.jar' para invocar al servicio usando la URI "+uriWWO+" desde nuestra aplicaci�n GWT");
    System.out.println("SALIDA ESPERADA: Servicio WorldWheather successful ");
    System.out.println("RESULTADO: "+resultado);;
    System.out.println("-----------------------------------------");
   
    assertTrue(salida,resultado=true);
  }
 
  @Test(timeout=10)
  void googleMapsTest(){
   
    contador++;
    resultado=true;
    salida="Servicio GoogleMaps failed";
 
    MapOptions myOptions = MapOptions.create();
    myOptions.setZoom(15.0);
    myOptions.setCenter(LatLng.create(latitud,longitud));
    myOptions.setMapTypeId(MapTypeId.ROADMAP);
   
   
    try{
          GoogleMap.create(Document.get().getElementById("map_canvas"), myOptions);
    }catch(Exception e){
      resGmaps=-1;
      resultado=false;
    }
    System.out.println("-----------------------------------------");
    System.out.println("ID: PRUEBA_"+contador);
    System.out.println("DESCRIPCI�N: Prueba para la detecci�n de errores al crear un mapa basico GoogleMaps");
    System.out.println("ENTRADA: Se hace uso de la librer�a 'gwt-maps.jar' de GoogleMaps para invocar al servicio desde GWT ");
    System.out.println("SALIDA ESPERADA: Servicio GoogleMaps successful");
    System.out.println("RESULTADO: "+resultado);
    System.out.println("-----------------------------------------");

    assertTrue(salida, resultado==true && resGmaps!=-1);
  }
 
  @Test(timeout=10)
  void huellaSolarTest1(){
   
    contador++;
    assertNotNull("huellaSolarTest: 'mes is null' ", mes);
    assertNotNull("huellaSolarTest: 'dia is null' ", dia);
    assertNotNull("huellaSolarTest: 'hora is null' ", hora);
    assertNotNull("huellaSolarTest: 'Latitud is null' ", latitud);
    assertNotNull("huellaSolarTest: 'Longitud is null' ", longitud);
   
    mashupService.getFormResponse(latitud, longitud, mes, dia, hora,
        new AsyncCallback<String>() {

          @Override
          public void onFailure(Throwable caught) {
            salida="Servicio HuellaSolar failed";
            resultado= false;

          }

          @Override
          public void onSuccess(String result) {
            Window.alert(result.toString());
            resHSolar = result.split(",");
            if (resHSolar.length == 2 && resHSolar[1].equals("Es de noche")){
             salida="Servicio HuellaSolar successful";
             resultado= true;
            }
          }
        });
   
   
    System.out.println("-----------------------------------------");
    System.out.println("ID: PRUEBA_"+contador);
    System.out.println("DESCRIPCI�N: Prueba para la detecci�n de errores al implementar la b�squeda en HuellaSolar mediante crawling");
    System.out.println("ENTRADA: Se hace uso de la librer�a HTMLUnit para capturar el servicio con una consulta POST con php desde "+uriHS+" hasta nuestra aplicaci�n GWT, pasando par�metros de horario nocturno");
    System.out.println("SALIDA ESPERADA: 'Es de noche' ");
    System.out.println("RESULTADO: "+resultado);
    System.out.println("-----------------------------------------");
    assertTrue(salida, resultado==true);
   
  }
 
  @Test(timeout=10)
  void huellaSolarTest2(){
   
    contador++;
    assertNotNull("huellaSolarTest: 'mes is null' ", mes);
    assertNotNull("huellaSolarTest: 'dia is null' ", dia);
    assertNotNull("huellaSolarTest: 'hora is null' ", hora);
   
    mashupService.getFormResponse(5, 5, mes, dia, hora,
        new AsyncCallback<String>() {

          @Override
          public void onFailure(Throwable caught) {
            salida="Servicio HuellaSolar failed";
            resultado= false;

          }

          @Override
          public void onSuccess(String result) {
            Window.alert(result.toString());
            resHSolar = result.split(",");
            if (resHSolar.length == 2 && resHSolar[1].equals("Los valores de latitud y longitud deben ser tipo Double")){
            salida="Servicio HuellaSolar successful";
            resultado= true;
            }
          }
        });
   
    System.out.println("-----------------------------------------");
    System.out.println("ID: PRUEBA_"+contador);
    System.out.println("DESCRIPCI�N: Prueba para la detecci�n de errores al implementear la b�squeda en HuellaSolar mediante crawling");
    System.out.println("ENTRADA: Se invoca el servicio suministrando valores incorrectos de latitud y longitud");
    System.out.println("SALIDA ESPERADA: 'Los parametros latitud y longitud deben ser tipo double'");
    System.out.println("RESULTADO: "+resultado);
    System.out.println("-----------------------------------------");
    assertTrue(salida, resultado==true);
  }
 
 

}
TOP

Related Classes of solysombra.AllTest

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.