/protocols/smpp/src/test/java/org/mobicents/protocols/smpp/AddressTest.java
Java | 83 lines | 51 code | 11 blank | 21 comment | 0 complexity | 64fc54f1c14adbce189fc533277ece2c MD5 | raw file
1/* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2011, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23package org.mobicents.protocols.smpp; 24 25import static org.testng.Assert.assertEquals; 26import static org.testng.Assert.assertTrue; 27import static org.testng.Assert.fail; 28 29import java.io.ByteArrayOutputStream; 30import java.io.IOException; 31 32import org.testng.annotations.Test; 33 34import org.mobicents.protocols.smpp.Address; 35import org.mobicents.protocols.smpp.Npi; 36import org.mobicents.protocols.smpp.Ton; 37import org.mobicents.protocols.smpp.util.PacketDecoderImpl; 38import org.mobicents.protocols.smpp.util.PacketEncoderImpl; 39 40@Test 41public class AddressTest { 42 private void testSize(Address addr) { 43 ByteArrayOutputStream out = new ByteArrayOutputStream(); 44 PacketEncoderImpl encoder = new PacketEncoderImpl(out); 45 try { 46 addr.writeTo(encoder); 47 } catch (IOException x) { 48 fail("Serializing address caused I/O Exception:\n" + x.toString()); 49 return; 50 } 51 byte[] array = out.toByteArray(); 52 PacketDecoderImpl decoder = new PacketDecoderImpl(array); 53 Address deserialized = decoder.readAddress(); 54 assertEquals(decoder.getParsePosition(), array.length); 55 assertEquals(addr.getLength(), array.length, "serialized. "); 56 assertEquals(array.length, deserialized.getLength(), "deserialized."); 57 } 58 59 public void testEmptyFieldSize() { 60 testSize(new Address()); 61 } 62 63 public void testFilledFieldSize() { 64 Address addr = new Address(); 65 addr.setTON(Ton.INTERNATIONAL); 66 addr.setNPI(Npi.ISDN); 67 addr.setAddress("353851234567"); 68 testSize(addr); 69 } 70 71 public void testEquals() { 72 Address a1 = new Address(Ton.NETWORK, 73 Npi.NATIONAL, "353851234567"); 74 Address a2 = new Address(Ton.NETWORK, 75 Npi.NATIONAL, "353851234567"); 76 Address a3 = new Address(Ton.NATIONAL, 77 Npi.NATIONAL, "441237654321"); 78 79 assertEquals(a2, a1); 80 assertTrue(!(a1.equals(a3))); 81 } 82} 83