Skip to content

Commit

Permalink
PHEE-419 Add errorprone configuration and resolve errors manually (#135)
Browse files Browse the repository at this point in the history
* Added errorprone cofiguration

* Resolved errorprone issues manually

* updated the request template spell

* testing the CI failure changes

* new changes

* Added the ngrok setup in workflow of GOV test cases

* Added Ngrok part in ams integration test workflow and steps

* Removed unnescessary line

* Updated the indentation for the ams tests

* added web addr and authtoken step in ams test

* Updated the path for ams tests

---------

Co-authored-by: Dhruv Sonagara <[email protected]>
  • Loading branch information
dhruvsonagara and Dhruv Sonagara authored Nov 10, 2023
1 parent a10de36 commit 848b174
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 16 deletions.
31 changes: 29 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ jobs:
export CALLBACK_URL="https://$NGROK_PUBLIC_URL"
echo -n "Public url ."
echo $CALLBACK_URL
./gradlew test -Dcucumber.filter.tags="@gov"
cd ph-ee-integration-test && ./gradlew test -Dcucumber.filter.tags="@gov"
echo -n "Test execution is completed, kill ngrok"
pkill ngrok
- store_test_results:
Expand All @@ -207,7 +207,32 @@ jobs:
- image: cimg/openjdk:17.0.0
steps:
- run: git clone https://github.com/openmf/ph-ee-integration-test
- run: cd ph-ee-integration-test && ./gradlew test -Dcucumber.filter.tags="@amsIntegration"
- run:
name: Ngrok setup
command: curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
- run:
name: Test execution
command: |
ngrok config add-authtoken $AUTH_TOKEN
echo "web_addr: $LOCAL_PORT" >> /home/circleci/.config/ngrok/ngrok.yml
ngrok http 53013 > /dev/null &
echo -n "Extracting ngrok public url ."
NGROK_PUBLIC_URL=""
while [ -z "$NGROK_PUBLIC_URL" ]; do
# Run 'curl' against ngrok API and extract public (using 'sed' command)
export NGROK_PUBLIC_URL=$(curl --silent --max-time 10 --connect-timeout 5 \
--show-error http://127.0.0.1:$LOCAL_PORT/api/tunnels | \
sed -nE 's/.*public_url":"https:..([^"]*).*/\1/p')
sleep 1
echo -n "."
done
export CALLBACK_URL="https://$NGROK_PUBLIC_URL"
echo -n "Public url ."
echo $CALLBACK_URL
cd ph-ee-integration-test && ./gradlew test -Dcucumber.filter.tags="@amsIntegration"
echo -n "Test execution is completed, kill ngrok"
pkill ngrok
- store_test_results:
path: ph-ee-integration-test/build/cucumber.xml
- store_artifacts:
Expand Down Expand Up @@ -261,10 +286,12 @@ workflows:
- AWS
- Helm
- slack
- Ngrok
- test-chart-ams:
requires:
- upgrade-helm-chart
context:
- AWS
- Helm
- slack
- Ngrok
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Description

* Describe the changes made and why they were made.
* Add a link to teh design document or include the design bullet points related to this PR here.
* Add a link to the design document or include the design bullet points related to this PR here.

_(Ignore if these details are present on the associated JIRA ticket)_

Expand Down
101 changes: 101 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id 'checkstyle'
id 'org.springframework.boot' version '2.6.2'
id 'com.diffplug.spotless' version '6.19.0'
id 'net.ltgt.errorprone' version '3.1.0'
}

