Running Junit Test in Play 1.4

Create a JUNIT Test class

package utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import com.google.gson.Gson;
import com.google.gson.JsonElement;

import controllers.KPIDashboard;
import org.junit.Assert;
import play.libs.WS.HttpResponse;
import play.test.UnitTest;

public class PlayRequestBodyTester extends UnitTest{

    Dashboard dashboard = new Dashboard();
   

    @Test
    public void testValidRequestBody () {

    List wellUidList = new ArrayList<>();
    String requestBody =    "[{" + "wellUidList" + ":" + "[" + "4225534251" + ","
    +  "4225534256" + "]}]";
    wellUidList = dashboard.extractWellListFromRequestBody(requestBody);
    Assert.assertEquals(wellUidList, getActualWellUidList());
    }
   
    @Test
    public void testNullRequestBody () {

    List wellUidList = new ArrayList<>();
    String requestBody = null;
    wellUidList = dashboard.extractWellListFromRequestBody(requestBody);
    Assert.assertEquals(wellUidList, null);
    }
   
    private List getActualWellUidList () {
    List wellUidList = new ArrayList<>();
    wellUidList.add("4225534251");
    wellUidList.add("4225534256");
   
    return wellUidList;
    }
   
}


// Method to Test
    public static List extractWellListFromRequestBody (String requestBodyString) {
    List wellUidList = new ArrayList<>();
   
    if (requestBodyString != null && !"".equals(requestBodyString)) {
    System.out.println(requestBodyString);
    String [] wellArray = requestBodyString.substring(requestBodyString.lastIndexOf(":") + 1).replace("[", "").replaceAll("\"","" ).
    replaceAll("]", "").replaceAll("}", "").split(",");
    wellUidList= new ArrayList(Arrays.asList(wellArray));
    }
   
    return wellUidList;
    }

In the command prompt

run > play test

Once the application is loaded, go to the browser and 

http://localhost:9005/@tests

select the test class and hit "Start"






No comments:

 Python Basics How to check the version of Python interpreter mac terminal

Popular in last 30 days