PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 674 lines | 442 code | 138 blank | 94 comment | 48 complexity | 8b4db83f71279255b39f47c95b971dbc 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 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.assertEquals;
  42. import static org.junit.Assert.assertFalse;
  43. import static org.junit.Assert.assertNull;
  44. import static org.junit.Assert.assertTrue;
  45. import static org.mobicents.slee.resources.diameter.tests.factories.BaseFactoriesTest.checkCorrectApplicationIdAVPs;
  46. import net.java.slee.resource.diameter.base.DiameterActivity;
  47. import net.java.slee.resource.diameter.base.events.avp.AuthSessionStateType;
  48. import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity;
  49. import net.java.slee.resource.diameter.sh.DiameterShAvpFactory;
  50. import net.java.slee.resource.diameter.sh.client.ShClientMessageFactory;
  51. import net.java.slee.resource.diameter.sh.events.ProfileUpdateAnswer;
  52. import net.java.slee.resource.diameter.sh.events.ProfileUpdateRequest;
  53. import net.java.slee.resource.diameter.sh.events.PushNotificationRequest;
  54. import net.java.slee.resource.diameter.sh.events.SubscribeNotificationsAnswer;
  55. import net.java.slee.resource.diameter.sh.events.SubscribeNotificationsRequest;
  56. import net.java.slee.resource.diameter.sh.events.UserDataAnswer;
  57. import net.java.slee.resource.diameter.sh.events.UserDataRequest;
  58. import net.java.slee.resource.diameter.sh.events.avp.DiameterShAvpCodes;
  59. import net.java.slee.resource.diameter.sh.events.avp.UserIdentityAvp;
  60. import org.jdiameter.api.ApplicationId;
  61. import org.jdiameter.api.Message;
  62. import org.jdiameter.api.Session;
  63. import org.jdiameter.api.Stack;
  64. import org.jdiameter.api.sh.ServerShSession;
  65. import org.jdiameter.client.impl.helpers.EmptyConfiguration;
  66. import org.jdiameter.common.impl.app.sh.ShSessionFactoryImpl;
  67. import org.jdiameter.server.impl.app.sh.ShServerSessionImpl;
  68. import org.junit.Test;
  69. import org.mobicents.diameter.dictionary.AvpDictionary;
  70. import org.mobicents.slee.resource.diameter.base.DiameterActivityHandle;
  71. import org.mobicents.slee.resource.diameter.base.DiameterAvpFactoryImpl;
  72. import org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl;
  73. import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl;
  74. import org.mobicents.slee.resource.diameter.base.handlers.DiameterRAInterface;
  75. import org.mobicents.slee.resource.diameter.sh.DiameterShAvpFactoryImpl;
  76. import org.mobicents.slee.resource.diameter.sh.client.ShClientMessageFactoryImpl;
  77. import org.mobicents.slee.resource.diameter.sh.events.avp.UserIdentityAvpImpl;
  78. import org.mobicents.slee.resource.diameter.sh.server.ShServerActivityImpl;
  79. import org.mobicents.slee.resource.diameter.sh.server.ShServerMessageFactoryImpl;
  80. import org.mobicents.slee.resource.diameter.sh.server.ShServerSubscriptionActivityImpl;
  81. /**
  82. * Test class for JAIN SLEE Diameter Sh (Server) RA Message and AVP Factories
  83. *
  84. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  85. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  86. */
  87. public class ShServerFactoriesTest implements DiameterRAInterface {
  88. private static String clientHost = "127.0.0.1";
  89. private static String clientPort = "13868";
  90. private static String clientURI = "aaa://" + clientHost + ":" + clientPort;
  91. private static String serverHost = "localhost";
  92. private static String serverPort = "3868";
  93. private static String serverURI = "aaa://" + serverHost + ":" + serverPort;
  94. private static String realmName = "mobicents.org";
  95. private static ShServerMessageFactoryImpl shServerFactory;
  96. private static ShClientMessageFactoryImpl shClientFactory;
  97. private static DiameterShAvpFactory shAvpFactory;
  98. //private static ShClientActivityImpl clientSession;
  99. private static ShServerActivityImpl serverSession;
  100. private static ShServerSubscriptionActivityImpl serverSubsSession;
  101. static {
  102. Stack stack = new org.jdiameter.client.impl.StackImpl();
  103. try {
  104. stack.init(new MyConfiguration());
  105. AvpDictionary.INSTANCE.parseDictionary(ShServerFactoriesTest.class.getClassLoader().getResourceAsStream("dictionary.xml"));
  106. }
  107. catch (Exception e) {
  108. throw new RuntimeException("Failed to initialize the stack.");
  109. }
  110. Session session = null;
  111. ShSessionFactoryImpl sf = null;
  112. try {
  113. session = stack.getSessionFactory().getNewSession();
  114. sf = new ShSessionFactoryImpl(stack.getSessionFactory());
  115. }
  116. catch (Exception e) {
  117. // let's go with null
  118. e.printStackTrace();
  119. }
  120. DiameterMessageFactoryImpl baseMessageFactory = new DiameterMessageFactoryImpl(stack);
  121. shAvpFactory = new DiameterShAvpFactoryImpl(new DiameterAvpFactoryImpl());
  122. shServerFactory = new ShServerMessageFactoryImpl(baseMessageFactory, session, stack, shAvpFactory);
  123. shClientFactory = new ShClientMessageFactoryImpl(session, stack);
  124. ApplicationId shAppId = org.jdiameter.api.ApplicationId.createByAuthAppId(ShClientMessageFactory._SH_VENDOR_ID, ShClientMessageFactory._SH_APP_ID);
  125. ShServerSessionImpl stackServerSession = (ShServerSessionImpl) sf.getNewSession("123", ServerShSession.class, shAppId, new Object[0]);
  126. serverSession = new ShServerActivityImpl(shServerFactory, shAvpFactory, stackServerSession, new DiameterIdentity("127.0.0.1"), new DiameterIdentity("mobicents.org"));
  127. serverSession.setSessionListener(new ShServerFactoriesTest());
  128. serverSubsSession = new ShServerSubscriptionActivityImpl(shServerFactory, shAvpFactory, stackServerSession, new DiameterIdentity("127.0.0.1"), new DiameterIdentity("mobicents.org"));
  129. serverSubsSession.setSessionListener(new ShServerFactoriesTest());
  130. //ShClientSessionImpl stackClientSession = (ShClientSessionImpl) sf.getNewSession("321", ClientShSession.class, shAppId, new Object[0]);
  131. //clientSession = new ShClientActivityImpl(shClientFactory, shAvpFactory, stackClientSession, null, null);
  132. }
  133. @Test
  134. public void isAnswerPUA() throws Exception {
  135. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest());
  136. assertFalse("Request Flag in Profile-Update-Answer is set.", pua.getHeader().isRequest());
  137. }
  138. @Test
  139. public void isProxiableCopiedPUA() throws Exception {
  140. ProfileUpdateRequest pur = shClientFactory.createProfileUpdateRequest();
  141. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(pur);
  142. assertEquals("The 'P' bit is not copied from request in Profile-Update-Answer, it should. [RFC3588/6.2]", pur.getHeader().isProxiable(), pua.getHeader().isProxiable());
  143. // Reverse 'P' bit ...
  144. ((DiameterMessageImpl) pur).getGenericData().setProxiable(!pur.getHeader().isProxiable());
  145. assertTrue("The 'P' bit was not modified in Profile-Update-Request, it should.", pur.getHeader().isProxiable() != pua.getHeader().isProxiable());
  146. pua = shServerFactory.createProfileUpdateAnswer(pur);
  147. assertEquals("The 'P' bit is not copied from request in Profile-Update-Answer, it should. [RFC3588/6.2]", pur.getHeader().isProxiable(), pua.getHeader().isProxiable());
  148. }
  149. @Test
  150. public void hasTFlagSetPUA() throws Exception {
  151. ProfileUpdateRequest pur = shClientFactory.createProfileUpdateRequest();
  152. ((DiameterMessageImpl) pur).getGenericData().setReTransmitted(true);
  153. assertTrue("The 'T' flag should be set in Profile-Update-Request", pur.getHeader().isPotentiallyRetransmitted());
  154. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(pur);
  155. assertFalse("The 'T' flag should not be set in Profile-Update-Answer", pua.getHeader().isPotentiallyRetransmitted());
  156. }
  157. @Test
  158. public void testGettersAndSettersPUA() throws Exception {
  159. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest());
  160. int nFailures = AvpAssistant.testMethods(pua, ProfileUpdateAnswer.class);
  161. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  162. }
  163. @Test
  164. public void hasDestinationHostPUA() throws Exception {
  165. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest());
  166. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", pua.getDestinationHost());
  167. }
  168. @Test
  169. public void hasDestinationRealmPUA() throws Exception {
  170. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest());
  171. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", pua.getDestinationRealm());
  172. }
  173. /**
  174. * Test for Issue #665 (Diameter Experimental Result AVP is Nested) http://code.google.com/p/mobicents/issues/detail?id=655
  175. *
  176. * @throws Exception
  177. */
  178. @Test
  179. public void isExperimentalResultCorrectlySetPUA() throws Exception {
  180. long originalValue = 5001;
  181. ProfileUpdateAnswer pua = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest(), originalValue, true);
  182. long obtainedValue = pua.getExperimentalResult().getExperimentalResultCode();
  183. assertTrue("Experimental-Result-Code in PUA should be " + originalValue + " and is " + obtainedValue + ".", originalValue == obtainedValue);
  184. }
  185. @Test
  186. public void isRequestPNR() throws Exception {
  187. PushNotificationRequest pnr = shServerFactory.createPushNotificationRequest();
  188. assertTrue("Request Flag in Push-Notification-Request is not set.", pnr.getHeader().isRequest());
  189. }
  190. @Test
  191. public void isProxiableRAR() throws Exception {
  192. PushNotificationRequest pnr = shServerFactory.createPushNotificationRequest();
  193. assertTrue("The 'P' bit is not set by default in Push-Notification-Request, it should.", pnr.getHeader().isProxiable());
  194. }
  195. @Test
  196. public void testGettersAndSettersPNR() throws Exception {
  197. PushNotificationRequest pnr = shServerFactory.createPushNotificationRequest();
  198. int nFailures = AvpAssistant.testMethods(pnr, PushNotificationRequest.class);
  199. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  200. }
  201. @Test
  202. public void isPNRPublicIdentityAccessibleTwice() throws Exception {
  203. String originalValue = "sip:alexandre@diameter.mobicents.org";
  204. UserIdentityAvpImpl uiAvp = new UserIdentityAvpImpl(DiameterShAvpCodes.USER_IDENTITY, 10415L, 1, 0, new byte[] {});
  205. uiAvp.setPublicIdentity(originalValue);
  206. PushNotificationRequest udr = shServerFactory.createPushNotificationRequest(uiAvp, new byte[1]);
  207. String obtainedValue1 = udr.getUserIdentity().getPublicIdentity();
  208. String obtainedValue2 = udr.getUserIdentity().getPublicIdentity();
  209. assertTrue("Obtained value for Public-Identity AVP differs from original.", obtainedValue1.equals(originalValue));
  210. assertTrue("Obtained #1 value for Public-Identity AVP differs from Obtained #2.", obtainedValue1.equals(obtainedValue2));
  211. }
  212. @Test
  213. public void isAnswerSNA() throws Exception {
  214. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest());
  215. assertFalse("Request Flag in Subscribe-Notifications-Answer is set.", sna.getHeader().isRequest());
  216. }
  217. @Test
  218. public void isProxiableCopiedSNA() throws Exception {
  219. SubscribeNotificationsRequest snr = shClientFactory.createSubscribeNotificationsRequest();
  220. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(snr);
  221. assertEquals("The 'P' bit is not copied from request in Subscribe-Notifications-Answer, it should. [RFC3588/6.2]", snr.getHeader().isProxiable(), sna.getHeader().isProxiable());
  222. // Reverse 'P' bit ...
  223. ((DiameterMessageImpl) snr).getGenericData().setProxiable(!snr.getHeader().isProxiable());
  224. assertTrue("The 'P' bit was not modified in Subscribe-Notifications-Request, it should.", snr.getHeader().isProxiable() != sna.getHeader().isProxiable());
  225. sna = shServerFactory.createSubscribeNotificationsAnswer(snr);
  226. assertEquals("The 'P' bit is not copied from request in Subscribe-Notifications-Answer, it should. [RFC3588/6.2]", snr.getHeader().isProxiable(), sna.getHeader().isProxiable());
  227. }
  228. @Test
  229. public void hasTFlagSetSNA() throws Exception {
  230. SubscribeNotificationsRequest snr = shClientFactory.createSubscribeNotificationsRequest();
  231. ((DiameterMessageImpl) snr).getGenericData().setReTransmitted(true);
  232. assertTrue("The 'T' flag should be set in Subscribe-Notifications-Request", snr.getHeader().isPotentiallyRetransmitted());
  233. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(snr);
  234. assertFalse("The 'T' flag should not be set in Subscribe-Notifications-Answer", sna.getHeader().isPotentiallyRetransmitted());
  235. }
  236. @Test
  237. public void testGettersAndSettersSNA() throws Exception {
  238. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest());
  239. int nFailures = AvpAssistant.testMethods(sna, SubscribeNotificationsAnswer.class);
  240. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  241. }
  242. @Test
  243. public void hasDestinationHostSNA() throws Exception {
  244. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest());
  245. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", sna.getDestinationHost());
  246. }
  247. @Test
  248. public void hasDestinationRealmSNA() throws Exception {
  249. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest());
  250. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", sna.getDestinationRealm());
  251. }
  252. /**
  253. * Test for Issue #665 (Diameter Experimental Result AVP is Nested) http://code.google.com/p/mobicents/issues/detail?id=655
  254. *
  255. * @throws Exception
  256. */
  257. @Test
  258. public void isExperimentalResultCorrectlySetSNA() throws Exception {
  259. long originalValue = 5001;
  260. SubscribeNotificationsAnswer sna = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest(), originalValue, true);
  261. long obtainedValue = sna.getExperimentalResult().getExperimentalResultCode();
  262. assertTrue("Experimental-Result-Code in SNA should be " + originalValue + " and is " + obtainedValue + ".", originalValue == obtainedValue);
  263. }
  264. @Test
  265. public void isAnswerUDA() throws Exception {
  266. UserDataAnswer uda = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest());
  267. assertFalse("Request Flag in User-Data-Answer is set.", uda.getHeader().isRequest());
  268. }
  269. @Test
  270. public void isProxiableCopiedUDA() throws Exception {
  271. UserDataRequest udr = shClientFactory.createUserDataRequest();
  272. UserDataAnswer uda = shServerFactory.createUserDataAnswer(udr);
  273. assertEquals("The 'P' bit is not copied from request in User-Data-Answer, it should. [RFC3588/6.2]", udr.getHeader().isProxiable(), uda.getHeader().isProxiable());
  274. // Reverse 'P' bit ...
  275. ((DiameterMessageImpl) udr).getGenericData().setProxiable(!udr.getHeader().isProxiable());
  276. assertTrue("The 'P' bit was not modified in User-Data-Request, it should.", udr.getHeader().isProxiable() != uda.getHeader().isProxiable());
  277. uda = shServerFactory.createUserDataAnswer(udr);
  278. assertEquals("The 'P' bit is not copied from request in User-Data-Answer, it should. [RFC3588/6.2]", udr.getHeader().isProxiable(), uda.getHeader().isProxiable());
  279. }
  280. @Test
  281. public void hasTFlagSetUDA() throws Exception {
  282. UserDataRequest udr = shClientFactory.createUserDataRequest();
  283. ((DiameterMessageImpl) udr).getGenericData().setReTransmitted(true);
  284. assertTrue("The 'T' flag should be set in User-Data-Request", udr.getHeader().isPotentiallyRetransmitted());
  285. UserDataAnswer uda = shServerFactory.createUserDataAnswer(udr);
  286. assertFalse("The 'T' flag should not be set in User-Data-Answer", uda.getHeader().isPotentiallyRetransmitted());
  287. }
  288. @Test
  289. public void testGettersAndSettersUDA() throws Exception {
  290. UserDataAnswer uda = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest());
  291. int nFailures = AvpAssistant.testMethods(uda, UserDataAnswer.class);
  292. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  293. }
  294. @Test
  295. public void hasDestinationHostUDA() throws Exception {
  296. UserDataAnswer uda = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest());
  297. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", uda.getDestinationHost());
  298. }
  299. @Test
  300. public void hasDestinationRealmUDA() throws Exception {
  301. UserDataAnswer uda = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest());
  302. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", uda.getDestinationRealm());
  303. }
  304. /**
  305. * Test for Issue #665 (Diameter Experimental Result AVP is Nested) http://code.google.com/p/mobicents/issues/detail?id=655
  306. *
  307. * @throws Exception
  308. */
  309. @Test
  310. public void isExperimentalResultCorrectlySetUDA() throws Exception {
  311. long originalValue = 5001;
  312. UserDataAnswer uda = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest(), originalValue, true);
  313. long obtainedValue = uda.getExperimentalResult().getExperimentalResultCode();
  314. assertTrue("Experimental-Result-Code in UDA should be " + originalValue + " and is " + obtainedValue + ".", originalValue == obtainedValue);
  315. }
  316. @Test
  317. public void testMessageFactoryApplicationIdChangePUA() throws Exception {
  318. long vendor = 10415L;
  319. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  320. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  321. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  322. boolean isVendor = originalAppId.getVendorId() != 0L;
  323. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  324. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  325. // let's create a message and see how it comes...
  326. ProfileUpdateAnswer originalPUA = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest());
  327. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPUA);
  328. // now we switch..
  329. originalPUA = null;
  330. isVendor = !isVendor;
  331. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  332. // create a new message and see how it comes...
  333. ProfileUpdateAnswer changedPUA = shServerFactory.createProfileUpdateAnswer(shClientFactory.createProfileUpdateRequest());
  334. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPUA);
  335. // revert back to default
  336. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  337. }
  338. @Test
  339. public void testServerSessionApplicationIdChangePUA() throws Exception {
  340. long vendor = 10415L;
  341. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  342. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  343. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  344. boolean isVendor = originalAppId.getVendorId() != 0L;
  345. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  346. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  347. // let's create a message and see how it comes...
  348. ProfileUpdateRequest pur = shClientFactory.createProfileUpdateRequest();
  349. UserIdentityAvp uiAvp = shAvpFactory.createUserIdentity();
  350. uiAvp.setPublicIdentity("alexandre@mobicents.org");
  351. pur.setUserIdentity(uiAvp);
  352. pur.setAuthSessionState(AuthSessionStateType.NO_STATE_MAINTAINED);
  353. serverSession.fetchSessionData(pur, true);
  354. ProfileUpdateAnswer originalPUA = serverSession.createProfileUpdateAnswer();
  355. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPUA);
  356. // now we switch..
  357. originalPUA = null;
  358. isVendor = !isVendor;
  359. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  360. // create a new message and see how it comes...
  361. ProfileUpdateAnswer changedPUA = serverSession.createProfileUpdateAnswer();
  362. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPUA);
  363. // revert back to default
  364. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  365. }
  366. @Test
  367. public void testMessageFactoryApplicationIdChangePNR() throws Exception {
  368. long vendor = 10415L;
  369. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  370. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  371. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  372. boolean isVendor = originalAppId.getVendorId() != 0L;
  373. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  374. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  375. // let's create a message and see how it comes...
  376. PushNotificationRequest originalPNR = shServerFactory.createPushNotificationRequest();
  377. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPNR);
  378. // now we switch..
  379. originalPNR = null;
  380. isVendor = !isVendor;
  381. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  382. // create a new message and see how it comes...
  383. PushNotificationRequest changedPNR = shServerFactory.createPushNotificationRequest();
  384. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPNR);
  385. // revert back to default
  386. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  387. }
  388. @Test
  389. public void testMessageFactoryApplicationIdChangeSNA() throws Exception {
  390. long vendor = 10415L;
  391. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  392. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  393. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  394. boolean isVendor = originalAppId.getVendorId() != 0L;
  395. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  396. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  397. // let's create a message and see how it comes...
  398. SubscribeNotificationsAnswer originalSNA = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest());
  399. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalSNA);
  400. // now we switch..
  401. originalSNA = null;
  402. isVendor = !isVendor;
  403. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  404. // create a new message and see how it comes...
  405. SubscribeNotificationsAnswer changedSNA = shServerFactory.createSubscribeNotificationsAnswer(shClientFactory.createSubscribeNotificationsRequest());
  406. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedSNA);
  407. // revert back to default
  408. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  409. }
  410. @Test
  411. public void testServerSessionApplicationIdChangeSNA() throws Exception {
  412. long vendor = 10415L;
  413. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  414. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  415. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  416. boolean isVendor = originalAppId.getVendorId() != 0L;
  417. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  418. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  419. // let's create a message and see how it comes...
  420. SubscribeNotificationsRequest snr = shClientFactory.createSubscribeNotificationsRequest();
  421. UserIdentityAvp uiAvp = shAvpFactory.createUserIdentity();
  422. uiAvp.setPublicIdentity("alexandre@mobicents.org");
  423. snr.setUserIdentity(uiAvp);
  424. snr.setAuthSessionState(AuthSessionStateType.NO_STATE_MAINTAINED);
  425. serverSession.fetchSessionData(snr, true);
  426. SubscribeNotificationsAnswer originalSNA = serverSession.createSubscribeNotificationsAnswer();
  427. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalSNA);
  428. // now we switch..
  429. originalSNA = null;
  430. isVendor = !isVendor;
  431. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  432. // create a new message and see how it comes...
  433. SubscribeNotificationsAnswer changedSNA = serverSession.createSubscribeNotificationsAnswer();
  434. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedSNA);
  435. // revert back to default
  436. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  437. }
  438. @Test
  439. public void testMessageFactoryApplicationIdChangeUDA() throws Exception {
  440. long vendor = 10415L;
  441. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  442. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  443. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  444. boolean isVendor = originalAppId.getVendorId() != 0L;
  445. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  446. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  447. // let's create a message and see how it comes...
  448. UserDataAnswer originalUDA = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest());
  449. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalUDA);
  450. // now we switch..
  451. originalUDA = null;
  452. isVendor = !isVendor;
  453. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  454. // create a new message and see how it comes...
  455. UserDataAnswer changedUDA = shServerFactory.createUserDataAnswer(shClientFactory.createUserDataRequest());
  456. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedUDA);
  457. // revert back to default
  458. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  459. }
  460. @Test
  461. public void testServerSessionApplicationIdChangeUDA() throws Exception {
  462. long vendor = 10415L;
  463. ApplicationId originalAppId = ((ShServerMessageFactoryImpl)shServerFactory).getApplicationId();
  464. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  465. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  466. boolean isVendor = originalAppId.getVendorId() != 0L;
  467. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  468. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  469. // let's create a message and see how it comes...
  470. UserDataRequest udr = shClientFactory.createUserDataRequest();
  471. UserIdentityAvp uiAvp = shAvpFactory.createUserIdentity();
  472. uiAvp.setPublicIdentity("alexandre@mobicents.org");
  473. udr.setUserIdentity(uiAvp);
  474. udr.setAuthSessionState(AuthSessionStateType.NO_STATE_MAINTAINED);
  475. serverSession.fetchSessionData(udr, true);
  476. UserDataAnswer originalUDA = serverSession.createUserDataAnswer();
  477. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalUDA);
  478. // now we switch..
  479. originalUDA = null;
  480. isVendor = !isVendor;
  481. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  482. // create a new message and see how it comes...
  483. UserDataAnswer changedUDA = serverSession.createUserDataAnswer();
  484. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedUDA);
  485. // revert back to default
  486. ((ShServerMessageFactoryImpl)shServerFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  487. }
  488. /**
  489. * Class representing the Diameter Configuration
  490. */
  491. public static class MyConfiguration extends EmptyConfiguration {
  492. public MyConfiguration() {
  493. super();
  494. add(Assembler, Assembler.defValue());
  495. add(OwnDiameterURI, clientURI);
  496. add(OwnRealm, realmName);
  497. add(OwnVendorID, 193L);
  498. // Set Ericsson SDK feature
  499. // add(UseUriAsFqdn, true);
  500. // Set Common Applications
  501. add(ApplicationId,
  502. // AppId 1
  503. getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L));
  504. // Set peer table
  505. add(PeerTable,
  506. // Peer 1
  507. getInstance().add(PeerRating, 1).add(PeerName, serverURI));
  508. // Set realm table
  509. add(RealmTable,
  510. // Realm 1
  511. getInstance().add(
  512. RealmEntry,
  513. getInstance().add(RealmName, realmName).add(ApplicationId, getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L)).add(RealmHosts, clientHost + ", " + serverHost)
  514. .add(RealmLocalAction, "LOCAL").add(RealmEntryIsDynamic, false).add(RealmEntryExpTime, 1000L)));
  515. }
  516. }
  517. public void fireEvent(String sessionId, Message message) {
  518. // NO-OP
  519. }
  520. public void endActivity(DiameterActivityHandle activityHandle) {
  521. // NO-OP
  522. }
  523. public ApplicationId[] getSupportedApplications() {
  524. // NO-OP
  525. return null;
  526. }
  527. public void update(DiameterActivityHandle activityHandle, DiameterActivity da) {
  528. // NO-OP
  529. }
  530. public void startActivityRemoveTimer(DiameterActivityHandle handle) {
  531. // NO-OP
  532. }
  533. public void stopActivityRemoveTimer(DiameterActivityHandle handle) {
  534. // NO-OP
  535. }
  536. }