Skip to content

Commit

Permalink
Merge pull request #258 from jayesh12234/develop
Browse files Browse the repository at this point in the history
MOSIP-30901
  • Loading branch information
aranaravi authored Jan 8, 2024
2 parents 73f776c + 10eaaea commit 6a0f24d
Show file tree
Hide file tree
Showing 18 changed files with 1,487 additions and 140 deletions.
66 changes: 62 additions & 4 deletions .github/workflows/push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,71 @@ jobs:
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

build-docker-admintest:
build-admintest-local:
needs: build-maven-admintest
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.dev_namespace_docker_hub }}
SERVICE_NAME: admintest
SERVICE_LOCATION: admintest
BUILD_ARTIFACT: admintest-local
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
ref: ${{ github.ref }}
java-version: 11
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup the settings file for ossrh server
run: echo "<settings> <servers> <server> <id>ossrh</id> <username>${{secrets.ossrh_user}}</username> <password>${{secrets.ossrh_secret}}</password> </server> </servers> <profiles> <profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>gpg2</gpg.executable> <gpg.passphrase>${{secrets.gpg_secret}}</gpg.passphrase> </properties> </profile> <profile> <id>allow-snapshots</id> <activation><activeByDefault>true</activeByDefault></activation> <repositories> <repository> <id>snapshots-repo</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>releases-repo</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </repository> </repositories> </profile> <profile> <id>sonar</id> <properties> <sonar.sources>.</sonar.sources> <sonar.host.url>https://sonarcloud.io</sonar.host.url> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles> </settings>" > $GITHUB_WORKSPACE/settings.xml

- name: Build residentuitests with Maven
run: |
cd ${{ env.SERVICE_LOCATION}}
mvn -U -B package -Dmaven.wagon.http.retryHandler.count=2 --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
- name: Ready the springboot artifacts
if: ${{ !contains(github.ref, 'master') || !contains(github.ref, 'main') }}
run: |
## FIND JARS & COPY ONLY EXECUTABLE JARs STORED UNDER TARGET DIRECTORY
find ${{ env.SERVICE_LOCATION }} -path '*/target/*' -name '*.jar' -type f -exec zip ${{ env.BUILD_ARTIFACT }}.zip {} +
- name: Upload the springboot jars
if: ${{ !contains(github.ref, 'master') || !contains(github.ref, 'main') }}
uses: actions/upload-artifact@v3
with:
name: ${{ env.BUILD_ARTIFACT }}
path: ${{ env.BUILD_ARTIFACT }}.zip

- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,author,commit,workflow,job # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: failure() # Pick up events even if the job fails or is canceled.


