PageRenderTime 41ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/servers/diameter/testsuite/tests/src/test/java/org/mobicents/slee/resources/diameter/tests/factories/CCAFactoriesTest.java

http://mobicents.googlecode.com/
Java | 854 lines | 404 code | 229 blank | 221 comment | 1 complexity | e9127ade5a444af03b53125c29f5b678 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2008-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. package org.mobicents.slee.resources.diameter.tests.factories;
  23. import static org.jdiameter.client.impl.helpers.Parameters.AcctApplId;
  24. import static org.jdiameter.client.impl.helpers.Parameters.ApplicationId;
  25. import static org.jdiameter.client.impl.helpers.Parameters.Assembler;
  26. import static org.jdiameter.client.impl.helpers.Parameters.AuthApplId;
  27. import static org.jdiameter.client.impl.helpers.Parameters.OwnDiameterURI;
  28. import static org.jdiameter.client.impl.helpers.Parameters.OwnRealm;
  29. import static org.jdiameter.client.impl.helpers.Parameters.OwnVendorID;
  30. import static org.jdiameter.client.impl.helpers.Parameters.PeerName;
  31. import static org.jdiameter.client.impl.helpers.Parameters.PeerRating;
  32. import static org.jdiameter.client.impl.helpers.Parameters.PeerTable;
  33. import static org.jdiameter.client.impl.helpers.Parameters.RealmEntry;
  34. import static org.jdiameter.client.impl.helpers.Parameters.RealmTable;
  35. import static org.jdiameter.client.impl.helpers.Parameters.VendorId;
  36. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryExpTime;
  37. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryIsDynamic;
  38. import static org.jdiameter.server.impl.helpers.Parameters.RealmHosts;
  39. import static org.jdiameter.server.impl.helpers.Parameters.RealmLocalAction;
  40. import static org.jdiameter.server.impl.helpers.Parameters.RealmName;
  41. import static org.junit.Assert.*;
  42. import net.java.slee.resource.diameter.cca.events.CreditControlAnswer;
  43. import net.java.slee.resource.diameter.cca.events.CreditControlRequest;
  44. import net.java.slee.resource.diameter.cca.events.avp.CcMoneyAvp;
  45. import net.java.slee.resource.diameter.cca.events.avp.CcUnitType;
  46. import net.java.slee.resource.diameter.cca.events.avp.CostInformationAvp;
  47. import net.java.slee.resource.diameter.cca.events.avp.FinalUnitActionType;
  48. import net.java.slee.resource.diameter.cca.events.avp.FinalUnitIndicationAvp;
  49. import net.java.slee.resource.diameter.cca.events.avp.GSUPoolReferenceAvp;
  50. import net.java.slee.resource.diameter.cca.events.avp.GrantedServiceUnitAvp;
  51. import net.java.slee.resource.diameter.cca.events.avp.MultipleServicesCreditControlAvp;
  52. import net.java.slee.resource.diameter.cca.events.avp.RedirectAddressType;
  53. import net.java.slee.resource.diameter.cca.events.avp.RedirectServerAvp;
  54. import net.java.slee.resource.diameter.cca.events.avp.RequestedServiceUnitAvp;
  55. import net.java.slee.resource.diameter.cca.events.avp.ServiceParameterInfoAvp;
  56. import net.java.slee.resource.diameter.cca.events.avp.SubscriptionIdAvp;
  57. import net.java.slee.resource.diameter.cca.events.avp.SubscriptionIdType;
  58. import net.java.slee.resource.diameter.cca.events.avp.UnitValueAvp;
  59. import net.java.slee.resource.diameter.cca.events.avp.UsedServiceUnitAvp;
  60. import net.java.slee.resource.diameter.cca.events.avp.UserEquipmentInfoAvp;
  61. import net.java.slee.resource.diameter.cca.events.avp.UserEquipmentInfoType;
  62. import org.jdiameter.api.Stack;
  63. import org.jdiameter.client.impl.helpers.EmptyConfiguration;
  64. import org.junit.Assert;
  65. import org.junit.Test;
  66. import org.mobicents.diameter.dictionary.AvpDictionary;
  67. import org.mobicents.slee.resource.diameter.base.DiameterAvpFactoryImpl;
  68. import org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl;
  69. import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl;
  70. import org.mobicents.slee.resource.diameter.cca.CreditControlAVPFactoryImpl;
  71. import org.mobicents.slee.resource.diameter.cca.CreditControlMessageFactoryImpl;
  72. /**
  73. * Test class for JAIN SLEE Diameter CCA RA Message and AVP Factories
  74. *
  75. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  76. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  77. */
  78. public class CCAFactoriesTest {
  79. private static String clientHost = "127.0.0.1";
  80. private static String clientPort = "13868";
  81. private static String clientURI = "aaa://" + clientHost + ":" + clientPort;
  82. private static String serverHost = "localhost";
  83. private static String serverPort = "3868";
  84. private static String serverURI = "aaa://" + serverHost + ":" + serverPort;
  85. private static String realmName = "mobicents.org";
  86. private static CreditControlMessageFactoryImpl ccaMessageFactory;
  87. private static CreditControlAVPFactoryImpl ccaAvpFactory;
  88. static {
  89. Stack stack = new org.jdiameter.client.impl.StackImpl();
  90. try {
  91. stack.init(new MyConfiguration());
  92. }
  93. catch (Exception e) {
  94. throw new RuntimeException("Failed to initialize the stack.");
  95. }
  96. DiameterMessageFactoryImpl baseFactory = new DiameterMessageFactoryImpl(stack);
  97. DiameterAvpFactoryImpl baseAvpFactory = new DiameterAvpFactoryImpl();
  98. ccaAvpFactory = new CreditControlAVPFactoryImpl(baseAvpFactory);
  99. try {
  100. ccaMessageFactory = new CreditControlMessageFactoryImpl(baseFactory, stack.getSessionFactory().getNewSession(), stack, ccaAvpFactory);
  101. }
  102. catch (Exception e) {
  103. e.printStackTrace();
  104. }
  105. try {
  106. AvpDictionary.INSTANCE.parseDictionary(CCAFactoriesTest.class.getClassLoader().getResourceAsStream("dictionary.xml"));
  107. }
  108. catch (Exception e) {
  109. throw new RuntimeException("Failed to parse dictionary file.");
  110. }
  111. }
  112. @Test
  113. public void isRequestCCR() throws Exception {
  114. CreditControlRequest ccr = ccaMessageFactory.createCreditControlRequest();
  115. assertTrue("Request Flag in Credit-Control-Request is not set.", ccr.getHeader().isRequest());
  116. }
  117. @Test
  118. public void isProxiableCCR() throws Exception {
  119. CreditControlRequest ccr = ccaMessageFactory.createCreditControlRequest();
  120. assertTrue("The 'P' bit is not set by default in Credit-Control-Request, it should.", ccr.getHeader().isProxiable());
  121. }
  122. @Test
  123. public void testGettersAndSettersCCR() throws Exception {
  124. CreditControlRequest ccr = ccaMessageFactory.createCreditControlRequest();
  125. int nFailures = AvpAssistant.testMethods(ccr, CreditControlRequest.class);
  126. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  127. }
  128. @Test
  129. public void isAnswerCCA() throws Exception {
  130. CreditControlRequest ccr = ccaMessageFactory.createCreditControlRequest();
  131. CreditControlAnswer cca = ccaMessageFactory.createCreditControlAnswer(ccr);
  132. assertFalse("Request Flag in Credit-Control-Answer is set.", cca.getHeader().isRequest());
  133. }
  134. @Test
  135. public void isProxiableCopiedCCA() throws Exception {
  136. CreditControlRequest ccr = ccaMessageFactory.createCreditControlRequest();
  137. CreditControlAnswer cca = ccaMessageFactory.createCreditControlAnswer(ccr);
  138. assertEquals("The 'P' bit is not copied from request in Credit-Control-Answer, it should. [RFC3588/6.2]", ccr.getHeader().isProxiable(), cca.getHeader().isProxiable());
  139. // Reverse 'P' bit ...
  140. ((DiameterMessageImpl) ccr).getGenericData().setProxiable(!ccr.getHeader().isProxiable());
  141. assertTrue("The 'P' bit was not modified in Credit-Control-Request, it should.", ccr.getHeader().isProxiable() != cca.getHeader().isProxiable());
  142. cca = ccaMessageFactory.createCreditControlAnswer(ccr);
  143. assertEquals("The 'P' bit is not copied from request in Credit-Control-Answer, it should. [RFC3588/6.2]", ccr.getHeader().isProxiable(), cca.getHeader().isProxiable());
  144. }
  145. @Test
  146. public void hasTFlagSetCCA() throws Exception {
  147. CreditControlRequest ccr = ccaMessageFactory.createCreditControlRequest();
  148. ((DiameterMessageImpl) ccr).getGenericData().setReTransmitted(true);
  149. assertTrue("The 'T' flag should be set in Credit-Control-Request", ccr.getHeader().isPotentiallyRetransmitted());
  150. CreditControlAnswer cca = ccaMessageFactory.createCreditControlAnswer(ccr);
  151. assertFalse("The 'T' flag should not be set in Credit-Control-Answer", cca.getHeader().isPotentiallyRetransmitted());
  152. }
  153. @Test
  154. public void testGettersAndSettersCCA() throws Exception {
  155. CreditControlAnswer cca = ccaMessageFactory.createCreditControlAnswer(ccaMessageFactory.createCreditControlRequest("582364567346578348"));
  156. int nFailures = AvpAssistant.testMethods(cca, CreditControlAnswer.class);
  157. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  158. }
  159. @Test
  160. public void hasDestinationHostCCA() throws Exception {
  161. CreditControlAnswer cca = ccaMessageFactory.createCreditControlAnswer(ccaMessageFactory.createCreditControlRequest("582364567346578348"));
  162. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", cca.getDestinationHost());
  163. }
  164. @Test
  165. public void hasDestinationRealmCCA() throws Exception {
  166. CreditControlAnswer cca = ccaMessageFactory.createCreditControlAnswer(ccaMessageFactory.createCreditControlRequest("582364567346578348"));
  167. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", cca.getDestinationRealm());
  168. }
  169. @Test
  170. public void testAvpFactoryCreateCcMoney() throws Exception {
  171. String avpName = "CC-Money";
  172. // Create AVP with mandatory values
  173. CcMoneyAvp ccmAvp1 = ccaAvpFactory.createCcMoney(ccaAvpFactory.createUnitValue(12345L));
  174. // Make sure it's not null
  175. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", ccmAvp1);
  176. // Create AVP with default constructor
  177. CcMoneyAvp ccmAvp2 = ccaAvpFactory.createCcMoney();
  178. // Should not contain mandatory values
  179. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Unit-Value AVP.", ccmAvp2.hasUnitValue());
  180. // Set mandatory values
  181. ccmAvp2.setUnitValue(ccaAvpFactory.createUnitValue(12345L));
  182. // Make sure it's equal to the one created with mandatory values constructor
  183. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", ccmAvp1, ccmAvp2);
  184. // Make new copy
  185. ccmAvp2 = ccaAvpFactory.createCcMoney();
  186. // And set all values using setters
  187. AvpAssistant.testSetters(ccmAvp2);
  188. // Create empty...
  189. CcMoneyAvp ccmAvp3 = ccaAvpFactory.createCcMoney();
  190. // Verify that no values have been set
  191. AvpAssistant.testHassers(ccmAvp3, false);
  192. // Set all previous values
  193. ccmAvp3.setExtensionAvps(ccmAvp2.getExtensionAvps());
  194. // Verify if values have been set
  195. AvpAssistant.testHassers(ccmAvp3, true);
  196. // Verify if values have been correctly set
  197. AvpAssistant.testGetters(ccmAvp3);
  198. // Make sure they match!
  199. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", ccmAvp2, ccmAvp3);
  200. }
  201. @Test
  202. public void testAvpFactoryCreateCostInformation() throws Exception {
  203. String avpName = "Cost-Information";
  204. // Create AVP with mandatory values
  205. CostInformationAvp ciAvp1 = ccaAvpFactory.createCostInformation(ccaAvpFactory.createUnitValue(12345L), 3L);
  206. // Make sure it's not null
  207. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", ciAvp1);
  208. // Create AVP with default constructor
  209. CostInformationAvp ciAvp2 = ccaAvpFactory.createCostInformation();
  210. // Should not contain mandatory values
  211. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Unit-Value AVP.", ciAvp2.hasUnitValue());
  212. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Currency-Code AVP.", ciAvp2.hasCurrencyCode());
  213. // Set mandatory values
  214. ciAvp2.setUnitValue(ccaAvpFactory.createUnitValue(12345L));
  215. ciAvp2.setCurrencyCode(3L);
  216. // Make sure it's equal to the one created with mandatory values constructor
  217. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", ciAvp1, ciAvp2);
  218. // Make new copy
  219. ciAvp2 = ccaAvpFactory.createCostInformation();
  220. // And set all values using setters
  221. AvpAssistant.testSetters(ciAvp2);
  222. // Create empty...
  223. CostInformationAvp ciAvp3 = ccaAvpFactory.createCostInformation();
  224. // Verify that no values have been set
  225. AvpAssistant.testHassers(ciAvp3, false);
  226. // Set all previous values
  227. ciAvp3.setExtensionAvps(ciAvp2.getExtensionAvps());
  228. // Verify if values have been set
  229. AvpAssistant.testHassers(ciAvp3, true);
  230. // Verify if values have been correctly set
  231. AvpAssistant.testGetters(ciAvp3);
  232. // Make sure they match!
  233. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", ciAvp2, ciAvp3);
  234. }
  235. @Test
  236. public void testAvpFactoryCreateFinalUnitIndication() throws Exception {
  237. String avpName = "Final-Unit-Indication";
  238. // Create AVP with mandatory values
  239. FinalUnitIndicationAvp fuiAvp1 = ccaAvpFactory.createFinalUnitIndication(FinalUnitActionType.RESTRICT_ACCESS);
  240. // Make sure it's not null
  241. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", fuiAvp1);
  242. // Create AVP with default constructor
  243. FinalUnitIndicationAvp fuiAvp2 = ccaAvpFactory.createFinalUnitIndication();
  244. // Should not contain mandatory values
  245. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Final-Unit-Action AVP.", fuiAvp2.hasFinalUnitAction());
  246. // Set mandatory values
  247. fuiAvp2.setFinalUnitAction(FinalUnitActionType.RESTRICT_ACCESS);
  248. // Make sure it's equal to the one created with mandatory values constructor
  249. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", fuiAvp1, fuiAvp2);
  250. // Make new copy
  251. fuiAvp2 = ccaAvpFactory.createFinalUnitIndication();
  252. // And set all values using setters
  253. AvpAssistant.testSetters(fuiAvp2);
  254. // Create empty...
  255. FinalUnitIndicationAvp fuiAvp3 = ccaAvpFactory.createFinalUnitIndication();
  256. // Verify that no values have been set
  257. AvpAssistant.testHassers(fuiAvp3, false);
  258. // Set all previous values
  259. fuiAvp3.setExtensionAvps(fuiAvp2.getExtensionAvps());
  260. // Verify if values have been set
  261. AvpAssistant.testHassers(fuiAvp3, true);
  262. // Verify if values have been correctly set
  263. AvpAssistant.testGetters(fuiAvp3);
  264. // Make sure they match!
  265. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", fuiAvp2, fuiAvp3);
  266. }
  267. @Test
  268. public void testAvpFactoryCreateGSUPoolReference() throws Exception {
  269. String avpName = "G-S-U-Pool-Reference";
  270. // Create AVP with mandatory values
  271. GSUPoolReferenceAvp gsuprAvp1 = ccaAvpFactory.createGSUPoolReference(12345L, CcUnitType.TIME, ccaAvpFactory.createUnitValue(67890L));
  272. // Make sure it's not null
  273. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", gsuprAvp1);
  274. // Create AVP with default constructor
  275. GSUPoolReferenceAvp gsuprAvp2 = ccaAvpFactory.createGSUPoolReference();
  276. // Should not contain mandatory values
  277. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have G-S-U-Pool-Identifier AVP.", gsuprAvp2.hasGSUPoolIdentifier());
  278. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have CC-Unit-Type AVP.", gsuprAvp2.hasCreditControlUnitType());
  279. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Unit-Value AVP.", gsuprAvp2.hasUnitValue());
  280. // Set mandatory values
  281. gsuprAvp2.setGSUPoolIdentifier(12345L);
  282. gsuprAvp2.setCreditControlUnitType(CcUnitType.TIME);
  283. gsuprAvp2.setUnitValue(ccaAvpFactory.createUnitValue(67890L));
  284. // Make sure it's equal to the one created with mandatory values constructor
  285. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", gsuprAvp1, gsuprAvp2);
  286. // Make new copy
  287. gsuprAvp2 = ccaAvpFactory.createGSUPoolReference();
  288. // And set all values using setters
  289. AvpAssistant.testSetters(gsuprAvp2);
  290. // Create empty...
  291. GSUPoolReferenceAvp gsuprAvp3 = ccaAvpFactory.createGSUPoolReference();
  292. // Verify that no values have been set
  293. AvpAssistant.testHassers(gsuprAvp3, false);
  294. // Set all previous values
  295. gsuprAvp3.setExtensionAvps(gsuprAvp2.getExtensionAvps());
  296. // Verify if values have been set
  297. AvpAssistant.testHassers(gsuprAvp3, true);
  298. // Verify if values have been correctly set
  299. AvpAssistant.testGetters(gsuprAvp3);
  300. // Make sure they match!
  301. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", gsuprAvp2, gsuprAvp3);
  302. }
  303. @Test
  304. public void testAvpFactoryCreateGrantedServiceUnit() throws Exception {
  305. String avpName = "Granted-Service-Unit";
  306. // Create AVP with mandatory values
  307. GrantedServiceUnitAvp gsuAvp1 = ccaAvpFactory.createGrantedServiceUnit();
  308. // Make sure it's not null
  309. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", gsuAvp1);
  310. // Create AVP with default constructor
  311. GrantedServiceUnitAvp gsuAvp2 = ccaAvpFactory.createGrantedServiceUnit();
  312. // Should not contain mandatory values
  313. // Set mandatory values
  314. // Make sure it's equal to the one created with mandatory values constructor
  315. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", gsuAvp1, gsuAvp2);
  316. // Make new copy
  317. gsuAvp2 = ccaAvpFactory.createGrantedServiceUnit();
  318. // And set all values using setters
  319. AvpAssistant.testSetters(gsuAvp2);
  320. // Create empty...
  321. GrantedServiceUnitAvp gsuAvp3 = ccaAvpFactory.createGrantedServiceUnit();
  322. // Verify that no values have been set
  323. AvpAssistant.testHassers(gsuAvp3, false);
  324. // Set all previous values
  325. gsuAvp3.setExtensionAvps(gsuAvp2.getExtensionAvps());
  326. // Verify if values have been set
  327. AvpAssistant.testHassers(gsuAvp3, true);
  328. // Verify if values have been correctly set
  329. AvpAssistant.testGetters(gsuAvp3);
  330. // Make sure they match!
  331. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", gsuAvp2, gsuAvp3);
  332. }
  333. @Test
  334. public void testAvpFactoryCreateMultipleServicesCreditControl() throws Exception {
  335. String avpName = "Multiple-Services-Credit-Control";
  336. // Create AVP with mandatory values
  337. MultipleServicesCreditControlAvp msccAvp1 = ccaAvpFactory.createMultipleServicesCreditControl();
  338. // Make sure it's not null
  339. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", msccAvp1);
  340. // Create AVP with default constructor
  341. MultipleServicesCreditControlAvp msccAvp2 = ccaAvpFactory.createMultipleServicesCreditControl();
  342. // Should not contain mandatory values
  343. // Set mandatory values
  344. // Make sure it's equal to the one created with mandatory values constructor
  345. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", msccAvp1, msccAvp2);
  346. // Make new copy
  347. msccAvp2 = ccaAvpFactory.createMultipleServicesCreditControl();
  348. // And set all values using setters
  349. AvpAssistant.testSetters(msccAvp2);
  350. // Create empty...
  351. MultipleServicesCreditControlAvp msccAvp3 = ccaAvpFactory.createMultipleServicesCreditControl();
  352. // Verify that no values have been set
  353. AvpAssistant.testHassers(msccAvp3, false);
  354. // Set all previous values
  355. msccAvp3.setExtensionAvps(msccAvp2.getExtensionAvps());
  356. // Verify if values have been set
  357. AvpAssistant.testHassers(msccAvp3, true);
  358. // Verify if values have been correctly set
  359. AvpAssistant.testGetters(msccAvp3);
  360. // Make sure they match!
  361. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", msccAvp2, msccAvp3);
  362. }
  363. @Test
  364. public void testAvpFactoryCreateRedirectServer() throws Exception {
  365. String avpName = "Redirect-Server";
  366. // Create AVP with mandatory values
  367. RedirectServerAvp rsAvp1 = ccaAvpFactory.createRedirectServer(RedirectAddressType.IPv4_Address, "127.0.0.3");
  368. // Make sure it's not null
  369. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", rsAvp1);
  370. // Create AVP with default constructor
  371. RedirectServerAvp rsAvp2 = ccaAvpFactory.createRedirectServer();
  372. // Should not contain mandatory values
  373. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Redirect-Address-Type AVP.", rsAvp2.hasRedirectAddressType());
  374. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Redirect-Server-Address AVP.", rsAvp2.hasRedirectServerAddress());
  375. // Set mandatory values
  376. rsAvp2.setRedirectAddressType(RedirectAddressType.IPv4_Address);
  377. rsAvp2.setRedirectServerAddress("127.0.0.3");
  378. // Make sure it's equal to the one created with mandatory values constructor
  379. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", rsAvp1, rsAvp2);
  380. // Make new copy
  381. rsAvp2 = ccaAvpFactory.createRedirectServer();
  382. // And set all values using setters
  383. AvpAssistant.testSetters(rsAvp2);
  384. // Create empty...
  385. RedirectServerAvp rsAvp3 = ccaAvpFactory.createRedirectServer();
  386. // Verify that no values have been set
  387. AvpAssistant.testHassers(rsAvp3, false);
  388. // Set all previous values
  389. rsAvp3.setExtensionAvps(rsAvp2.getExtensionAvps());
  390. // Verify if values have been set
  391. AvpAssistant.testHassers(rsAvp3, true);
  392. // Verify if values have been correctly set
  393. AvpAssistant.testGetters(rsAvp3);
  394. // Make sure they match!
  395. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", rsAvp2, rsAvp3);
  396. }
  397. @Test
  398. public void testAvpFactoryCreateRequestedServiceUnit() throws Exception {
  399. String avpName = "Requested-Service-Unit";
  400. // Create AVP with mandatory values
  401. RequestedServiceUnitAvp rsuAvp1 = ccaAvpFactory.createRequestedServiceUnit();
  402. // Make sure it's not null
  403. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", rsuAvp1);
  404. // Create AVP with default constructor
  405. RequestedServiceUnitAvp rsuAvp2 = ccaAvpFactory.createRequestedServiceUnit();
  406. // Should not contain mandatory values
  407. // Set mandatory values
  408. // Make sure it's equal to the one created with mandatory values constructor
  409. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", rsuAvp1, rsuAvp2);
  410. // Make new copy
  411. rsuAvp2 = ccaAvpFactory.createRequestedServiceUnit();
  412. // And set all values using setters
  413. AvpAssistant.testSetters(rsuAvp2);
  414. // Create empty...
  415. RequestedServiceUnitAvp rsuAvp3 = ccaAvpFactory.createRequestedServiceUnit();
  416. // Verify that no values have been set
  417. AvpAssistant.testHassers(rsuAvp3, false);
  418. // Set all previous values
  419. rsuAvp3.setExtensionAvps(rsuAvp2.getExtensionAvps());
  420. // Verify if values have been set
  421. AvpAssistant.testHassers(rsuAvp3, true);
  422. // Verify if values have been correctly set
  423. AvpAssistant.testGetters(rsuAvp3);
  424. // Make sure they match!
  425. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", rsuAvp2, rsuAvp3);
  426. }
  427. @Test
  428. public void testAvpFactoryCreateServiceParameterInfo() throws Exception {
  429. String avpName = "Service-Parameter-Info";
  430. // Create AVP with mandatory values
  431. ServiceParameterInfoAvp spiAvp1 = ccaAvpFactory.createServiceParameterInfo(55555L, "mobicents diameter".getBytes());
  432. // Make sure it's not null
  433. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", spiAvp1);
  434. // Create AVP with default constructor
  435. ServiceParameterInfoAvp spiAvp2 = ccaAvpFactory.createServiceParameterInfo();
  436. // Should not contain mandatory values
  437. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Service-Parameter-Type AVP.", spiAvp2.hasServiceParameterType());
  438. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Service-Parameter-Value AVP.", spiAvp2.hasServiceParameterValue());
  439. // Set mandatory values
  440. spiAvp2.setServiceParameterType(55555L);
  441. spiAvp2.setServiceParameterValue("mobicents diameter".getBytes());
  442. // Make sure it's equal to the one created with mandatory values constructor
  443. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", spiAvp1, spiAvp2);
  444. // Make new copy
  445. spiAvp2 = ccaAvpFactory.createServiceParameterInfo();
  446. // And set all values using setters
  447. AvpAssistant.testSetters(spiAvp2);
  448. // Create empty...
  449. ServiceParameterInfoAvp spiAvp3 = ccaAvpFactory.createServiceParameterInfo();
  450. // Verify that no values have been set
  451. AvpAssistant.testHassers(spiAvp3, false);
  452. // Set all previous values
  453. spiAvp3.setExtensionAvps(spiAvp2.getExtensionAvps());
  454. // Verify if values have been set
  455. AvpAssistant.testHassers(spiAvp3, true);
  456. // Verify if values have been correctly set
  457. AvpAssistant.testGetters(spiAvp3);
  458. // Make sure they match!
  459. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", spiAvp2, spiAvp3);
  460. }
  461. @Test
  462. public void testAvpFactoryCreateSubscriptionId() throws Exception {
  463. String avpName = "Subscription-Id";
  464. // Create AVP with mandatory values
  465. SubscriptionIdAvp sidAvp1 = ccaAvpFactory.createSubscriptionId(SubscriptionIdType.END_USER_SIP_URI, "sip:alexandre@mobicents.org");
  466. // Make sure it's not null
  467. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", sidAvp1);
  468. // Create AVP with default constructor
  469. SubscriptionIdAvp sidAvp2 = ccaAvpFactory.createSubscriptionId();
  470. // Should not contain mandatory values
  471. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Subscription-Id-Type AVP.", sidAvp2.hasSubscriptionIdType());
  472. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Subscription-Id-Data AVP.", sidAvp2.hasSubscriptionIdData());
  473. // Set mandatory values
  474. sidAvp2.setSubscriptionIdType(SubscriptionIdType.END_USER_SIP_URI);
  475. sidAvp2.setSubscriptionIdData("sip:alexandre@mobicents.org");
  476. // Make sure it's equal to the one created with mandatory values constructor
  477. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", sidAvp1, sidAvp2);
  478. // Make new copy
  479. sidAvp2 = ccaAvpFactory.createSubscriptionId();
  480. // And set all values using setters
  481. AvpAssistant.testSetters(sidAvp2);
  482. // Create empty...
  483. SubscriptionIdAvp sidAvp3 = ccaAvpFactory.createSubscriptionId();
  484. // Verify that no values have been set
  485. AvpAssistant.testHassers(sidAvp3, false);
  486. // Set all previous values
  487. sidAvp3.setExtensionAvps(sidAvp2.getExtensionAvps());
  488. // Verify if values have been set
  489. AvpAssistant.testHassers(sidAvp3, true);
  490. // Verify if values have been correctly set
  491. AvpAssistant.testGetters(sidAvp3);
  492. // Make sure they match!
  493. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", sidAvp2, sidAvp3);
  494. }
  495. @Test
  496. public void testAvpFactoryCreateUnitValue() throws Exception {
  497. String avpName = "Unit-Value";
  498. // Create AVP with mandatory values
  499. UnitValueAvp uvAvp1 = ccaAvpFactory.createUnitValue(19191L);
  500. // Make sure it's not null
  501. Assert.assertNotNull("Created Unit-Value AVP from objects should not be null.", uvAvp1);
  502. // Create AVP with default constructor
  503. UnitValueAvp uvAvp2 = ccaAvpFactory.createUnitValue();
  504. // Should not contain mandatory values
  505. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Value-Digits AVP.", uvAvp2.hasValueDigits());
  506. // Set mandatory values
  507. uvAvp2.setValueDigits(19191L);
  508. // Make sure it's equal to the one created with mandatory values constructor
  509. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", uvAvp1, uvAvp2);
  510. // Make new copy
  511. uvAvp2 = ccaAvpFactory.createUnitValue();
  512. // And set all values using setters
  513. AvpAssistant.testSetters(uvAvp2);
  514. // Create empty...
  515. UnitValueAvp uvAvp3 = ccaAvpFactory.createUnitValue();
  516. // Verify that no values have been set
  517. AvpAssistant.testHassers(uvAvp3, false);
  518. // Set all previous values
  519. uvAvp3.setExtensionAvps(uvAvp2.getExtensionAvps());
  520. // Verify if values have been set
  521. AvpAssistant.testHassers(uvAvp3, true);
  522. // Verify if values have been correctly set
  523. AvpAssistant.testGetters(uvAvp3);
  524. // Make sure they match!
  525. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", uvAvp2, uvAvp3);
  526. }
  527. @Test
  528. public void testAvpFactoryCreateUsedServiceUnit() throws Exception {
  529. String avpName = "Used-Service-Unit";
  530. // Create AVP with mandatory values
  531. UsedServiceUnitAvp usuAvp1 = ccaAvpFactory.createUsedServiceUnit();
  532. // Make sure it's not null
  533. Assert.assertNotNull("Created Unit-Value AVP from objects should not be null.", usuAvp1);
  534. // Create AVP with default constructor
  535. UsedServiceUnitAvp usuAvp2 = ccaAvpFactory.createUsedServiceUnit();
  536. // Should not contain mandatory values
  537. // Set mandatory values
  538. // Make sure it's equal to the one created with mandatory values constructor
  539. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", usuAvp1, usuAvp2);
  540. // Make new copy
  541. usuAvp2 = ccaAvpFactory.createUsedServiceUnit();
  542. // And set all values using setters
  543. AvpAssistant.testSetters(usuAvp2);
  544. // Create empty...
  545. UsedServiceUnitAvp usuAvp3 = ccaAvpFactory.createUsedServiceUnit();
  546. // Verify that no values have been set
  547. AvpAssistant.testHassers(usuAvp3, false);
  548. // Set all previous values
  549. usuAvp3.setExtensionAvps(usuAvp2.getExtensionAvps());
  550. // Verify if values have been set
  551. AvpAssistant.testHassers(usuAvp3, true);
  552. // Verify if values have been correctly set
  553. AvpAssistant.testGetters(usuAvp3);
  554. // Make sure they match!
  555. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", usuAvp2, usuAvp3);
  556. }
  557. @Test
  558. public void testAvpFactoryCreateUserEquipmentInfo() throws Exception {
  559. String avpName = "User-Equipment-Info";
  560. // Create AVP with mandatory values
  561. UserEquipmentInfoAvp ueiAvp1 = ccaAvpFactory.createUserEquipmentInfo(UserEquipmentInfoType.MAC, "00:11:22:33:44:55".getBytes());
  562. // Make sure it's not null
  563. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", ueiAvp1);
  564. // Create AVP with default constructor
  565. UserEquipmentInfoAvp ueiAvp2 = ccaAvpFactory.createUserEquipmentInfo();
  566. // Should not contain mandatory values
  567. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have User-Equipment-Info-Type AVP.", ueiAvp2.hasUserEquipmentInfoType());
  568. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have User-Equipment-Info-Value AVP.", ueiAvp2.hasUserEquipmentInfoValue());
  569. // Set mandatory values
  570. ueiAvp2.setUserEquipmentInfoType(UserEquipmentInfoType.MAC);
  571. ueiAvp2.setUserEquipmentInfoValue("00:11:22:33:44:55".getBytes());
  572. // Make sure it's equal to the one created with mandatory values constructor
  573. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", ueiAvp1, ueiAvp2);
  574. // Make new copy
  575. ueiAvp2 = ccaAvpFactory.createUserEquipmentInfo();
  576. // And set all values using setters
  577. AvpAssistant.testSetters(ueiAvp2);
  578. // Create empty...
  579. UserEquipmentInfoAvp ueiAvp3 = ccaAvpFactory.createUserEquipmentInfo();
  580. // Verify that no values have been set
  581. AvpAssistant.testHassers(ueiAvp3, false);
  582. // Set all previous values
  583. ueiAvp3.setExtensionAvps(ueiAvp2.getExtensionAvps());
  584. // Verify if values have been set
  585. AvpAssistant.testHassers(ueiAvp3, true);
  586. // Verify if values have been correctly set
  587. AvpAssistant.testGetters(ueiAvp3);
  588. // Make sure they match!
  589. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", ueiAvp2, ueiAvp3);
  590. }
  591. /**
  592. * Class representing the Diameter Configuration
  593. */
  594. public static class MyConfiguration extends EmptyConfiguration {
  595. public MyConfiguration() {
  596. super();
  597. add(Assembler, Assembler.defValue());
  598. add(OwnDiameterURI, clientURI);
  599. add(OwnRealm, realmName);
  600. add(OwnVendorID, 193L);
  601. // Set Ericsson SDK feature
  602. // add(UseUriAsFqdn, true);
  603. // Set Common Applications
  604. add(ApplicationId,
  605. // AppId 1
  606. getInstance().
  607. add(VendorId, 193L).
  608. add(AuthApplId, 0L).
  609. add(AcctApplId, 19302L));
  610. // Set peer table
  611. add(PeerTable,
  612. // Peer 1
  613. getInstance().
  614. add(PeerRating, 1).
  615. add(PeerName, serverURI));
  616. // Set realm table
  617. add(RealmTable,
  618. // Realm 1
  619. getInstance().add(RealmEntry, getInstance().
  620. add(RealmName, realmName).
  621. add(ApplicationId, getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L)).
  622. add(RealmHosts, clientHost + ", " + serverHost).add(RealmLocalAction, "LOCAL").add(RealmEntryIsDynamic, false).add(RealmEntryExpTime, 1000L)));
  623. }
  624. }
  625. }