Skip to content

Commit 5a4970a

Browse files
[fix][client] Add tests for ignored json fields (#3)
1 parent 7570614 commit 5a4970a

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

pulsar-client/src/test/java/org/apache/pulsar/client/impl/conf/ClientConfigurationDataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void testDoNotPrintSensitiveInfo() throws JsonProcessingException {
3939
ObjectMapper objectMapper = new ObjectMapper();
4040
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
4141
String serializedConf = objectMapper.writeValueAsString(clientConfigurationData);
42-
assertThat(serializedConf).doesNotContain("xxxx", "yyyy", "zzzz");
42+
assertThat(serializedConf).doesNotContain("xxxx", "yyyy", "zzzz", "serviceUrlProvider");
4343
}
4444

4545
}

pulsar-client/src/test/java/org/apache/pulsar/client/impl/conf/ConsumerConfigurationDataTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
package org.apache.pulsar.client.impl.conf;
2020

2121
import static org.assertj.core.api.Assertions.assertThat;
22+
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.fasterxml.jackson.databind.SerializationFeature;
2225
import java.util.regex.Pattern;
2326
import org.testng.annotations.DataProvider;
2427
import org.testng.annotations.Test;
@@ -45,4 +48,13 @@ public void testTopicConsumerConfigurationData(String topicName, int expectedPri
4548

4649
assertThat(topicConsumerConfigurationData.getPriorityLevel()).isEqualTo(expectedPriority);
4750
}
51+
52+
@Test
53+
public void testConsumerConfigurationDataSerializedWithoutIgnoredTransientFields() throws JsonProcessingException {
54+
ConsumerConfigurationData<String> consumerConfigurationData = new ConsumerConfigurationData<>();
55+
ObjectMapper objectMapper = new ObjectMapper();
56+
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
57+
String serializedConf = objectMapper.writeValueAsString(consumerConfigurationData);
58+
assertThat(serializedConf).doesNotContain("messageCrypto", "keySharedPolicy", "payloadProcessor");
59+
}
4860
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.client.impl.conf;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.fasterxml.jackson.databind.SerializationFeature;
25+
import org.testng.annotations.Test;
26+
27+
/**
28+
* Unit tests for {@link ProducerConfigurationData}.
29+
*/
30+
public class ProducerConfigurationDataTest {
31+
@Test
32+
public void testProducerConfigurationDataSerializedWithoutIgnoredTransientFields() throws JsonProcessingException {
33+
ProducerConfigurationData producerConfigurationData = new ProducerConfigurationData();
34+
ObjectMapper objectMapper = new ObjectMapper();
35+
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
36+
String serializedConf = objectMapper.writeValueAsString(producerConfigurationData);
37+
assertThat(serializedConf).doesNotContain("messageCrypto");
38+
}
39+
}

pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/SchemaInfoTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
*/
1919
package org.apache.pulsar.client.impl.schema;
2020

21+
import static org.assertj.core.api.Assertions.assertThat;
2122
import static org.testng.Assert.assertEquals;
23+
import com.fasterxml.jackson.core.JsonProcessingException;
24+
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.databind.SerializationFeature;
2226
import java.util.HashMap;
2327
import java.util.Map;
2428
import org.apache.pulsar.client.api.Schema;
@@ -286,7 +290,18 @@ public static Object[][] schemas() {
286290

287291
@Test(dataProvider = "schemas")
288292
public void testSchemaInfoToString(SchemaInfo si, String jsonifiedStr) {
289-
assertEquals(si.toString(), jsonifiedStr);
293+
String schemaInfoString = si.toString();
294+
assertEquals(schemaInfoString, jsonifiedStr);
295+
assertThat(schemaInfoString).doesNotContain("schemaHash");
296+
}
297+
298+
@Test(dataProvider = "schemas")
299+
public void testSerializedSchemaInfoDoesntContainIgnoredTransientFields(SchemaInfo si, String jsonifiedStr) throws
300+
JsonProcessingException {
301+
ObjectMapper objectMapper = new ObjectMapper();
302+
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
303+
String schemaInfoString = objectMapper.writeValueAsString(si);
304+
assertThat(schemaInfoString).doesNotContain("schemaHash");
290305
}
291306

292307
public static class SchemaInfoBuilderTest {

0 commit comments

Comments
 (0)