PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 1433 lines | 744 code | 319 blank | 370 comment | 85 complexity | 7110cafc3426c755b6946ff0a529772f 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

Large files files are truncated, but you can click here to view the full 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. 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.mobicents.slee.resources.diameter.tests.factories.BaseFactoriesTest.*;
  42. import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity;
  43. import net.java.slee.resource.diameter.base.events.avp.IPFilterRule;
  44. import net.java.slee.resource.diameter.rx.RxAvpFactory;
  45. import net.java.slee.resource.diameter.rx.RxMessageFactory;
  46. import net.java.slee.resource.diameter.rx.events.*;
  47. import net.java.slee.resource.diameter.rx.events.avp.AcceptableServiceInfoAvp;
  48. import net.java.slee.resource.diameter.rx.events.avp.AccessNetworkChargingIdentifierAvp;
  49. import net.java.slee.resource.diameter.rx.events.avp.FlowUsage;
  50. import net.java.slee.resource.diameter.rx.events.avp.FlowsAvp;
  51. import net.java.slee.resource.diameter.rx.events.avp.MediaComponentDescriptionAvp;
  52. import net.java.slee.resource.diameter.rx.events.avp.MediaSubComponentAvp;
  53. import net.java.slee.resource.diameter.rx.events.avp.SponsoredConnectivityDataAvp;
  54. import net.java.slee.resource.diameter.rx.events.avp.SupportedFeaturesAvp;
  55. import static org.junit.Assert.*;
  56. import org.jdiameter.api.Answer;
  57. import org.jdiameter.api.ApplicationId;
  58. import org.jdiameter.api.IllegalDiameterStateException;
  59. import org.jdiameter.api.Request;
  60. import org.jdiameter.api.Stack;
  61. import org.jdiameter.api.rx.ClientRxSession;
  62. import org.jdiameter.api.rx.ServerRxSession;
  63. import org.jdiameter.client.api.ISessionFactory;
  64. import org.jdiameter.client.impl.app.rx.ClientRxSessionDataLocalImpl;
  65. import org.jdiameter.client.impl.app.rx.ClientRxSessionImpl;
  66. import org.jdiameter.client.impl.helpers.EmptyConfiguration;
  67. import org.jdiameter.common.impl.app.rx.RxSessionFactoryImpl;
  68. import org.jdiameter.server.impl.app.rx.ServerRxSessionDataLocalImpl;
  69. import org.jdiameter.server.impl.app.rx.ServerRxSessionImpl;
  70. import org.junit.Assert;
  71. import org.junit.Test;
  72. import org.mobicents.diameter.dictionary.AvpDictionary;
  73. import org.mobicents.slee.resource.diameter.base.DiameterAvpFactoryImpl;
  74. import org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl;
  75. import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl;
  76. import org.mobicents.slee.resource.diameter.rx.RxAvpFactoryImpl;
  77. import org.mobicents.slee.resource.diameter.rx.RxClientSessionActivityImpl;
  78. import org.mobicents.slee.resource.diameter.rx.RxMessageFactoryImpl;
  79. import org.mobicents.slee.resource.diameter.rx.RxServerSessionActivityImpl;
  80. /**
  81. * Test class for JAIN SLEE Diameter Rx' RA Message and AVP Factories
  82. *
  83. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  84. */
  85. public class RxFactoriesTest {
  86. private static String clientHost = "127.0.0.1";
  87. private static String clientPort = "13868";
  88. private static String clientURI = "aaa://" + clientHost + ":" + clientPort;
  89. private static String serverHost = "localhost";
  90. private static String serverPort = "3868";
  91. private static String serverURI = "aaa://" + serverHost + ":" + serverPort;
  92. private static String realmName = "mobicents.org";
  93. private static RxMessageFactory rxMessageFactory;
  94. private static RxAvpFactory rxAvpFactory;
  95. private static Stack stack;
  96. private static ServerRxSession serverSession;
  97. private static ClientRxSession clientSession;
  98. static {
  99. stack = new org.jdiameter.client.impl.StackImpl();
  100. try {
  101. stack.init(new MyConfiguration());
  102. }
  103. catch ( Exception e ) {
  104. throw new RuntimeException("Failed to initialize the stack.",e);
  105. }
  106. DiameterMessageFactoryImpl baseFactory = new DiameterMessageFactoryImpl(stack);
  107. DiameterAvpFactoryImpl baseAvpFactory = new DiameterAvpFactoryImpl();
  108. rxAvpFactory = new RxAvpFactoryImpl(baseAvpFactory);
  109. try {
  110. rxMessageFactory = new RxMessageFactoryImpl(baseFactory, stack.getSessionFactory().getNewSession().getSessionId(), stack);
  111. }
  112. catch ( Exception e ) {
  113. e.printStackTrace();
  114. }
  115. try {
  116. AvpDictionary.INSTANCE.parseDictionary( RxFactoriesTest.class.getClassLoader().getResourceAsStream( "dictionary.xml" ) );
  117. }
  118. catch ( Exception e ) {
  119. throw new RuntimeException("Failed to parse dictionary file.");
  120. }
  121. }
  122. private RxServerSessionActivityImpl rxServerSession = null;
  123. private RxClientSessionActivityImpl rxClientSession = null;
  124. public RxFactoriesTest() {
  125. try {
  126. RxSessionFactoryImpl rxSessionFactory = new RxSessionFactoryImpl(stack.getSessionFactory());
  127. serverSession = new ServerRxSessionImpl(new ServerRxSessionDataLocalImpl(), rxSessionFactory, (ISessionFactory) stack.getSessionFactory(), rxSessionFactory, rxSessionFactory, rxSessionFactory);
  128. rxServerSession = new RxServerSessionActivityImpl(rxMessageFactory, rxAvpFactory, serverSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack);
  129. clientSession = new ClientRxSessionImpl(new ClientRxSessionDataLocalImpl(), rxSessionFactory, (ISessionFactory) stack.getSessionFactory(), rxSessionFactory, rxSessionFactory, rxSessionFactory);
  130. rxClientSession = new RxClientSessionActivityImpl(rxMessageFactory, rxAvpFactory, clientSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack);
  131. //????
  132. //((RxServerSessionActivityImpl)roServerSession).fetchCurrentState(roMessageFactory.createRxAARequest());
  133. }
  134. catch (IllegalDiameterStateException e) {
  135. throw new RuntimeException("Failed to parse dictionary file.");
  136. }
  137. }
  138. // // AA-Request
  139. //
  140. // @Test
  141. // public void isRequestAAR() throws Exception {
  142. // AARequest aar = rxMessageFactory.createAARequest();
  143. // assertTrue("Request Flag in AA-Request is not set.", aar.getHeader().isRequest());
  144. // }
  145. //
  146. // @Test
  147. // public void isProxiableAAR() throws Exception {
  148. // AARequest rar = rxMessageFactory.createAARequest();
  149. // assertTrue("The 'P' bit is not set by default in Rx' AA-Request, it should.", rar.getHeader().isProxiable());
  150. // }
  151. //
  152. // @Test
  153. // public void testGettersAndSettersAAR() throws Exception {
  154. // AARequest aar = rxMessageFactory.createAARequest();
  155. // int nFailures = AvpAssistant.testMethods(aar, AARequest.class);
  156. //
  157. // assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  158. // }
  159. //
  160. @Test
  161. public void hasRxApplicationIdAAR() throws Exception {
  162. AARequest aar = rxMessageFactory.createAARequest();
  163. assertTrue("Auth-Application-Id AVP in Rx AAR must be " + RxMessageFactory._Rx_AUTH_APP_ID + ", it is " + aar.getAuthApplicationId(), aar.getAuthApplicationId() == RxMessageFactory._Rx_AUTH_APP_ID);
  164. }
  165. // AA-Answer
  166. @Test
  167. public void isAnswerAAA() throws Exception {
  168. rxServerSession.fetchCurrentState(rxMessageFactory.createAARequest());
  169. AAAnswer aaa = rxServerSession.createAAAnswer();
  170. assertFalse("Request Flag in AA-Answer is set.", aaa.getHeader().isRequest());
  171. }
  172. @Test
  173. public void isProxiableCopiedAAA() throws Exception {
  174. AARequest rar = rxMessageFactory.createAARequest();
  175. AAAnswer raa = rxMessageFactory.createAAAnswer(rar);
  176. assertEquals("The 'P' bit is not copied from request in Rx' AA-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  177. // Reverse 'P' bit ...
  178. ((DiameterMessageImpl) rar).getGenericData().setProxiable(!rar.getHeader().isProxiable());
  179. assertTrue("The 'P' bit was not modified in Rx' AA-Request, it should.", rar.getHeader().isProxiable() != raa.getHeader().isProxiable());
  180. raa = rxMessageFactory.createAAAnswer(rar);
  181. assertEquals("The 'P' bit is not copied from request in Rx' AA-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  182. }
  183. @Test
  184. public void hasTFlagSetAAA() throws Exception {
  185. AARequest aar = rxMessageFactory.createAARequest();
  186. ((DiameterMessageImpl) aar).getGenericData().setReTransmitted(true);
  187. assertTrue("The 'T' flag should be set in AA-Request", aar.getHeader().isPotentiallyRetransmitted());
  188. AAAnswer aaa = rxMessageFactory.createAAAnswer(aar);
  189. assertFalse("The 'T' flag should not be set in AA-Answer", aaa.getHeader().isPotentiallyRetransmitted());
  190. }
  191. @Test
  192. public void testGettersAndSettersAAA() throws Exception {
  193. rxServerSession.fetchCurrentState(rxMessageFactory.createAARequest());
  194. AAAnswer aaa = rxServerSession.createAAAnswer();
  195. int nFailures = AvpAssistant.testMethods(aaa, AAAnswer.class);
  196. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  197. }
  198. @Test
  199. public void hasRxApplicationIdAAA() throws Exception {
  200. rxServerSession.fetchCurrentState(rxMessageFactory.createAARequest());
  201. AAAnswer aaa = rxServerSession.createAAAnswer();
  202. assertTrue("Auth-Application-Id AVP in Rx AAA must be " + RxMessageFactory._Rx_AUTH_APP_ID + ", it is " + aaa.getAuthApplicationId(), aaa.getAuthApplicationId() == RxMessageFactory._Rx_AUTH_APP_ID);
  203. }
  204. @Test
  205. public void hasDestinationHostAAA() throws Exception {
  206. rxServerSession.fetchCurrentState(rxMessageFactory.createAARequest());
  207. AAAnswer aaa = rxServerSession.createAAAnswer();
  208. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", aaa.getDestinationHost());
  209. }
  210. @Test
  211. public void hasDestinationRealmAAA() throws Exception {
  212. rxServerSession.fetchCurrentState(rxMessageFactory.createAARequest());
  213. AAAnswer aaa = rxServerSession.createAAAnswer();
  214. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", aaa.getDestinationRealm());
  215. }
  216. // Abort-Session-Request
  217. @Test
  218. public void isRequestASR() throws Exception {
  219. AbortSessionRequest asr = rxMessageFactory.createAbortSessionRequest();
  220. assertTrue("Request Flag in Abort-Session-Request is not set.", asr.getHeader().isRequest());
  221. }
  222. @Test
  223. public void isProxiableASR() throws Exception {
  224. AbortSessionRequest rar = rxMessageFactory.createAbortSessionRequest();
  225. assertTrue("The 'P' bit is not set by default in Rx' Abort-Session-Request, it should.", rar.getHeader().isProxiable());
  226. }
  227. @Test
  228. public void testGettersAndSettersASR() throws Exception {
  229. AbortSessionRequest asr = rxMessageFactory.createAbortSessionRequest();
  230. int nFailures = AvpAssistant.testMethods(asr, AbortSessionRequest.class);
  231. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  232. }
  233. @Test
  234. public void hasRxApplicationIdASR() throws Exception {
  235. AbortSessionRequest asr = rxMessageFactory.createAbortSessionRequest();
  236. assertTrue("Auth-Application-Id AVP in Rx ASR must be " + RxMessageFactory._Rx_AUTH_APP_ID + ", it is " + asr.getAuthApplicationId(), asr.getAuthApplicationId() == RxMessageFactory._Rx_AUTH_APP_ID);
  237. }
  238. // Abort-Session-Answer
  239. @Test
  240. public void isAnswerASA() throws Exception {
  241. AbortSessionAnswer asa = rxMessageFactory.createAbortSessionAnswer(rxMessageFactory.createAbortSessionRequest());
  242. assertFalse("Request Flag in Abort-Session-Answer is set.", asa.getHeader().isRequest());
  243. }
  244. @Test
  245. public void isProxiableCopiedASA() throws Exception {
  246. AbortSessionRequest rar = rxMessageFactory.createAbortSessionRequest();
  247. AbortSessionAnswer raa = rxMessageFactory.createAbortSessionAnswer(rar);
  248. assertEquals("The 'P' bit is not copied from request in Rx' Abort-Session-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  249. // Reverse 'P' bit ...
  250. ((DiameterMessageImpl) rar).getGenericData().setProxiable(!rar.getHeader().isProxiable());
  251. assertTrue("The 'P' bit was not modified in Rx' Abort-Session-Request, it should.", rar.getHeader().isProxiable() != raa.getHeader().isProxiable());
  252. raa = rxMessageFactory.createAbortSessionAnswer(rar);
  253. assertEquals("The 'P' bit is not copied from request in Rx' Abort-Session-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  254. }
  255. @Test
  256. public void hasTFlagSetASA() throws Exception {
  257. AbortSessionRequest asr = rxMessageFactory.createAbortSessionRequest();
  258. ((DiameterMessageImpl) asr).getGenericData().setReTransmitted(true);
  259. assertTrue("The 'T' flag should be set in Abort-Session-Request", asr.getHeader().isPotentiallyRetransmitted());
  260. AbortSessionAnswer asa = rxMessageFactory.createAbortSessionAnswer(asr);
  261. assertFalse("The 'T' flag should not be set in Abort-Session-Answer", asa.getHeader().isPotentiallyRetransmitted());
  262. }
  263. @Test
  264. public void testGettersAndSettersASA() throws Exception {
  265. AbortSessionAnswer asa = rxMessageFactory.createAbortSessionAnswer(rxMessageFactory.createAbortSessionRequest());
  266. int nFailures = AvpAssistant.testMethods(asa, AbortSessionAnswer.class);
  267. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  268. }
  269. @Test
  270. public void hasDestinationHostASA() throws Exception {
  271. AbortSessionAnswer asa = rxMessageFactory.createAbortSessionAnswer(rxMessageFactory.createAbortSessionRequest());
  272. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", asa.getDestinationHost());
  273. }
  274. @Test
  275. public void hasDestinationRealmASA() throws Exception {
  276. AbortSessionAnswer asa = rxMessageFactory.createAbortSessionAnswer(rxMessageFactory.createAbortSessionRequest());
  277. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", asa.getDestinationRealm());
  278. }
  279. // Re-Auth-Request
  280. @Test
  281. public void isRequestRAR() throws Exception {
  282. ReAuthRequest rar = rxMessageFactory.createReAuthRequest();
  283. assertTrue("Request Flag in Re-Auth-Request is not set.", rar.getHeader().isRequest());
  284. }
  285. @Test
  286. public void isProxiableRAR() throws Exception {
  287. ReAuthRequest rar = rxMessageFactory.createReAuthRequest();
  288. assertTrue("The 'P' bit is not set by default in Rx' Re-Auth-Request, it should.", rar.getHeader().isProxiable());
  289. }
  290. @Test
  291. public void testGettersAndSettersRAR() throws Exception {
  292. ReAuthRequest rar = rxMessageFactory.createReAuthRequest();
  293. int nFailures = AvpAssistant.testMethods(rar, ReAuthRequest.class);
  294. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  295. }
  296. @Test
  297. public void hasRxApplicationIdRAR() throws Exception {
  298. ReAuthRequest rar = rxMessageFactory.createReAuthRequest();
  299. assertTrue("Auth-Application-Id AVP in Rx RAR must be " + RxMessageFactory._Rx_AUTH_APP_ID + ", it is " + rar.getAuthApplicationId(), rar.getAuthApplicationId() == RxMessageFactory._Rx_AUTH_APP_ID);
  300. }
  301. // Re-Auth-Answer
  302. @Test
  303. public void isAnswerRAA() throws Exception {
  304. ReAuthAnswer raa = rxMessageFactory.createReAuthAnswer(rxMessageFactory.createReAuthRequest());
  305. assertFalse("Request Flag in Re-Auth-Answer is set.", raa.getHeader().isRequest());
  306. }
  307. @Test
  308. public void isProxiableCopiedRAA() throws Exception {
  309. ReAuthRequest rar = rxMessageFactory.createReAuthRequest();
  310. ReAuthAnswer raa = rxMessageFactory.createReAuthAnswer(rar);
  311. assertEquals("The 'P' bit is not copied from request in Rx' Re-Auth-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  312. // Reverse 'P' bit ...
  313. ((DiameterMessageImpl) rar).getGenericData().setProxiable(!rar.getHeader().isProxiable());
  314. assertTrue("The 'P' bit was not modified in Rx' Re-Auth-Request, it should.", rar.getHeader().isProxiable() != raa.getHeader().isProxiable());
  315. raa = rxMessageFactory.createReAuthAnswer(rar);
  316. assertEquals("The 'P' bit is not copied from request in Rx' Re-Auth-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  317. }
  318. @Test
  319. public void hasTFlagSetRAA() throws Exception {
  320. ReAuthRequest rar = rxMessageFactory.createReAuthRequest();
  321. ((DiameterMessageImpl) rar).getGenericData().setReTransmitted(true);
  322. assertTrue("The 'T' flag should be set in Re-Auth-Request", rar.getHeader().isPotentiallyRetransmitted());
  323. ReAuthAnswer raa = rxMessageFactory.createReAuthAnswer(rar);
  324. assertFalse("The 'T' flag should not be set in Re-Auth-Answer", raa.getHeader().isPotentiallyRetransmitted());
  325. }
  326. @Test
  327. public void testGettersAndSettersRAA() throws Exception {
  328. ReAuthAnswer raa = rxMessageFactory.createReAuthAnswer(rxMessageFactory.createReAuthRequest());
  329. int nFailures = AvpAssistant.testMethods(raa, ReAuthAnswer.class);
  330. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  331. }
  332. @Test
  333. public void hasDestinationHostRAA() throws Exception {
  334. ReAuthAnswer raa = rxMessageFactory.createReAuthAnswer(rxMessageFactory.createReAuthRequest());
  335. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", raa.getDestinationHost());
  336. }
  337. @Test
  338. public void hasDestinationRealmRAA() throws Exception {
  339. ReAuthAnswer raa = rxMessageFactory.createReAuthAnswer(rxMessageFactory.createReAuthRequest());
  340. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", raa.getDestinationRealm());
  341. }
  342. // Session-Termination-Request
  343. @Test
  344. public void isRequestSTR() throws Exception {
  345. SessionTerminationRequest str = rxMessageFactory.createSessionTerminationRequest();
  346. assertTrue("Request Flag in Session-Termination-Request is not set.", str.getHeader().isRequest());
  347. }
  348. @Test
  349. public void isProxiableSTR() throws Exception {
  350. SessionTerminationRequest str = rxMessageFactory.createSessionTerminationRequest();
  351. assertTrue("The 'P' bit is not set by default in Session-Termination-Request, it should.", str.getHeader().isProxiable());
  352. }
  353. @Test
  354. public void testGettersAndSettersSTR() throws Exception {
  355. SessionTerminationRequest str = rxMessageFactory.createSessionTerminationRequest();
  356. int nFailures = AvpAssistant.testMethods(str, SessionTerminationRequest.class);
  357. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  358. }
  359. @Test
  360. public void hasRxApplicationIdSTR() throws Exception {
  361. SessionTerminationRequest str = rxMessageFactory.createSessionTerminationRequest();
  362. assertTrue("Auth-Application-Id AVP in Rx STR must be " + RxMessageFactory._Rx_AUTH_APP_ID + ", it is " + str.getAuthApplicationId(), str.getAuthApplicationId() == RxMessageFactory._Rx_AUTH_APP_ID);
  363. }
  364. // Session-Termination-Answer
  365. @Test
  366. public void isAnswerSTA() throws Exception {
  367. SessionTerminationAnswer sta = rxMessageFactory.createSessionTerminationAnswer(rxMessageFactory.createSessionTerminationRequest());
  368. assertFalse("Request Flag in Re-Auth-Answer is set.", sta.getHeader().isRequest());
  369. }
  370. @Test
  371. public void isProxiableCopiedSTA() throws Exception {
  372. SessionTerminationRequest str = rxMessageFactory.createSessionTerminationRequest();
  373. SessionTerminationAnswer sta = rxMessageFactory.createSessionTerminationAnswer(str);
  374. assertEquals("The 'P' bit is not copied from request in Session-Termination-Answer, it should. [RFC3588/6.2]", str.getHeader().isProxiable(), sta.getHeader().isProxiable());
  375. // Reverse 'P' bit ...
  376. ((DiameterMessageImpl) str).getGenericData().setProxiable(!str.getHeader().isProxiable());
  377. assertTrue("The 'P' bit was not modified in Session-Termination-Request, it should.", str.getHeader().isProxiable() != sta.getHeader().isProxiable());
  378. sta = rxMessageFactory.createSessionTerminationAnswer(str);
  379. assertEquals("The 'P' bit is not copied from request in Session-Termination-Answer, it should. [RFC3588/6.2]", str.getHeader().isProxiable(), sta.getHeader().isProxiable());
  380. }
  381. @Test
  382. public void hasTFlagSetSTA() throws Exception {
  383. SessionTerminationRequest str = rxMessageFactory.createSessionTerminationRequest();
  384. ((DiameterMessageImpl) str).getGenericData().setReTransmitted(true);
  385. assertTrue("The 'T' flag should be set in Session-Termination-Request", str.getHeader().isPotentiallyRetransmitted());
  386. SessionTerminationAnswer sta = rxMessageFactory.createSessionTerminationAnswer(str);
  387. assertFalse("The 'T' flag should not be set in Session-Termination-Answer", sta.getHeader().isPotentiallyRetransmitted());
  388. }
  389. @Test
  390. public void testGettersAndSettersSTA() throws Exception {
  391. SessionTerminationAnswer sta = rxMessageFactory.createSessionTerminationAnswer(rxMessageFactory.createSessionTerminationRequest());
  392. int nFailures = AvpAssistant.testMethods(sta, SessionTerminationAnswer.class);
  393. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  394. }
  395. @Test
  396. public void hasDestinationHostSTA() throws Exception {
  397. SessionTerminationAnswer sta = rxMessageFactory.createSessionTerminationAnswer(rxMessageFactory.createSessionTerminationRequest());
  398. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", sta.getDestinationHost());
  399. }
  400. @Test
  401. public void hasDestinationRealmSTA() throws Exception {
  402. SessionTerminationAnswer sta = rxMessageFactory.createSessionTerminationAnswer(rxMessageFactory.createSessionTerminationRequest());
  403. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", sta.getDestinationRealm());
  404. }
  405. // Rx AVP Factory Tests
  406. // private static BindingInformation BI_AVP_DEFAULT = rxAvpFactory.createBindingInformation();
  407. // private static BindingInputList BIL_AVP_DEFAULT = rxAvpFactory.createBindingInputList();
  408. // private static BindingOutputList BOL_AVP_DEFAULT = rxAvpFactory.createBindingOutputList();
  409. // private static FlowGrouping FG_AVP_DEFAULT = rxAvpFactory.createFlowGrouping();
  410. // private static Flows F_AVP_DEFAULT = rxAvpFactory.createFlows();
  411. // private static GloballyUniqueAddress GUA_AVP_DEFAULT = rxAvpFactory.createGloballyUniqueAddress();
  412. // private static MediaComponentDescription MCD_AVP_DEFAULT = rxAvpFactory.createMediaComponentDescription();
  413. // private static MediaSubComponent MSC_AVP_DEFAULT = rxAvpFactory.createMediaSubComponent();
  414. // private static V4TransportAddress V4TA_AVP_DEFAULT = rxAvpFactory.createV4TransportAddress();
  415. // private static V6TransportAddress V6TA_AVP_DEFAULT = rxAvpFactory.createV6TransportAddress();
  416. //
  417. // static {
  418. // V4TA_AVP_DEFAULT.setFramedIPAddress("255.255.255.254");
  419. // V4TA_AVP_DEFAULT.setPortNumber(13579);
  420. //
  421. // V6TA_AVP_DEFAULT.setFramedIPV6Prefix("A123:B456:C789:DE80::/57");
  422. // V6TA_AVP_DEFAULT.setPortNumber(24680);
  423. //
  424. // BIL_AVP_DEFAULT.setV4TransportAddress(V4TA_AVP_DEFAULT);
  425. // BIL_AVP_DEFAULT.setV6TransportAddress(V6TA_AVP_DEFAULT);
  426. //
  427. // BI_AVP_DEFAULT.setBindingInputList(BIL_AVP_DEFAULT);
  428. // BI_AVP_DEFAULT.setBindingOutputList(BOL_AVP_DEFAULT);
  429. //
  430. // F_AVP_DEFAULT.setFlowNumber(1);
  431. // F_AVP_DEFAULT.setMediaComponentNumber(2);
  432. //
  433. // FG_AVP_DEFAULT.setFlow(F_AVP_DEFAULT);
  434. //
  435. // GUA_AVP_DEFAULT.setAddressRealm("mobicents.org");
  436. // GUA_AVP_DEFAULT.setFramedIPAddress("255.255.255.254");
  437. // GUA_AVP_DEFAULT.setFramedIPV6Prefix("A123:B456:C789:DE80::/57");
  438. //
  439. // MSC_AVP_DEFAULT.setFlowDescription(new IPFilterRule("deny in ip from 1.2.3.4/24 to any"));
  440. // MSC_AVP_DEFAULT.setFlowNumber(7);
  441. // MSC_AVP_DEFAULT.setFlowStatus(FlowStatus.ENABLED);
  442. // MSC_AVP_DEFAULT.setFlowUsage(FlowUsage.RTCP);
  443. // MSC_AVP_DEFAULT.setMaxRequestedBandwidthDL(555);
  444. // MSC_AVP_DEFAULT.setMaxRequestedBandwidthUL(222);
  445. //
  446. // MCD_AVP_DEFAULT.setAFApplicationIdentifier("AFApplicationIdentifier");
  447. // MCD_AVP_DEFAULT.setCodecData("codecData");
  448. // MCD_AVP_DEFAULT.setFlowStatus(FlowStatus.DISABLED);
  449. // MCD_AVP_DEFAULT.setMaxRequestedBandwidthDL(999);
  450. // MCD_AVP_DEFAULT.setMaxRequestedBandwidthUL(111);
  451. // MCD_AVP_DEFAULT.setMediaAuthorizationContextId("mediaAuthorizationContextId");
  452. // MCD_AVP_DEFAULT.setMediaComponentNumber(1);
  453. // MCD_AVP_DEFAULT.setMediaSubComponent(MSC_AVP_DEFAULT);
  454. // MCD_AVP_DEFAULT.setReservationClass(4);
  455. // MCD_AVP_DEFAULT.setReservationPriority(ReservationPriority.PRIORITYSEVEN);
  456. // MCD_AVP_DEFAULT.setRRBandwidth(65);
  457. // MCD_AVP_DEFAULT.setRSBandwidth(56);
  458. // MCD_AVP_DEFAULT.setTransportClass(76576);
  459. // }
  460. //
  461. @Test
  462. public void testAvpFactoryCreateAcceptableServiceInfo() throws Exception {
  463. String avpName = "Acceptable-Service-Info";
  464. // Create AVP with mandatory values
  465. AcceptableServiceInfoAvp biAvp1 = rxAvpFactory.createAcceptableServiceInfo();
  466. // Make sure it's not null
  467. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", biAvp1);
  468. // Create AVP with default constructor
  469. AcceptableServiceInfoAvp biAvp2 = rxAvpFactory.createAcceptableServiceInfo();
  470. // Should not contain mandatory values
  471. // Set mandatory values
  472. // Make sure it's equal to the one created with mandatory values constructor
  473. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", biAvp1, biAvp2);
  474. // Make new copy
  475. biAvp2 = rxAvpFactory.createAcceptableServiceInfo();
  476. // And set all values using setters
  477. AvpAssistant.testSetters(biAvp2);
  478. // Create empty...
  479. AcceptableServiceInfoAvp biAvp3 = rxAvpFactory.createAcceptableServiceInfo();
  480. // Verify that no values have been set
  481. AvpAssistant.testHassers(biAvp3, false);
  482. // Set all previous values
  483. biAvp3.setExtensionAvps(biAvp2.getExtensionAvps());
  484. // Verify if values have been set
  485. AvpAssistant.testHassers(biAvp3, true);
  486. // Verify if values have been correctly set
  487. AvpAssistant.testGetters(biAvp3);
  488. // Make sure they match!
  489. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", biAvp2, biAvp3);
  490. }
  491. @Test
  492. public void testAvpFactoryAccessNetworkChargingIdentifier() throws Exception {
  493. String avpName = "Access-Network-Charging-Identifier";
  494. // Create AVP with mandatory values
  495. AccessNetworkChargingIdentifierAvp bilAvp1 = rxAvpFactory.createAccessNetworkChargingIdentifier();
  496. // Make sure it's not null
  497. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", bilAvp1);
  498. // Create AVP with default constructor
  499. AccessNetworkChargingIdentifierAvp bilAvp2 = rxAvpFactory.createAccessNetworkChargingIdentifier();
  500. // Should not contain mandatory values
  501. // Set mandatory values
  502. // Make sure it's equal to the one created with mandatory values constructor
  503. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", bilAvp1, bilAvp2);
  504. // Make new copy
  505. bilAvp2 = rxAvpFactory.createAccessNetworkChargingIdentifier();
  506. // And set all values using setters
  507. AvpAssistant.testSetters(bilAvp2);
  508. // Create empty...
  509. AccessNetworkChargingIdentifierAvp bilAvp3 = rxAvpFactory.createAccessNetworkChargingIdentifier();
  510. // Verify that no values have been set
  511. AvpAssistant.testHassers(bilAvp3, false);
  512. // Set all previous values
  513. bilAvp3.setExtensionAvps(bilAvp2.getExtensionAvps());
  514. // Verify if values have been set
  515. AvpAssistant.testHassers(bilAvp3, true);
  516. // Verify if values have been correctly set
  517. AvpAssistant.testGetters(bilAvp3);
  518. // Make sure they match!
  519. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", bilAvp2, bilAvp3);
  520. }
  521. @Test
  522. public void testAvpFactoryFlows() throws Exception {
  523. String avpName = "Flows";
  524. // Create AVP with mandatory values
  525. FlowsAvp bolAvp1 = rxAvpFactory.createFlows();
  526. // Make sure it's not null
  527. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", bolAvp1);
  528. // Create AVP with default constructor
  529. FlowsAvp bolAvp2 = rxAvpFactory.createFlows();
  530. // Should not contain mandatory values
  531. // Set mandatory values
  532. // Make sure it's equal to the one created with mandatory values constructor
  533. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", bolAvp1, bolAvp2);
  534. // Make new copy
  535. bolAvp2 = rxAvpFactory.createFlows();
  536. // And set all values using setters
  537. AvpAssistant.testSetters(bolAvp2);
  538. // Create empty...
  539. FlowsAvp bolAvp3 = rxAvpFactory.createFlows();
  540. // Verify that no values have been set
  541. AvpAssistant.testHassers(bolAvp3, false);
  542. // Set all previous values
  543. bolAvp3.setExtensionAvps(bolAvp2.getExtensionAvps());
  544. // Verify if values have been set
  545. AvpAssistant.testHassers(bolAvp3, true);
  546. // Verify if values have been correctly set
  547. AvpAssistant.testGetters(bolAvp3);
  548. // Make sure they match!
  549. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", bolAvp2, bolAvp3);
  550. }
  551. @Test
  552. public void testAvpFactoryMediaComponentDescription() throws Exception {
  553. String avpName = "Media-Component-Description";
  554. // Create AVP with mandatory values
  555. MediaComponentDescriptionAvp fgAvp1 = rxAvpFactory.createMediaComponentDescription();
  556. // Make sure it's not null
  557. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", fgAvp1);
  558. // Create AVP with default constructor
  559. MediaComponentDescriptionAvp fgAvp2 = rxAvpFactory.createMediaComponentDescription();
  560. // Should not contain mandatory values
  561. // Set mandatory values
  562. // Make sure it's equal to the one created with mandatory values constructor
  563. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", fgAvp1, fgAvp2);
  564. // Make new copy
  565. fgAvp2 = rxAvpFactory.createMediaComponentDescription();
  566. // And set all values using setters
  567. AvpAssistant.testSetters(fgAvp2);
  568. // Create empty...
  569. MediaComponentDescriptionAvp fgAvp3 = rxAvpFactory.createMediaComponentDescription();
  570. // Verify that no values have been set
  571. AvpAssistant.testHassers(fgAvp3, false);
  572. // Set all previous values
  573. fgAvp3.setExtensionAvps(fgAvp2.getExtensionAvps());
  574. // Verify if values have been set
  575. AvpAssistant.testHassers(fgAvp3, true);
  576. // Verify if values have been correctly set
  577. AvpAssistant.testGetters(fgAvp3);
  578. // Make sure they match!
  579. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", fgAvp2, fgAvp3);
  580. }
  581. //Commented out since Gx has different definition.
  582. @Test
  583. public void testAvpFactoryMediaSubComponent() throws Exception {
  584. String avpName = "Media-Sub-Component";
  585. // Create AVP with mandatory values
  586. MediaSubComponentAvp mscAvp1 = rxAvpFactory.createMediaSubComponent();
  587. // Make sure it's not null
  588. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", mscAvp1);
  589. // Create AVP with default constructor
  590. MediaSubComponentAvp mscAvp2 = rxAvpFactory.createMediaSubComponent();
  591. // Should not contain mandatory values
  592. // Set mandatory values
  593. // Make sure it's equal to the one created with mandatory values constructor
  594. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", mscAvp1, mscAvp2);
  595. // Make new copy
  596. mscAvp2 = rxAvpFactory.createMediaSubComponent();
  597. // And set all values using setters
  598. AvpAssistant.testSetters(mscAvp2);
  599. // Create empty...
  600. MediaSubComponentAvp mscAvp3 = rxAvpFactory.createMediaSubComponent();
  601. // Verify that no values have been set
  602. AvpAssistant.testHassers(mscAvp3, false);
  603. // Set all previous values
  604. mscAvp3.setExtensionAvps(mscAvp2.getExtensionAvps());
  605. // Verify if values have been set
  606. AvpAssistant.testHassers(mscAvp3, true);
  607. // Verify if values have been correctly set
  608. AvpAssistant.testGetters(mscAvp3);
  609. // Make sure they match!
  610. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", mscAvp2, mscAvp3);
  611. }
  612. @Test
  613. public void testAvpFactorySponsoredConnectivityData() throws Exception {
  614. String avpName = "Sponsored-Connectivity-Data";
  615. // Create AVP with mandatory values
  616. SponsoredConnectivityDataAvp guaAvp1 = rxAvpFactory.createSponsoredConnectivityData();
  617. // Make sure it's not null
  618. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", guaAvp1);
  619. // Create AVP with default constructor
  620. SponsoredConnectivityDataAvp guaAvp2 = rxAvpFactory.createSponsoredConnectivityData();
  621. // Should not contain mandatory values
  622. // Set mandatory values
  623. // Make sure it's equal to the one created with mandatory values constructor
  624. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", guaAvp1, guaAvp2);
  625. // Make new copy
  626. guaAvp2 = rxAvpFactory.createSponsoredConnectivityData();
  627. // And set all values using setters
  628. AvpAssistant.testSetters(guaAvp2);
  629. // Create empty...
  630. SponsoredConnectivityDataAvp guaAvp3 = rxAvpFactory.createSponsoredConnectivityData();
  631. // Verify that no values have been set
  632. AvpAssistant.testHassers(guaAvp3, false);
  633. // Set all previous values
  634. guaAvp3.setExtensionAvps(guaAvp2.getExtensionAvps());
  635. // Verify if values have been set
  636. AvpAssistant.testHassers(guaAvp3, true);
  637. // Verify if values have been correctly set
  638. AvpAssistant.testGetters(guaAvp3);
  639. // Make sure they match!
  640. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", guaAvp2, guaAvp3);
  641. }
  642. @Test
  643. public void testAvpFactorySupportedFeatures() throws Exception {
  644. String avpName = "SupportedFeatures";
  645. // Create AVP with mandatory values
  646. SupportedFeaturesAvp mcdAvp1 = rxAvpFactory.createSupportedFeatures();
  647. // Make sure it's not null
  648. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", mcdAvp1);
  649. // Create AVP with default constructor
  650. SupportedFeaturesAvp mcdAvp2 = rxAvpFactory.createSupportedFeatures();
  651. // Should not contain mandatory values
  652. // Set mandatory values
  653. // Make sure it's equal to the one created with mandatory values constructor
  654. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", mcdAvp1, mcdAvp2);
  655. // Make new copy
  656. mcdAvp2 = rxAvpFactory.createSupportedFeatures();
  657. // And set all values using setters
  658. AvpAssistant.testSetters(mcdAvp2);
  659. // Create empty...
  660. SupportedFeaturesAvp mcdAvp3 = rxAvpFactory.createSupportedFeatures();
  661. // Verify that no values have been set
  662. AvpAssistant.testHassers(mcdAvp3, false);
  663. // Set all previous values
  664. mcdAvp3.setExtensionAvps(mcdAvp2.getExtensionAvps());
  665. // Verify if values have been set
  666. AvpAssistant.testHassers(mcdAvp3, true);
  667. // Verify if values have been correctly set
  668. AvpAssistant.testGetters(mcdAvp3);
  669. // Make sure they match!
  670. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", mcdAvp2, mcdAvp3);
  671. }
  672. /**
  673. * Class representing the Diameter Configuration
  674. */
  675. public static class MyConfiguration extends EmptyConfiguration {
  676. public MyConfiguration() {
  677. super();
  678. add(Assembler, Assembler.defValue());
  679. add(OwnDiameterURI, clientURI);
  680. add(OwnRealm, realmName);
  681. add(OwnVendorID, 193L);
  682. // Set Ericsson SDK feature
  683. //add(UseUriAsFqdn, true);
  684. // Set Common Applications
  685. add(ApplicationId,
  686. // AppId 1
  687. getInstance().
  688. add(VendorId, 193L).
  689. add(AuthApplId, 0L).
  690. add(AcctApplId, 19302L)
  691. );
  692. // Set peer table
  693. add(PeerTable,
  694. // Peer 1
  695. getInstance().
  696. add(PeerRating, 1).
  697. add(PeerName, serverURI));
  698. // Set realm table
  699. add(RealmTable,
  700. // Realm 1
  701. getInstance().add(RealmEntry, getInstance().
  702. add(RealmName, realmName).
  703. add(ApplicationId, getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L)).
  704. add(RealmHosts, clientHost + ", " + serverHost).
  705. add(RealmLocalAction, "LOCAL").
  706. add(RealmEntryIsDynamic, false).
  707. add(RealmEntryExpTime, 1000L)));
  708. }
  709. }
  710. @Test
  711. public void testMediaComponentDescription() {
  712. AARequest aar = rxMessageFactory.createAARequest();
  713. MediaComponentDescriptionAvp mcdAvp = rxAvpFactory.createMediaComponentDescription();
  714. MediaSubComponentAvp mscAvp = rxAvpFactory.createMediaSubComponent();
  715. mscAvp.setFlowUsage(FlowUsage.AF_SIGNALLING);
  716. IPFilterRule fd1Avp = new IPFilterRule("permit in ip from 192.168.0.0/24 10,11,12,20-30 to 192.168.1.1 99 frag established");
  717. IPFilterRule fd2Avp = new IPFilterRule("permit out 2 from 192.1.0.0/24 to 192.1.1.1/0 frag established setup tcpoptions mrss");
  718. IPFilterRule fd3Avp = new IPFilterRule("permit out 4 from 10.0.1.91 4060 to 10.0.0.190 43772 ");
  719. mscAvp.setFlowDescriptions(new IPFilterRule[]{fd1Avp, fd2Avp, fd3Avp});
  720. mcdAvp.setMediaSubComponent(mscAvp);
  721. aar.setMediaComponentDescription(mcdAvp);
  722. // from Richard Good
  723. if(aar.hasMediaComponentDescription()) {
  724. System.err.println("Has media component description");
  725. MediaComponentDescriptionAvp[] mcd = aar.getMediaComponentDescriptions();
  726. if(mcd[0].hasMediaSubComponent()) {
  727. System.err.println("Has media sub component");
  728. MediaSubComponentAvp[] msc = mcd[0].getMediaSubComponents();
  729. if (msc[0].hasFlowUsage()) {
  730. System.err.println("Has flow usage");
  731. }
  732. System.err.println("msc[0] flow usage: " + msc[0].getFlowUsage());
  733. System.err.println("msc[0] flow usage value: " + msc[0].getFlowUsage().getValue());
  734. // other from Richarg Good
  735. IPFilterRule[] ipf = msc[0].getFlowDescriptions();
  736. System.err.println("msc[0] flow descriptions " + ipf.toString());
  737. System.err.println("msc[0] flow description length " + ipf.length);
  738. for (int b = 0; b < ipf.length; b++) {
  739. System.err.println("msc[0] flow description " + ipf[b].toString()); // THIS DOES NOT PRINT!
  740. }
  741. }
  742. }
  743. }
  744. @Test
  745. public void testMessageFactoryApplicationIdChangeAAR() throws Exception {
  746. long vendor = 10415L;
  747. ApplicationId originalAppId = ((RxMessageFactoryImpl)rxMessageFactory).getApplicationId();
  748. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  749. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  750. boolean isVendor = originalAppId.getVendorId() != 0L;
  751. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  752. System.out.println("Default VENDOR-ID for Rx is " + originalAppId.getVendorId());
  753. // let's create a message and see how it comes...
  754. AARequest originalAAR = rxMessageFactory.createAARequest();
  755. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalAAR);
  756. // now we switch..
  757. originalAAR = null;
  758. isVendor = !isVendor;
  759. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  760. // create a new message and see how it comes...
  761. AARequest changedAAR = rxMessageFactory.createAARequest();
  762. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedAAR);
  763. // revert back to default
  764. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  765. }
  766. @Test
  767. public void testClientSessionApplicationIdChangeAAR() throws Exception {
  768. long vendor = 10415L;
  769. ApplicationId originalAppId = ((RxMessageFactoryImpl)rxMessageFactory).getApplicationId();
  770. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  771. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  772. boolean isVendor = originalAppId.getVendorId() != 0L;
  773. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  774. System.out.println("Default VENDOR-ID for Rx is " + originalAppId.getVendorId());
  775. // let's create a message and see how it comes...
  776. AARequest originalAAR = rxClientSession.createRxAARequest();
  777. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalAAR);
  778. // now we switch..
  779. originalAAR = null;
  780. isVendor = !isVendor;
  781. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  782. // create a new message and see how it comes...
  783. AARequest changedAAR = rxClientSession.createRxAARequest();
  784. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedAAR);
  785. // revert back to default
  786. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  787. }
  788. @Test
  789. public void testMessageFactoryApplicationIdChangeAAA() throws Exception {
  790. long vendor = 10415L;
  791. ApplicationId originalAppId = ((RxMessageFactoryImpl)rxMessageFactory).getApplicationId();
  792. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  793. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  794. boolean isVendor = originalAppId.getVendorId() != 0L;
  795. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  796. System.out.println("Default VENDOR-ID for Rx is " + originalAppId.getVendorId());
  797. // let's create a message and see how it comes...
  798. AAAnswer originalAAA = rxMessageFactory.createAAAnswer(rxMessageFactory.createAARequest());
  799. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalAAA);
  800. // now we switch..
  801. originalAAA = null;
  802. isVendor = !isVendor;
  803. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  804. // create a new message and see how it comes...
  805. AAAnswer changedAAA = rxMessageFactory.createAAAnswer(rxMessageFactory.createAARequest());
  806. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedAAA);
  807. // revert back to default
  808. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  809. }
  810. @Test
  811. public void testServerSessionApplicationIdChangeAAA() throws Exception {
  812. long vendor = 10415L;
  813. ApplicationId originalAppId = ((RxMessageFactoryImpl)rxMessageFactory).getApplicationId();
  814. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  815. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  816. boolean isVendor = originalAppId.getVendorId() != 0L;
  817. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  818. System.out.println("Default VENDOR-ID for Rx is " + originalAppId.getVendorId());
  819. // let's create a message and see how it comes...
  820. AARequest aar = rxMessageFactory.createAARequest();
  821. rxServerSession.fetchCurrentState(aar);
  822. AAAnswer originalAAA = rxServerSession.createAAAnswer();
  823. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalAAA);
  824. // now we switch..
  825. originalAAA = null;
  826. isVendor = !isVendor;
  827. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  828. // create a new message and see how it comes...
  829. AAAnswer changedAAA = rxServerSession.createAAAnswer();
  830. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedAAA);
  831. // revert back to default
  832. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  833. }
  834. @Test
  835. public void testMessageFactoryApplicationIdChangeASR() throws Exception {
  836. long vendor = 10415L;
  837. ApplicationId originalAppId = ((RxMessageFactoryImpl)rxMessageFactory).getApplicationId();
  838. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  839. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  840. boolean isVendor = originalAppId.getVendorId() != 0L;
  841. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  842. System.out.println("Default VENDOR-ID for Rx is " + originalAppId.getVendorId());
  843. // let's create a message and see how it comes...
  844. AbortSessionRequest originalASR = rxMessageFactory.createAbortSessionRequest();
  845. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalASR);
  846. // now we switch..
  847. originalASR = null;
  848. isVendor = !isVendor;
  849. ((RxMessageFactoryImpl)rxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  850. // create a new message and see ho…

Large files files are truncated, but you can click here to view the full file