PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 642 lines | 396 code | 149 blank | 97 comment | 32 complexity | c207d4b12be14fbfe61f3610bad7fd24 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. package org.mobicents.slee.resources.diameter.tests.factories;
  2. import static org.jdiameter.client.impl.helpers.Parameters.AcctApplId;
  3. import static org.jdiameter.client.impl.helpers.Parameters.ApplicationId;
  4. import static org.jdiameter.client.impl.helpers.Parameters.Assembler;
  5. import static org.jdiameter.client.impl.helpers.Parameters.AuthApplId;
  6. import static org.jdiameter.client.impl.helpers.Parameters.OwnDiameterURI;
  7. import static org.jdiameter.client.impl.helpers.Parameters.OwnRealm;
  8. import static org.jdiameter.client.impl.helpers.Parameters.OwnVendorID;
  9. import static org.jdiameter.client.impl.helpers.Parameters.PeerName;
  10. import static org.jdiameter.client.impl.helpers.Parameters.PeerRating;
  11. import static org.jdiameter.client.impl.helpers.Parameters.PeerTable;
  12. import static org.jdiameter.client.impl.helpers.Parameters.RealmEntry;
  13. import static org.jdiameter.client.impl.helpers.Parameters.RealmTable;
  14. import static org.jdiameter.client.impl.helpers.Parameters.VendorId;
  15. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryExpTime;
  16. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryIsDynamic;
  17. import static org.jdiameter.server.impl.helpers.Parameters.RealmHosts;
  18. import static org.jdiameter.server.impl.helpers.Parameters.RealmLocalAction;
  19. import static org.jdiameter.server.impl.helpers.Parameters.RealmName;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.junit.Assert.assertFalse;
  22. import static org.junit.Assert.assertNull;
  23. import static org.junit.Assert.assertTrue;
  24. import static org.mobicents.slee.resources.diameter.tests.factories.BaseFactoriesTest.checkCorrectApplicationIdAVPs;
  25. import net.java.slee.resource.diameter.base.events.avp.AuthSessionStateType;
  26. import net.java.slee.resource.diameter.sh.client.ShClientMessageFactory;
  27. import net.java.slee.resource.diameter.sh.events.ProfileUpdateRequest;
  28. import net.java.slee.resource.diameter.sh.events.PushNotificationAnswer;
  29. import net.java.slee.resource.diameter.sh.events.PushNotificationRequest;
  30. import net.java.slee.resource.diameter.sh.events.SubscribeNotificationsRequest;
  31. import net.java.slee.resource.diameter.sh.events.UserDataRequest;
  32. import net.java.slee.resource.diameter.sh.events.avp.DataReferenceType;
  33. import net.java.slee.resource.diameter.sh.events.avp.DiameterShAvpCodes;
  34. import net.java.slee.resource.diameter.sh.events.avp.SubsReqType;
  35. import net.java.slee.resource.diameter.sh.events.avp.SupportedApplicationsAvp;
  36. import net.java.slee.resource.diameter.sh.events.avp.SupportedFeaturesAvp;
  37. import net.java.slee.resource.diameter.sh.events.avp.UserIdentityAvp;
  38. import org.jdiameter.api.ApplicationId;
  39. import org.jdiameter.api.Session;
  40. import org.jdiameter.api.Stack;
  41. import org.jdiameter.api.sh.ClientShSession;
  42. import org.jdiameter.client.impl.app.sh.ShClientSessionImpl;
  43. import org.jdiameter.client.impl.helpers.EmptyConfiguration;
  44. import org.jdiameter.common.impl.app.sh.ShSessionFactoryImpl;
  45. import org.junit.Assert;
  46. import org.junit.Test;
  47. import org.mobicents.diameter.dictionary.AvpDictionary;
  48. import org.mobicents.slee.resource.diameter.base.DiameterAvpFactoryImpl;
  49. import org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl;
  50. import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl;
  51. import org.mobicents.slee.resource.diameter.sh.DiameterShAvpFactoryImpl;
  52. import org.mobicents.slee.resource.diameter.sh.client.ShClientMessageFactoryImpl;
  53. import org.mobicents.slee.resource.diameter.sh.client.ShClientSubscriptionActivityImpl;
  54. import org.mobicents.slee.resource.diameter.sh.events.avp.UserIdentityAvpImpl;
  55. import org.mobicents.slee.resource.diameter.sh.server.ShServerMessageFactoryImpl;
  56. /**
  57. *
  58. * ShClientFactoriesTest.java
  59. *
  60. * <br>
  61. * Project: mobicents <br>
  62. * 6:39:33 PM Feb 27, 2009 <br>
  63. *
  64. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  65. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  66. */
  67. public class ShClientFactoriesTest {
  68. private static String clientHost = "127.0.0.1";
  69. private static String clientPort = "13868";
  70. private static String clientURI = "aaa://" + clientHost + ":" + clientPort;
  71. private static String serverHost = "localhost";
  72. private static String serverPort = "3868";
  73. private static String serverURI = "aaa://" + serverHost + ":" + serverPort;
  74. private static String realmName = "mobicents.org";
  75. private static ShClientMessageFactoryImpl shClientFactory;
  76. private static ShServerMessageFactoryImpl shServerFactory;
  77. private static DiameterShAvpFactoryImpl shAvpFactory;
  78. private static Stack stack;
  79. //private static ShServerActivityImpl serverSession;
  80. //private static ShClientActivityImpl clientSession;
  81. private static ShClientSubscriptionActivityImpl clientSubsSession;
  82. static {
  83. stack = new org.jdiameter.client.impl.StackImpl();
  84. try {
  85. stack.init(new MyConfiguration());
  86. AvpDictionary.INSTANCE.parseDictionary(ShClientFactoriesTest.class.getClassLoader().getResourceAsStream("dictionary.xml"));
  87. }
  88. catch (Exception e) {
  89. throw new RuntimeException("Failed to initialize the stack.");
  90. }
  91. DiameterMessageFactoryImpl baseMessageFactory = new DiameterMessageFactoryImpl(stack);
  92. Session session = null;
  93. ShSessionFactoryImpl sf = null;
  94. try {
  95. session = stack.getSessionFactory().getNewSession();
  96. sf = new ShSessionFactoryImpl(stack.getSessionFactory());
  97. }
  98. catch (Exception e) {
  99. // let's go with null
  100. e.printStackTrace();
  101. }
  102. shAvpFactory = new DiameterShAvpFactoryImpl(new DiameterAvpFactoryImpl());
  103. shClientFactory = new ShClientMessageFactoryImpl(stack);
  104. shServerFactory = new ShServerMessageFactoryImpl(baseMessageFactory, session, stack, shAvpFactory);
  105. ApplicationId shAppId = org.jdiameter.api.ApplicationId.createByAuthAppId(ShClientMessageFactory._SH_VENDOR_ID, ShClientMessageFactory._SH_APP_ID);
  106. //ShServerSessionImpl stackServerSession = (ShServerSessionImpl) sf.getNewSession("123", ServerShSession.class, shAppId, new Object[0]);
  107. //serverSession = new ShServerActivityImpl(shServerFactory, shAvpFactory, stackServerSession, null, null);
  108. ShClientSessionImpl stackClientSession = (ShClientSessionImpl) sf.getNewSession("321", ClientShSession.class, shAppId, new Object[0]);
  109. //clientSession = new ShClientActivityImpl(shClientFactory, shAvpFactory, stackClientSession, null, null);
  110. clientSubsSession = new ShClientSubscriptionActivityImpl(shClientFactory, shAvpFactory, stackClientSession, null, null);
  111. }
  112. @Test
  113. public void isRequestPUR() throws Exception {
  114. ProfileUpdateRequest pur = shClientFactory.createProfileUpdateRequest();
  115. assertTrue("Request Flag in Profile-Update-Request is not set.", pur.getHeader().isRequest());
  116. }
  117. @Test
  118. public void isProxiablePUR() throws Exception {
  119. ProfileUpdateRequest pur = shClientFactory.createProfileUpdateRequest();
  120. assertTrue("The 'P' bit is not set by default in Profile-Update-Request, it should.", pur.getHeader().isProxiable());
  121. }
  122. @Test
  123. public void testGettersAndSettersPUR() throws Exception {
  124. ProfileUpdateRequest pur = shClientFactory.createProfileUpdateRequest();
  125. int nFailures = AvpAssistant.testMethods(pur, ProfileUpdateRequest.class);
  126. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  127. }
  128. @Test
  129. public void isAnswerPNA() throws Exception {
  130. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest());
  131. assertFalse("Request Flag in Push-Notification-Answer is set.", pna.getHeader().isRequest());
  132. }
  133. @Test
  134. public void isProxiableCopiedPNA() throws Exception {
  135. PushNotificationRequest pnr = shServerFactory.createPushNotificationRequest();
  136. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(pnr);
  137. assertEquals("The 'P' bit is not copied from request in Push-Notification-Answer, it should. [RFC3588/6.2]", pnr.getHeader().isProxiable(), pna.getHeader().isProxiable());
  138. // Reverse 'P' bit ...
  139. ((DiameterMessageImpl) pnr).getGenericData().setProxiable(!pnr.getHeader().isProxiable());
  140. assertTrue("The 'P' bit was not modified in Push-Notification-Request, it should.", pnr.getHeader().isProxiable() != pna.getHeader().isProxiable());
  141. pna = shClientFactory.createPushNotificationAnswer(pnr);
  142. assertEquals("The 'P' bit is not copied from request in Push-Notification-Answer, it should. [RFC3588/6.2]", pnr.getHeader().isProxiable(), pna.getHeader().isProxiable());
  143. }
  144. @Test
  145. public void hasTFlagSetPNA() throws Exception {
  146. PushNotificationRequest pnr = shServerFactory.createPushNotificationRequest();
  147. ((DiameterMessageImpl) pnr).getGenericData().setReTransmitted(true);
  148. assertTrue("The 'T' flag should be set in Push-Notification-Request", pnr.getHeader().isPotentiallyRetransmitted());
  149. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(pnr);
  150. assertFalse("The 'T' flag should not be set in Push-Notification-Answer", pna.getHeader().isPotentiallyRetransmitted());
  151. }
  152. @Test
  153. public void testGettersAndSettersPNA() throws Exception {
  154. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest());
  155. int nFailures = AvpAssistant.testMethods(pna, PushNotificationAnswer.class);
  156. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  157. }
  158. @Test
  159. public void hasDestinationHostPNA() throws Exception {
  160. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest());
  161. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", pna.getDestinationHost());
  162. }
  163. @Test
  164. public void hasDestinationRealmPNA() throws Exception {
  165. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest());
  166. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", pna.getDestinationRealm());
  167. }
  168. /**
  169. * Test for Issue #665 (Diameter Experimental Result AVP is Nested) http://code.google.com/p/mobicents/issues/detail?id=655
  170. *
  171. * @throws Exception
  172. */
  173. @Test
  174. public void isExperimentalResultCorrectlySetPNA() throws Exception {
  175. long originalValue = 5001;
  176. PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest(), originalValue, true);
  177. long obtainedValue = pna.getExperimentalResult().getExperimentalResultCode();
  178. assertTrue("Experimental-Result-Code in PNA should be " + originalValue + " and is " + obtainedValue + ".", originalValue == obtainedValue);
  179. }
  180. @Test
  181. public void isRequestSNR() throws Exception {
  182. SubscribeNotificationsRequest snr = shClientFactory.createSubscribeNotificationsRequest();
  183. assertTrue("Request Flag in Subscribe-Notifications-Request is not set.", snr.getHeader().isRequest());
  184. }
  185. @Test
  186. public void isProxiableSNR() throws Exception {
  187. SubscribeNotificationsRequest snr = shClientFactory.createSubscribeNotificationsRequest();
  188. assertTrue("The 'P' bit is not set by default in Subscribe-Notifications-Request, it should.", snr.getHeader().isProxiable());
  189. }
  190. @Test
  191. public void testGettersAndSettersSNR() throws Exception {
  192. SubscribeNotificationsRequest snr = shClientFactory.createSubscribeNotificationsRequest();
  193. int nFailures = AvpAssistant.testMethods(snr, SubscribeNotificationsRequest.class);
  194. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  195. }
  196. @Test
  197. public void isRequestUDR() throws Exception {
  198. UserDataRequest udr = shClientFactory.createUserDataRequest();
  199. assertTrue("Request Flag in User-Data-Request is not set.", udr.getHeader().isRequest());
  200. }
  201. @Test
  202. public void isProxiableUDR() throws Exception {
  203. UserDataRequest udr = shClientFactory.createUserDataRequest();
  204. assertTrue("The 'P' bit is not set by default in User-Data-Request, it should.", udr.getHeader().isProxiable());
  205. }
  206. @Test
  207. public void testGettersAndSettersUDR() throws Exception {
  208. UserDataRequest udr = shClientFactory.createUserDataRequest();
  209. int nFailures = AvpAssistant.testMethods(udr, UserDataRequest.class);
  210. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  211. }
  212. @Test
  213. public void isUDRPublicIdentityAccessibleTwice() throws Exception {
  214. String originalValue = "sip:alexandre@diameter.mobicents.org";
  215. UserIdentityAvpImpl uiAvp = new UserIdentityAvpImpl(DiameterShAvpCodes.USER_IDENTITY, 10415L, 1, 0, new byte[] {});
  216. uiAvp.setPublicIdentity(originalValue);
  217. UserDataRequest udr = shClientFactory.createUserDataRequest(uiAvp, DataReferenceType.IMS_PUBLIC_IDENTITY);
  218. String obtainedValue1 = udr.getUserIdentity().getPublicIdentity();
  219. String obtainedValue2 = udr.getUserIdentity().getPublicIdentity();
  220. assertTrue("Obtained value for Public-Identity AVP differs from original.", obtainedValue1.equals(originalValue));
  221. assertTrue("Obtained #1 value for Public-Identity AVP differs from Obtained #2.", obtainedValue1.equals(obtainedValue2));
  222. }
  223. @Test
  224. public void isPURPublicIdentityAccessibleTwice() throws Exception {
  225. String originalValue = "sip:alexandre@diameter.mobicents.org";
  226. UserIdentityAvpImpl uiAvp = new UserIdentityAvpImpl(DiameterShAvpCodes.USER_IDENTITY, 10415L, 1, 0, new byte[] {});
  227. uiAvp.setPublicIdentity(originalValue);
  228. ProfileUpdateRequest udr = shClientFactory.createProfileUpdateRequest(uiAvp, DataReferenceType.IMS_PUBLIC_IDENTITY, new byte[1]);
  229. String obtainedValue1 = udr.getUserIdentity().getPublicIdentity();
  230. String obtainedValue2 = udr.getUserIdentity().getPublicIdentity();
  231. assertTrue("Obtained value for Public-Identity AVP differs from original.", obtainedValue1.equals(originalValue));
  232. assertTrue("Obtained #1 value for Public-Identity AVP differs from Obtained #2.", obtainedValue1.equals(obtainedValue2));
  233. }
  234. @Test
  235. public void isSNRPublicIdentityAccessibleTwice() throws Exception {
  236. String originalValue = "sip:alexandre@diameter.mobicents.org";
  237. UserIdentityAvpImpl uiAvp = new UserIdentityAvpImpl(DiameterShAvpCodes.USER_IDENTITY, 10415L, 1, 0, new byte[] {});
  238. uiAvp.setPublicIdentity(originalValue);
  239. SubscribeNotificationsRequest udr = shClientFactory.createSubscribeNotificationsRequest(uiAvp, DataReferenceType.IMS_PUBLIC_IDENTITY, SubsReqType.SUBSCRIBE);
  240. String obtainedValue1 = udr.getUserIdentity().getPublicIdentity();
  241. String obtainedValue2 = udr.getUserIdentity().getPublicIdentity();
  242. assertTrue("Obtained value for Public-Identity AVP differs from original.", obtainedValue1.equals(originalValue));
  243. assertTrue("Obtained #1 value for Public-Identity AVP differs from Obtained #2.", obtainedValue1.equals(obtainedValue2));
  244. }
  245. // AVP Factory Testing
  246. @Test
  247. public void testAvpFactoryCreateSupportedApplications() throws Exception {
  248. String avpName = "Supported-Applications";
  249. // Create AVP with mandatory values
  250. SupportedApplicationsAvp saAvp1 = shAvpFactory.createSupportedApplications(123L, 456L, shAvpFactory.getBaseFactory().createVendorSpecificApplicationId(999L));
  251. // Make sure it's not null
  252. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", saAvp1);
  253. // Create AVP with default constructor
  254. SupportedApplicationsAvp saAvp2 = shAvpFactory.createSupportedApplications();
  255. // Should not contain mandatory values
  256. // Set mandatory values
  257. saAvp2.setAuthApplicationId(123L);
  258. saAvp2.setAcctApplicationId(456L);
  259. saAvp2.setVendorSpecificApplicationId(shAvpFactory.getBaseFactory().createVendorSpecificApplicationId(999L));
  260. // Make sure it's equal to the one created with mandatory values constructor
  261. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", saAvp1, saAvp2);
  262. // Make new copy
  263. saAvp2 = shAvpFactory.createSupportedApplications();
  264. // And set all values using setters
  265. AvpAssistant.testSetters(saAvp2);
  266. // Create empty...
  267. SupportedApplicationsAvp saAvp3 = shAvpFactory.createSupportedApplications();
  268. // Verify that no values have been set
  269. AvpAssistant.testHassers(saAvp3, false);
  270. // Set all previous values
  271. saAvp3.setExtensionAvps(saAvp2.getExtensionAvps());
  272. // Verify if values have been set
  273. AvpAssistant.testHassers(saAvp3, true);
  274. // Verify if values have been correctly set
  275. AvpAssistant.testGetters(saAvp3);
  276. // Make sure they match!
  277. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setUnitValue should be equal to original.", saAvp2, saAvp3);
  278. }
  279. @Test
  280. public void testAvpFactoryCreateSupportedFeatures() throws Exception {
  281. String avpName = "Supported-Features";
  282. // Create AVP with mandatory values
  283. SupportedFeaturesAvp sfAvp1 = shAvpFactory.createSupportedFeatures(123L, 456L, 789L);
  284. // Make sure it's not null
  285. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", sfAvp1);
  286. // Create AVP with default constructor
  287. SupportedFeaturesAvp sfAvp2 = shAvpFactory.createSupportedFeatures();
  288. // Should not contain mandatory values
  289. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Vendor-Id AVP.", sfAvp2.hasVendorId());
  290. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Feature-List-Id AVP.", sfAvp2.hasFeatureListId());
  291. Assert.assertFalse("Created " + avpName + " AVP from default constructor should not have Feature-List AVP.", sfAvp2.hasFeatureList());
  292. // Set mandatory values
  293. sfAvp2.setVendorId(123L);
  294. sfAvp2.setFeatureListId(456L);
  295. sfAvp2.setFeatureList(789L);
  296. // Make sure it's equal to the one created with mandatory values constructor
  297. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", sfAvp1, sfAvp2);
  298. // Make new copy
  299. sfAvp2 = shAvpFactory.createSupportedFeatures();
  300. // And set all values using setters
  301. AvpAssistant.testSetters(sfAvp2);
  302. // Create empty...
  303. SupportedFeaturesAvp sfAvp3 = shAvpFactory.createSupportedFeatures();
  304. // Verify that no values have been set
  305. AvpAssistant.testHassers(sfAvp3, false);
  306. // Set all previous values
  307. sfAvp3.setExtensionAvps(sfAvp2.getExtensionAvps());
  308. // Verify if values have been set
  309. AvpAssistant.testHassers(sfAvp3, true);
  310. // Verify if values have been correctly set
  311. AvpAssistant.testGetters(sfAvp3);
  312. // Make sure they match!
  313. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", sfAvp2, sfAvp3);
  314. }
  315. @Test
  316. public void testAvpFactoryCreateUserIdentity() throws Exception {
  317. String avpName = "User-Identity";
  318. // Create AVP with mandatory values
  319. UserIdentityAvp uiAvp1 = shAvpFactory.createUserIdentity();
  320. // Make sure it's not null
  321. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", uiAvp1);
  322. // Create AVP with default constructor
  323. UserIdentityAvp uiAvp2 = shAvpFactory.createUserIdentity();
  324. // Should not contain mandatory values
  325. // Set mandatory values
  326. // Make sure it's equal to the one created with mandatory values constructor
  327. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", uiAvp1, uiAvp2);
  328. // Make new copy
  329. uiAvp2 = shAvpFactory.createUserIdentity();
  330. // And set all values using setters
  331. AvpAssistant.testSetters(uiAvp2);
  332. // Create empty...
  333. UserIdentityAvp uiAvp3 = shAvpFactory.createUserIdentity();
  334. // Verify that no values have been set
  335. AvpAssistant.testHassers(uiAvp3, false);
  336. // Set all previous values
  337. uiAvp3.setExtensionAvps(uiAvp2.getExtensionAvps());
  338. // Verify if values have been set
  339. AvpAssistant.testHassers(uiAvp3, true);
  340. // Verify if values have been correctly set
  341. AvpAssistant.testGetters(uiAvp3);
  342. // Make sure they match!
  343. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", uiAvp2, uiAvp3);
  344. }
  345. @Test
  346. public void testMessageFactoryApplicationIdChangePUR() throws Exception {
  347. long vendor = 10415L;
  348. ApplicationId originalAppId = ((ShClientMessageFactoryImpl)shClientFactory).getApplicationId();
  349. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  350. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  351. boolean isVendor = originalAppId.getVendorId() != 0L;
  352. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  353. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  354. // let's create a message and see how it comes...
  355. ProfileUpdateRequest originalPUR = shClientFactory.createProfileUpdateRequest();
  356. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPUR);
  357. // now we switch..
  358. originalPUR = null;
  359. isVendor = !isVendor;
  360. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  361. // create a new message and see how it comes...
  362. ProfileUpdateRequest changedPUR = shClientFactory.createProfileUpdateRequest();
  363. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPUR);
  364. // revert back to default
  365. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  366. }
  367. @Test
  368. public void testMessageFactoryApplicationIdChangePNA() throws Exception {
  369. long vendor = 10415L;
  370. ApplicationId originalAppId = ((ShClientMessageFactoryImpl)shClientFactory).getApplicationId();
  371. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  372. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  373. boolean isVendor = originalAppId.getVendorId() != 0L;
  374. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  375. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  376. // let's create a message and see how it comes...
  377. PushNotificationAnswer originalPNA = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest());
  378. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPNA);
  379. // now we switch..
  380. originalPNA = null;
  381. isVendor = !isVendor;
  382. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  383. // create a new message and see how it comes...
  384. PushNotificationAnswer changedPNA = shClientFactory.createPushNotificationAnswer(shServerFactory.createPushNotificationRequest());
  385. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPNA);
  386. // revert back to default
  387. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  388. }
  389. @Test
  390. public void testClientSessionApplicationIdChangePNA() throws Exception {
  391. long vendor = 10415L;
  392. ApplicationId originalAppId = ((ShClientMessageFactoryImpl)shClientFactory).getApplicationId();
  393. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  394. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  395. boolean isVendor = originalAppId.getVendorId() != 0L;
  396. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  397. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  398. // let's create a message and see how it comes...
  399. PushNotificationRequest pnr = shServerFactory.createPushNotificationRequest();
  400. UserIdentityAvp uiAvp = shAvpFactory.createUserIdentity();
  401. uiAvp.setPublicIdentity("alexandre@mobicents.org");
  402. pnr.setUserIdentity(uiAvp);
  403. pnr.setAuthSessionState(AuthSessionStateType.NO_STATE_MAINTAINED);
  404. clientSubsSession.fetchSessionData(pnr, true);
  405. PushNotificationAnswer originalPNA = clientSubsSession.createPushNotificationAnswer();
  406. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPNA);
  407. // now we switch..
  408. originalPNA = null;
  409. isVendor = !isVendor;
  410. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  411. // create a new message and see how it comes...
  412. PushNotificationAnswer changedPNA = clientSubsSession.createPushNotificationAnswer();
  413. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPNA);
  414. // revert back to default
  415. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  416. }
  417. @Test
  418. public void testMessageFactoryApplicationIdChangeSNR() throws Exception {
  419. long vendor = 10415L;
  420. ApplicationId originalAppId = ((ShClientMessageFactoryImpl)shClientFactory).getApplicationId();
  421. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  422. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  423. boolean isVendor = originalAppId.getVendorId() != 0L;
  424. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  425. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  426. // let's create a message and see how it comes...
  427. SubscribeNotificationsRequest originalSNR = shClientFactory.createSubscribeNotificationsRequest();
  428. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalSNR);
  429. // now we switch..
  430. originalSNR = null;
  431. isVendor = !isVendor;
  432. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  433. // create a new message and see how it comes...
  434. SubscribeNotificationsRequest changedSNR = shClientFactory.createSubscribeNotificationsRequest();
  435. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedSNR);
  436. // revert back to default
  437. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  438. }
  439. @Test
  440. public void testMessageFactoryApplicationIdChangeUDR() throws Exception {
  441. long vendor = 10415L;
  442. ApplicationId originalAppId = ((ShClientMessageFactoryImpl)shClientFactory).getApplicationId();
  443. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  444. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  445. boolean isVendor = originalAppId.getVendorId() != 0L;
  446. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  447. System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
  448. // let's create a message and see how it comes...
  449. UserDataRequest originalUDR = shClientFactory.createUserDataRequest();
  450. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalUDR);
  451. // now we switch..
  452. originalUDR = null;
  453. isVendor = !isVendor;
  454. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  455. // create a new message and see how it comes...
  456. UserDataRequest changedUDR = shClientFactory.createUserDataRequest();
  457. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedUDR);
  458. // revert back to default
  459. ((ShClientMessageFactoryImpl)shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  460. }
  461. /**
  462. * Class representing the Diameter Configuration
  463. */
  464. public static class MyConfiguration extends EmptyConfiguration {
  465. public MyConfiguration() {
  466. super();
  467. add(Assembler, Assembler.defValue());
  468. add(OwnDiameterURI, clientURI);
  469. add(OwnRealm, realmName);
  470. add(OwnVendorID, 193L);
  471. // Set Ericsson SDK feature
  472. // add(UseUriAsFqdn, true);
  473. // Set Common Applications
  474. add(org.jdiameter.client.impl.helpers.Parameters.ApplicationId,
  475. // AppId 1
  476. getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L));
  477. // Set peer table
  478. add(PeerTable,
  479. // Peer 1
  480. getInstance().add(PeerRating, 1).add(PeerName, serverURI));
  481. // Set realm table
  482. add(RealmTable,
  483. // Realm 1
  484. getInstance().add(RealmEntry, getInstance().
  485. add(RealmName, realmName).
  486. add(ApplicationId, getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L)).
  487. add(RealmHosts, clientHost + ", " + serverHost).
  488. add(RealmLocalAction, "LOCAL").
  489. add(RealmEntryIsDynamic, false).
  490. add(RealmEntryExpTime, 1000L)));
  491. }
  492. }
  493. }