44package com .imsweb .seerapi .compare ;
55
66import java .io .IOException ;
7+ import java .util .ArrayList ;
78import java .util .Date ;
89import java .util .HashMap ;
910import java .util .LinkedHashMap ;
1516import org .junit .jupiter .api .Test ;
1617
1718import com .imsweb .seerapi .client .SeerApi ;
19+ import com .imsweb .seerapi .client .glossary .Glossary ;
20+ import com .imsweb .seerapi .client .glossary .GlossarySearchResults ;
21+ import com .imsweb .seerapi .client .glossary .GlossaryService ;
1822import com .imsweb .seerapi .client .hcpcs .Hcpcs ;
1923import com .imsweb .seerapi .client .hcpcs .HcpcsService ;
2024import com .imsweb .seerapi .client .ndc .NdcProduct ;
@@ -38,17 +42,17 @@ private String getApiKey() {
3842
3943 @ Test
4044 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 ();
45+ NdcService prodService = new SeerApi .Builder ().url (PROD_URL ).apiKey (getApiKey ()).connect ().ndc ();
46+ NdcService localService = new SeerApi .Builder ().url (LOCAL_URL ).apiKey (getApiKey ()).connect ().ndc ();
4347
4448 long page = 1 ;
4549
4650 Map <String , String > params = new HashMap <>();
4751 params .put ("page" , String .valueOf (page ));
4852 params .put ("per_page" , "100" );
4953 params .put ("order" , "ndc" );
50- List <NdcProduct > prodList = ndcProd .search (params ).execute ().body ();
51- List <NdcProduct > localList = ndcLocal .search (params ).execute ().body ();
54+ List <NdcProduct > prodList = prodService .search (params ).execute ().body ();
55+ List <NdcProduct > localList = localService .search (params ).execute ().body ();
5256
5357 while (!Objects .requireNonNull (prodList ).isEmpty () && !Objects .requireNonNull (localList ).isEmpty ()) {
5458 assertThat (localList )
@@ -60,15 +64,15 @@ void testNdc() throws IOException {
6064
6165 page += 1 ;
6266 params .put ("page" , String .valueOf (page ));
63- prodList = ndcProd .search (params ).execute ().body ();
64- localList = ndcLocal .search (params ).execute ().body ();
67+ prodList = prodService .search (params ).execute ().body ();
68+ localList = localService .search (params ).execute ().body ();
6569 }
6670 }
6771
6872 @ Test
6973 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 ();
74+ HcpcsService prodService = new SeerApi .Builder ().url (PROD_URL ).apiKey (getApiKey ()).connect ().hcpcs ();
75+ HcpcsService localService = new SeerApi .Builder ().url (LOCAL_URL ).apiKey (getApiKey ()).connect ().hcpcs ();
7276
7377 long page = 1 ;
7478
@@ -77,8 +81,8 @@ void testHcpcs() throws IOException {
7781 params .put ("per_page" , "100" );
7882 params .put ("order" , "hcpcs_code" );
7983
80- List <Hcpcs > prodList = hcpcsProd .search (params ).execute ().body ();
81- List <Hcpcs > localList = hcpcsLocal .search (params ).execute ().body ();
84+ List <Hcpcs > prodList = prodService .search (params ).execute ().body ();
85+ List <Hcpcs > localList = localService .search (params ).execute ().body ();
8286
8387 while (!Objects .requireNonNull (prodList ).isEmpty ()) {
8488 System .out .println ("HCPCS page " + page );
@@ -90,8 +94,8 @@ void testHcpcs() throws IOException {
9094
9195 page += 1 ;
9296 params .put ("page" , String .valueOf (page ));
93- prodList = hcpcsProd .search (params ).execute ().body ();
94- localList = hcpcsLocal .search (params ).execute ().body ();
97+ prodList = prodService .search (params ).execute ().body ();
98+ localList = localService .search (params ).execute ().body ();
9599 }
96100 }
97101
@@ -108,17 +112,17 @@ private Map<String, String> getAlgorithmVersions() {
108112
109113 @ Test
110114 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 ();
115+ StagingService prodService = new SeerApi .Builder ().url (PROD_URL ).apiKey (getApiKey ()).connect ().staging ();
116+ StagingService localService = new SeerApi .Builder ().url (LOCAL_URL ).apiKey (getApiKey ()).connect ().staging ();
113117
114118 Map <String , String > algorithmMap = getAlgorithmVersions ();
115119 for (String algorithmId : algorithmMap .keySet ()) {
116120 String algorithmVersion = algorithmMap .get (algorithmId );
117121
118122 System .out .println ("Getting list of all schemas in " + algorithmId + ":" + algorithmVersion );
119123
120- List <StagingSchemaInfo > prodSchemas = stagingProd .schemas (algorithmId , algorithmVersion ).execute ().body ();
121- List <StagingSchemaInfo > localSchemas = stagingLocal .schemas (algorithmId , algorithmVersion ).execute ().body ();
124+ List <StagingSchemaInfo > prodSchemas = prodService .schemas (algorithmId , algorithmVersion ).execute ().body ();
125+ List <StagingSchemaInfo > localSchemas = localService .schemas (algorithmId , algorithmVersion ).execute ().body ();
122126
123127 assertThat (localSchemas )
124128 .hasSameSizeAs (prodSchemas ) // Ensure both lists have the same size
@@ -127,8 +131,8 @@ void testStagingSchemas() throws IOException {
127131 .isEqualTo (prodSchemas );
128132
129133 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 ();
134+ StagingSchema prod = prodService .schemaById (algorithmId , algorithmVersion , prodSchema .getId ()).execute ().body ();
135+ StagingSchema local = localService .schemaById (algorithmId , algorithmVersion , prodSchema .getId ()).execute ().body ();
132136
133137 System .out .println ("Comparing [" + algorithmId + ":" + algorithmVersion + "] schema " + prodSchema .getId ());
134138
@@ -151,17 +155,17 @@ void testStagingSchemas() throws IOException {
151155
152156 @ Test
153157 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 ();
158+ StagingService prodService = new SeerApi .Builder ().url (PROD_URL ).apiKey (getApiKey ()).connect ().staging ();
159+ StagingService localService = new SeerApi .Builder ().url (LOCAL_URL ).apiKey (getApiKey ()).connect ().staging ();
156160
157161 Map <String , String > algorithmMap = getAlgorithmVersions ();
158162 for (String algorithmId : algorithmMap .keySet ()) {
159163 String algorithmVersion = algorithmMap .get (algorithmId );
160164
161165 System .out .println ("Getting list of all tables in " + algorithmId + ":" + algorithmVersion );
162166
163- List <StagingTable > prodTables = stagingProd .tables (algorithmId , algorithmVersion ).execute ().body ();
164- List <StagingTable > localTables = stagingLocal .tables (algorithmId , algorithmVersion ).execute ().body ();
167+ List <StagingTable > prodTables = prodService .tables (algorithmId , algorithmVersion ).execute ().body ();
168+ List <StagingTable > localTables = localService .tables (algorithmId , algorithmVersion ).execute ().body ();
165169
166170 assertThat (localTables )
167171 .hasSameSizeAs (prodTables ) // Ensure both lists have the same size
@@ -170,8 +174,8 @@ void testStagingTables() throws IOException {
170174 .isEqualTo (prodTables );
171175
172176 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 ();
177+ StagingTable prod = prodService .tableById (algorithmId , algorithmVersion , prodTable .getId ()).execute ().body ();
178+ StagingTable local = localService .tableById (algorithmId , algorithmVersion , prodTable .getId ()).execute ().body ();
175179
176180 System .out .println ("Comparing [" + algorithmId + ":" + algorithmVersion + "] table " + prodTable .getId ());
177181
@@ -190,4 +194,61 @@ void testStagingTables() throws IOException {
190194 }
191195 }
192196 }
197+
198+ @ Test
199+ void testGlossary () throws IOException {
200+ GlossaryService prodService = new SeerApi .Builder ().url (PROD_URL ).apiKey (getApiKey ()).connect ().glossary ();
201+ GlossaryService localService = new SeerApi .Builder ().url (LOCAL_URL ).apiKey (getApiKey ()).connect ().glossary ();
202+
203+ Map <String , String > params = new HashMap <>();
204+
205+ long offset = 0 ;
206+ long perPage = 100 ;
207+ params .put ("offset" , String .valueOf (offset ));
208+ params .put ("count" , String .valueOf (perPage ));
209+
210+ // get a list of ids
211+ List <String > ids = new ArrayList <>();
212+
213+ System .out .println ("Collecting identifiers for glossary 'latest' version" );
214+
215+ GlossarySearchResults prod = prodService .search ("latest" , params ).execute ().body ();
216+
217+ while (Objects .requireNonNull (prod ).getResults () != null && !prod .getResults ().isEmpty ()) {
218+ for (Glossary glossary : prod .getResults ())
219+ ids .add (glossary .getId ());
220+
221+ offset += perPage ;
222+ params .put ("offset" , String .valueOf (offset ));
223+
224+ prod = prodService .search ("latest" , params ).execute ().body ();
225+ }
226+
227+ System .out .println ("Found " + ids .size () + " identifiers for glossary 'latest' version" );
228+
229+ for (String id : ids ) {
230+ System .out .println ("Comparing " + id );
231+ Glossary prodGlossary = prodService .getById ("latest" , id ).execute ().body ();
232+ Glossary localGlossary = localService .getById ("latest" , id ).execute ().body ();
233+
234+ assertThat (localGlossary )
235+ .usingRecursiveComparison ()
236+ .withComparatorForType (
237+ (value1 , value2 ) -> {
238+ // Treat null and empty string as equal
239+ if (value1 == null && "" .equals (value2 ) || "" .equals (value1 ) && value2 == null ) {
240+ return 0 ; // Consider them equal
241+ }
242+ if (value1 == null )
243+ return -1 ;
244+ if (value2 == null )
245+ return 1 ;
246+ return value1 .compareTo (value2 );
247+ },
248+ String .class // Apply to all String fields, including in lists
249+ )
250+ .isEqualTo (prodGlossary );
251+ }
252+ }
253+
193254}
0 commit comments