3
3
import static org .assertj .core .api .Assertions .assertThat ;
4
4
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
5
5
6
- import com .fasterxml .jackson .core . JsonProcessingException ;
6
+ import com .fasterxml .jackson .databind . JsonMappingException ;
7
7
import com .google .common .collect .ImmutableMap ;
8
8
import com .hubspot .jinjava .Jinjava ;
9
9
import com .hubspot .jinjava .JinjavaConfig ;
10
10
import com .hubspot .jinjava .LegacyOverrides ;
11
11
import com .hubspot .jinjava .interpret .JinjavaInterpreter ;
12
+ import com .hubspot .jinjava .interpret .OutputTooBigException ;
12
13
import com .hubspot .jinjava .objects .collections .SizeLimitingPyMap ;
13
14
import java .util .AbstractMap ;
14
15
import java .util .ArrayList ;
15
16
import java .util .HashMap ;
16
17
import java .util .List ;
17
18
import java .util .Map ;
19
+ import org .apache .commons .lang3 .RandomStringUtils ;
18
20
import org .junit .Test ;
19
21
20
22
public class PyishObjectMapperTest {
@@ -29,7 +31,7 @@ public void itSerializesMapWithNullKeysAsEmptyString() {
29
31
}
30
32
31
33
@ Test
32
- public void itSerializesMapEntrySet () throws JsonProcessingException {
34
+ public void itSerializesMapEntrySet () {
33
35
SizeLimitingPyMap map = new SizeLimitingPyMap (new HashMap <>(), 10 );
34
36
map .put ("foo" , "bar" );
35
37
map .put ("bar" , ImmutableMap .of ("foobar" , new ArrayList <>()));
@@ -39,7 +41,7 @@ public void itSerializesMapEntrySet() throws JsonProcessingException {
39
41
}
40
42
41
43
@ Test
42
- public void itSerializesMapEntrySetWithLimit () throws JsonProcessingException {
44
+ public void itSerializesMapEntrySetWithLimit () {
43
45
SizeLimitingPyMap map = new SizeLimitingPyMap (new HashMap <>(), 10 );
44
46
map .put ("foo" , "bar" );
45
47
map .put ("bar" , ImmutableMap .of ("foobar" , new ArrayList <>()));
@@ -85,7 +87,24 @@ public void itLimitsDepth() {
85
87
JinjavaInterpreter .pushCurrent (jinjava .newInterpreter ());
86
88
assertThatThrownBy (() -> PyishObjectMapper .getAsPyishStringOrThrow (original ))
87
89
.as ("The string to be serialized is larger than the max output size" )
88
- .isInstanceOf (LengthLimitingJsonProcessingException .class );
90
+ .isInstanceOf (JsonMappingException .class )
91
+ .hasMessageContaining ("Max length of 10000 chars reached" );
92
+ } finally {
93
+ JinjavaInterpreter .popCurrent ();
94
+ }
95
+ }
96
+
97
+ @ Test
98
+ public void itLimitsOutputSize () {
99
+ String input = RandomStringUtils .random (10002 );
100
+ try {
101
+ Jinjava jinjava = new Jinjava (
102
+ JinjavaConfig .newBuilder ().withMaxOutputSize (10000 ).build ()
103
+ );
104
+ JinjavaInterpreter .pushCurrent (jinjava .newInterpreter ());
105
+ assertThatThrownBy (() -> PyishObjectMapper .getAsPyishString (input ))
106
+ .isInstanceOf (OutputTooBigException .class )
107
+ .hasMessageContaining ("over limit of 10000 bytes" );
89
108
} finally {
90
109
JinjavaInterpreter .popCurrent ();
91
110
}
0 commit comments