diff --git a/tools/api-automation/extend-config2.xml b/tools/api-automation/extend-config2.xml new file mode 100644 index 0000000..0274d88 --- /dev/null +++ b/tools/api-automation/extend-config2.xml @@ -0,0 +1,41 @@ + + + + + standard + + + UTF-8 + + + https + + + ToolsQA - Cucumber Framework + + + ToolsQA - Cucumber Report + + + yyyy-MM-dd + + + HH:mm:ss + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/api-automation/extent-config.xml b/tools/api-automation/extent-config.xml new file mode 100755 index 0000000..7b46c72 --- /dev/null +++ b/tools/api-automation/extent-config.xml @@ -0,0 +1,49 @@ + + + + + + standard + + + + UTF-8 + + + + https + + + ExtentReports 2.0 + + + + + + Automation Report + + + + yyyy-MM-dd + + + + HH:mm:ss + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/api-automation/files/Test_formA_2.csv b/tools/api-automation/files/Test_formA_2.csv new file mode 100644 index 0000000..7ebe032 --- /dev/null +++ b/tools/api-automation/files/Test_formA_2.csv @@ -0,0 +1,19 @@ +today,start,imei,end,group_1/resp_name,group_1/resp_age,group_1/resp_sex,group_1/hhh_female,group_1/child_num,group_1/photo,group_2/food,group_2/transport,group_2/total,meta/instanceID +2018-12-14,2018-12-14T10:35:17.502000+03:00,enketo.ona.io:0CgMXF5tuvFTfOkw,2018-12-14T10:35:49.154000+03:00,Druid,30,2,1,2,http://classic.ona.io/api/v1/files/10488009?filename=qastuff/attachments/368110_Test_formA/Tulips-10_35_41.jpg,4000,5000,9000,n/a +2018-12-14,2018-12-14T10:35:49.219000+03:00,enketo.ona.io:0CgMXF5tuvFTfOkw,2018-12-14T10:36:13.882000+03:00,Gregory,34,1,n/a,1,http://classic.ona.io/api/v1/files/10488011?filename=qastuff/attachments/368110_Test_formA/pic2-10_36_5.jpg,5000,6000,11000,n/a +2019-02-13,2019-02-13T15:19:00.754000+03:00,enketo.ona.io:prE2UMRUzWFqhuPt,2019-02-13T15:19:33.744000+03:00,Janice,30,2,1,25,http://classic.ona.io/api/v1/files/10925902?filename=qastuff/attachments/368110_Test_formA/Desert-15_19_24.jpg,3000,4000,7000,n/a +2019-02-13,2019-02-13T15:19:33.774000+03:00,enketo.ona.io:prE2UMRUzWFqhuPt,2019-02-13T15:20:19.963000+03:00,Kalunde,30,2,1,4,http://classic.ona.io/api/v1/files/10925917?filename=qastuff/attachments/368110_Test_formA/Hydrangeas-15_20_11.jpg,3000,5000,8000,n/a +2021-05-27,2021-05-27T11:26:44.098000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:27:13.505000+03:00,Hannah,28,2,1,3,http://classic.ona.io/api/v1/files/20450401?filename=qastuff/attachments/368110_Test_formA/Screenshot_2021-05-24_at_17.56.33-11_27_6.png,3000,4000,7000,n/a +2021-05-27,2021-05-27T11:27:13.631000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:28:10.506000+03:00,leila,27,2,1,1,n/a,4000,3000,7000,n/a +2021-05-27,2021-05-27T11:28:10.563000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:28:31.761000+03:00,Jane,29,2,1,2,n/a,5000,6000,11000,n/a +2021-05-27,2021-05-27T11:28:31.831000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:28:52.185000+03:00,Jason,37,1,n/a,3,n/a,4000,1000,5000,n/a +2018-12-14,2018-12-14T10:29:30.373000+03:00,enketo.ona.io:0CgMXF5tuvFTfOkw,2018-12-14T10:30:42.480000+03:00,Kayla,20,2,n/a,3,http://classic.ona.io/api/v1/files/10487989?filename=qastuff/attachments/368110_Test_formA/Koala-10_30_34.jpg,3000,2000,5000,n/a +2018-12-14,2018-12-14T10:30:42.546000+03:00,enketo.ona.io:0CgMXF5tuvFTfOkw,2018-12-14T10:31:00.860000+03:00,Brian,4,1,n/a,4,http://classic.ona.io/api/v1/files/10487990?filename=qastuff/attachments/368110_Test_formA/pic3-10_30_53.JPG,5000,4000,9000,n/a +2018-12-14,2018-12-14T10:35:17.502000+03:00,enketo.ona.io:0CgMXF5tuvFTfOkw,2018-12-14T10:35:49.154000+03:00,Druid,30,2,1,2,http://classic.ona.io/api/v1/files/10488009?filename=qastuff/attachments/368110_Test_formA/Tulips-10_35_41.jpg,4000,5000,9000,n/a +2018-12-14,2018-12-14T10:35:49.219000+03:00,enketo.ona.io:0CgMXF5tuvFTfOkw,2018-12-14T10:36:13.882000+03:00,Gregory,34,1,n/a,1,http://classic.ona.io/api/v1/files/10488011?filename=qastuff/attachments/368110_Test_formA/pic2-10_36_5.jpg,5000,6000,11000,n/a +2019-02-13,2019-02-13T15:19:00.754000+03:00,enketo.ona.io:prE2UMRUzWFqhuPt,2019-02-13T15:19:33.744000+03:00,Janice,30,2,1,25,http://classic.ona.io/api/v1/files/10925902?filename=qastuff/attachments/368110_Test_formA/Desert-15_19_24.jpg,3000,4000,7000,n/a +2019-02-13,2019-02-13T15:19:33.774000+03:00,enketo.ona.io:prE2UMRUzWFqhuPt,2019-02-13T15:20:19.963000+03:00,Kalunde,30,2,1,4,http://classic.ona.io/api/v1/files/10925917?filename=qastuff/attachments/368110_Test_formA/Hydrangeas-15_20_11.jpg,3000,5000,8000,n/a +2021-05-27,2021-05-27T11:26:44.098000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:27:13.505000+03:00,Hannah,28,2,1,3,http://classic.ona.io/api/v1/files/20450401?filename=qastuff/attachments/368110_Test_formA/Screenshot_2021-05-24_at_17.56.33-11_27_6.png,3000,4000,7000,n/a +2021-05-27,2021-05-27T11:27:13.631000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:28:10.506000+03:00,leila,27,2,1,1,n/a,4000,3000,7000,n/a +2021-05-27,2021-05-27T11:28:10.563000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:28:31.761000+03:00,Jane,29,2,1,2,n/a,5000,6000,11000,n/a +2021-05-27,2021-05-27T11:28:31.831000+03:00,enketo.ona.io:xQ8HNoTbjmYcQhXo,2021-05-27T11:28:52.185000+03:00,Jason,37,1,n/a,3,n/a,4000,1000,5000,n/a \ No newline at end of file diff --git a/tools/api-automation/pom.xml b/tools/api-automation/pom.xml new file mode 100644 index 0000000..2c331aa --- /dev/null +++ b/tools/api-automation/pom.xml @@ -0,0 +1,167 @@ + + + + + 4.0.0 + + RestAssuredFramework + RestAssuredFramework + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.14.1 + + + test + **/RunCukesTest*.java + + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + com.relevantcodes + extentreports + 2.41.0 + + + io.rest-assured + rest-assured + 3.0.0 + + + ru.qatools.commons + properties + 2.0.RC6 + + + mysql + mysql-connector-java + 8.0.12 + + + org.json + json + 20180813 + + + com.google.code.gson + gson + 2.8.0 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + com.sun.mail + javax.mail + 1.6.2 + + + + org.apache.poi + poi-ooxml + 3.13-beta1 + + + org.slf4j + slf4j-simple + 1.7.30 + + + org.skyscreamer + jsonassert + 1.5.0 + test + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.8 + + + com.jayway.jsonpath + json-path + 2.4.0 + + + + com.google.guava + guava + 28.2-jre + + + + io.rest-assured + json-schema-validator + 3.3.0 + compile + + + javax.xml.bind + jaxb-api + 2.3.0 + + + org.postgresql + postgresql + 42.1.1 + + + io.cucumber + cucumber-java + 3.0.2 + + + + io.cucumber + cucumber-junit + 3.0.2 + + + junit + junit + 4.12 + + + com.aventstack + extentreports + 4.0.9 + + + + + com.vimalselvam + cucumber-extentsreport + 3.1.1 + + + + com.aventstack + extentreports-cucumber4-adapter + 1.0.7 + + + \ No newline at end of file diff --git a/tools/api-automation/src/test/java/config/ApplicationConfigReader.java b/tools/api-automation/src/test/java/config/ApplicationConfigReader.java new file mode 100755 index 0000000..ceb9ddf --- /dev/null +++ b/tools/api-automation/src/test/java/config/ApplicationConfigReader.java @@ -0,0 +1,151 @@ + +package config; + + +import ru.qatools.properties.Property; +import ru.qatools.properties.PropertyLoader; +import ru.qatools.properties.Resource.Classpath; + + +@Classpath({"application.properties"}) + +public class ApplicationConfigReader { + + @Property("baseUrl") + private String baseUrl; + @Property("htmlReportPath") + private String htmlReportPath; + @Property("LogTestRail") + private String LogTestRail; + @Property("TestRailurl") + private String TestRailurl; + @Property("TestRailusername") + private String TestRailusername; + @Property("TestRailpassword") + private String TestRailpassword; + @Property("TestRailprojectid") + private String TestRailprojectid; + @Property("isEnableReporting") + private String isEnableReporting; + @Property("SendEmailAfterExecution") + private String SendEmailAfterExecution; + @Property("From") + private String From; + @Property("FromPassword") + private String FromPassword; + @Property("To") + private String[] To; + @Property("ProjectDescription") + private String ProjectDescription; + @Property("filePath") + private String filePath; + + + @Property("Project") + private String Project; + @Property("Platform") + private String Platform; + @Property("Environment") + private String Environment; + + @Property("UpdateCase") + private String UpdateCase; + + @Property("username") + private String username; + + @Property("password") + private String password; + + @Property("privateKey") + private String privateKey; + + public ApplicationConfigReader() { + PropertyLoader.newInstance().populate(this); + } + + + public String getBaseUrl() { + return this.baseUrl; + } + + public String getHtmlReportPath() { + return this.htmlReportPath; + } + + public String getLogTestRail() { + return this.LogTestRail; + } + + public String getTestRailurl() { + return this.TestRailurl; + } + + public String getTestRailusername() { + return this.TestRailusername; + } + + public String getTestRailpassword() { + return this.TestRailpassword; + } + + + public String getIsEnableReporting() { + return this.isEnableReporting; + } + + + public String getSendEmailAfterExecution() { + return this.SendEmailAfterExecution; + } + + public String getFrom() { + return this.From; + } + + public String getFromPassword() { + return this.FromPassword; + } + + public String[] getTo() { + return this.To; + } + + + public String getProject() { + return this.Project; + } + + public String getPlatform() { + return this.Platform; + } + + public String getEnviroment() { + return this.Environment; + } + + public String getUpdateTestRail() { + return this.UpdateCase; + } + + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } + + public String getTestRailprojectid() { + return this.TestRailprojectid; + } + + public String getPrivateKey() { + return this.privateKey; + } + + public String getfilePath() { + return System.getProperty("user.dir")+filePath; + } + +} \ No newline at end of file diff --git a/tools/api-automation/src/test/java/config/ConfigProperties.java b/tools/api-automation/src/test/java/config/ConfigProperties.java new file mode 100755 index 0000000..ffc89da --- /dev/null +++ b/tools/api-automation/src/test/java/config/ConfigProperties.java @@ -0,0 +1,36 @@ +/* +# set & get environment/globals variables +*/ + +package config; + + +public class ConfigProperties { + public static config.ApplicationConfigReader appConfig = new config.ApplicationConfigReader(); + public static String htmlReportPath = appConfig.getHtmlReportPath(); + public static String baseUrl = appConfig.getBaseUrl(); + public static String logTestRail = appConfig.getLogTestRail(); + public static String testRailUsername = appConfig.getTestRailusername(); + public static String testRailPassword = appConfig.getTestRailpassword(); + public static String testRailUrl = appConfig.getTestRailurl(); + public static String isReportingEnable = appConfig.getIsEnableReporting(); + + public static String sendEmail = appConfig.getSendEmailAfterExecution(); + public static String from = appConfig.getFrom(); + public static String[] To = appConfig.getTo(); + public static String fromPassword = appConfig.getFromPassword(); + + public static String Project = appConfig.getProject(); + public static String Platform = appConfig.getPlatform(); + public static String Environment = appConfig.getEnviroment(); + public static String username = appConfig.getUsername(); + public static String password = appConfig.getPassword(); + public static String testTrailProjectId = appConfig.getTestRailprojectid(); + public static String filePath = appConfig.getfilePath(); + public static String privateKey = appConfig.getPrivateKey(); + + + + + +} diff --git a/tools/api-automation/src/test/java/config/EndpointURLs.java b/tools/api-automation/src/test/java/config/EndpointURLs.java new file mode 100755 index 0000000..141f732 --- /dev/null +++ b/tools/api-automation/src/test/java/config/EndpointURLs.java @@ -0,0 +1,34 @@ + +package config; + + +public class EndpointURLs { + +public static String GET_AUTHNETICATION = "/security/authenticate"; +public static String SYNC_BY_LOCATION= "/rest/event/sync?locationId=%s&serverVersion=0&limit=250"; +public static String SYNC_BY_PROVIDER= "/rest/event/sync?providerId=%s&serverVersion=0&limit=250"; +public static String SYNC_BY_TEAM ="/rest/event/sync?team=%s&serverVersion=0&limit=250"; +public static String GET_UNIQUE_ID_REQ ="/uniqueids/get?source=1&numberToGenerate=5"; +public static String SEARCH_CLIENT_BY_PATH="/rest/search/path?first_name=a&last_name=am"; +public static String SEARCH_CLIENT_II ="/rest/search/search?lastName=admin"; +public static String FETCH_CLIENT_BY_ID = "/rest/client/1000001V"; +public static String SEARCH_CLIENT_BY_GENDER = "/rest/client/search?gender=female"; +public static String SYNC_VIEW_CONFIGURATION = "/rest/viewconfiguration/sync?serverVersion=0"; +public static String SEARCH_CLIENT_BY_BIRTHDAY ="/rest/client/search?birthdate=2017-12-16:2019-12-19"; +public static String GET_ALL_USERS= "/rest/user?page_size=10&start_index=0&source=Keycloak"; +public static String SEARCH_CLIENT_BY_NAME = "/rest/client/search?name=web"; +public static String SYNC_SERVERSIDE_SETTING = "/rest/settings/sync?serverVersion=0"; +public static String GET_ALL_EVENTS= "/rest/event/getAll?serverVersion=0&limit=10"; +public static String GET_ALL_STOCK= "/rest/stockresource/getall?serverVersion=0&limit=10"; +public static String GET_ALL_STOCK_BY_ID= "/rest/stockresource/xxxx"; +public static String SEARCH_EVENT_BY_TEAM= "/rest/event/search?team=%s"; +public static String SEARCH_EVENT_BY_TEAM_ID= "/rest/event/search?teamId=%s"; +public static String SEARCH_EVENT_BY_LOCATION_ID ="/rest/event/search?locationId=%s"; +public static String SEARCH_EVENT_BY_PROVIDER_ID ="/rest/event/search?providerId=%s"; +public static String SEARCH_EVENT_BY_ENTITY_TYPE ="/rest/event/search?entityType=child"; +public static String SEARCH_EVENT_ID_BY_EVENT_TYPE ="/rest/event/findIdsByEventType?eventType=Birth Registration&serverVersion=0"; +public static String SEARCH_EVENT_BY_ID ="/rest/event/%s"; +public static String GET_PROVIDER_ACTION ="/actions?anmIdentifier=%s&timeStamp=1553817603433"; +public static String POST_EVENT ="/rest/event/add/"; +public static String POST_CLIENT ="/rest/client/add/"; +} diff --git a/tools/api-automation/src/test/java/config/EnvGlobals.java b/tools/api-automation/src/test/java/config/EnvGlobals.java new file mode 100755 index 0000000..dec8277 --- /dev/null +++ b/tools/api-automation/src/test/java/config/EnvGlobals.java @@ -0,0 +1,24 @@ +/* +Define global variables to use re-use them + */ + +package config; + +import io.restassured.specification.RequestSpecification; + +public class EnvGlobals { + + public static String accessToken; + public static RequestSpecification requestSpecification; + public static String clientBasicEntityID_uuid; + public static String clientId_uuid; + public static String clientAddress_uuid; + public static String teamName; + public static String teamUuid; + public static String eventBasicEntityID_uuid; + public static String eventLocation_uuid; + public static String formSubmissionId_uuid; + public static String eventId_uuid; + + + } diff --git a/tools/api-automation/src/test/java/general/APIClient.java b/tools/api-automation/src/test/java/general/APIClient.java new file mode 100644 index 0000000..bcc02cb --- /dev/null +++ b/tools/api-automation/src/test/java/general/APIClient.java @@ -0,0 +1,159 @@ +package general; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Base64; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +public class APIClient { + private String m_user; + private String m_password; + private String m_url; + + public APIClient(String base_url) { + if (!base_url.endsWith("/")) { + base_url = base_url + "/"; + } + + this.m_url = base_url + "index.php?/api/v2/"; + } + + + public void setUser(String user) { + this.m_user = user; + } + + public void setPassword(String password) { + this.m_password = password; + } + + + public Object sendPost(String uri, Object data) throws MalformedURLException, IOException, APIException { + return this.sendRequest("POST", uri, data); + } + + private Object sendRequest(String method, String uri, Object data) throws MalformedURLException, IOException, APIException { + URL url = new URL(this.m_url + uri); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + String auth = getAuthorization(this.m_user, this.m_password); + conn.addRequestProperty("Authorization", "Basic " + auth); + if (method.equals("POST")) { + conn.setRequestMethod("POST"); + if (data != null) { + if (uri.startsWith("add_attachment")) { + String boundary = "TestRailAPIAttachmentBoundary"; + File uploadFile = new File((String)data); + conn.setDoOutput(true); + conn.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); + OutputStream ostreamBody = conn.getOutputStream(); + BufferedWriter bodyWriter = new BufferedWriter(new OutputStreamWriter(ostreamBody)); + bodyWriter.write("\n\n--" + boundary + "\r\n"); + bodyWriter.write("Content-Disposition: form-data; name=\"attachment\"; filename=\"" + uploadFile.getName() + "\""); + bodyWriter.write("\r\n\r\n"); + bodyWriter.flush(); + InputStream istreamFile = new FileInputStream(uploadFile); + byte[] dataBuffer = new byte[1024]; + + int bytesRead; + while((bytesRead = istreamFile.read(dataBuffer)) != -1) { + ostreamBody.write(dataBuffer, 0, bytesRead); + } + + ostreamBody.flush(); + bodyWriter.write("\r\n--" + boundary + "--\r\n"); + bodyWriter.flush(); + istreamFile.close(); + ostreamBody.close(); + bodyWriter.close(); + } else { + conn.addRequestProperty("Content-Type", "application/json"); + byte[] block = JSONValue.toJSONString(data).getBytes("UTF-8"); + conn.setDoOutput(true); + OutputStream ostream = conn.getOutputStream(); + ostream.write(block); + ostream.close(); + } + } + } else { + conn.addRequestProperty("Content-Type", "application/json"); + } + + int status = conn.getResponseCode(); + InputStream istream; + if (status != 200) { + istream = conn.getErrorStream(); + if (istream == null) { + throw new APIException("testrail API return HTTP " + status + " (No additional error message received)"); + } + } else { + istream = conn.getInputStream(); + } + + if (istream != null && uri.startsWith("get_attachment/")) { +// FileOutputStream outputStream = new FileOutputStream((String)data); +// boolean bytesRead = false; +// byte[] buffer = new byte[1024]; +// +// int bytesRead; +// while((bytesRead = istream.read(buffer)) > 0) { +// outputStream.write(buffer, 0, bytesRead); +// } +// +// outputStream.close(); +// istream.close(); + return (String)data; + } else { + String text = ""; + String error; + if (istream != null) { + BufferedReader reader; + for(reader = new BufferedReader(new InputStreamReader(istream, "UTF-8")); (error = reader.readLine()) != null; text = text + System.getProperty("line.separator")) { + text = text + error; + } + + reader.close(); + } + + Object result; + if (!text.equals("")) { + result = JSONValue.parse(text); + } else { + result = new JSONObject(); + } + + if (status != 200) { + error = "No additional error message received"; + if (result != null && result instanceof JSONObject) { + JSONObject obj = (JSONObject)result; + if (obj.containsKey("error")) { + error = '"' + (String)obj.get("error") + '"'; + } + } + + throw new APIException("testrail API returned HTTP " + status + "(" + error + ")"); + } else { + return result; + } + } + } + + private static String getAuthorization(String user, String password) { + try { + return new String(Base64.getEncoder().encode((user + ":" + password).getBytes())); + } catch (IllegalArgumentException var3) { + return ""; + } + } +} diff --git a/tools/api-automation/src/test/java/general/APIException.java b/tools/api-automation/src/test/java/general/APIException.java new file mode 100644 index 0000000..4e5bf53 --- /dev/null +++ b/tools/api-automation/src/test/java/general/APIException.java @@ -0,0 +1,8 @@ +package general; + + +public class APIException extends Exception { + public APIException(String message) { + super(message); + } +} diff --git a/tools/api-automation/src/test/java/general/DataClass.java b/tools/api-automation/src/test/java/general/DataClass.java new file mode 100644 index 0000000..f97769b --- /dev/null +++ b/tools/api-automation/src/test/java/general/DataClass.java @@ -0,0 +1,19 @@ +package general; + +import java.io.File; +import java.util.ArrayList; + +public class DataClass { + public String summary; + public String Description; + String Method; + String methodName; + String csvRow; + File imageFile; + ArrayList automationSteps; + Integer lengthBeforeTestCase; + Integer lengthAfterTestCase; + + public DataClass() { + } +} \ No newline at end of file diff --git a/tools/api-automation/src/test/java/general/DataList.java b/tools/api-automation/src/test/java/general/DataList.java new file mode 100644 index 0000000..82cadd7 --- /dev/null +++ b/tools/api-automation/src/test/java/general/DataList.java @@ -0,0 +1,11 @@ +package general; + +import java.util.ArrayList; +import java.util.List; + +public interface DataList { + List caseid = new ArrayList(); + List result = new ArrayList(); + List updateData = new ArrayList(); + List JIRA = new ArrayList(); +} diff --git a/tools/api-automation/src/test/java/general/EnvGlobals.java b/tools/api-automation/src/test/java/general/EnvGlobals.java new file mode 100644 index 0000000..95c0512 --- /dev/null +++ b/tools/api-automation/src/test/java/general/EnvGlobals.java @@ -0,0 +1,14 @@ +package general; + + +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; + +public class EnvGlobals { + public static StringBuilder difference = new StringBuilder(); + public static RequestSpecification requestSpecification; + public static Response response; + + public EnvGlobals() { + } +} \ No newline at end of file diff --git a/tools/api-automation/src/test/java/general/GeneralFunctions.java b/tools/api-automation/src/test/java/general/GeneralFunctions.java new file mode 100644 index 0000000..d4b1301 --- /dev/null +++ b/tools/api-automation/src/test/java/general/GeneralFunctions.java @@ -0,0 +1,14 @@ +package general; + + +import java.util.*; + +public class GeneralFunctions +{ + + public static Date getTime() { + Calendar calendar = Calendar.getInstance(); + return calendar.getTime(); + } + +} \ No newline at end of file diff --git a/tools/api-automation/src/test/java/general/ReusableFunctions.java b/tools/api-automation/src/test/java/general/ReusableFunctions.java new file mode 100644 index 0000000..b521337 --- /dev/null +++ b/tools/api-automation/src/test/java/general/ReusableFunctions.java @@ -0,0 +1,287 @@ +package general; + +import config.ConfigProperties; +import io.restassured.RestAssured; +import io.restassured.path.json.JsonPath; +import io.restassured.response.Response; +import io.restassured.response.ValidatableResponse; +import io.restassured.specification.RequestSpecification; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + + +import java.io.File; +import java.util.*; + +public class ReusableFunctions { + public static RequestSpecification REQUEST; + + public ReusableFunctions() { + } + + public static ArrayList responseList(String key) { + return (ArrayList)((ValidatableResponse) general.EnvGlobals.response.then()).extract().path(key, new String[0]); + } + + public static int getResponseLength() { + return (Integer) general.EnvGlobals.response.body().path("list.size()", new String[0]); + } + + public static void printResponse() { + if (general.EnvGlobals.response != null) { + System.out.println(general.EnvGlobals.response.getBody().asString()); + } + + } + + public static void givenHeaderFormData(Map headers, Map formData) { + contentType("multipart/form-data"); + Iterator> it = formData.entrySet().iterator(); + Map.Entry pair; + if (headers == null) { + EnvGlobals.requestSpecification = REQUEST.given(); + + while(it.hasNext()) { + pair = (Map.Entry)it.next(); + EnvGlobals.requestSpecification = REQUEST.given().multiPart((String)pair.getKey(), (String)pair.getValue()); + it.remove(); + } + } else { + EnvGlobals.requestSpecification = REQUEST.given().headers(headers); + + while(it.hasNext()) { + pair = (Map.Entry)it.next(); + EnvGlobals.requestSpecification = REQUEST.given().multiPart((String)pair.getKey(), pair.getValue()); + it.remove(); + } + } + + + } + + public static void givenHeaderFormData(Map headers) { + System.out.println(headers); + contentType("multipart/form-data"); + EnvGlobals.requestSpecification = REQUEST.given().headers(headers); + } + + + public static void addFileInHeader(String filename,String fileKey,String fileType) { + config.EnvGlobals.requestSpecification = ReusableFunctions.REQUEST.given().multiPart(fileKey,(new File(ConfigProperties.filePath+filename)),fileType); + } + + public static String getResponse() { + return general.EnvGlobals.response != null ? general.EnvGlobals.response.getBody().asString() : null; + } + + + private static JSONArray sortApiResponse(JSONArray jsonArr, final String sortBy, boolean sortOrder) { + JSONArray sortedJsonArray = new JSONArray(); + List jsonValues = new ArrayList(); + + for(int i = 0; i < jsonArr.length(); ++i) { + jsonValues.add(jsonArr.getJSONObject(i)); + } + + final Boolean SORT_ORDER = sortOrder; + Collections.sort(jsonValues, new Comparator() { + public int compare(JSONObject a, JSONObject b) { + Integer valA = new Integer(0); + Integer valB = new Integer(0); + + try { + valA = (Integer)a.get(sortBy); + valB = (Integer)b.get(sortBy); + } catch (JSONException var6) { + } + + return SORT_ORDER ? valA.compareTo(valB) : -valA.compareTo(valB); + } + }); + + for(int i = 0; i < jsonArr.length(); ++i) { + sortedJsonArray.put(jsonValues.get(i)); + } + + return sortedJsonArray; + } + + + public static String getResponsePath(String key) { + return general.EnvGlobals.response.getBody().path(key, new String[0]).toString(); + } + + + + public static JSONArray getResponseJson(String... params) { + JsonPath jsonPathEvaluator = general.EnvGlobals.response.jsonPath(); + JSONArray jArray = new JSONArray(); + ArrayList list1 = (ArrayList)jsonPathEvaluator.get(params[0]); + ArrayList list2 = (ArrayList)jsonPathEvaluator.get(params[1]); + + for(int i = 0; i < getResponseLength(); ++i) { + JSONObject obj = new JSONObject(); + + for(int j = 0; j < params.length; ++j) { + if (j == 0) { + obj.put(params[j], list1.get(i)); + } else { + obj.put(params[j], list2.get(i)); + } + } + + jArray.put(obj); + } + + return sortApiResponse(jArray, "id", true); + } + + private static void contentType(String contentType) { + REQUEST = RestAssured.given().contentType(contentType); + } + + public static void given() { + contentType("application/json"); + general.EnvGlobals.requestSpecification = REQUEST.given(); + } + + + + + public static void givenHeaders() { + contentType("application/json"); + general.EnvGlobals.requestSpecification = REQUEST.given(); + } + public static void givenHeaderPayload(Map headers, String payload) { + contentType("application/json"); + general.EnvGlobals.requestSpecification = REQUEST.given(); + if (headers == null) { + general.EnvGlobals.requestSpecification = REQUEST.given().body(payload); + } else if (payload == null) { + general.EnvGlobals.requestSpecification = REQUEST.given().headers(headers); + } else { + general.EnvGlobals.requestSpecification = REQUEST.given().headers(headers).body(payload); + } + + } + + + + public static void whenFunction(String requestType, String endPoint) { + byte var3 = -1; + switch(requestType.hashCode()) { + case -1335458389: + if (requestType.equals("delete")) { + var3 = 2; + } + break; + case 102230: + if (requestType.equals("get")) { + var3 = 1; + } + break; + case 111375: + if (requestType.equals("put")) { + var3 = 3; + } + break; + case 3446944: + if (requestType.equals("post")) { + var3 = 0; + } + break; + case 106438728: + if (requestType.equals("patch")) { + var3 = 4; + } + } + + switch(var3) { + case 0: + general.EnvGlobals.response = (Response)((RequestSpecification) general.EnvGlobals.requestSpecification.when().log().all()).post(endPoint, new Object[0]); + break; + case 1: + general.EnvGlobals.response = (Response)((RequestSpecification) general.EnvGlobals.requestSpecification.when().log().all()).get(endPoint, new Object[0]); + break; + case 2: + general.EnvGlobals.response = (Response)((RequestSpecification) general.EnvGlobals.requestSpecification.when().log().all()).delete(endPoint, new Object[0]); + break; + case 3: + general.EnvGlobals.response = (Response)((RequestSpecification) general.EnvGlobals.requestSpecification.when().log().all()).put(endPoint, new Object[0]); + break; + case 4: + general.EnvGlobals.response = (Response)((RequestSpecification) general.EnvGlobals.requestSpecification.when().log().all()).patch(endPoint, new Object[0]); + } + + } + + public static void thenFunction(int statusCode) { + ((ValidatableResponse)((ValidatableResponse) general.EnvGlobals.response.then()).log().all()).statusCode(statusCode); + } + public static void givenHeaders(Map headers) { + contentType("application/json"); + EnvGlobals.requestSpecification = REQUEST.given().headers(headers); + } + + public static Map headers(Object... keyValues) { + Map map = new HashMap(); + + for(int index = 0; index < keyValues.length / 2; ++index) { + map.put((K)keyValues[index * 2], (V)keyValues[index * 2 + 1]); + } + + return map; + } + + public static Map form_data(Object... keyValues) { + Map map = new HashMap(); + + for(int index = 0; index < keyValues.length / 2; ++index) { + map.put((K)keyValues[index * 2], (V)keyValues[index * 2 + 1]); + } + + return map; + } + + public static Map params(Object... keyValues) { + Map map = new HashMap(); + + for(int index = 0; index < keyValues.length / 2; ++index) { + map.put((K)keyValues[index * 2], (V)keyValues[index * 2 + 1]); + } + + return map; + } + + + private static int WorkingDays(Date startDate, Date endDate, int SpecialHolidays) { + Calendar startCal = Calendar.getInstance(); + startCal.setTime(startDate); + Calendar endCal = Calendar.getInstance(); + endCal.setTime(endDate); + int workDays = 0; + if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) { + return 1; + } else { + if (startCal.getTimeInMillis() > endCal.getTimeInMillis()) { + startCal.setTime(endDate); + endCal.setTime(startDate); + } + + do { + if (startCal.get(7) != 7 && startCal.get(7) != 1) { + ++workDays; + } + + startCal.add(5, 1); + } while(startCal.getTimeInMillis() <= endCal.getTimeInMillis()); + + if (SpecialHolidays != 0) { + return workDays - SpecialHolidays; + } else { + return workDays; + } + } + } +} diff --git a/tools/api-automation/src/test/java/general/SendEmailAfterExecution.java b/tools/api-automation/src/test/java/general/SendEmailAfterExecution.java new file mode 100644 index 0000000..a4b7bdf --- /dev/null +++ b/tools/api-automation/src/test/java/general/SendEmailAfterExecution.java @@ -0,0 +1,71 @@ +package general; + + +import config.ConfigProperties; + +import java.time.LocalDate; +import java.util.Properties; +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; +import javax.mail.BodyPart; +import javax.mail.MessagingException; +import javax.mail.Multipart; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.Message.RecipientType; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; + +public class SendEmailAfterExecution { + + + public SendEmailAfterExecution() { + } + + public static void sendReportAfterExecution(Integer passed, Integer failed, Integer skipped) throws MessagingException { + Integer Total = passed + failed + skipped; + if (ConfigProperties.sendEmail.toLowerCase().equals("true")) { + String[] recepientTo = ConfigProperties.To; + String senderFrom = ConfigProperties.from; + String path = System.getProperty("user.dir") + "/reports/ExtentReport.html"; + + Properties prop = System.getProperties(); + prop.setProperty("mail.smtp.host", "smtp.gmail.com"); + Session session = Session.getDefaultInstance(prop); + MimeMessage msg = new MimeMessage(session); + InternetAddress frmAddress = new InternetAddress(senderFrom); + msg.setFrom(frmAddress); + + for(int i = 0; i < recepientTo.length; ++i) { + msg.addRecipients(RecipientType.TO, String.valueOf(new InternetAddress(recepientTo[i]))); + } + + LocalDate dateTime = LocalDate.now(); + msg.setSubject(ConfigProperties.Project + "-" + ConfigProperties.Platform + "-" + ConfigProperties.Environment + "-Execution Report " + dateTime); + BodyPart msgBody = new MimeBodyPart(); + msgBody.setText(ConfigProperties.Project + "-" + ConfigProperties.Platform + "-" + ConfigProperties.Environment + "-Execution Report " + dateTime + "\nTotal Cases Executed:" + Total + "\nPassed:" + passed + "\nFailed:" + failed + "\nSkipped:" + skipped); + Multipart multiPart = new MimeMultipart(); + multiPart.addBodyPart(msgBody); + msgBody = new MimeBodyPart(); + DataSource source = new FileDataSource(path); + DataHandler dataHandler = new DataHandler(source); + msgBody.setDataHandler(dataHandler); + msgBody.setFileName(path); + + multiPart.addBodyPart(msgBody); + msg.setContent(multiPart); + Transport transport = session.getTransport("smtps"); + transport.connect("smtp.gmail.com", 465, ConfigProperties.from, ConfigProperties.fromPassword); + transport.sendMessage(msg, msg.getAllRecipients()); + transport.close(); + System.out.println("Email send to respective Recipients"); + } else { + System.out.println("Email Not sent as permissions are not given"); + } + + } + +} diff --git a/tools/api-automation/src/test/java/general/TestRail.java b/tools/api-automation/src/test/java/general/TestRail.java new file mode 100644 index 0000000..45be5ec --- /dev/null +++ b/tools/api-automation/src/test/java/general/TestRail.java @@ -0,0 +1,145 @@ +package general; + +import com.google.common.base.Throwables; +import config.ConfigProperties; +import cucumber.api.Result; +import cucumber.api.Scenario; +import cucumber.runtime.ScenarioImpl; +import org.apache.commons.lang3.reflect.FieldUtils; + +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.time.LocalDate; +import java.util.*; +import java.util.stream.Stream; + +public class TestRail { + + public static String TestRunName; + public static Long suiteId; + static JSONParser jsonParser; + static APIClient client; + + public static void getCaseIdandResultBDD(Scenario scenario, String CaseId, Integer beforeAddingStepsLength, Integer afterAddingStepsLength, ArrayList automationSteps, Integer beforeAddingExpectedResultLength, Integer afterAddingExpectedResultLength, ArrayList expectedResults, String customPreconds) throws IOException, IllegalAccessException { + if (CaseId != null && CaseId != "") { + DataList.caseid.add(CaseId); + } + + DataList.result.add(getCaseResultBdd(scenario)); + DataList.updateData.add(updatetestcaseBdd(scenario, beforeAddingStepsLength, afterAddingStepsLength, automationSteps, beforeAddingExpectedResultLength, afterAddingExpectedResultLength, expectedResults, customPreconds)); + } + static { + TestRunName = "API"+ "-Automation-Test-" + LocalDate.now(); + jsonParser = new JSONParser(); + if (!Stream.of(ConfigProperties.testRailUrl, ConfigProperties.testRailUsername, ConfigProperties.testRailPassword).anyMatch(Objects::isNull) && !Stream.of(ConfigProperties.testRailUrl, ConfigProperties.testRailUsername, ConfigProperties.testRailPassword).anyMatch((i) -> { + return i.isEmpty(); + })) { + try { + client = new APIClient(ConfigProperties + .testRailUrl); + client.setUser(ConfigProperties.testRailUsername); + client.setPassword(ConfigProperties.testRailPassword); + } catch (Exception var1) { + System.out.println(Throwables.getStackTraceAsString(var1)); + } + } else { + System.out.println("Failed to read credentials for Test Rail. Please make sure the credentials are present in either config.properties or environmental variables"); + } + + } + + + public static Map getCaseResultBdd(Scenario scenario) throws IllegalAccessException { + Map data = new HashMap(); + if (scenario.getStatus() == Result.Type.PASSED) { + data.put("status_id", 1); + } else if (scenario.getStatus() == Result.Type.SKIPPED) { + data.put("status_id", 3); + } else { + data.put("status_id", 5); + Field field = FieldUtils.getField(((ScenarioImpl)scenario).getClass(), "stepResults", true); + field.setAccessible(true); + ArrayList results = (ArrayList)field.get(scenario); + Iterator var4 = results.iterator(); + + while(var4.hasNext()) { + Result result = (Result)var4.next(); + if (result.getError() != null) { + data.put("comment", result.getError().toString()); + } + } + + // data.put("defects", JiraServiceProvider.issueName); + } + + return data; + } + + public static Map updatetestcaseBdd(Scenario scenario, Integer beforeAddingStepsLength, Integer afterAddingStepsLength, ArrayList automationSteps, Integer beforeAddingExpectedResultLength, Integer afterAddingExpectedResultLength, ArrayList expectedResults, String customPreconds) { + ArrayList> dataset = new ArrayList(); + Map data1 = new HashMap(); + + for(int i = beforeAddingExpectedResultLength; i < afterAddingExpectedResultLength; ++i) { + HashMap stepData = new HashMap(); + if (automationSteps.get(i) == null) { + stepData.put("content", ""); + } else { + stepData.put("content", (String)automationSteps.get(i)); + } + + stepData.put("expected", (String)expectedResults.get(i)); + dataset.add(stepData); + } + + System.out.println("\n \n" + dataset); + data1.put("custom_steps_separated", dataset); + data1.put("custom_description", "" + scenario.getName()); + data1.put("custom_preconds", "" + customPreconds); + return data1; + } + + + public static void createSuite() throws IOException { + Map data = new HashMap(); + data.put("include_all", false); + System.out.println(DataList.caseid); + data.put("case_ids", DataList.caseid); + data.put("name", TestRunName); + JSONObject c = null; + if (client != null) { + try { + c = (JSONObject) client.sendPost("add_run/" + ConfigProperties.testTrailProjectId, data); //2 replace by project id + suiteId = (Long) c.get("id"); + } catch (Exception var3) { + System.out.println(Throwables.getStackTraceAsString(var3)); + } + } + } + public static void updateTestRail() throws IOException, APIException { + if (client != null) { + System.out.println(DataList.caseid); + + for(int i = 0; i < DataList.caseid.size(); ++i) { + System.out.println(DataList.caseid.get(i) + "" + DataList.result.get(i)); +// if (ConfigProperties.UpdateCase.toLowerCase().equals("true")) { +// try { +// client.sendPost("update_case/" + DataList.caseid.get(i), DataList.updateData.get(i)); +// } catch (Exception var3) { +// System.out.println(Throwables.getStackTraceAsString(var3)); +// } +// } + + try { + client.sendPost("add_result_for_case/" + suiteId + "/" + DataList.caseid.get(i), DataList.result.get(i)); + } catch (Exception var2) { + System.out.println(Throwables.getStackTraceAsString(var2)); + } + } + } + + } + +} diff --git a/tools/api-automation/src/test/java/payloads/Client.java b/tools/api-automation/src/test/java/payloads/Client.java new file mode 100644 index 0000000..3a05125 --- /dev/null +++ b/tools/api-automation/src/test/java/payloads/Client.java @@ -0,0 +1,66 @@ +package payloads; + +public class Client { + + public static String addClient(String baseEntityUuid,String addressUuid,String id_uuid) + { + return "{\n" + + " \"firstName\": \"Web\",\n" + + " \"lastName\": \"admin\",\n" + + " \"birthdate\":\"2019-12-09T00:00:00.000Z\",\n" + + " \"birthdateApprox\": false,\n" + + " \"deathdateApprox\": false,\n" + + " \"gender\": \"female\",\n" + + " \"baseEntityId\": \""+baseEntityUuid+"\",\n" + + " \"identifiers\": {\n" + + " \"M_ZEIR_ID\": \"1001202L_mother\"\n" + + " },\n" + + " \"addresses\": [\n" + + " {\n" + + " \"addressType\": \"usual_residence\",\n" + + " \"addressFields\": {\n" + + " \"address2\": \"Nouakchott\",\n" + + " \"address3\": \""+addressUuid+"\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"attributes\": {},\n" + + " \"dateCreated\": \"2019-12-12T16:32:55.557Z\",\n" + + " \"serverVersion\": 1576168375509,\n" + + " \"type\": \"Client\",\n" + + " \"id\": \""+id_uuid+"\",\n" + + " \"revision\": \"v1\"\n" + + "}"; + } + + public static String UpdateClient(String baseEntityUuid,String addressUuid,String id_uuid,String gender) + { + return "{\n" + + " \"firstName\": \"Web\",\n" + + " \"lastName\": \"admin\",\n" + + " \"birthdate\":\"2019-12-09T00:00:00.000Z\",\n" + + " \"birthdateApprox\": false,\n" + + " \"deathdateApprox\": false,\n" + + " \"gender\": \""+gender+"\",\n" + + " \"baseEntityId\": \""+baseEntityUuid+"\",\n" + + " \"identifiers\": {\n" + + " \"M_ZEIR_ID\": \"1001202L_mother\"\n" + + " },\n" + + " \"addresses\": [\n" + + " {\n" + + " \"addressType\": \"usual_residence\",\n" + + " \"addressFields\": {\n" + + " \"address2\": \"Nouakchott\",\n" + + " \"address3\": \""+addressUuid+"\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"attributes\": {},\n" + + " \"dateCreated\": \"2019-12-12T16:32:55.557Z\",\n" + + " \"serverVersion\": 1576168375509,\n" + + " \"type\": \"Client\",\n" + + " \"id\": \""+id_uuid+"\",\n" + + " \"revision\": \"v1\"\n" + + "}"; + } +} diff --git a/tools/api-automation/src/test/java/payloads/Events.java b/tools/api-automation/src/test/java/payloads/Events.java new file mode 100644 index 0000000..eb3f79a --- /dev/null +++ b/tools/api-automation/src/test/java/payloads/Events.java @@ -0,0 +1,173 @@ +package payloads; + +public class Events { + public static String addEvent(String clientBase,String clientAddress,String clientId,String teamName,String teamId,String eventBase,String location,String form,String eventId,String provider,String gender) + { + return "{\n" + + " \"clients\": [\n" + + " {\n" + + " \"firstName\": \"Web\",\n" + + " \"lastName\": \"admin\",\n" + + " \"birthdateApprox\": false,\n" + + " \"deathdateApprox\": false,\n" + + " \"gender\": \""+gender+"\",\n" + + " \"baseEntityId\": \""+clientBase+"\",\n" + + " \"identifiers\": {\n" + + " \"M_ZEIR_ID\": \"1001202L_mother\"\n" + + " },\n" + + " \"addresses\": [\n" + + " {\n" + + " \"addressType\": \"usual_residence\",\n" + + " \"addressFields\": {\n" + + " \"address2\": \"Nouakchott\",\n" + + " \"address3\": \""+clientAddress+"\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"attributes\": {},\n" + + " \"dateCreated\": \"2019-12-12T16:32:55.557Z\",\n" + + " \"serverVersion\": 1576168375509,\n" + + " \"type\": \"Client\",\n" + + " \"id\": \""+clientId+"\",\n" + + " \"revision\": \"v1\"\n" + + " }\n" + + " ],\n" + + " \"no_of_events\": 1,\n" + + " \"events\": [\n" + + " {\n" + + " \"identifiers\": {},\n" + + " \"baseEntityId\": \""+eventBase+"\",\n" + + " \"locationId\": \""+location+"\",\n" + + " \"eventDate\": \"2019-12-09T00:00:00.000Z\",\n" + + " \"eventType\": \"Birth Registration\",\n" + + " \"formSubmissionId\": \""+form+"\",\n" + + " \"providerId\": \""+provider+"\",\n" + + " \"duration\": 0,\n" + + " \"obs\": [\n" + + " {\n" + + " \"fieldType\": \"formsubmissionField\",\n" + + " \"fieldDataType\": \"text\",\n" + + " \"fieldCode\": \"isConsented\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"true\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"isConsented\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"concept\",\n" + + " \"fieldDataType\": \"text\",\n" + + " \"fieldCode\": \"5916AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"3.6\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"Birth_Weight\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"concept\",\n" + + " \"fieldDataType\": \"text\",\n" + + " \"fieldCode\": \"164826AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"Birth_Tetanus_Protection\",\n" + + " \"humanReadableValues\": [\n" + + " \"Yes\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"formsubmissionField\",\n" + + " \"fieldDataType\": \"text\",\n" + + " \"fieldCode\": \"Home_Facility\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"b1b8c8dd-55fe-4ad3-aa73-740ae3114cd5\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"Home_Facility\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"concept\",\n" + + " \"fieldDataType\": \"text\",\n" + + " \"fieldCode\": \"159635AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"69854785\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"Mother_Guardian_Phone_Number\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"formsubmissionField\",\n" + + " \"fieldDataType\": \"text\",\n" + + " \"fieldCode\": \"last_interacted_with\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"1575923858647\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"last_interacted_with\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"concept\",\n" + + " \"fieldDataType\": \"start\",\n" + + " \"fieldCode\": \"163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"2019-12-09 15:36:28\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"start\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"concept\",\n" + + " \"fieldDataType\": \"end\",\n" + + " \"fieldCode\": \"163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"2019-12-09 15:37:38\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"end\",\n" + + " \"humanReadableValues\": []\n" + + " },\n" + + " {\n" + + " \"fieldType\": \"concept\",\n" + + " \"fieldDataType\": \"deviceid\",\n" + + " \"fieldCode\": \"163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\n" + + " \"parentCode\": \"\",\n" + + " \"values\": [\n" + + " \"89fb8b070bbd5ce6\"\n" + + " ],\n" + + " \"set\": [],\n" + + " \"formSubmissionField\": \"deviceid\",\n" + + " \"humanReadableValues\": []\n" + + " }\n" + + " ],\n" + + " \"entityType\": \"child\",\n" + + " \"version\": 1575923858656,\n" + + " \"teamId\": \""+teamId+"\",\n" + + " \"team\": \""+teamName+"\",\n" + + " \"dateCreated\": \"2019-12-09T20:40:07.033Z\",\n" + + " \"serverVersion\": 1575924007025,\n" + + " \"clientApplicationVersion\": 11,\n" + + " \"clientDatabaseVersion\": 11,\n" + + " \"type\": \"Event\",\n" + + " \"id\": \""+eventId+"\",\n" + + " \"revision\": \"v1\"\n" + + " }\n" + + " ]\n" + + "}"; + } +} diff --git a/tools/api-automation/src/test/java/stepdefs/Authentication.java b/tools/api-automation/src/test/java/stepdefs/Authentication.java new file mode 100644 index 0000000..699721f --- /dev/null +++ b/tools/api-automation/src/test/java/stepdefs/Authentication.java @@ -0,0 +1,21 @@ +package stepdefs; + +import config.EndpointURLs; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import general.ReusableFunctions; + +import static stepdefs.Hooks.endPoint; + +public class Authentication { + @Given("I Set GET authentication api service endpoint") + public void i_Set_GET_authentication_api_service_endpoint() { + endPoint = EndpointURLs.GET_AUTHNETICATION; + } + @Then("I receive valid Response for GET Authentication service") + public void i_receive_valid_Response_for_GET_Authentication_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Authentication.validateUserName(); + } + +} diff --git a/tools/api-automation/src/test/java/stepdefs/Event.java b/tools/api-automation/src/test/java/stepdefs/Event.java new file mode 100644 index 0000000..a33330f --- /dev/null +++ b/tools/api-automation/src/test/java/stepdefs/Event.java @@ -0,0 +1,73 @@ +package stepdefs; + +import config.ConfigProperties; +import config.EndpointURLs; +import config.EnvGlobals; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import general.ReusableFunctions; +import payloads.Client; +import payloads.Events; +import utils.Uuid; + +import static stepdefs.Hooks.RequestPayLoad; +import static stepdefs.Hooks.endPoint; + +public class Event { + + + @Given("I Set POST event service api endpoint") + public void i_Set_POST_event_service_api_endpoint() { + EnvGlobals.eventBasicEntityID_uuid = Uuid.generateUuid(); + EnvGlobals.eventLocation_uuid = Uuid.generateUuid(); + EnvGlobals.formSubmissionId_uuid = Uuid.generateUuid(); + EnvGlobals.eventId_uuid=Uuid.generateUuid(); + endPoint = EndpointURLs.POST_EVENT; + RequestPayLoad = Events.addEvent(EnvGlobals.clientBasicEntityID_uuid,EnvGlobals.clientAddress_uuid,EnvGlobals.clientId_uuid,EnvGlobals.teamName,EnvGlobals.teamUuid,EnvGlobals.eventBasicEntityID_uuid,EnvGlobals.eventLocation_uuid ,EnvGlobals.formSubmissionId_uuid,EnvGlobals.eventId_uuid, ConfigProperties.username,"female"); + } + + @Then("I receive valid Response for POST event service") + public void i_receive_valid_Response_for_POST_event_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_CREATED); + } + +// @Given("I Set Put event service api endpoint") +// public void i_Set_Put_event_service_api_endpoint() { +// endPoint = EndpointURLs.POST_EVENT; +// RequestPayLoad = Events.addEvent(EnvGlobals.clientBasicEntityID_uuid,EnvGlobals.clientAddress_uuid,EnvGlobals.clientId_uuid,EnvGlobals.teamName,EnvGlobals.teamUuid,EnvGlobals.eventBasicEntityID_uuid,EnvGlobals.eventLocation_uuid ,EnvGlobals.formSubmissionId_uuid,EnvGlobals.eventId_uuid, ConfigProperties.username,"male"); +// } +// +// @Then("I receive valid Response for Put event service") +// public void i_receive_valid_Response_for_Put_event_service() { +// ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); +// } + + + @Given("I Set POST Client service api endpoint") + public void i_Set_POST_client_service_api_endpoint() { + EnvGlobals.clientBasicEntityID_uuid = Uuid.generateUuid(); + EnvGlobals.clientId_uuid = Uuid.generateUuid(); + EnvGlobals.clientAddress_uuid = Uuid.generateUuid(); + endPoint = EndpointURLs.POST_CLIENT; + RequestPayLoad = Client.addClient(EnvGlobals.clientBasicEntityID_uuid,EnvGlobals.clientAddress_uuid,EnvGlobals.clientId_uuid); + } + + @Then("I receive valid Response for POST Client service") + public void i_receive_valid_Response_for_POST_client_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Client.validateClientResponseBody(); + } + +// @Given("I Set Put Client service api endpoint") +// public void i_Set_Put_client_service_api_endpoint() { +// endPoint = EndpointURLs.POST_CLIENT; +// RequestPayLoad = Client.UpdateClient(EnvGlobals.clientBasicEntityID_uuid,EnvGlobals.clientAddress_uuid,EnvGlobals.clientId_uuid,"male"); +// } +// +// @Then("I receive valid Response for Put Client service") +// public void i_receive_valid_Response_for_Post_client_service() { +// ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); +// validation.Client.validateClientResponseBody(); +// validation.Client.validateUpdatedField("male"); +// } +} diff --git a/tools/api-automation/src/test/java/stepdefs/Hooks.java b/tools/api-automation/src/test/java/stepdefs/Hooks.java new file mode 100644 index 0000000..467e617 --- /dev/null +++ b/tools/api-automation/src/test/java/stepdefs/Hooks.java @@ -0,0 +1,90 @@ +package stepdefs; + +import com.relevantcodes.extentreports.ExtentTest; +import com.relevantcodes.extentreports.LogStatus; +import config.ConfigProperties; +import cucumber.api.Result; +import cucumber.api.Scenario; +import cucumber.api.java.After; +import cucumber.api.java.Before; +import cucumber.runtime.ScenarioImpl; +import general.GeneralFunctions; +import general.TestRail; +import org.apache.commons.lang3.reflect.FieldUtils; +import tests.RunCukesTest; +import utils.Reports; + +import java.lang.reflect.Field; +import java.util.ArrayList; + + +public class Hooks extends RunCukesTest { + public static final String HEADER_AUTHORIZATION = "Authorization"; + public static final String HTTP_METHOD_POST= "post"; + public static final String HTTP_METHOD_GET= "get"; + public static final String HTTP_METHOD_DELETE= "delete"; + public static final String HTTP_METHOD_PUT= "put"; + public static final int HTTP_RESPONSE_SUCCESS= 200; + public static final int HTTP_RESPONSE_CREATED= 201; + public static final int HTTP_RESPONSE_NO_CONTENT= 204; + public static final int HTTP_RESPONSE_NOT_FOUND = 404; + public static String caseID; + static ExtentTest logger; + public static Integer beforeAddingStepsLength; + public static Integer afterAddingStepsLength; + public static Integer beforeAddingExpectedResultLength; + public static Integer afterAddingExpectedResultLength; + public static String RequestPayLoad; + public static String endPoint; + + @Before + public static void testStart(Scenario scenario) throws Throwable { + beforeAddingStepsLength=automationSteps.size(); + beforeAddingExpectedResultLength=expectedResults.size(); + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) { + logger = Reports.getExtentReport().startTest(scenario.getName(), ""); + logger.setStartedTime(GeneralFunctions.getTime()); + } + + + } + + @After + public static void testEnd(Scenario scenario) throws Throwable + { + afterAddingStepsLength=automationSteps.size(); + afterAddingExpectedResultLength=expectedResults.size(); + if ( scenario.getStatus() == Result.Type.FAILED ) { + setFailCount(getFailCount()+1); + Field field = FieldUtils.getField(((ScenarioImpl) scenario).getClass(), "stepResults", true); + field.setAccessible(true); + ArrayList results = (ArrayList) field.get(scenario); + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) { + for (Result result : results) { + if (result.getError() != null) + logger.log(LogStatus.FAIL, "Test Case Failed reason is: " + result.getError()); + } + } + } + else if (scenario.getStatus() == Result.Type.SKIPPED ) { + setSkippedCount(getSkippedCount()+1); + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) + logger.log(LogStatus.SKIP, "Test Case Skipped is: "); + + } + else { + setPassCount(getPassCount()+1); + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) + logger.log(LogStatus.PASS, scenario.getName() + " is Passed"); + } + + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) + Reports.getExtentReport().endTest(logger); + if(ConfigProperties.logTestRail.toLowerCase().equals("true")) + TestRail.getCaseIdandResultBDD(scenario,caseID,beforeAddingStepsLength,afterAddingStepsLength,automationSteps,beforeAddingExpectedResultLength,afterAddingExpectedResultLength,expectedResults,null); + + + } + + +} \ No newline at end of file diff --git a/tools/api-automation/src/test/java/stepdefs/Search.java b/tools/api-automation/src/test/java/stepdefs/Search.java new file mode 100644 index 0000000..733788a --- /dev/null +++ b/tools/api-automation/src/test/java/stepdefs/Search.java @@ -0,0 +1,215 @@ +package stepdefs; + +import config.ConfigProperties; +import config.EndpointURLs; +import config.EnvGlobals; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import general.ReusableFunctions; + +import static stepdefs.Hooks.endPoint; + +public class Search { + @Given("I Set GET Unique Id request api service endpoint") + public void i_Set_GET_Unique_Id_request_api_service_endpoint() { + endPoint = EndpointURLs.GET_UNIQUE_ID_REQ; + } + + @Then("I receive valid Response for GET Unique Id request service") + public void i_receive_valid_Response_for_GET_Unique_Id_request_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Search Client By Path api service endpoint") + public void i_Set_Search_Client_By_Path_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_CLIENT_BY_PATH; + } + + @Then("I receive valid Response for Search Client By Path service") + public void i_receive_valid_Response_for_Search_Client_By_Path_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Search Client II api service endpoint") + public void i_Set_Search_Client_II_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_CLIENT_II; + } + + @Then("I receive valid Response for Search Client II service") + public void i_receive_valid_Response_for_Search_Client_II_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateLastName(); + } + + @Given("I Set Search Client By Gender api service endpoint") + public void i_Set_Search_Client_By_Gender_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_CLIENT_BY_GENDER; + } + + @Then("I receive valid Response for Search Client By Gender service") + public void i_receive_valid_Response_for_Search_Client_By_Gender_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateGender(); + } + + @Given("I Set Fetch Client By Id api service endpoint") + public void i_Set_Fetch_Client_By_Id_api_service_endpoint() { + endPoint = EndpointURLs.FETCH_CLIENT_BY_ID; + } + + @Then("I receive valid Response for SFetch Client By Id service") + public void i_receive_valid_Response_for_SFetch_Client_By_Id_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Search Client By Birthday api service endpoint") + public void i_Set_Search_Client_By_Birthday_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_CLIENT_BY_BIRTHDAY; + } + + @Then("I receive valid Response for Search Client By Birthday service") + public void i_receive_valid_Response_for_Search_Client_By_Birthday_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Search Client By Name api service endpoint") + public void i_Set_Search_Client_By_Name_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_CLIENT_BY_NAME; + } + + @Then("I receive valid Response for Search Client By Name service") + public void i_receive_valid_Response_for_Search_Client_By_Name_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateClientName(); + } + + @Given("I Set GET all users api service endpoint") + public void i_Set_GET_all_users_api_service_endpoint() { + endPoint = EndpointURLs.GET_ALL_USERS; + } + + @Then("I receive valid Response for GET all users service") + public void i_receive_valid_Response_for_GET_all_users_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set GET all events api service endpoint") + public void i_Set_GET_all_events_api_service_endpoint() { + endPoint = EndpointURLs.GET_ALL_EVENTS; + } + + @Then("I receive valid Response for GET all events service") + public void i_receive_valid_Response_for_GET_all_events_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set GET all stocks api service endpoint") + public void i_Set_GET_all_stocks_api_service_endpoint() { + endPoint = EndpointURLs.GET_ALL_STOCK; + } + + @Then("I receive valid Response for GET all stocks service") + public void i_receive_valid_Response_for_GET_all_stocks_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set GET stock by id api service endpoint") + public void i_Set_GET_stock_by_id_api_service_endpoint() { + endPoint = EndpointURLs.GET_ALL_STOCK_BY_ID; + } + + @Then("I receive valid Response for GET stock by id service") + public void i_receive_valid_Response_for_GET_stock_by_id_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Search Event By team api service endpoint") + public void i_Set_Search_Event_By_team_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SEARCH_EVENT_BY_TEAM, EnvGlobals.teamName); + } + + @Then("I receive valid Response for Search Event By team service") + public void i_receive_valid_Response_for_Search_Event_By_team_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateTeamName(); + } + + @Given("I Set Search Event By team id api service endpoint") + public void i_Set_Search_Event_By_team_id_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SEARCH_EVENT_BY_TEAM_ID,EnvGlobals.teamUuid); + } + + @Then("I receive valid Response for Search Event By team id service") + public void i_receive_valid_Response_for_Search_Event_By_team_id_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateTeamId(); + } + + @Given("I Set Search Event By Location id api service endpoint") + public void i_Set_Search_Event_By_Location_id_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SEARCH_EVENT_BY_LOCATION_ID,EnvGlobals.eventLocation_uuid); + } + + @Then("I receive valid Response for Search Event By Location id service") + public void i_receive_valid_Response_for_Search_Event_By_Location_id_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateLocationId(); + } + + @Given("I Set Search Event By Provider id api service endpoint") + public void i_Set_Search_Event_By_Provider_id_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SEARCH_EVENT_BY_PROVIDER_ID,ConfigProperties.username); + + } + + @Then("I receive valid Response for Search Event By Provider id service") + public void i_receive_valid_Response_for_Search_Event_By_Provider_id_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateProviderId(); + } + + @Given("I Set Search Event By Entity type api service endpoint") + public void i_Set_Search_Event_By_Entity_type_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_EVENT_BY_ENTITY_TYPE; + + } + + @Then("I receive valid Response for Search Event By Entity type service") + public void i_receive_valid_Response_for_Search_Event_By_Entity_type_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.Search.validateEntityType(); + } + + @Given("I Set Search Event By Event type api service endpoint") + public void i_Set_Search_Event_By_Event_type_api_service_endpoint() { + endPoint = EndpointURLs.SEARCH_EVENT_ID_BY_EVENT_TYPE; + } + + @Then("I receive valid Response for Search Event By Event type service") + public void i_receive_valid_Response_for_Search_Event_By_Event_type_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Search Event By id api service endpoint") + public void i_Set_Search_Event_By_id_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SEARCH_EVENT_BY_ID,EnvGlobals.eventId_uuid); + } + + @Then("I receive valid Response for Search Event By id service") + public void i_receive_valid_Response_for_Search_Event_By_id_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + @Given("I Set Fetch Provider action api service endpoint") + public void i_Set_Fetch_Provider_action_api_service_endpoint() { + endPoint = String.format(EndpointURLs.GET_PROVIDER_ACTION,ConfigProperties.username); + } + + @Then("I receive valid Response for Fetch Provider action service") + public void i_receive_valid_Response_for_Fetch_Provider_action_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + + +} + diff --git a/tools/api-automation/src/test/java/stepdefs/Syncing.java b/tools/api-automation/src/test/java/stepdefs/Syncing.java new file mode 100644 index 0000000..e31fc54 --- /dev/null +++ b/tools/api-automation/src/test/java/stepdefs/Syncing.java @@ -0,0 +1,69 @@ +package stepdefs; + +import config.ConfigProperties; +import config.EndpointURLs; +import config.EnvGlobals; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import general.ReusableFunctions; + +import static stepdefs.Hooks.endPoint; + +public class Syncing { + @Given("I Set GET Event Sync by Location api service endpoint") + public void i_Set_GET_Event_Sync_by_Location_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SYNC_BY_LOCATION, EnvGlobals.eventLocation_uuid); + + } + + @Then("I receive valid Response for GET Event Sync by Location service") + public void i_receive_valid_Response_for_GET_Event_Sync_by_Location_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.SYNC.validateSyncByLocation(); + + } + + @Given("I Set GET Event Sync by Provider api service endpoint") + public void i_Set_GET_Event_Sync_by_Provider_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SYNC_BY_PROVIDER, ConfigProperties.username); + + } + + @Then("I receive valid Response for GET Event Sync by Provider service") + public void i_receive_valid_Response_for_GET_Event_Sync_by_Provider_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.SYNC.validateProviderId(); + + } + + @Given("I Set GET Event Sync by Team api service endpoint") + public void i_Set_GET_Event_Sync_by_Team_api_service_endpoint() { + endPoint = String.format(EndpointURLs.SYNC_BY_TEAM,EnvGlobals.teamName); + + } + + @Then("I receive valid Response for GET Event Sync by Team service") + public void i_receive_valid_Response_for_GET_Event_Sync_by_Team_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + validation.SYNC.validateTeamId(); + + } + @Given("I Set GET Sync View Configuration api service endpoint") + public void i_Set_GET_Sync_View_Configuration_api_service_endpoint() { + endPoint = EndpointURLs.SYNC_VIEW_CONFIGURATION; + } + + @Then("I receive valid Response for GET Sync View Configuration service") + public void i_receive_valid_Response_for_GET_Sync_View_Configuration_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } + @Given("I Set Sync ServerSide Client api service endpoint") + public void i_Set_Sync_ServerSide_Client_api_service_endpoint() { + endPoint = EndpointURLs.SYNC_SERVERSIDE_SETTING; + } + + @Then("I receive valid Response for Sync ServerSide Client service") + public void i_receive_valid_Response_for_Sync_ServerSide_Client_service() { + ReusableFunctions.thenFunction(Hooks.HTTP_RESPONSE_SUCCESS); + } +} diff --git a/tools/api-automation/src/test/java/stepdefs/genericSteps.java b/tools/api-automation/src/test/java/stepdefs/genericSteps.java new file mode 100644 index 0000000..952476c --- /dev/null +++ b/tools/api-automation/src/test/java/stepdefs/genericSteps.java @@ -0,0 +1,43 @@ +package stepdefs; + +import config.ConfigProperties; +import config.EnvGlobals; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.When; +import general.ReusableFunctions; + +import static stepdefs.Hooks.RequestPayLoad; +import static stepdefs.Hooks.endPoint; + +public class genericSteps { + + @Given("I am Testing Case : {string}") + public void i_am_Testing_Case(String caseId) { + Hooks.caseID = caseId; + } + + @When("I Set request HEADER and PAYLOAD") + public void i_Set_request_HEADER_and_PAYLOAD() { + ReusableFunctions.givenHeaderPayload(ReusableFunctions.headers(Hooks.HEADER_AUTHORIZATION,EnvGlobals.accessToken), RequestPayLoad); + } + + @When("Send a POST HTTP request") + public void send_a_POST_HTTP_request() { + ReusableFunctions.whenFunction(Hooks.HTTP_METHOD_POST, ConfigProperties.baseUrl + endPoint); + } + @When("I Set request HEADER") + public void i_Set_request_HEADER() { + ReusableFunctions.givenHeaders(ReusableFunctions.headers(Hooks.HEADER_AUTHORIZATION,EnvGlobals.accessToken)); + } + @When("Send a GET HTTP request") + public void send_a_GET_HTTP_request() { + ReusableFunctions.whenFunction(Hooks.HTTP_METHOD_GET, ConfigProperties.baseUrl + endPoint); + } + + @When("Send a PUT HTTP request") + public void send_a_PUT_HTTP_request() { + ReusableFunctions.whenFunction(Hooks.HTTP_METHOD_PUT, ConfigProperties.baseUrl + endPoint); + } + + +} diff --git a/tools/api-automation/src/test/java/tests/RunCukesTest.java b/tools/api-automation/src/test/java/tests/RunCukesTest.java new file mode 100644 index 0000000..71a4d38 --- /dev/null +++ b/tools/api-automation/src/test/java/tests/RunCukesTest.java @@ -0,0 +1,95 @@ +package tests; + +import config.ConfigProperties; +import config.EnvGlobals; +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; + +import general.APIException; +import general.SendEmailAfterExecution; +import general.TestRail; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import utils.Reports; +import utils.TestUtils; + + +import javax.mail.MessagingException; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; + + + +import static config.ConfigProperties.sendEmail; + + +@RunWith(Cucumber.class) +@CucumberOptions(features = { "src/test/resources/feature" }, + glue = {"stepdefs"}, + plugin = { "pretty", "html:target/cucumber" }, + tags={"@auth,@client,@event,@Sync,@search"}) + + +public class RunCukesTest +{ + static Integer passedCount = 0; + static Integer failedCount = 0; + static Integer skippedCount = 0; + public static Integer getPassCount() + { + return passedCount; + } + public static Integer getFailCount() + { + return failedCount; + } + public static Integer getSkippedCount() + { + return skippedCount; + } + public static void setPassCount(Integer passCount) + { + passedCount=passCount; + } + public static void setFailCount(Integer failCount) + { + failedCount = failCount; + } + public static void setSkippedCount(Integer skipCount) + { + skippedCount = skipCount; + } + public static ArrayList automationSteps; + public static ArrayList expectedResults; + @BeforeClass + public static void beforeClass() throws SQLException { + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) + Reports.startReport(); + automationSteps = new ArrayList(); + expectedResults=new ArrayList(); + EnvGlobals.accessToken = "Bearer "+TestUtils.testOAuthWithAuthorizationCode(); + System.out.println(EnvGlobals.accessToken); + } + + @AfterClass + public static void AfterClass() throws IOException, MessagingException, APIException { + if(ConfigProperties.isReportingEnable.toLowerCase().equals("true")) { + Reports.getExtentReport().flush(); + Reports.getExtentReport().close(); + } + if(ConfigProperties.logTestRail.toLowerCase().equals("true")) { + TestRail.createSuite(); + TestRail.updateTestRail(); + + } + if (sendEmail.toLowerCase().equals("true")) { + SendEmailAfterExecution.sendReportAfterExecution(passedCount, failedCount, skippedCount); + } + + } + + + +} diff --git a/tools/api-automation/src/test/java/utils/Reports.java b/tools/api-automation/src/test/java/utils/Reports.java new file mode 100644 index 0000000..59cb211 --- /dev/null +++ b/tools/api-automation/src/test/java/utils/Reports.java @@ -0,0 +1,27 @@ +package utils; + +import com.relevantcodes.extentreports.ExtentReports; +import config.ConfigProperties; + +public class Reports { + + private static ExtentReports extent; + + public static void startReport() { + extent = new ExtentReports(System.getProperty("user.dir") + ConfigProperties.htmlReportPath, true); + } + + public static ExtentReports getExtentReport() { + if (extent != null) { + return extent; + } else { + throw new IllegalStateException("Extent Report object not initialized"); + } + } + public static String getReportConfigPath(){ + String reportConfigPath = System.getProperty("user.dir")+"/extend-config2.xml"; + if(reportConfigPath!= null) return reportConfigPath; + else throw new RuntimeException("Report Config Path not specified in the Configuration.properties file for the Key:reportConfigPath"); + } + +} diff --git a/tools/api-automation/src/test/java/utils/TestUtils.java b/tools/api-automation/src/test/java/utils/TestUtils.java new file mode 100644 index 0000000..6d6f87b --- /dev/null +++ b/tools/api-automation/src/test/java/utils/TestUtils.java @@ -0,0 +1,25 @@ +package utils; + +import config.ConfigProperties; +import io.restassured.response.Response; +import org.json.JSONException; +import org.json.JSONObject; + +import static io.restassured.RestAssured.given; + +public class TestUtils { + public static String testOAuthWithAuthorizationCode() throws JSONException { + Response response = given().auth().preemptive().basic("opensrp-stage-server", ConfigProperties.privateKey) + .contentType("application/x-www-form-urlencoded") + .formParam("grant_type", "password") + .formParam("username", ConfigProperties.username) + .formParam("password", ConfigProperties.password) + .when() + .post("https://keycloak-stage.smartregister.org/auth/realms/opensrp-web-stage/protocol/openid-connect/token"); + + JSONObject jsonObject = new JSONObject(response.getBody().asString()); + String accessToken = jsonObject.get("access_token").toString(); + System.out.println(accessToken); + return accessToken; + } +} \ No newline at end of file diff --git a/tools/api-automation/src/test/java/utils/Uuid.java b/tools/api-automation/src/test/java/utils/Uuid.java new file mode 100644 index 0000000..29056d1 --- /dev/null +++ b/tools/api-automation/src/test/java/utils/Uuid.java @@ -0,0 +1,26 @@ +package utils; + +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; + +public class Uuid { + + public static int randomNum; + + public static int generateRandomRequestUuid() { + randomNum = ThreadLocalRandom.current().nextInt(1, 100000000 + 1); + return randomNum; + } + + public static int generateRandomNumber() { + randomNum = ThreadLocalRandom.current().nextInt(1, 100000 + 1); + return randomNum; + } + + public static String generateUuid() { + UUID uuid = UUID.randomUUID(); + String uuidAsString = uuid.toString(); + return uuidAsString; + } + +} diff --git a/tools/api-automation/src/test/java/validation/Authentication.java b/tools/api-automation/src/test/java/validation/Authentication.java new file mode 100644 index 0000000..a722bde --- /dev/null +++ b/tools/api-automation/src/test/java/validation/Authentication.java @@ -0,0 +1,17 @@ +package validation; + +import config.ConfigProperties; +import config.EnvGlobals; +import general.ReusableFunctions; +import org.junit.Assert; + +public class Authentication { + + public static void validateUserName() { + EnvGlobals.teamName = ReusableFunctions.getResponsePath("team.team.teamName"); + EnvGlobals.teamUuid = ReusableFunctions.getResponsePath("team.uuid"); + System.out.println(EnvGlobals.teamName); + System.out.println(EnvGlobals.teamUuid); + Assert.assertEquals(ReusableFunctions.getResponsePath("user.username"), ConfigProperties.username); + } +} diff --git a/tools/api-automation/src/test/java/validation/Client.java b/tools/api-automation/src/test/java/validation/Client.java new file mode 100644 index 0000000..2825fac --- /dev/null +++ b/tools/api-automation/src/test/java/validation/Client.java @@ -0,0 +1,22 @@ +package validation; + +import config.ConfigProperties; +import config.EnvGlobals; +import general.ReusableFunctions; +import org.junit.Assert; + +public class Client { + + public static void validateClientResponseBody() { + EnvGlobals.clientBasicEntityID_uuid = ReusableFunctions.getResponsePath("baseEntityId"); + EnvGlobals.clientId_uuid = ReusableFunctions.getResponsePath("_id"); + Assert.assertNotNull(ReusableFunctions.getResponsePath("baseEntityId")); + Assert.assertNotNull(ReusableFunctions.getResponsePath("_id")); + Assert.assertEquals(ReusableFunctions.getResponsePath("addresses.addressFields.address3"), "["+EnvGlobals.clientAddress_uuid+"]"); + } + + + public static void validateUpdatedField(String gender) { + Assert.assertEquals(ReusableFunctions.getResponsePath("gender"), gender); + } +} diff --git a/tools/api-automation/src/test/java/validation/ManagingOrg.java b/tools/api-automation/src/test/java/validation/ManagingOrg.java new file mode 100644 index 0000000..14383fc --- /dev/null +++ b/tools/api-automation/src/test/java/validation/ManagingOrg.java @@ -0,0 +1,51 @@ +package validation; + +import com.jayway.jsonpath.JsonPath; +import config.EnvGlobals; +import general.ReusableFunctions; +import org.junit.Assert; + +public class ManagingOrg { + + public static final String RESPONSE_ID = "id"; + public static final String RESPONSE_NAME = "name"; + public static final String RESPONSE_RESOURCE_TYPE = "resourceType"; + public static final String RESPONSE_LINE = "address.line"; + public static final String RESPONSE_CITY = "address.city"; + public static final String RESPONSE_STATE = "address.state"; + public static final String RESPONSE_POSTAL= "address.postalCode"; + public static final String RESPONSE_COUNTRY = "address.country"; + public static final String RESPONSE_ENTRY = "entry[%s].resource."; + + + + public static void validatePostResponse(String name) { + Assert.assertNotNull(ReusableFunctions.getResponsePath(RESPONSE_ID)); + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_NAME), name); + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_RESOURCE_TYPE), "Organization"); + } + + public static void validateOrganizationId(String id) { + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_ID), id); + } + public static void validateOrganizationAddress() { + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_LINE), "[[3300 Washtenaw Avenue, Suite 227]]"); + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_CITY), "[Ann Arbor]"); + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_STATE), "[MI]"); + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_POSTAL), "[48104]"); + Assert.assertEquals(ReusableFunctions.getResponsePath(RESPONSE_COUNTRY), "[USA]"); + } + + public static void validateLocation() + { + + for(int i = 0 ; i< 10;i++) { + + Assert.assertEquals(ReusableFunctions.getResponsePath(String.format(RESPONSE_ENTRY+RESPONSE_STATE,i)), "[MI]"); + + } + } + + + +} diff --git a/tools/api-automation/src/test/java/validation/SYNC.java b/tools/api-automation/src/test/java/validation/SYNC.java new file mode 100644 index 0000000..e3ce6a9 --- /dev/null +++ b/tools/api-automation/src/test/java/validation/SYNC.java @@ -0,0 +1,40 @@ +package validation; + +import config.ConfigProperties; +import config.EnvGlobals; +import cucumber.runtime.Env; +import general.ReusableFunctions; +import org.junit.Assert; + +public class SYNC { + + public static void validateSyncByLocation() { + Assert.assertEquals(ReusableFunctions.getResponsePath("events.type"), "[Event]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events.baseEntityId"), "["+EnvGlobals.eventBasicEntityID_uuid+"]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events.locationId"), "["+EnvGlobals.eventLocation_uuid+"]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events.formSubmissionId"), "["+EnvGlobals.formSubmissionId_uuid+"]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events.providerId"), "["+ConfigProperties.username+"]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events.teamId"),"["+ EnvGlobals.teamUuid+"]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events.team"), "["+EnvGlobals.teamName+"]"); + Assert.assertEquals(ReusableFunctions.getResponsePath("events._id"), "["+EnvGlobals.eventId_uuid+"]"); + } + + + public static void validateProviderId() + { + for(int i=0;i} +ProjectDescription= API Automation Results + +Platform= API +Project= SERVER API +Environment= QA \ No newline at end of file diff --git a/tools/api-automation/src/test/resources/feature/01authentication.feature b/tools/api-automation/src/test/resources/feature/01authentication.feature new file mode 100644 index 0000000..2c3c73e --- /dev/null +++ b/tools/api-automation/src/test/resources/feature/01authentication.feature @@ -0,0 +1,13 @@ +@test @auth +Feature: Authentication + + + @test + Scenario: Get Security Authentication + Given I am Testing Case : "115" + Given I Set GET authentication api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET Authentication service + + diff --git a/tools/api-automation/src/test/resources/feature/02_event.feature b/tools/api-automation/src/test/resources/feature/02_event.feature new file mode 100644 index 0000000..1cfdc6a --- /dev/null +++ b/tools/api-automation/src/test/resources/feature/02_event.feature @@ -0,0 +1,39 @@ + + +Feature: event + + @test @client + Scenario: Create New Client + Given I am Testing Case : "115" + And I Set POST Client service api endpoint + When I Set request HEADER and PAYLOAD + And Send a POST HTTP request + Then I receive valid Response for POST Client service + + @test @client + Scenario: Update Client + Given I am Testing Case : "115" + And I Set Put Client service api endpoint + When I Set request HEADER and PAYLOAD + And Send a PUT HTTP request + Then I receive valid Response for Put Client service + + + @test @event + Scenario: Create New Event + Given I am Testing Case : "115" + And I Set POST event service api endpoint + When I Set request HEADER and PAYLOAD + And Send a POST HTTP request + Then I receive valid Response for POST event service + + + @test @event + Scenario: Update Event + Given I am Testing Case : "115" + And I Set Put event service api endpoint + When I Set request HEADER and PAYLOAD + And Send a PUT HTTP request + Then I receive valid Response for Put event service + + diff --git a/tools/api-automation/src/test/resources/feature/03_Search.feature b/tools/api-automation/src/test/resources/feature/03_Search.feature new file mode 100644 index 0000000..7171794 --- /dev/null +++ b/tools/api-automation/src/test/resources/feature/03_Search.feature @@ -0,0 +1,141 @@ +@test @search +Feature: Search + + Scenario: Get Unique Id request + Given I am Testing Case : "115" + Given I Set GET Unique Id request api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET Unique Id request service + + + Scenario: Search Client By Path + Given I am Testing Case : "115" + Given I Set Search Client By Path api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Client By Path service + + + + Scenario: Search Client II + Given I am Testing Case : "115" + Given I Set Search Client II api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Client II service + + Scenario: Search Client By Gender + Given I am Testing Case : "115" + Given I Set Search Client By Gender api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Client By Gender service + + Scenario: Fetch Client By Id + Given I am Testing Case : "115" + Given I Set Fetch Client By Id api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for SFetch Client By Id service + + Scenario: Search Client By Birthday + Given I am Testing Case : "115" + Given I Set Search Client By Birthday api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Client By Birthday service + + Scenario: Search Client By Name + Given I am Testing Case : "115" + Given I Set Search Client By Name api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Client By Name service + + Scenario: Get All users + Given I am Testing Case : "115" + Given I Set GET all users api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET all users service + + Scenario: Get All Events + Given I am Testing Case : "115" + Given I Set GET all events api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET all events service + + Scenario: Get All stocks + Given I am Testing Case : "115" + Given I Set GET all stocks api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET all stocks service + + Scenario: Get stock by id + Given I am Testing Case : "115" + Given I Set GET stock by id api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET stock by id service + + Scenario: Search Event By team + Given I am Testing Case : "115" + Given I Set Search Event By team api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By team service + + Scenario: Search Event By team id + Given I am Testing Case : "115" + Given I Set Search Event By team id api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By team id service + + + Scenario: Search Event By Location id + Given I am Testing Case : "115" + Given I Set Search Event By Location id api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By Location id service + + Scenario: Search Event By Provider id + Given I am Testing Case : "115" + Given I Set Search Event By Provider id api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By Provider id service + + + Scenario: Search Event By Entity type + Given I am Testing Case : "115" + Given I Set Search Event By Entity type api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By Entity type service + + Scenario: Search Event By Event type + Given I am Testing Case : "115" + Given I Set Search Event By Event type api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By Event type service + + Scenario: Search Event By id + Given I am Testing Case : "115" + Given I Set Search Event By id api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Search Event By id service + + + Scenario: Fetch Provider action + Given I am Testing Case : "115" + Given I Set Fetch Provider action api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Fetch Provider action service diff --git a/tools/api-automation/src/test/resources/feature/03_Syncing.feature b/tools/api-automation/src/test/resources/feature/03_Syncing.feature new file mode 100644 index 0000000..141f9c5 --- /dev/null +++ b/tools/api-automation/src/test/resources/feature/03_Syncing.feature @@ -0,0 +1,45 @@ +@test +Feature: Sync + + + @Sync @loc + Scenario: Get Event Sync by Location + Given I am Testing Case : "115" + Given I Set GET Event Sync by Location api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET Event Sync by Location service + + @Sync + Scenario: Get Event Sync by Provider + Given I am Testing Case : "115" + Given I Set GET Event Sync by Provider api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET Event Sync by Provider service + + + @Sync + Scenario: Get Event Sync by Team + Given I am Testing Case : "115" + Given I Set GET Event Sync by Team api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET Event Sync by Team service + + @Sync + Scenario: Get Sync View Configuration + Given I am Testing Case : "115" + Given I Set GET Sync View Configuration api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for GET Sync View Configuration service + + + @Sync + Scenario: Sync ServerSide Client + Given I am Testing Case : "115" + Given I Set Sync ServerSide Client api service endpoint + When I Set request HEADER + And Send a GET HTTP request + Then I receive valid Response for Sync ServerSide Client service