| 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.Date; |
| 25 |
|
| 26 |
import org.apache.qpid.proton.amqp.Binary; |
| 27 |
import org.apache.qpid.proton.amqp.Symbol; |
| 28 |
import org.apache.qpid.proton.amqp.UnsignedInteger; |
| 29 |
import org.apache.qpid.proton.amqp.messaging.Properties; |
| 30 |
import org.junit.Test; |
| 31 |
|
| 32 |
/** |
| 33 |
* Test for decoder of AMQP Properties type. |
| 34 |
*/ |
| 35 |
public class PropertiesCodecTest extends CodecTestSupport { |
| 36 |
|
| 37 |
private final int LARGE_SIZE = 1024; |
| 38 |
private final int SMALL_SIZE = 32; |
| 39 |
|
| 40 |
@Test |
| 41 |
public void testDecodeSmallSeriesOfPropertiess() throws IOException { |
| 42 |
doTestDecodePropertiesSeries(SMALL_SIZE); |
| 43 |
} |
| 44 |
|
| 45 |
@Test |
| 46 |
public void testDecodeLargeSeriesOfPropertiess() throws IOException { |
| 47 |
doTestDecodePropertiesSeries(LARGE_SIZE); |
| 48 |
} |
| 49 |
|
| 50 |
private void doTestDecodePropertiesSeries(int size) throws IOException { |
| 51 |
Properties properties = new Properties(); |
| 52 |
|
| 53 |
Date timeNow = new Date(System.currentTimeMillis()); |
| 54 |
|
| 55 |
properties.setMessageId("ID:Message-1:1:1:0"); |
| 56 |
properties.setUserId(new Binary(new byte[1])); |
| 57 |
properties.setTo("queue:work"); |
| 58 |
properties.setSubject("help"); |
| 59 |
properties.setReplyTo("queue:temp:me"); |
| 60 |
properties.setContentEncoding(Symbol.valueOf("text/UTF-8")); |
| 61 |
properties.setContentType(Symbol.valueOf("text")); |
| 62 |
properties.setCorrelationId("correlation-id"); |
| 63 |
properties.setAbsoluteExpiryTime(timeNow); |
| 64 |
properties.setCreationTime(timeNow); |
| 65 |
properties.setGroupId("group-1"); |
| 66 |
properties.setGroupSequence(UnsignedInteger.valueOf(1)); |
| 67 |
properties.setReplyToGroupId("group-1"); |
| 68 |
|
| 69 |
for (int i = 0; i < size; ++i) { |
| 70 |
encoder.writeObject(properties); |
| 71 |
} |
| 72 |
|
| 73 |
buffer.clear(); |
| 74 |
|
| 75 |
for (int i = 0; i < size; ++i) { |
| 76 |
final Object result = decoder.readObject(); |
| 77 |
|
| 78 |
assertNotNull(result); |
| 79 |
assertTrue(result instanceof Properties); |
| 80 |
|
| 81 |
Properties decoded = (Properties) result; |
| 82 |
|
| 83 |
assertNotNull(decoded.getAbsoluteExpiryTime()); |
| 84 |
assertEquals(timeNow, decoded.getAbsoluteExpiryTime()); |
| 85 |
assertEquals(Symbol.valueOf("text/UTF-8"), decoded.getContentEncoding()); |
| 86 |
assertEquals(Symbol.valueOf("text"), decoded.getContentType()); |
| 87 |
assertEquals("correlation-id", decoded.getCorrelationId()); |
| 88 |
assertEquals(timeNow, decoded.getCreationTime()); |
| 89 |
assertEquals("group-1", decoded.getGroupId()); |
| 90 |
assertEquals(UnsignedInteger.valueOf(1), decoded.getGroupSequence()); |
| 91 |
assertEquals("ID:Message-1:1:1:0", decoded.getMessageId()); |
| 92 |
assertEquals("queue:temp:me", decoded.getReplyTo()); |
| 93 |
assertEquals("group-1", decoded.getReplyToGroupId()); |
| 94 |
assertEquals("help", decoded.getSubject()); |
| 95 |
assertEquals("queue:work", decoded.getTo()); |
| 96 |
assertTrue(decoded.getUserId() instanceof Binary); |
| 97 |
} |
| 98 |
} |
| 99 |
} |