1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ package org .apache .pekko .serialization .jackson
19+
20+ import com .typesafe .config .ConfigFactory
21+ import org .scalatest .BeforeAndAfterAll
22+ import org .scalatest .matchers .should .Matchers
23+ import org .scalatest .wordspec .AnyWordSpecLike
24+ import org .apache .pekko
25+ import pekko .actor .{ ActorSystem , ExtendedActorSystem }
26+ import pekko .testkit .TestKit
27+
28+ class JacksonFactorySpec extends TestKit (ActorSystem (" JacksonFactorySpec" ))
29+ with AnyWordSpecLike with Matchers with BeforeAndAfterAll {
30+
31+ private val defaultConfig = ConfigFactory .defaultReference()
32+ private val dynamicAccess = system.asInstanceOf [ExtendedActorSystem ].dynamicAccess
33+ private val objectMapperFactory = new JacksonObjectMapperFactory
34+
35+ override def afterAll (): Unit = {
36+ super .afterAll()
37+ system.terminate()
38+ }
39+
40+ " Jackson Factory config" must {
41+ " support StreamReadConstraints" in {
42+ val bindingName = " testJackson"
43+ val maxNumLen = 987
44+ val maxStringLen = 1234567
45+ val maxDocLen = 123456789L
46+ val maxNestingDepth = 5
47+ val config = ConfigFactory .parseString(
48+ s """ pekko.serialization.jackson.read.max-number-length= $maxNumLen
49+ |pekko.serialization.jackson.read.max-string-length= $maxStringLen
50+ |pekko.serialization.jackson.read.max-document-length= $maxDocLen
51+ |pekko.serialization.jackson.read.max-nesting-depth= $maxNestingDepth
52+ | """ .stripMargin)
53+ .withFallback(defaultConfig)
54+ val jacksonConfig = JacksonObjectMapperProvider .configForBinding(bindingName, config)
55+ val mapper = JacksonObjectMapperProvider .createObjectMapper(
56+ bindingName, None , objectMapperFactory, jacksonConfig, dynamicAccess, None )
57+ val streamReadConstraints = mapper.getFactory.streamReadConstraints()
58+ streamReadConstraints.getMaxNumberLength shouldEqual maxNumLen
59+ streamReadConstraints.getMaxStringLength shouldEqual maxStringLen
60+ streamReadConstraints.getMaxDocumentLength shouldEqual maxDocLen
61+ streamReadConstraints.getMaxNestingDepth shouldEqual maxNestingDepth
62+ }
63+ " support StreamWriteConstraints" in {
64+ val bindingName = " testJackson"
65+ val maxNestingDepth = 54321
66+ val config = ConfigFactory .parseString(
67+ s " pekko.serialization.jackson.write.max-nesting-depth= $maxNestingDepth" )
68+ .withFallback(defaultConfig)
69+ val jacksonConfig = JacksonObjectMapperProvider .configForBinding(bindingName, config)
70+ val mapper = JacksonObjectMapperProvider .createObjectMapper(
71+ bindingName, None , objectMapperFactory, jacksonConfig, dynamicAccess, None )
72+ val streamWriteConstraints = mapper.getFactory.streamWriteConstraints()
73+ streamWriteConstraints.getMaxNestingDepth shouldEqual maxNestingDepth
74+ }
75+ }
76+ }
0 commit comments