Skip to content

Commit

Permalink
Merge pull request #7 from project-sunbird/constant-cleanup
Browse files Browse the repository at this point in the history
Issues #SB-00 fix: there are two Constant files one Constant and anot…
  • Loading branch information
AMIT KUMAR authored May 31, 2018
2 parents e10b840 + 3813e3d commit 5a83490
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ private Constant() {}

public static final String EMAIL = "email";
public static final String USER_NAME = "userName";
public static final String REQUEST = "request";
public static final String CHANNEL = "channel";
public static final String PROVIDER = "provider";
public static final String EXTERNAL_ID = "externalId";
public static final String PASSWORD = "password";
public static final String LAST_NAME = "lastName";
public static final String FIRST_NAME = "firstName";
public static final String ID = "id";
public static final String USER_ID = "userId";
public static final String REG_ORG_ID = "regOrgId";
public static final String ROOT_ORG_ID = "rootOrgId";
public static final String UPDATE_USER_TEMPLATE_LOCATION = "templates/user/update/";
public static final String AUTHORIZATION = "Authorization";
public static final String BEARER = "Bearer ";
public static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
public static final String EQUAL_SIGN = "=";
public static final String USER_TEMPLATE_LOCATION = "templates/user/create/";
public static final String USER_NAME_PREFIX = "ft_testinstance";
public static final String X_AUTHENTICATED_USER_TOKEN = "x-authenticated-user-token";
public static final String PARENT_CODE = "parentCode";
public static final String CODE = "code";
public static final String LOCATION_TYPE = "type";
public static final String PARENT_ID = "parentId";
public static final String NAME = "name";
public static final String ID = "id";
public static final String REQUEST = "request";
public static final String RESPONSE = "response";
public static final String ES_REST_API_PORT = "9200";
public static final String MULTIPART_FILE_NAME = "file";
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
package org.sunbird.common.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.sunbird.integration.test.user.EndpointConfig.TestGlobalProperty;

