Skip to content

Commit 25c74c2

Browse files
committed
Adding comparison test
1 parent a0157bc commit 25c74c2

File tree

1 file changed

+193
-0
lines changed

1 file changed

+193
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
* Copyright (C) 2024 Information Management Services, Inc.
3+
*/
4+
package com.imsweb.seerapi.compare;
5+
6+
import java.io.IOException;
7+
import java.util.Date;
8+
import java.util.HashMap;
9+
import java.util.LinkedHashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.Objects;
13+
14+
import org.junit.jupiter.api.Disabled;
15+
import org.junit.jupiter.api.Test;
16+
17+
import com.imsweb.seerapi.client.SeerApi;
18+
import com.imsweb.seerapi.client.hcpcs.Hcpcs;
19+
import com.imsweb.seerapi.client.hcpcs.HcpcsService;
20+
import com.imsweb.seerapi.client.ndc.NdcProduct;
21+
import com.imsweb.seerapi.client.ndc.NdcService;
22+
import com.imsweb.seerapi.client.staging.StagingSchema;
23+
import com.imsweb.seerapi.client.staging.StagingSchemaInfo;
24+
import com.imsweb.seerapi.client.staging.StagingService;
25+
import com.imsweb.seerapi.client.staging.StagingTable;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
@Disabled("Only for manual testing")
30+
class ComparisonTest {
31+
32+
private static final String PROD_URL = "https://api.seer.cancer.gov/rest/";
33+
private static final String LOCAL_URL = "http://localhost:8080/rest/";
34+
35+
private String getApiKey() {
36+
return System.getenv("TESTING_API_KEY");
37+
}
38+
39+
@Test
40+
void testNdc() throws IOException {
41+
NdcService ndcProd = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().ndc();
42+
NdcService ndcLocal = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().ndc();
43+
44+
long page = 1;
45+
46+
Map<String, String> params = new HashMap<>();
47+
params.put("page", String.valueOf(page));
48+
params.put("per_page", "100");
49+
params.put("order", "ndc");
50+
List<NdcProduct> prodList = ndcProd.search(params).execute().body();
51+
List<NdcProduct> localList = ndcLocal.search(params).execute().body();
52+
53+
while (!Objects.requireNonNull(prodList).isEmpty() && !Objects.requireNonNull(localList).isEmpty()) {
54+
assertThat(localList)
55+
.hasSameSizeAs(prodList) // Ensure both lists have the same size
56+
.usingRecursiveComparison()
57+
.isEqualTo(prodList);
58+
59+
System.out.println("NDC page " + page);
60+
61+
page += 1;
62+
params.put("page", String.valueOf(page));
63+
prodList = ndcProd.search(params).execute().body();
64+
localList = ndcLocal.search(params).execute().body();
65+
}
66+
}
67+
68+
@Test
69+
void testHcpcs() throws IOException {
70+
HcpcsService hcpcsProd = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().hcpcs();
71+
HcpcsService hcpcsLocal = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().hcpcs();
72+
73+
long page = 1;
74+
75+
Map<String, String> params = new HashMap<>();
76+
params.put("page", String.valueOf(page));
77+
params.put("per_page", "100");
78+
params.put("order", "hcpcs_code");
79+
80+
List<Hcpcs> prodList = hcpcsProd.search(params).execute().body();
81+
List<Hcpcs> localList = hcpcsLocal.search(params).execute().body();
82+
83+
while (!Objects.requireNonNull(prodList).isEmpty()) {
84+
System.out.println("HCPCS page " + page);
85+
assertThat(localList)
86+
.hasSameSizeAs(prodList) // Ensure both lists have the same size
87+
.usingRecursiveComparison()
88+
.ignoringCollectionOrderInFields("categories")
89+
.isEqualTo(prodList);
90+
91+
page += 1;
92+
params.put("page", String.valueOf(page));
93+
prodList = hcpcsProd.search(params).execute().body();
94+
localList = hcpcsLocal.search(params).execute().body();
95+
}
96+
}
97+
98+
private Map<String, String> getAlgorithmVersions() {
99+
Map<String, String> versions = new LinkedHashMap<>();
100+
101+
versions.put("pediatric", "1.2");
102+
versions.put("eod_public", "3.2");
103+
versions.put("tnm", "2.0");
104+
versions.put("cs", "02.05.50");
105+
106+
return versions;
107+
}
108+
109+
@Test
110+
void testStagingSchemas() throws IOException {
111+
StagingService stagingProd = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().staging();
112+
StagingService stagingLocal = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().staging();
113+
114+
Map<String, String> algorithmMap = getAlgorithmVersions();
115+
for (String algorithmId : algorithmMap.keySet()) {
116+
String algorithmVersion = algorithmMap.get(algorithmId);
117+
118+
System.out.println("Getting list of all schemas in " + algorithmId + ":" + algorithmVersion);
119+
120+
List<StagingSchemaInfo> prodSchemas = stagingProd.schemas(algorithmId, algorithmVersion).execute().body();
121+
List<StagingSchemaInfo> localSchemas = stagingLocal.schemas(algorithmId, algorithmVersion).execute().body();
122+
123+
assertThat(localSchemas)
124+
.hasSameSizeAs(prodSchemas) // Ensure both lists have the same size
125+
.usingRecursiveComparison()
126+
.ignoringCollectionOrder()
127+
.isEqualTo(prodSchemas);
128+
129+
for (StagingSchemaInfo prodSchema : Objects.requireNonNull(prodSchemas)) {
130+
StagingSchema prod = stagingProd.schemaById(algorithmId, algorithmVersion, prodSchema.getId()).execute().body();
131+
StagingSchema local = stagingLocal.schemaById(algorithmId, algorithmVersion, prodSchema.getId()).execute().body();
132+
133+
System.out.println("Comparing [" + algorithmId + ":" + algorithmVersion + "] schema " + prodSchema.getId());
134+
135+
assertThat(local)
136+
.usingRecursiveComparison()
137+
.ignoringCollectionOrder()
138+
.withComparatorForType(
139+
(date1, date2) -> {
140+
// ignore milliseconds when comparing two Date objects
141+
long time1 = date1.getTime() / 1000;
142+
long time2 = date2.getTime() / 1000;
143+
return Long.compare(time1, time2);
144+
},
145+
Date.class
146+
)
147+
.isEqualTo(prod);
148+
}
149+
}
150+
}
151+
152+
@Test
153+
void testStagingTables() throws IOException {
154+
StagingService stagingProd = new SeerApi.Builder().url(PROD_URL).apiKey(getApiKey()).connect().staging();
155+
StagingService stagingLocal = new SeerApi.Builder().url(LOCAL_URL).apiKey(getApiKey()).connect().staging();
156+
157+
Map<String, String> algorithmMap = getAlgorithmVersions();
158+
for (String algorithmId : algorithmMap.keySet()) {
159+
String algorithmVersion = algorithmMap.get(algorithmId);
160+
161+
System.out.println("Getting list of all tables in " + algorithmId + ":" + algorithmVersion);
162+
163+
List<StagingTable> prodTables = stagingProd.tables(algorithmId, algorithmVersion).execute().body();
164+
List<StagingTable> localTables = stagingLocal.tables(algorithmId, algorithmVersion).execute().body();
165+
166+
assertThat(localTables)
167+
.hasSameSizeAs(prodTables) // Ensure both lists have the same size
168+
.usingRecursiveComparison()
169+
.ignoringCollectionOrder()
170+
.isEqualTo(prodTables);
171+
172+
for (StagingTable prodTable : Objects.requireNonNull(prodTables)) {
173+
StagingTable prod = stagingProd.tableById(algorithmId, algorithmVersion, prodTable.getId()).execute().body();
174+
StagingTable local = stagingLocal.tableById(algorithmId, algorithmVersion, prodTable.getId()).execute().body();
175+
176+
System.out.println("Comparing [" + algorithmId + ":" + algorithmVersion + "] table " + prodTable.getId());
177+
178+
assertThat(local)
179+
.usingRecursiveComparison()
180+
.withComparatorForType(
181+
(date1, date2) -> {
182+
// ignore milliseconds when comparing two Date objects
183+
long time1 = date1.getTime() / 1000;
184+
long time2 = date2.getTime() / 1000;
185+
return Long.compare(time1, time2);
186+
},
187+
Date.class
188+
)
189+
.isEqualTo(prod);
190+
}
191+
}
192+
}
193+
}

0 commit comments

Comments
 (0)