Hello I have write a juint test case for rest api using HttpUriRequest. The Test case gives the proper result but the issue is that i need to run the tomcat server to test the junit test case. why??
Here is my Code:
package com.dataguise.webservices;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import com.dataguise.webservices.beans.DgException;
class RestAPIsTest {
final String versionNumber = "v1";
final String baseUrl = "http://localhost:10181/dgcontroller/services/restAPIs/";
final String sessionId = "2";
@Test
public void idpsTest() throws ClientProtocolException, IOException {
HttpUriRequest request = new HttpGet(baseUrl + versionNumber + "/idps");
request.addHeader("sessionId", sessionId);
HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request);
System.out.println(">>>>>>>>>>>>>>>." + httpResponse.getStatusLine().getStatusCode());
assertEquals(200, httpResponse.getStatusLine().getStatusCode());
// Getting Json From Http Response
String json = EntityUtils.toString(httpResponse.getEntity());
System.out.println(">>>>>>>>>>>>>>>." + json);
}
}
This test case is working fine but when i stop the server the test case is not executed. Is there is any way to test this case without run the server?? Thanks