/**
* Class to perform the clean up from elastic search.
*
* @author arvind.
*/
public class ElasticSearchCleanUp {

@Autowired
private TestGlobalProperty initGlobalValues;
@Autowired private TestGlobalProperty initGlobalValues;

private static ElasticSearchCleanUp elasticSearchcleanUp;

private ElasticSearchCleanUp(){
}
private ElasticSearchCleanUp() {}

public static ElasticSearchCleanUp getInstance(){
if(null == elasticSearchcleanUp){
public static ElasticSearchCleanUp getInstance() {
if (null == elasticSearchcleanUp) {
elasticSearchcleanUp = new ElasticSearchCleanUp();
}
return elasticSearchcleanUp;
}

public void deleteFromElasticSearch(Map<String, List<String>> map){
map.forEach((k, v) -> {
if (v != null)
for (String value : v) {
boolean response = deleteDataFromES(initGlobalValues.getEsHost(), Constants.ES_REST_API_PORT,
initGlobalValues.getIndex(), k, value);
}
});
public void deleteFromElasticSearch(Map<String, List<String>> map) {
map.forEach(
(k, v) -> {
if (v != null)
for (String value : v) {
boolean response =
deleteDataFromES(
initGlobalValues.getEsHost(),
Constant.ES_REST_API_PORT,
initGlobalValues.getIndex(),
k,
value);
}
});
}

private boolean deleteDataFromES(String host, String port, String index, String type, String id) {
Expand All @@ -44,16 +48,11 @@ private boolean deleteDataFromES(String host, String port, String index, String
/**
* This method will create url for ES get and deleted by Id.
*
* @param host
* String
* @param port
* String
* @param index
* String
* @param type
* String
* @param id
* String
* @param host String
* @param port String
* @param index String
* @param type String
* @param id String
* @return String
*/
private static String createURL(String host, String port, String index, String type, String id) {
Expand All @@ -62,5 +61,4 @@ private static String createURL(String host, String port, String index, String t
builder.append(":" + port + "/" + index + "/" + type + "/" + id);
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ public void multipartPost(
new Scanner(new File(getClass().getClassLoader().getResource(formDataFile).getFile()))) {

while (scanner.hasNext()) {
String[] param = scanner.nextLine().split(Constants.EQUAL_SIGN);
String[] param = scanner.nextLine().split(Constant.EQUAL_SIGN);
if (param != null && param.length == 2) {
if (param[0].equalsIgnoreCase(Constants.MULTIPART_FILE_NAME)) {
formData.add(Constants.MULTIPART_FILE_NAME, new ClassPathResource(formDataFileFolderPath + "/" + param[1]));
if (param[0].equalsIgnoreCase(Constant.MULTIPART_FILE_NAME)) {
formData.add(
Constant.MULTIPART_FILE_NAME,
new ClassPathResource(formDataFileFolderPath + "/" + param[1]));
} else {
formData.add(param[0], param[1]);
}
Expand All @@ -95,7 +97,7 @@ public void multipartPost(
.send()
.post(url)
.contentType(MediaType.MULTIPART_FORM_DATA)
.header(Constants.AUTHORIZATION, Constants.BEARER + config.getApiKey())
.header(Constant.AUTHORIZATION, Constant.BEARER + config.getApiKey())
.payload(formData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.sunbird.common.models.response.Response;
import org.sunbird.common.models.response.ResponseCode;
import org.sunbird.common.util.CassandraCleanUp;
import org.sunbird.common.util.Constants;
import org.sunbird.common.util.Constant;
import org.sunbird.common.util.ElasticSearchCleanUp;
import org.sunbird.integration.test.common.BaseCitrusTest;
import org.sunbird.integration.test.user.EndpointConfig.TestGlobalProperty;
Expand Down Expand Up @@ -164,8 +164,8 @@ public void testCreateLocationState(String requestJson, String responseJson, Str
.client(restTestClient)
.send()
.post(CREATE_LOCATION_URI)
.contentType(Constants.CONTENT_TYPE_APPLICATION_JSON)
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey())
.contentType(Constant.CONTENT_TYPE_APPLICATION_JSON)
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey())
.payload(requestJson);
if ((LOCATION_TEMPLATE_PATH + "create_location_success_response.json").equals(responseJson)) {
HttpClientReceiveActionBuilder response = http().client(restTestClient).receive();
Expand Down Expand Up @@ -199,8 +199,8 @@ public void testUpdateStateLocation(String requestJson, String responseJson, Str
.client(restTestClient)
.send()
.patch(UPDATE_LOCATION_URI)
.contentType(Constants.CONTENT_TYPE_APPLICATION_JSON)
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey())
.contentType(Constant.CONTENT_TYPE_APPLICATION_JSON)
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey())
.payload(requestJson);
if ((LOCATION_TEMPLATE_PATH_UPDATE + "update_location_name_success_response.json")
.equals(responseJson)) {
Expand Down Expand Up @@ -240,8 +240,8 @@ public void testCreateLocationDistrict(String requestJson, String responseJson,
.client(restTestClient)
.send()
.post(CREATE_LOCATION_URI)
.contentType(Constants.CONTENT_TYPE_APPLICATION_JSON)
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey())
.contentType(Constant.CONTENT_TYPE_APPLICATION_JSON)
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey())
.payload(requestJson);
if ((LOCATION_TEMPLATE_PATH + "create_location_success_response.json").equals(responseJson)) {
HttpClientReceiveActionBuilder response = http().client(restTestClient).receive();
Expand Down Expand Up @@ -274,8 +274,8 @@ public void testUpdateDistrictLocation(String requestJson, String responseJson,
.client(restTestClient)
.send()
.patch(UPDATE_LOCATION_URI)
.contentType(Constants.CONTENT_TYPE_APPLICATION_JSON)
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey())
.contentType(Constant.CONTENT_TYPE_APPLICATION_JSON)
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey())
.payload(requestJson);
if ((LOCATION_TEMPLATE_PATH_UPDATE + "update_location_name_success_response.json")
.equals(responseJson)) {
Expand Down Expand Up @@ -308,7 +308,7 @@ public void testDeleteStateLocation(String responseJson, String testName) {
.client(restTestClient)
.send()
.delete(DELETE_LOCATION_URI + "/" + stateLocationId)
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey());
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey());
http()
.client(restTestClient)
.receive()
Expand All @@ -333,7 +333,7 @@ public void testDeleteDistrictLocation(String responseJson, String testName) {
.client(restTestClient)
.send()
.delete(DELETE_LOCATION_URI + "/" + districtLocationId)
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey());
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey());
http()
.client(restTestClient)
.receive()
Expand All @@ -344,7 +344,7 @@ public void testDeleteDistrictLocation(String responseJson, String testName) {
.client(restTestClient)
.send()
.delete(DELETE_LOCATION_URI + "/" + districtLocationId + "invalid")
.header(Constants.AUTHORIZATION, Constants.BEARER + initGlobalValues.getApiKey());
.header(Constant.AUTHORIZATION, Constant.BEARER + initGlobalValues.getApiKey());
http()
.client(restTestClient)
.receive()
Expand All @@ -365,8 +365,8 @@ public void validate(
Response response, Map<String, Object> headers, TestContext context) {
Assert.assertNotNull(response.getId());
Assert.assertEquals(response.getResponseCode(), ResponseCode.OK);
Assert.assertNotNull(response.getResult().get(Constants.RESPONSE));
String locationId = (String) response.getResult().get(Constants.ID);
Assert.assertNotNull(response.getResult().get(Constant.RESPONSE));
String locationId = (String) response.getResult().get(Constant.ID);
Assert.assertNotNull(locationId);
if (locationType.equalsIgnoreCase("state")) {
stateLocationId = locationId;
Expand Down Expand Up @@ -397,12 +397,12 @@ public void validate(
private String createStateLocationMap() {
Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(Constants.CODE, STATE_CODE);
innerMap.put(Constants.NAME, STATE_NAME);
innerMap.put(Constants.PARENT_CODE, null);
innerMap.put(Constants.LOCATION_TYPE, "state");
innerMap.put(Constants.PARENT_ID, null);
requestMap.put(Constants.REQUEST, innerMap);
innerMap.put(Constant.CODE, STATE_CODE);
innerMap.put(Constant.NAME, STATE_NAME);
innerMap.put(Constant.PARENT_CODE, null);
innerMap.put(Constant.LOCATION_TYPE, "state");
innerMap.put(Constant.PARENT_ID, null);
requestMap.put(Constant.REQUEST, innerMap);
try {
return objectMapper.writeValueAsString(requestMap);
} catch (JsonProcessingException e) {
Expand All @@ -415,11 +415,11 @@ private Object createDistrictLocationMap() {

Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(Constants.CODE, DISTRICT_CODE);
innerMap.put(Constants.NAME, DISTRICT_NAME);
innerMap.put(Constants.LOCATION_TYPE, "district");
innerMap.put(Constants.PARENT_CODE, STATE_CODE);
requestMap.put(Constants.REQUEST, innerMap);
innerMap.put(Constant.CODE, DISTRICT_CODE);
innerMap.put(Constant.NAME, DISTRICT_NAME);
innerMap.put(Constant.LOCATION_TYPE, "district");
innerMap.put(Constant.PARENT_CODE, STATE_CODE);
requestMap.put(Constant.REQUEST, innerMap);
try {
return objectMapper.writeValueAsString(requestMap);
} catch (JsonProcessingException e) {
Expand All @@ -431,9 +431,9 @@ private Object createDistrictLocationMap() {
private Object updateStateLocationMap() {
Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(Constants.NAME, STATE_NAME + 01);
innerMap.put(Constants.ID, stateLocationId);
requestMap.put(Constants.REQUEST, innerMap);
innerMap.put(Constant.NAME, STATE_NAME + 01);
innerMap.put(Constant.ID, stateLocationId);
requestMap.put(Constant.REQUEST, innerMap);
try {
return objectMapper.writeValueAsString(requestMap);
} catch (JsonProcessingException e) {
Expand All @@ -445,9 +445,9 @@ private Object updateStateLocationMap() {
private Object updateStateLocationTypeMap() {
Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(Constants.LOCATION_TYPE, "district");
innerMap.put(Constants.ID, stateLocationId);
requestMap.put(Constants.REQUEST, innerMap);
innerMap.put(Constant.LOCATION_TYPE, "district");
innerMap.put(Constant.ID, stateLocationId);
requestMap.put(Constant.REQUEST, innerMap);
try {
return objectMapper.writeValueAsString(requestMap);
} catch (JsonProcessingException e) {
Expand All @@ -459,9 +459,9 @@ private Object updateStateLocationTypeMap() {
private Object updateDistrictNameLocationMap() {
Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(Constants.NAME, DISTRICT_NAME + 01);
innerMap.put(Constants.ID, districtLocationId);
requestMap.put(Constants.REQUEST, innerMap);
innerMap.put(Constant.NAME, DISTRICT_NAME + 01);
innerMap.put(Constant.ID, districtLocationId);
requestMap.put(Constant.REQUEST, innerMap);
try {
return objectMapper.writeValueAsString(requestMap);
} catch (JsonProcessingException e) {
Expand All @@ -473,9 +473,9 @@ private Object updateDistrictNameLocationMap() {
private Object updateDistrictLocationTypeMap() {
Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(Constants.LOCATION_TYPE, "state");
innerMap.put(Constants.ID, districtLocationId);
requestMap.put(Constants.REQUEST, innerMap);
innerMap.put(Constant.LOCATION_TYPE, "state");
innerMap.put(Constant.ID, districtLocationId);
requestMap.put(Constant.REQUEST, innerMap);
try {
return objectMapper.writeValueAsString(requestMap);
} catch (JsonProcessingException e) {
Expand Down
Loading

0 comments on commit 5a83490

Please sign in to comment.