Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: release 2.0 testing bugs and issues fix #320

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Collections;
import java.util.Date;

import static dev.sunbirdrc.registry.middleware.util.Constants.ENTITY_LIST;

@RestController
@ConditionalOnProperty(name = "claims.enabled", havingValue = "true")
public class RegistryClaimsController extends AbstractController{
Expand All @@ -49,7 +51,7 @@ public ResponseEntity<Object> getAllClaims(@PathVariable String entityName, Page
HttpServletRequest request) {
try {
JsonNode result = registryHelper.getRequestedUserDetails(request, entityName);
JsonNode claims = claimRequestClient.getClaims(result.get(entityName).get(0), pageable, entityName);
JsonNode claims = claimRequestClient.getClaims(result.get(entityName).get(ENTITY_LIST).get(0), pageable, entityName);
logger.info("Received {} claims", claims.size());
return new ResponseEntity<>(claims, HttpStatus.OK);
} catch (Exception e) {
Expand All @@ -63,7 +65,7 @@ public ResponseEntity<Object> getClaim(@PathVariable String entityName, @PathVar
HttpServletRequest request) {
try {
JsonNode result = registryHelper.getRequestedUserDetails(request, entityName);
JsonNode claim = claimRequestClient.getClaim(result.get(entityName).get(0), entityName, claimId);
JsonNode claim = claimRequestClient.getClaim(result.get(entityName).get(ENTITY_LIST).get(0), entityName, claimId);
return new ResponseEntity<>(claim, HttpStatus.OK);
} catch (HttpClientErrorException | HttpServerErrorException e) {
logger.error("Fetching claim failed {}", ExceptionUtils.getStackTrace(e));
Expand Down Expand Up @@ -109,7 +111,7 @@ private ObjectNode generateAdditionInput(String claimId, String entityName, Obje
JsonNode notes = requestBody.get("notes");
logger.info("Action : {} , Notes: {}", action, notes);
JsonNode result = registryHelper.getRequestedUserDetails(request, entityName);
JsonNode attestorInfo = result.get(entityName).get(0);
JsonNode attestorInfo = result.get(entityName).get(ENTITY_LIST).get(0);
ObjectNode additionalInputs = JsonNodeFactory.instance.objectNode();
additionalInputs.set("attestorInfo", attestorInfo);
additionalInputs.set("action", action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@

import static dev.sunbirdrc.registry.Constants.*;
import static dev.sunbirdrc.registry.helper.RegistryHelper.ServiceNotEnabledResponse;
import static dev.sunbirdrc.registry.middleware.util.Constants.ENTITY_TYPE;
import static dev.sunbirdrc.registry.middleware.util.Constants.TOTAL_COUNT;
import static dev.sunbirdrc.registry.middleware.util.Constants.*;

@RestController
public class RegistryEntityController extends AbstractController {
Expand Down Expand Up @@ -483,7 +482,7 @@ public ResponseEntity<Object> getEntityWithConsent(
checkEntityNameInDefinitionManager(entityName);
ArrayList<String> fields = getConsentFields(request);
JsonNode userInfoFromRegistry = registryHelper.getRequestedUserDetails(request, entityName);
JsonNode jsonNode = userInfoFromRegistry.get(entityName);
JsonNode jsonNode = userInfoFromRegistry.get(entityName).get(ENTITY_LIST);
if (jsonNode instanceof ArrayNode) {
ArrayNode values = (ArrayNode) jsonNode;
if (values.size() > 0) {
Expand Down Expand Up @@ -856,9 +855,9 @@ public ResponseEntity<Object> getSignedEntityByToken(@PathVariable String entity
try {
checkEntityNameInDefinitionManager(entityName);
JsonNode result = registryHelper.getRequestedUserDetails(request, entityName);
if (result.get(entityName).size() > 0) {
if (result.get(entityName).get(ENTITY_LIST).size() > 0) {
Object credentialTemplate = definitionsManager.getCredentialTemplate(entityName);
Object signedCredentials = registryHelper.getSignedDoc(entityName, result.get(entityName).get(0), credentialTemplate);
Object signedCredentials = registryHelper.getSignedDoc(entityName, result.get(entityName).get(ENTITY_LIST).get(0), credentialTemplate);
return new ResponseEntity<>(signedCredentials, HttpStatus.OK);
} else {
responseParams.setErrmsg("Entity not found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static dev.sunbirdrc.registry.Constants.Schema;
import static dev.sunbirdrc.registry.Constants.TITLE;
import static dev.sunbirdrc.registry.middleware.util.Constants.ENTITY_LIST;

@RestController
@ConditionalOnProperty(name = "api-swagger.enabled", havingValue = "true")
Expand Down Expand Up @@ -74,7 +75,7 @@ private TextNode getHost(HttpServletRequest request) {
public ResponseEntity<Object> getUserSwaggerDoc(HttpServletRequest request) throws Exception {
JsonNode userCreatedSchemas = registryHelper.getRequestedUserDetails(request, Schema);
Set<String> schemas = new HashSet<>();
for (JsonNode schemaRes : userCreatedSchemas.get(Schema)) {
for (JsonNode schemaRes : userCreatedSchemas.get(Schema).get(ENTITY_LIST)) {
JsonNode schema = objectMapper.readTree(schemaRes.get(Schema.toLowerCase()).asText());
schemas.add(schema.get(TITLE).textValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,9 @@ private JsonNode getUserInfoFromKeyCloak(HttpServletRequest request, String enti
// To maintain the consistency with searchEntity we are using ArrayNode
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
arrayNode.add(rolesNode);
result.set(entityName, arrayNode);
ObjectNode searchResp = JsonNodeFactory.instance.objectNode().set(ENTITY_LIST, arrayNode);
searchResp.put(TOTAL_COUNT, 1L);
result.set(entityName, searchResp);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public String findDidForProperty(String propertyName, String value) throws Excep
filters.set(propertyName, JsonNodeFactory.instance.objectNode().put("eq", value));
payload.set(FILTERS, filters);
JsonNode results = searchService.search(payload, "");
if(results.get(authorSchemaName).isEmpty()) {
if(results.get(authorSchemaName).get(ENTITY_LIST).isEmpty()) {
throw new RuntimeException(String.format("%s %s not found in schema %s for property %s", propertyName, value, authorSchemaName, propertyName));
}
return results.get(authorSchemaName).get(0).get(propertyName).asText();
return results.get(authorSchemaName).get(ENTITY_LIST).get(0).get(didPropertyName).asText();
}

public String ensureDidForName(String name, String method) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.sunbirdrc.registry.service;

import static dev.sunbirdrc.registry.middleware.util.Constants.ENTITY_LIST;
import static dev.sunbirdrc.registry.middleware.util.Constants.TOTAL_COUNT;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -89,7 +91,9 @@ public void testFindDidForProperty() throws Exception {
ObjectNode resultsNode = JsonNodeFactory.instance.objectNode();
ArrayNode authorArray = JsonNodeFactory.instance.arrayNode();
authorArray.add(authorNode);
resultsNode.set("Issuer", authorArray);
ObjectNode resp = JsonNodeFactory.instance.objectNode().set(ENTITY_LIST, authorArray);
resp.put(TOTAL_COUNT, 1L);
resultsNode.set(authorSchemaName, resp);

when(searchService.search(any(), anyString())).thenReturn(resultsNode);

Expand All @@ -98,7 +102,7 @@ public void testFindDidForProperty() throws Exception {
assertEquals("1234567890", foundDid);

// Negative test case when no results are found
resultsNode.set("Issuer", JsonNodeFactory.instance.arrayNode());
resultsNode.set(authorSchemaName, JsonNodeFactory.instance.objectNode().set(ENTITY_LIST, JsonNodeFactory.instance.arrayNode()));
when(searchService.search(any(), anyString())).thenReturn(resultsNode);
try {
didService.findDidForProperty(propertyName, value);
Expand Down Expand Up @@ -202,18 +206,22 @@ private JsonNode createMockJsonNode() {
// Create a mock JsonNode for testing
ObjectNode results = JsonNodeFactory.instance.objectNode();
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(1);
results.set(authorSchemaName, arrayNode);
ObjectNode record = JsonNodeFactory.instance.objectNode();
record.set(didPropertyName, JsonNodeFactory.instance.textNode("did:test:1234"));
arrayNode.add(record);
ObjectNode resp = JsonNodeFactory.instance.objectNode().set(ENTITY_LIST, arrayNode);
resp.put(TOTAL_COUNT, 1L);
results.set(authorSchemaName, resp);
return results;
}

private JsonNode createEmptyJsonNode() {
// Create an empty JsonNode for testing
ObjectNode results = JsonNodeFactory.instance.objectNode();
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(1);
results.set(authorSchemaName, arrayNode);
ObjectNode resp = JsonNodeFactory.instance.objectNode().set(ENTITY_LIST, arrayNode);
resp.put(TOTAL_COUNT, 1L);
results.set(authorSchemaName, resp);
return results;
}

Expand Down
Loading