You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ad...@apache.org on 2023/06/30 11:34:03 UTC
[fineract] branch develop updated: FINERACT-1724: Fineract Idempotency status null fix - [x] Return 500 when the idempotency status is inconsistent in the database - [x] Unit test for the mapper to avoid NullPointerException
This is an automated email from the ASF dual-hosted git repository.
adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 4c7c3544d FINERACT-1724: Fineract Idempotency status null fix - [x] Return 500 when the idempotency status is inconsistent in the database - [x] Unit test for the mapper to avoid NullPointerException
4c7c3544d is described below
commit 4c7c3544d2db9c2458f27ee5e3f15e040ea87fe4
Author: Janos Haber <ja...@finesolution.hu>
AuthorDate: Thu Jun 29 14:19:31 2023 +0200
FINERACT-1724: Fineract Idempotency status null fix
- [x] Return 500 when the idempotency status is inconsistent in the database
- [x] Unit test for the mapper to avoid NullPointerException
---
.../IdempotentCommandProcessFailedException.java | 4 ++
...empotencyCommandProcessFailedExceptionTest.java | 62 ++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessFailedException.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessFailedException.java
index 16af11090..a08b2d9b9 100644
--- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessFailedException.java
+++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exception/IdempotentCommandProcessFailedException.java
@@ -34,6 +34,10 @@ public class IdempotentCommandProcessFailedException extends AbstractIdempotentC
}
public Integer getStatusCode() {
+ // If the database inconsistent we return http 500 instead of null pointer exception
+ if (statusCode == null) {
+ return 500;
+ }
return statusCode;
}
}
diff --git a/fineract-core/src/test/java/org/apache/fineract/infrastructure/core/exception/IdempotencyCommandProcessFailedExceptionTest.java b/fineract-core/src/test/java/org/apache/fineract/infrastructure/core/exception/IdempotencyCommandProcessFailedExceptionTest.java
new file mode 100644
index 000000000..5ab233ee7
--- /dev/null
+++ b/fineract-core/src/test/java/org/apache/fineract/infrastructure/core/exception/IdempotencyCommandProcessFailedExceptionTest.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.core.exception;
+
+import static org.apache.fineract.infrastructure.core.exception.AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import jakarta.ws.rs.core.Response;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.fineract.commands.domain.CommandSource;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.domain.ActionContext;
+import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
+import org.apache.fineract.infrastructure.core.exceptionmapper.IdempotentCommandProcessFailedExceptionMapper;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class IdempotencyCommandProcessFailedExceptionTest {
+
+ private final LocalDate actualDate = LocalDate.now(ZoneId.systemDefault());
+
+ @BeforeEach
+ public void setUp() {
+ ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
+ ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
+ ThreadLocalContextUtil.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, actualDate)));
+ }
+
+ @Test
+ public void testInconsistentStatus() {
+ IdempotentCommandProcessFailedExceptionMapper mapper = new IdempotentCommandProcessFailedExceptionMapper();
+ CommandWrapper command = new CommandWrapper(null, null, null, null, null, null, null, null, null, null, null, null, null, null,
+ null, null, null, null);
+ CommandSource source = CommandSource.fullEntryFrom(command, JsonCommand.from("{}"), null, "dummy-key", null);
+ IdempotentCommandProcessFailedException exception = new IdempotentCommandProcessFailedException(command, source);
+ Response result = mapper.toResponse(exception);
+ assertEquals(500, result.getStatus());
+ assertEquals("true", result.getHeaderString(IDEMPOTENT_CACHE_HEADER));
+ }
+}