Skip to content

Commit

Permalink
Issue #LR-583 merge: release-5.4.0 to master (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmiableAnil authored Oct 27, 2023
1 parent 461c188 commit d96e779
Show file tree
Hide file tree
Showing 68 changed files with 410 additions and 312 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- checkout
- restore_cache:
key: userorg-dependency-cache-{{ checksum "pom.xml" }}
- run: mvn clean install
- run: mvn clean install -DCLOUD_STORE_GROUP_ID=$CLOUD_STORE_GROUP_ID -DCLOUD_STORE_ARTIFACT_ID=$CLOUD_STORE_ARTIFACT_ID -DCLOUD_STORE_VERSION=$CLOUD_STORE_VERSION
- run: cd controller && mvn play2:dist
- save_cache:
key: userorg-dependency-cache-{{ checksum "pom.xml" }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ RUNNING_PID
/.target/
/bin/
/logs
.vscode
.vscode/**
2 changes: 1 addition & 1 deletion Dockerfile.Build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ ENV M2_HOME /opt/apache-maven-3.3.9
ENV PATH ${M2_HOME}/bin:${PATH}
COPY userorg /opt/userorg/
WORKDIR /opt/userorg/services
RUN mvn clean install -DskipTests
RUN mvn clean install -DskipTests -DCLOUD_STORE_GROUP_ID=org.sunbird -DCLOUD_STORE_ARTIFACT_ID=cloud-store-sdk -DCLOUD_STORE_VERSION=1.4.6
WORKDIR /opt/userorg/services/userorg-service
CMD ["mvn", "play2:dist"]
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ node('build-slave') {
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
sh 'git log -1'
sh 'mvn clean install -U -DskipTests=true '
sh "mvn clean install -DskipTests=true -DCLOUD_STORE_GROUP_ID=${params.cloud_store_group_id} -DCLOUD_STORE_ARTIFACT_ID=${params.cloud_store_artifact_id} -DCLOUD_STORE_VERSION=${params.cloud_store_version}"
}

stage('Unit Tests') {
sh "mvn clean install '-Dtest=!%regex[io.opensaber.registry.client.*]' -DfailIfNoTests=false"
sh "mvn clean install '-Dtest=!%regex[io.opensaber.registry.client.*]' -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -DCLOUD_STORE_GROUP_ID=org.sunbird -DCLOUD_STORE_ARTIFACT_ID=cloud-store-sdk -DCLOUD_STORE_VERSION=1.4.6"
}
stage('Package') {
dir('controller') {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ git clone https://github.com/Sunbird-Lern/sunbird-lms-service.git

3. Build the application using the following maven command in the path `<project-base-path>/sunbird-lms-service`:
```shell
mvn clean install -DskipTests
mvn clean install -DskipTests -DCLOUD_STORE_GROUP_ID=org.sunbird -DCLOUD_STORE_ARTIFACT_ID=cloud-store-sdk -DCLOUD_STORE_VERSION=1.4.6
```
Make sure the build is successful before proceeding to the next step. If the build is not successful,
fix any configuration issues and rebuild the application.
Expand Down
2 changes: 1 addition & 1 deletion auto_build_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ node('build-slave') {

// stage Build
env.NODE_ENV = "build"
sh 'mvn clean install -U -DskipTests=false '
sh "mvn clean install -U -DskipTests=false -DCLOUD_STORE_GROUP_ID=${params.cloud_store_group_id} -DCLOUD_STORE_ARTIFACT_ID=${params.cloud_store_artifact_id} -DCLOUD_STORE_VERSION=${params.cloud_store_version}"

// stage Package
dir('controller') {
Expand Down
6 changes: 3 additions & 3 deletions controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.1</version>
<version>2.10.5.1</version>
</dependency>
<!-- Add actor here itself to avoid netty jar conflict. -->
<dependency>
Expand Down Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-netty-server_2.11</artifactId>
<version>2.7.2</version>
<version>${play2.version}</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -212,7 +212,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
package controllers.organisationmanagement;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;

import akka.stream.javadsl.FileIO;
import akka.stream.javadsl.Source;
import akka.util.ByteString;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import controllers.BaseApplicationTest;
import controllers.DummyActor;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import modules.OnRequestHandler;
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -29,15 +15,24 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.sunbird.exception.ResponseCode;
import org.sunbird.keys.JsonKey;
import org.sunbird.response.Response;
import org.sunbird.response.ResponseParams;
import play.libs.Json;
import play.mvc.Http;
import play.mvc.Result;
import play.test.Helpers;
import util.ACTORS;
import util.RequestInterceptor;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.powermock.api.mockito.PowerMockito.when;

@PrepareForTest(OnRequestHandler.class)
@PowerMockIgnore({"javax.management.*", "jdk.internal.reflect.*", "javax.crypto.*"})
// @Ignore
Expand All @@ -63,7 +58,7 @@ public void testCreateOrgSuccess() {
"POST",
createOrUpdateOrganisationRequest(orgName, null, false, null, null));
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
Expand All @@ -73,7 +68,7 @@ public void testCreateSubOrgWithLicenseSuccess() {
((Map<String, Object>) reqMap.get(JsonKey.REQUEST)).put(JsonKey.LICENSE, "Test MIT license");
Result result = performTest("/v1/org/create", "POST", reqMap);
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
Expand All @@ -83,7 +78,7 @@ public void testCreateRootOrgWithLicenseSuccess() {
((Map<String, Object>) reqMap.get(JsonKey.REQUEST)).put(JsonKey.LICENSE, "Test MIT license");
Result result = performTest("/v1/org/create", "POST", reqMap);
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
Expand All @@ -93,7 +88,7 @@ public void testCreateRootOrgWithLicenseEmptyFailure() {
((Map<String, Object>) reqMap.get(JsonKey.REQUEST)).put(JsonKey.LICENSE, "");
Result result = performTest("/v1/org/create", "POST", reqMap);
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
Expand All @@ -104,7 +99,7 @@ public void testCreateOrgFailureWithoutOrgName() {
"POST",
createOrUpdateOrganisationRequest(null, null, false, null, null));
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
Expand All @@ -115,7 +110,7 @@ public void testCreateOrgFailureWithRootOrgWithoutChannel() {
"POST",
createOrUpdateOrganisationRequest(orgName, null, true, rootOrgId, null));
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
Expand All @@ -126,7 +121,7 @@ public void testUpdateOrgSuccess() {
"PATCH",
createOrUpdateOrganisationRequest(null, orgId, false, rootOrgId, null));
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
Expand All @@ -137,7 +132,7 @@ public void testUpdateOrgFailureWithoutOrgId() {
"PATCH",
createOrUpdateOrganisationRequest(null, null, false, rootOrgId, null));
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
Expand All @@ -148,7 +143,7 @@ public void testUpdateOrgStatusSuccess() {
"PATCH",
createOrUpdateOrganisationRequest(null, orgId, false, null, status));
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
Expand All @@ -159,51 +154,52 @@ public void testUpdateOrgStatusFailureWithoutOrgId() {
"PATCH",
createOrUpdateOrganisationRequest(null, null, false, null, status));
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
public void testGetOrgDetailsSuccess() {
Result result = performTest("/v1/org/read", "POST", getOrganisationRequest(orgId, status));
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
public void testGetOrgDetailsFailureWithoutOrgId() {
Result result = performTest("/v1/org/read", "POST", getOrganisationRequest(null, status));
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
public void testSearchOrgSuccess() {
Result result =
performTest("/v1/org/search", "POST", searchOrganisationRequest(status, new HashMap<>()));
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
public void testSearchOrgV2Success() {
Result result =
performTest("/v2/org/search", "POST", searchOrganisationRequest(status, new HashMap<>()));
assertEquals(getResponseCode(result), ResponseCode.SUCCESS.name());
assertTrue(getResponseStatus(result) == 200);
assertEquals(200, getResponseStatus(result));
}

@Test
public void testSearchOrgFailureWithoutFilters() {
Result result = performTest("/v1/org/search", "POST", searchOrganisationRequest(status, null));
assertEquals(getResponseCode(result), ResponseCode.CLIENT_ERROR.name());
assertTrue(getResponseStatus(result) == 400);
assertEquals(400, getResponseStatus(result));
}

@Test
public void testAddEncyptionKeyPublicPem() throws IOException {
String controllerPath = (Paths.get("").toAbsolutePath().toString().endsWith("controller"))?Paths.get("").toAbsolutePath().toString():Paths.get("").toAbsolutePath().toString()+File.separator +"controller";
File file =
new File(
Paths.get("").toAbsolutePath() + File.separator + "test/resources/samplepublic.pem");
controllerPath + File.separator + "test/resources/samplepublic.pem");
Http.MultipartFormData.Part<Source<ByteString, ?>> part =
new Http.MultipartFormData.FilePart<>(
"fileName",
Expand All @@ -227,8 +223,9 @@ public void testAddEncyptionKeyPublicPem() throws IOException {

@Test
public void testAddEncyptionKeyPDF() throws IOException {
String controllerPath = (Paths.get("").toAbsolutePath().toString().endsWith("controller"))?Paths.get("").toAbsolutePath().toString():Paths.get("").toAbsolutePath().toString()+File.separator +"controller";
File file =
new File(Paths.get("").toAbsolutePath() + File.separator + "test/resources/sample.pdf");
new File(controllerPath + File.separator + "test/resources/sample.pdf");
Http.MultipartFormData.Part<Source<ByteString, ?>> part =
new Http.MultipartFormData.FilePart<>(
"fileName",
Expand Down Expand Up @@ -280,7 +277,7 @@ private Map createOrUpdateOrganisationRequest(
innerMap.put(JsonKey.IS_TENANT, isRootOrg);
innerMap.put(JsonKey.ORG_TYPE, "board");

if (status != null) innerMap.put(JsonKey.STATUS, new Integer(status));
if (status != null) innerMap.put(JsonKey.STATUS, Integer.valueOf(status));

requestMap.put(JsonKey.REQUEST, innerMap);

Expand All @@ -292,7 +289,7 @@ private Map getOrganisationRequest(String orgId, String status) {

Map<String, Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.ORGANISATION_ID, orgId);
if (status != null) innerMap.put(JsonKey.STATUS, new Integer(status));
if (status != null) innerMap.put(JsonKey.STATUS, Integer.valueOf(status));

requestMap.put(JsonKey.REQUEST, innerMap);

Expand All @@ -304,60 +301,10 @@ private Map searchOrganisationRequest(String status, HashMap<Object, Object> fil

Map<String, Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.FILTERS, filterMap);
if (status != null) innerMap.put(JsonKey.STATUS, new Integer(status));
if (status != null) innerMap.put(JsonKey.STATUS, Integer.valueOf(status));

requestMap.put(JsonKey.REQUEST, innerMap);

return requestMap;
}

public Result performTest(String url, String method, Map map) {
String data = mapToJson(map);
Http.RequestBuilder req;
if (StringUtils.isNotBlank(data)) {
JsonNode json = Json.parse(data);
req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
} else {
req = new Http.RequestBuilder().uri(url).method(method);
}
// req.headers(new Http.Headers(headerMap));
Result result = Helpers.route(application, req);
return result;
}

public String mapToJson(Map map) {
ObjectMapper mapperObj = new ObjectMapper();
String jsonResp = "";

if (map != null) {
try {
jsonResp = mapperObj.writeValueAsString(map);
} catch (IOException e) {
e.printStackTrace();
}
}
return jsonResp;
}

public String getResponseCode(Result result) {
String responseStr = Helpers.contentAsString(result);
ObjectMapper mapper = new ObjectMapper();

try {
Response response = mapper.readValue(responseStr, Response.class);
ResponseParams params = response.getParams();
if (result.status() != 200) {
return response.getResponseCode().name();
} else {
return params.getStatus();
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}

public int getResponseStatus(Result result) {
return result.status();
}
}
4 changes: 2 additions & 2 deletions core/actor-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.1</version>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.1</version>
<version>2.10.5.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
Expand Down
2 changes: 1 addition & 1 deletion core/cassandra-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.1</version>
<version>2.10.5.1</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
Expand Down
Loading

0 comments on commit d96e779

Please sign in to comment.