repositories {
Expand Down Expand Up @@ -93,6 +94,7 @@ configure(this) {
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'checkstyle'
apply plugin: 'net.ltgt.errorprone'
configurations {
implementation.setCanBeResolved(true)
api.setCanBeResolved(true)
Expand Down Expand Up @@ -184,6 +186,104 @@ configure(this) {
checkstyle 'com.puppycrawl.tools:checkstyle:10.3.1'
checkstyle 'com.github.sevntu-checkstyle:sevntu-checks:1.42.0'
}
// Configuration for the errorprone plugin
// https://github.com/tbroyer/gradle-errorprone-plugin
dependencies {
errorprone "com.google.errorprone:error_prone_core:2.20.0"
}

tasks.withType(JavaCompile) {
options.errorprone {
enabled = project.gradle.startParameter.taskNames.contains('build') || project.gradle.startParameter.taskNames.contains('check')
disableWarningsInGeneratedCode = true
excludedPaths = ".*/build/.*"
excludedPaths = ".*/gsmastub/.*"
disable(
// TODO Remove disabled checks from this list, by fixing remaining usages
"UnusedVariable",
"TypeParameterUnusedInFormals",
"EmptyBlockTag",
"MissingSummary",
"InvalidParam",
"ReturnFromVoid",
"AlmostJavadoc",
"InvalidBlockTag",
"JavaUtilDate", // TODO FINERACT-1298
"ReturnValueIgnored",
"DirectInvocationOnMock",
"CanIgnoreReturnValueSuggester",
"SameNameButDifferent", // Until errorprone recognizes Lombok
"MultiVariableDeclaration", // Until errorprone recognizes Lombok
"UnnecessaryDefaultInEnumSwitch" // FINERACT-1911
)
error(
"DefaultCharset",
"RemoveUnusedImports",
"WaitNotInLoop",
"ThreeLetterTimeZoneID",
"VariableNameSameAsType",
"UnnecessaryParentheses",
"MultipleTopLevelClasses",
"MixedMutabilityReturnType",
"AssertEqualsArgumentOrderChecker",
"EmptySetMultibindingContributions",
"BigDecimalEquals",
"MixedArrayDimensions",
"PackageLocation",
"UseBinds",
"BadImport",
"IntLongMath",
"FloatCast",
"ReachabilityFenceUsage",
"StreamResourceLeak",
"TruthIncompatibleType",
"ByteBufferBackingArray",
"OrphanedFormatString",
"CatchAndPrintStackTrace",
"ObjectToString",
"StringSplitter",
"AssertThrowsMultipleStatements",
"BoxedPrimitiveConstructor",
"EmptyCatch",
"BoxedPrimitiveEquality",
"SynchronizeOnNonFinalField",
"WildcardImport",
"PrivateConstructorForNoninstantiableModule",
"ClassCanBeStatic",
"ClassNewInstance",
"UnnecessaryStaticImport",
"UnsafeFinalization",
"JavaTimeDefaultTimeZone",
"JodaPlusMinusLong",
"SwitchDefault",
"VarTypeName",
"ArgumentSelectionDefectChecker",
"CompareToZero",
"InjectOnConstructorOfAbstractClass",
"ImmutableEnumChecker",
"NarrowingCompoundAssignment",
"MissingCasesInEnumSwitch",
"ReferenceEquality",
"UndefinedEquals",
"UnescapedEntity",
"ModifyCollectionInEnhancedForLoop",
"NonCanonicalType",
"InvalidInlineTag",
"MutablePublicArray",
"StaticAssignmentInConstructor",
"ProtectedMembersInFinalClass",
"OperatorPrecedence",
"EqualsGetClass",
"EqualsUnsafeCast",
"DoubleBraceInitialization",
"UnusedNestedClass",
"UnusedMethod",
"ModifiedButNotUsed",
"InconsistentCapitalization",
"MissingOverride",
)
}
}
}


Expand All @@ -192,6 +292,7 @@ checkstyle {
}



group = 'org.mifos'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public interface GSMATransactionApi {
GsmaP2PResponseDto gsmatransaction(@RequestBody GsmaTransfer requestBody,
@RequestHeader(value = CLIENTCORRELATIONID, required = false) String correlationId,
@RequestHeader(value = "amsName") String amsName, @RequestHeader(value = "accountHoldingInstitutionId") String accountHoldId,
@RequestHeader(value = "X-CallbackURL") String callbackURL)
throws JsonProcessingException;
@RequestHeader(value = "X-CallbackURL") String callbackURL) throws JsonProcessingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class GSMATransactionApiController implements GSMATransactionApi {
private Logger logger = LoggerFactory.getLogger(this.getClass());

@Override
public GsmaP2PResponseDto gsmatransaction(GsmaTransfer requestBody, String correlationId, String amsName, String accountHoldId, String callbackURL)
throws JsonProcessingException {
public GsmaP2PResponseDto gsmatransaction(GsmaTransfer requestBody, String correlationId, String amsName, String accountHoldId,
String callbackURL) throws JsonProcessingException {
Headers headers = new Headers.HeaderBuilder().addHeader("X-CorrelationID", correlationId).addHeader("amsName", amsName)
.addHeader("accountHoldingInstitutionId", accountHoldId).addHeader("X-CallbackURL",callbackURL).build();
.addHeader("accountHoldingInstitutionId", accountHoldId).addHeader("X-CallbackURL", callbackURL).build();
Exchange exchange = SpringWrapperUtil.getDefaultWrappedExchange(producerTemplate.getCamelContext(), headers,
objectMapper.writeValueAsString(requestBody));
producerTemplate.send("direct:post-gsma-transaction", exchange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import io.camunda.zeebe.client.ZeebeClient;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -205,8 +206,8 @@ private void transferRoutes() {
Client client = clientProperties.getClient(tenantId);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Platform-TenantId", tenantId);
httpHeaders.add("Authorization",
"Basic " + getEncoder().encodeToString((client.getClientId() + ":" + client.getClientSecret()).getBytes()));
httpHeaders.add("Authorization", "Basic " + getEncoder()
.encodeToString((client.getClientId() + ":" + client.getClientSecret()).getBytes(StandardCharsets.UTF_8)));

HttpEntity<String> entity = new HttpEntity<>(null, httpHeaders);
ResponseEntity<String> exchange = restTemplate.exchange(restAuthHost + "/oauth/token?grant_type=client_credentials",
Expand Down Expand Up @@ -662,7 +663,7 @@ private void inboundTransferC2bImplementationRoutes() {
variables.put(TENANT_ID, accountHoldingInstitutionId);
variables.put(CHANNEL_REQUEST, objectMapper.writeValueAsString(gsmaTranfer));
variables.put("clientCorrelationId", clientCorrelationId);
variables.put("X-CallbackURL",callbackURL);
variables.put("X-CallbackURL", callbackURL);
String workflowName = new StringBuilder().append(subtype).append("_").append(type).append("_").append(amsName)
.append("-").append(accountHoldingInstitutionId).toString();
logger.info("Workflow Name:{}", workflowName);
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/mifos/connector/channel/utils/MpesaUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mifos.connector.channel.utils;

import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import org.json.JSONArray;
import org.json.JSONObject;

Expand Down Expand Up @@ -40,10 +42,11 @@ public static String mpesaChannelRequestToChannelRequestConvertor(String channel
}

// setting payer and payee
mpesaChannelRequestJson.put("payer", getPartyInfoJson(payer.split(" ")[0], payer.split(" ")[1]));

mpesaChannelRequestJson.put("payee", getPartyInfoJson(payee.split(" ")[0], payee.split(" ")[1]));

// mpesaChannelRequestJson.put("payer", getPartyInfoJson(payer.split(" ")[0], payer.split(" ")[1]));
mpesaChannelRequestJson.put("payer",
getPartyInfoJson(Iterables.get(Splitter.on(' ').split(payer), 0), Iterables.get(Splitter.on(' ').split(payer), 1)));
mpesaChannelRequestJson.put("payee",
getPartyInfoJson(Iterables.get(Splitter.on(' ').split(payee), 0), Iterables.get(Splitter.on(' ').split(payee), 1)));
return mpesaChannelRequestJson.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private String randomCharOfSize(int size) {
char[] arr = data.toCharArray();
StringBuilder s = new StringBuilder();
for (int i = 0; i < size; i++) {
int index = (int) (Math.random() * (data.length()));
int index = (int) (Math.random() * data.length());
s.append(arr[index]);
}
return s.toString();
Expand Down

0 comments on commit 848b174

Please sign in to comment.