88import com .fasterxml .jackson .databind .JsonMappingException ;
99import com .fasterxml .jackson .databind .JsonNode ;
1010import com .fasterxml .jackson .databind .ObjectMapper ;
11- import edu .suffolk .litlab .efsp .model .FilingDoc ;
1211import edu .suffolk .litlab .efsp .model .PartyId ;
1312import edu .suffolk .litlab .efsp .utils .FailFastCollector ;
1413import edu .suffolk .litlab .efsp .utils .FilingError ;
1918import java .time .format .DateTimeParseException ;
2019import java .util .List ;
2120import java .util .Map ;
22- import java .util .Optional ;
2321import org .junit .jupiter .api .BeforeEach ;
2422import org .junit .jupiter .api .DisplayName ;
2523import org .junit .jupiter .api .Nested ;
@@ -35,7 +33,6 @@ public class FilingDocDocassembleJacksonDeserializerTest {
3533
3634 // TODO: more tests FilingAttachment separately, if possible
3735
38- Optional <FilingDoc > doc ;
3936 InfoCollector collector ;
4037 Map <String , PartyId > varToPartyId ;
4138
@@ -49,19 +46,19 @@ public void setUp() {
4946 public void testWeirdJsonShouldBeEmpty ()
5047 throws JsonMappingException , JsonProcessingException , FilingError {
5148 ObjectMapper m = new ObjectMapper ();
52- assertThatThrownBy (() -> fromNode (m .readTree ("null" ), varToPartyId , true , collector ))
49+ assertThatThrownBy (() -> fromNode (m .readTree ("null" ), varToPartyId , 0 , collector ))
5350 .isInstanceOf (FilingError .class );
54- assertThatThrownBy (() -> fromNode (m .readTree ("[]" ), varToPartyId , true , collector ))
51+ assertThatThrownBy (() -> fromNode (m .readTree ("[]" ), varToPartyId , 0 , collector ))
5552 .isInstanceOf (FilingError .class );
56- doc = fromNode (m .readTree ("{}" ), varToPartyId , true , collector );
53+ var doc = fromNode (m .readTree ("{}" ), varToPartyId , 0 , collector );
5754 assertThat (doc ).isEmpty ();
5855 }
5956
6057 // Aka, the old style
6158 @ Test
6259 public void noAttachmentsShouldLoadDocument () throws FilingError , IOException {
6360 JsonNode node = readFile ("old_style_doc.json" );
64- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
61+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
6562 assertThat (doc ).isPresent ();
6663 var attachments = doc .get ().getFilingAttachments ();
6764 assertThat (attachments .length ()).isEqualTo (1 );
@@ -71,8 +68,28 @@ public void noAttachmentsShouldLoadDocument() throws FilingError, IOException {
7168 @ Test
7269 public void oneAttachmentShouldLoadDocument () throws FilingError , IOException {
7370 JsonNode node = readFile ("one_attachment.json" );
74- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
71+ var maybeDoc =
72+ FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
73+ assertThat (maybeDoc ).isPresent ();
74+ var doc = maybeDoc .get ();
75+ assertThat (doc .sequenceNum ()).isEqualTo (0 );
76+ var attachments = doc .getFilingAttachments ();
77+ assertThat (attachments .length ()).isEqualTo (1 );
78+ assertThat (attachments .head ().getDocumentTypeFormatStandardName ()).isEqualTo ("6586" );
79+ var parties = doc .getFilingPartyIds ();
80+ assertThat (parties .size ()).isEqualTo (1 );
81+ assertThat (parties .get (0 ).isNewInCurrentFiling ()).isTrue ();
82+ assertThat (doc .getDescription ()).isPresent ();
83+ assertThat (doc .getDescription ().get ().get ())
84+ .isEqualTo ("The Motion to Stay Eviction for Bob Ma" );
85+ }
86+
87+ @ Test
88+ public void oneAttachmentAsSecondSequenceShouldLoadDocument () throws FilingError , IOException {
89+ JsonNode node = readFile ("one_attachment.json" );
90+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 2 , collector );
7591 assertThat (doc ).isPresent ();
92+ assertThat (doc .get ().sequenceNum ()).isEqualTo (2 );
7693 var attachments = doc .get ().getFilingAttachments ();
7794 assertThat (attachments .length ()).isEqualTo (1 );
7895 assertThat (attachments .head ().getDocumentTypeFormatStandardName ()).isEqualTo ("6586" );
@@ -84,7 +101,7 @@ public void oneAttachmentShouldLoadDocument() throws FilingError, IOException {
84101 @ Test
85102 public void partyIdNotPresent () throws IOException , FilingError {
86103 JsonNode node = readFile ("one_attachment.json" );
87- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , Map .of (), true , collector );
104+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , Map .of (), 0 , collector );
88105 assertThat (doc ).isPresent ();
89106 var parties = doc .get ().getFilingPartyIds ();
90107 assertThat (parties .size ()).isEqualTo (1 );
@@ -94,7 +111,7 @@ public void partyIdNotPresent() throws IOException, FilingError {
94111 @ Test
95112 public void oneEnabledOneDisabledShouldLoadOneAttachment () throws FilingError , IOException {
96113 JsonNode node = readFile ("one_enabled_one_disabled.json" );
97- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
114+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
98115 assertThat (doc ).isPresent ();
99116 var attachments = doc .get ().getFilingAttachments ();
100117 assertThat (attachments .length ()).isEqualTo (1 );
@@ -104,14 +121,14 @@ public void oneEnabledOneDisabledShouldLoadOneAttachment() throws FilingError, I
104121 @ Test
105122 public void noEnabledShouldFilingError () throws IOException , FilingError {
106123 JsonNode node = readFile ("fail_no_enabled_attachment.json" );
107- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
124+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
108125 assertThat (doc ).as ("Document shouldn't have parsed" ).isEmpty ();
109126 }
110127
111128 @ Test
112129 public void shouldFallbackToParentDocIfNoEnabled () throws FilingError , IOException {
113130 JsonNode node = readFile ("fallback_to_upper_doc.json" );
114- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
131+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
115132 assertThat (doc ).isPresent ();
116133 var attachments = doc .get ().getFilingAttachments ();
117134 assertThat (attachments .length ()).isEqualTo (1 );
@@ -122,7 +139,7 @@ public void shouldFallbackToParentDocIfNoEnabled() throws FilingError, IOExcepti
122139 @ Test
123140 public void noDocTypesShouldBeEmptyStrings () throws IOException , FilingError {
124141 JsonNode node = readFile ("fail_missing_doc_types.json" );
125- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
142+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
126143 assertThat (doc ).isPresent ();
127144 var attachments = doc .get ().getFilingAttachments ();
128145 assertThat (attachments .length ()).isEqualTo (1 );
@@ -132,7 +149,7 @@ public void noDocTypesShouldBeEmptyStrings() throws IOException, FilingError {
132149 @ Test
133150 public void twoAttachmentsShouldLoadTwoAttachments () throws FilingError , IOException {
134151 JsonNode node = readFile ("two_attachments.json" );
135- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
152+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
136153 assertThat (doc ).isPresent ();
137154 var attachments = doc .get ().getFilingAttachments ();
138155 assertThat (attachments .length ()).isEqualTo (2 );
@@ -146,7 +163,7 @@ public void twoAttachmentsShouldLoadTwoAttachments() throws FilingError, IOExcep
146163 @ Test
147164 public void hasOptionalServicesShouldParse () throws FilingError , IOException {
148165 JsonNode node = readFile ("has_optional_services.json" );
149- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
166+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
150167 assertThat (doc ).isPresent ();
151168 var optionalServices = doc .get ().getOptionalServices ();
152169 assertThat (optionalServices ).hasSize (1 );
@@ -157,7 +174,7 @@ public void hasOptionalServicesShouldParse() throws FilingError, IOException {
157174 public void filingActionShouldAlwaysParse () throws IOException , FilingError {
158175 for (var emptyData : List .of ("null" , "\" \" " , "\" clearly_wrong\" " )) {
159176 JsonNode node = readTemplate ("template_filing_action.json" , emptyData );
160- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
177+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
161178 assertThat (doc ).isPresent ();
162179 assertThat (doc .get ().getFilingAction ()).isEmpty ();
163180 }
@@ -169,7 +186,7 @@ public void filingActionShouldAlwaysParse() throws IOException, FilingError {
169186 "\" e_file_and_serve\" " ,
170187 "\" serve\" " )) {
171188 JsonNode node = readTemplate ("template_filing_action.json" , data );
172- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
189+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
173190 assertThat (doc ).isPresent ();
174191 assertThat (doc .get ().getFilingAction ()).isPresent ();
175192 }
@@ -178,7 +195,7 @@ public void filingActionShouldAlwaysParse() throws IOException, FilingError {
178195 @ Test
179196 public void testTylerMergeAttachments () throws IOException , FilingError {
180197 JsonNode node = readFile ("tyler_merge_attachments.json" );
181- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
198+ var doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
182199 assertThat (doc ).isPresent ();
183200 var attachments = doc .get ().getFilingAttachments ();
184201 assertThat (attachments .length ()).isEqualTo (1 );
@@ -202,7 +219,8 @@ record InputSaved(String dateInput, String savedDate) {}
202219 // TODO: weird behavior: local date parses based on server's timezone? Should fix
203220 new InputSaved ("\" 2024-02-29T01:19:00.123Z\" " , "2024-02-28" ))) {
204221 JsonNode node = readTemplate (INPUT_FILE , testData .dateInput );
205- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
222+ var doc =
223+ FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
206224 assertThat (doc ).isPresent ();
207225 assertThat (doc .get ().getDueDate ()).isPresent ();
208226 assertThat (doc .get ().getDueDate ().get ()).isEqualTo (testData .savedDate );
@@ -217,7 +235,8 @@ public void nonTextDueDateShouldBeEmpty() throws IOException, FilingError {
217235 )) { // TODO(brycew): Should also include an empty and blank string, but those error
218236 // right now
219237 JsonNode node = readTemplate (INPUT_FILE , emptyData );
220- doc = FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , true , collector );
238+ var doc =
239+ FilingDocDocassembleJacksonDeserializer .fromNode (node , varToPartyId , 0 , collector );
221240 assertThat (doc ).isPresent ();
222241 assertThat (doc .get ().getDueDate ()).isEmpty ();
223242 }
@@ -238,7 +257,7 @@ public void invalidDueDateShouldThrow() throws IOException, FilingError {
238257 assertThatThrownBy (
239258 () ->
240259 FilingDocDocassembleJacksonDeserializer .fromNode (
241- node , varToPartyId , true , collector ))
260+ node , varToPartyId , 0 , collector ))
242261 .withFailMessage ("Failed on %s" , badData )
243262 .isInstanceOf (DateTimeParseException .class );
244263 }
@@ -262,7 +281,7 @@ public void testMalformedDataUrlShouldThrow() throws IOException {
262281 assertThatThrownBy (
263282 () ->
264283 FilingDocDocassembleJacksonDeserializer .fromNode (
265- node , varToPartyId , true , collector ))
284+ node , varToPartyId , 0 , collector ))
266285 .withFailMessage ("Using %s" , badData )
267286 .isInstanceOf (FilingError .class );
268287 }
0 commit comments