Refactor response handling and centralize JSON configuration

Replaced direct fields in `AbstractResponse` with `ResponseResultInfo` for better encapsulation and consistency. Introduced `JsonConf` to provide a shared, reusable `ObjectMapper` configuration. Updated tests and logic to align with the refactored response structure, enhancing maintainability and readability.
This commit is contained in:
2025-04-21 14:06:25 +02:00
parent af4e09f938
commit c1675d0fba
10 changed files with 325 additions and 71 deletions
@@ -0,0 +1,20 @@
package codes.thischwa.cf;
import codes.thischwa.cf.model.ZoneMultipleResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
public class ObjectMapperTest {
@Test
void testObjectMapper() throws IOException {
ObjectMapper mapper = JsonConf.initObjectMapper();
ZoneMultipleResponse resp =
mapper.readValue(this.getClass().getResourceAsStream("/zone-list-response.json"),
ZoneMultipleResponse.class);
assertNotNull(resp.getResponseResultInfo());
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"result": null,
"success": false,
"errors": [
{
"code": 81053,
"message": "An A, AAAA, or CNAME record with that host already exists. For more details, refer to \u003chttps://developers.cloudflare.com/dns/manage-dns-records/troubleshooting/records-with-same-name/\u003e."
}
],
"messages": []
}
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<configuration>
<appender name="current"
class="ch.qos.logback.core.ConsoleAppender">
+174
View File
@@ -0,0 +1,174 @@
{
"result": [
{
"id": "0a83dd6e7f8c46039f2517bbded8115e",
"name": "mein-d-ns.de",
"status": "active",
"paused": false,
"type": "full",
"development_mode": -230181,
"name_servers": [
"blair.ns.cloudflare.com",
"sergi.ns.cloudflare.com"
],
"original_name_servers": [
"c.ns14.net",
"b.ns14.net",
"a.ns14.net",
"d.ns14.net"
],
"original_registrar": null,
"original_dnshost": null,
"modified_on": "2025-01-20T09:06:52.122538Z",
"created_on": "2025-01-20T08:56:34.736214Z",
"activated_on": "2025-01-20T09:06:52.122538Z",
"meta": {
"step": 2,
"custom_certificate_quota": 0,
"page_rule_quota": 3,
"phishing_detected": false
},
"owner": {
"id": null,
"type": "user",
"email": null
},
"account": {
"id": "563335e3d73549dbbc0620f4ce82d527",
"name": "myAccount"
},
"tenant": {
"id": null,
"name": null
},
"tenant_unit": {
"id": null
},
"permissions": [
"#image:read",
"#image:edit",
"#worker:edit",
"#analytics:read",
"#ssl:edit",
"#zone_settings:read",
"#organization:edit",
"#waf:read",
"#waf:edit",
"#logs:read",
"#member:read",
"#worker:read",
"#blocks:read",
"#blocks:edit",
"#access:read",
"#access:edit",
"#billing:read",
"#teams:read",
"#organization:read",
"#logs:edit",
"#zaraz:publish",
"#zone_settings:edit",
"#fbm:read",
"#subscription:read",
"#lb:read",
"#waitingroom:edit",
"#ssl:read",
"#subscription:edit",
"#dns_records:read",
"#dns_records:edit",
"#api_gateway:read",
"#api_gateway:edit",
"#cds_compute_account:edit",
"#ces_submissions:read",
"#fbm:edit",
"#healthchecks:edit",
"#stream:edit",
"#lb:edit",
"#healthchecks:read",
"#billing:edit",
"#member:edit",
"#cfone_read",
"#cfone_edit",
"#integration:read",
"#zaraz:edit",
"#magic:read",
"#magic:edit",
"#zaraz:read",
"#stream:read",
"#integration:install",
"#dash_sso:edit",
"#zone:read",
"#http_applications:read",
"#http_applications:edit",
"#ces_analytics:read",
"#resilience:edit",
"#teams:edit",
"#r2_bucket_warehouse:read",
"#r2_bucket_warehouse:edit",
"#query_cache:read",
"#query_cache:edit",
"#dex:read",
"#zone_versioning:read",
"#zone_versioning:edit",
"#cds:read",
"#ces_search:action",
"#ces_search:read",
"#ces_search:preview",
"#ces_search:raw",
"#ces_search:trace",
"#fbm_acc:edit",
"#teams:pii",
"#r2_bucket_item:read",
"#r2_bucket_item:edit",
"#integration:edit",
"#resilience:read",
"#zone:edit",
"#dash_sso:read",
"#legal:read",
"#ces_integration:edit",
"#ces_integration:read",
"#cache_purge:edit",
"#vectorize:read",
"#vectorize:edit",
"#auditlogs:read",
"#teams:report",
"#ces_settings:edit",
"#ces_settings:read",
"#waitingroom:read",
"#web3:read",
"#web3:edit",
"#dex:edit",
"#cds_compute_account:read",
"#cds:edit",
"#r2_bucket:read",
"#r2_bucket:edit",
"#ces_phishguard:read",
"#page_shield:read",
"#page_shield:edit",
"#legal:edit",
"#app:edit"
],
"plan": {
"id": "0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"name": "Free Website",
"price": 0,
"currency": "USD",
"frequency": "",
"is_subscribed": false,
"can_subscribe": false,
"legacy_id": "free",
"legacy_discount": false,
"externally_managed": false
}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"total_pages": 1,
"count": 1,
"total_count": 1
},
"success": true,
"errors": [],
"messages": []
}