Debian Codegraph @

proton-j/src/test/java/org/apache/qpid/proton/codec/ApplicationPropertiesCodecTest.java

raw
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 package org.apache.qpid.proton.codec;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertTrue;
22
23 import java.io.IOException;
24 import java.util.LinkedHashMap;
25 import java.util.Map;
26
27 import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
28 import org.junit.Test;
29
30 public class ApplicationPropertiesCodecTest extends CodecTestSupport {
31
32 private final int LARGE_SIZE = 1024;
33 private final int SMALL_SIZE = 32;
34
35 @Test
36 public void testDecodeSmallSeriesOfApplicationProperties() throws IOException {
37 doTestDecodeHeaderSeries(SMALL_SIZE);
38 }
39
40 @Test
41 public void testDecodeLargeSeriesOfApplicationProperties() throws IOException {
42 doTestDecodeHeaderSeries(LARGE_SIZE);
43 }
44
45 private void doTestDecodeHeaderSeries(int size) throws IOException {
46
47 Map<String, Object> propertiesMap = new LinkedHashMap<>();
48 ApplicationProperties properties = new ApplicationProperties(propertiesMap);
49
50 propertiesMap.put("key-1", "1");
51 propertiesMap.put("key-2", "2");
52 propertiesMap.put("key-3", "3");
53 propertiesMap.put("key-4", "4");
54 propertiesMap.put("key-5", "5");
55 propertiesMap.put("key-6", "6");
56 propertiesMap.put("key-7", "7");
57 propertiesMap.put("key-8", "8");
58
59 for (int i = 0; i < size; ++i) {
60 encoder.writeObject(properties);
61 }
62
63 buffer.clear();
64
65 for (int i = 0; i < size; ++i) {
66 final Object result = decoder.readObject();
67
68 assertNotNull(result);
69 assertTrue(result instanceof ApplicationProperties);
70
71 ApplicationProperties decoded = (ApplicationProperties) result;
72
73 assertEquals(8, decoded.getValue().size());
74 assertTrue(decoded.getValue().equals(propertiesMap));
75 }
76 }
77 }