build-docker-admintest:
needs: build-admintest-local
strategy:
matrix:
include:
- SERVICE_LOCATION: 'admintest'
SERVICE_NAME: 'admintest'
BUILD_ARTIFACT: 'admintest'
BUILD_ARTIFACT: 'admintest-local'
fail-fast: false
name: ${{ matrix.SERVICE_NAME }}
uses: mosip/kattu/.github/workflows/docker-build.yml@master
Expand All @@ -98,8 +155,9 @@ jobs:
ACTOR_DOCKER_HUB: ${{ secrets.ACTOR_DOCKER_HUB }}
RELEASE_DOCKER_HUB: ${{ secrets.RELEASE_DOCKER_HUB }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

sonar-analysis-admintest:
needs: build-maven-admintest
needs: build-admintest-local
if: "${{ github.event_name != 'pull_request' }}"
uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master
with:
Expand All @@ -113,4 +171,4 @@ jobs:
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
35 changes: 20 additions & 15 deletions admintest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
FROM openjdk:11-jre
FROM selenium/standalone-chrome:latest

USER root

# Define build-time arguments
ARG SOURCE
ARG COMMIT_HASH
ARG COMMIT_ID
ARG BUILD_TIME

# Set labels for metadata
LABEL source=${SOURCE}
LABEL commit_hash=${COMMIT_HASH}
LABEL commit_id=${COMMIT_ID}
LABEL build_time=${BUILD_TIME}

# can be passed during Docker build as build time environment for github branch to pickup configuration from.
# Define build-time arguments for user and group
ARG container_user=mosip

# can be passed during Docker build as build time environment for github branch to pickup configuration from.
ARG container_user_group=mosip

# can be passed during Docker build as build time environment for github branch to pickup configuration from.
ARG container_user_uid=1001

# can be passed during Docker build as build time environment for github branch to pickup configuration from.
ARG container_user_gid=1001

# set working directory for the user
# Set working directory for the user
ENV work_dir=/home/${container_user}/

# install packages and create user
RUN groupadd -g ${container_user_gid} ${container_user_group} \
&& useradd -u ${container_user_uid} -g ${container_user_group} -s /bin/bash -m ${container_user} -d ${work_dir}
&& useradd -u ${container_user_uid} -g ${container_user_group} -s /bin/bash -m ${container_user} -d ${work_dir} \
&& chown -R ${container_user}:${container_user} /home/${container_user}/

# select container user for all tasks
# Switch to the specified user for the subsequent commands
USER ${container_user_uid}:${container_user_gid}

# Copy files
COPY --chown=${container_user_uid}:${container_user} --chmod=771 ./entrypoint.sh ${work_dir}/entrypoint.sh
COPY --chown=${container_user}:${container_user} ./src/main/resources/ ${work_dir}
COPY --chown=${container_user}:${container_user} ./src/main/resources/ ${work_dir}/resources/
COPY --chown=${container_user_uid}:${container_user} ./target/*.jar ${work_dir}

# Set working directory
WORKDIR /home/${container_user}/


# set working directory
WORKDIR ${work_dir}

ENTRYPOINT ["/bin/bash", "-c", "./entrypoint.sh"]
# Entrypoint for the container
ENTRYPOINT ["/bin/bash", "-c", "./entrypoint.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import static io.restassured.RestAssured.given;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

import io.mosip.testrig.adminui.kernel.util.ConfigManager;
import io.restassured.RestAssured;
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
Expand All @@ -14,6 +18,7 @@
public class RestClient {

private static final Logger RESTCLIENT_LOGGER = Logger.getLogger(RestClient.class);
public static String ZONECODE;
private static RestAssuredConfig config = RestAssured.config()
.httpClient(HttpClientConfig.httpClientConfig().setParam("http.connection.timeout", 500000)
.setParam("http.socket.timeout", 500000).setParam("http.connection-manager.timeout", 500000));
Expand All @@ -30,6 +35,40 @@ public static Response getRequest(String url, String contentHeader, String accep
return getResponse;
}

static String getZoneCode(JSONArray responseArray, String code) {
String ZoneCode="";

for (int i = 0; i < responseArray.length(); i++) {
ZoneCode = responseArray.getJSONObject(i).getString("code");
}

return ZoneCode;
}
public static Response getRequestWithCookieAndPathParm(String url, Map<String, String> body, String contentHeader,
String acceptHeader, String cookieName, String cookieValue) {
Response getResponse;
JSONObject responseJson = null;

RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a GET request to " + url);

getResponse = given().config(config).relaxedHTTPSValidation().pathParams(body)
.cookie(cookieName, cookieValue).log().all().when().get(url).then().log().all().extract()
.response();

RESTCLIENT_LOGGER.info( getResponse.asString());
RESTCLIENT_LOGGER.info( getResponse.time());
responseJson = new JSONObject(getResponse.getBody().asString());
if(responseJson.has("response")) {
org.json.JSONArray responseArray = responseJson.getJSONArray("response");
ZONECODE = getZoneCode (responseArray,"code");
RESTCLIENT_LOGGER.info( ZONECODE);

}


return getResponse;
}

public static Response getRequestWithCookie(String url, String contentHeader, String acceptHeader,
String cookieName, String cookieValue) {
RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a GET request to " + url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void execute(Connection connection) throws SQLException {
statement
.addBatch("delete from zone_user_h where cr_by ='"+BaseClass.userid+"'");
statement.addBatch("delete from blocklisted_words where cr_by ='"+BaseClass.userid+"'");
statement.addBatch("delete from bulkupload_transaction where cr_by ='"+BaseClass.userid+"'");



Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package io.mosip.testrig.adminui.fw.util;
import static io.restassured.RestAssured.given;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand All @@ -21,6 +26,8 @@
import io.mosip.testrig.adminui.kernel.util.KernelAuthentication;
import io.mosip.testrig.adminui.kernel.util.KeycloakUserManager;
import io.mosip.testrig.adminui.utility.BaseTestCaseFunc;
import io.mosip.testrig.adminui.utility.TestRunner;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.apache.commons.lang.RandomStringUtils;

Expand All @@ -32,6 +39,9 @@ public class AdminTestUtil extends BaseTestCaseFunc {
public static String tokenRoleIdRepo = "idrepo";
public static String tokenRoleAdmin = "admin";
public static boolean initialized = false;
public static String propsHealthCheckURL = TestRunner.getResourcePath() + "/"
+ "config/healthCheckEndpoint.properties";
private static String serverComponentsCommitDetails;

public static String getUnUsedUIN(String role){

Expand All @@ -53,6 +63,63 @@ public static String getMasterDataSchema(String role){

return response.asString();
}
public static String getCommitDetails(String path) {

Response response = null;
response = given().contentType(ContentType.JSON).get(path);
if (response != null && response.getStatusCode() == 200) {
logger.info(response.getBody().asString());
JSONObject jsonResponse = new JSONObject(response.getBody().asString());
return "Group: " + jsonResponse.getJSONObject("build").getString("group") + ", Artifact: "
+ jsonResponse.getJSONObject("build").getString("artifact") + ", version: "
+ jsonResponse.getJSONObject("build").getString("version") + ", Commit ID: "
+ jsonResponse.getJSONObject("git").getJSONObject("commit").getString("id");
}
return path + "- No Response";
}
public static String getServerComponentsDetails() {
if (serverComponentsCommitDetails != null && !serverComponentsCommitDetails.isEmpty())
return serverComponentsCommitDetails;

File file = new File(propsHealthCheckURL);
FileReader fileReader = null;
BufferedReader bufferedReader = null;
StringBuilder stringBuilder = new StringBuilder();
try {
fileReader = new FileReader(file);
bufferedReader = new BufferedReader(fileReader);
String line;

while ((line = bufferedReader.readLine()) != null) {
if (line.trim().equals("") || line.trim().startsWith("#"))
continue;
String[] parts = line.trim().split("=");
if (parts.length > 1) {
if (ConfigManager.isInServiceNotDeployedList(parts[1])) {
continue;
}
stringBuilder.append("\n")
.append(getCommitDetails(BaseTestCaseFunc.ApplnURI + parts[1].replace("health", "info")));
}
}
} catch (Exception e) {
logger.error(e.getMessage());
} finally {
AdminTestUtil.closeBufferedReader(bufferedReader);
AdminTestUtil.closeFileReader(fileReader);
}
serverComponentsCommitDetails = stringBuilder.toString();
return serverComponentsCommitDetails;
}
public static void closeBufferedReader(BufferedReader bufferedReader) {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
// logger.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
}
}
}

public static String generateCurrentUTCTimeStamp() {
Date date = new Date();
Expand All @@ -74,6 +141,15 @@ public static boolean activateUIN(String inputJson, String role) {

return responseJson.getJSONObject("response").getString("status").equalsIgnoreCase("ACTIVATED");
}
public static void closeFileReader(FileReader fileReader) {
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {
// logger.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
}
}
}

public static String buildaddIdentityRequestBody(String schemaJson, String uin, String rid) {
org.json.JSONObject schemaresponseJson = new org.json.JSONObject(schemaJson);
Expand Down Expand Up @@ -237,7 +313,8 @@ public static void initialize() {

// Generate Keycloak Users
KeycloakUserManager.createUsers();
BaseTestCaseFunc.mapUserToZone(BaseTestCaseFunc.currentModule+"-"+propsKernel.getProperty("admin_userName"),"CSB");
BaseTestCaseFunc.getLeafeZone();
BaseTestCaseFunc.mapUserToZone(BaseTestCaseFunc.currentModule+"-"+propsKernel.getProperty("admin_userName"),RestClient.ZONECODE);
BaseTestCaseFunc.mapZone(BaseTestCaseFunc.currentModule+"-"+propsKernel.getProperty("admin_userName"));
initialized = true;
}
Expand Down
Loading

0 comments on commit 6a0f24d

Please sign in to comment.