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

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

http://mobicents.googlecode.com/
Java | 581 lines | 399 code | 113 blank | 69 comment | 36 complexity | 0d15442842cff836ba50caf419eaa725 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 2010, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.slee.resources.diameter.tests.factories;
  23. import static org.jdiameter.client.impl.helpers.Parameters.AcctApplId;
  24. import static org.jdiameter.client.impl.helpers.Parameters.ApplicationId;
  25. import static org.jdiameter.client.impl.helpers.Parameters.Assembler;
  26. import static org.jdiameter.client.impl.helpers.Parameters.AuthApplId;
  27. import static org.jdiameter.client.impl.helpers.Parameters.OwnDiameterURI;
  28. import static org.jdiameter.client.impl.helpers.Parameters.OwnRealm;
  29. import static org.jdiameter.client.impl.helpers.Parameters.OwnVendorID;
  30. import static org.jdiameter.client.impl.helpers.Parameters.PeerName;
  31. import static org.jdiameter.client.impl.helpers.Parameters.PeerRating;
  32. import static org.jdiameter.client.impl.helpers.Parameters.PeerTable;
  33. import static org.jdiameter.client.impl.helpers.Parameters.RealmEntry;
  34. import static org.jdiameter.client.impl.helpers.Parameters.RealmTable;
  35. import static org.jdiameter.client.impl.helpers.Parameters.VendorId;
  36. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryExpTime;
  37. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryIsDynamic;
  38. import static org.jdiameter.server.impl.helpers.Parameters.RealmHosts;
  39. import static org.jdiameter.server.impl.helpers.Parameters.RealmLocalAction;
  40. import static org.jdiameter.server.impl.helpers.Parameters.RealmName;
  41. import static org.junit.Assert.*;
  42. import static org.mobicents.slee.resources.diameter.tests.factories.BaseFactoriesTest.*;
  43. import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity;
  44. import net.java.slee.resource.diameter.cca.events.avp.CcRequestType;
  45. import net.java.slee.resource.diameter.gx.GxAvpFactory;
  46. import net.java.slee.resource.diameter.gx.GxClientSessionActivity;
  47. import net.java.slee.resource.diameter.gx.GxMessageFactory;
  48. import net.java.slee.resource.diameter.gx.GxServerSessionActivity;
  49. import net.java.slee.resource.diameter.gx.events.GxCreditControlAnswer;
  50. import net.java.slee.resource.diameter.gx.events.GxCreditControlRequest;
  51. import net.java.slee.resource.diameter.gx.events.GxReAuthAnswer;
  52. import net.java.slee.resource.diameter.gx.events.GxReAuthRequest;
  53. import org.jdiameter.api.Answer;
  54. import org.jdiameter.api.ApplicationId;
  55. import org.jdiameter.api.IllegalDiameterStateException;
  56. import org.jdiameter.api.InternalException;
  57. import org.jdiameter.api.OverloadException;
  58. import org.jdiameter.api.Request;
  59. import org.jdiameter.api.RouteException;
  60. import org.jdiameter.api.Stack;
  61. import org.jdiameter.api.app.AppAnswerEvent;
  62. import org.jdiameter.api.app.AppRequestEvent;
  63. import org.jdiameter.api.app.AppSession;
  64. import org.jdiameter.api.gx.ClientGxSession;
  65. import org.jdiameter.api.gx.ClientGxSessionListener;
  66. import org.jdiameter.api.gx.ServerGxSession;
  67. import org.jdiameter.api.gx.ServerGxSessionListener;
  68. import org.jdiameter.client.api.ISessionFactory;
  69. import org.jdiameter.client.impl.app.gx.ClientGxSessionDataLocalImpl;
  70. import org.jdiameter.client.impl.app.gx.ClientGxSessionImpl;
  71. import org.jdiameter.client.impl.helpers.EmptyConfiguration;
  72. import org.jdiameter.common.api.app.gx.IGxMessageFactory;
  73. import org.jdiameter.server.impl.app.gx.ServerGxSessionDataLocalImpl;
  74. import org.jdiameter.server.impl.app.gx.ServerGxSessionImpl;
  75. import org.junit.Test;
  76. import org.mobicents.diameter.dictionary.AvpDictionary;
  77. import org.mobicents.slee.resource.diameter.base.DiameterAvpFactoryImpl;
  78. import org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl;
  79. import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl;
  80. import org.mobicents.slee.resource.diameter.gx.GxAvpFactoryImpl;
  81. import org.mobicents.slee.resource.diameter.gx.GxClientSessionActivityImpl;
  82. import org.mobicents.slee.resource.diameter.gx.GxMessageFactoryImpl;
  83. import org.mobicents.slee.resource.diameter.gx.GxServerSessionActivityImpl;
  84. /**
  85. * Test class for JAIN SLEE Diameter Gx RA Message and AVP Factories
  86. *
  87. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  88. */
  89. public class GxFactoriesTest implements IGxMessageFactory, ServerGxSessionListener, ClientGxSessionListener {
  90. private static String clientHost = "127.0.0.1";
  91. private static String clientPort = "13868";
  92. private static String clientURI = "aaa://" + clientHost + ":" + clientPort;
  93. private static String serverHost = "localhost";
  94. private static String serverPort = "3868";
  95. private static String serverURI = "aaa://" + serverHost + ":" + serverPort;
  96. private static String realmName = "mobicents.org";
  97. private static GxMessageFactory gxMessageFactory;
  98. private static GxAvpFactory gxAvpFactory;
  99. private static Stack stack;
  100. private static ServerGxSession serverSession;
  101. private static ClientGxSession clientSession;
  102. static
  103. {
  104. stack = new org.jdiameter.client.impl.StackImpl();
  105. try {
  106. stack.init(new MyConfiguration());
  107. }
  108. catch (Exception e) {
  109. throw new RuntimeException("Failed to initialize the stack.");
  110. }
  111. DiameterMessageFactoryImpl baseFactory = new DiameterMessageFactoryImpl(stack);
  112. DiameterAvpFactoryImpl baseAvpFactory = new DiameterAvpFactoryImpl();
  113. gxAvpFactory = new GxAvpFactoryImpl(baseAvpFactory);
  114. try {
  115. gxMessageFactory = new GxMessageFactoryImpl(baseFactory, stack.getSessionFactory().getNewSession().getSessionId(), stack);
  116. // Gx: Vendor-Specific-Application-Id is not permitted, only Auth-Application-Id;
  117. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(0L, 16777224L);
  118. }
  119. catch (Exception e) {
  120. e.printStackTrace();
  121. }
  122. try {
  123. AvpDictionary.INSTANCE.parseDictionary(GxFactoriesTest.class.getClassLoader().getResourceAsStream("dictionary.xml"));
  124. }
  125. catch (Exception e) {
  126. throw new RuntimeException("Failed to parse dictionary file.");
  127. }
  128. }
  129. private GxServerSessionActivity gxServerSession = null;
  130. private GxClientSessionActivity gxClientSession = null;
  131. public GxFactoriesTest() {
  132. try {
  133. serverSession = new ServerGxSessionImpl(new ServerGxSessionDataLocalImpl(), this, (ISessionFactory) stack.getSessionFactory(), this, null, null);
  134. clientSession = new ClientGxSessionImpl(new ClientGxSessionDataLocalImpl(), this, (ISessionFactory) stack.getSessionFactory(), this, null, null);
  135. gxServerSession = new GxServerSessionActivityImpl(gxMessageFactory, gxAvpFactory, serverSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack);
  136. gxClientSession = new GxClientSessionActivityImpl(gxMessageFactory, gxAvpFactory, clientSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack);
  137. ((GxServerSessionActivityImpl)gxServerSession).fetchCurrentState(gxMessageFactory.createGxCreditControlRequest());
  138. }
  139. catch (IllegalDiameterStateException e) {
  140. throw new RuntimeException("Failed to parse dictionary file.");
  141. }
  142. }
  143. @Test
  144. public void isRequestCCR() throws Exception {
  145. GxCreditControlRequest ccr = gxMessageFactory.createGxCreditControlRequest();
  146. assertTrue("Request Flag in Credit-Control-Request is not set.", ccr.getHeader().isRequest());
  147. }
  148. @Test
  149. public void testGettersAndSettersCCR() throws Exception {
  150. GxCreditControlRequest ccr = gxMessageFactory.createGxCreditControlRequest();
  151. int nFailures = AvpAssistant.testMethods(ccr, GxCreditControlRequest.class);
  152. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  153. }
  154. @Test
  155. public void isProxiableCCR() throws Exception {
  156. GxCreditControlRequest ccr = gxMessageFactory.createGxCreditControlRequest();
  157. assertTrue("The 'P' bit is not set by default in Gx Credit-Control-Request, it should.", ccr.getHeader().isProxiable());
  158. }
  159. @Test
  160. public void GxApplicationIdCCR() throws Exception {
  161. GxCreditControlRequest ccr = gxMessageFactory.createGxCreditControlRequest();
  162. assertTrue("Auth-Application-Id AVP in Gx CCR must be 16777224, it is " + ccr.getAuthApplicationId(), ccr.getAuthApplicationId() == 16777224);
  163. }
  164. @Test
  165. public void isAnswerCCA() throws Exception {
  166. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  167. assertFalse("Request Flag in Credit-Control-Answer is set.", cca.getHeader().isRequest());
  168. }
  169. @Test
  170. public void isProxiableCopiedCCA() throws Exception {
  171. GxCreditControlRequest ccr = gxMessageFactory.createGxCreditControlRequest();
  172. ((GxServerSessionActivityImpl)gxServerSession).fetchCurrentState(ccr);
  173. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  174. assertEquals("The 'P' bit is not copied from request in Credit-Control-Answer, it should. [RFC3588/6.2]", ccr.getHeader().isProxiable(), cca.getHeader().isProxiable());
  175. // Reverse 'P' bit ...
  176. ((DiameterMessageImpl) ccr).getGenericData().setProxiable(!ccr.getHeader().isProxiable());
  177. assertTrue("The 'P' bit was not modified in Credit-Control-Request, it should.", ccr.getHeader().isProxiable() != cca.getHeader().isProxiable());
  178. ((GxServerSessionActivityImpl)gxServerSession).fetchCurrentState(ccr);
  179. cca = gxServerSession.createGxCreditControlAnswer();
  180. assertEquals("The 'P' bit is not copied from request in Credit-Control-Answer, it should. [RFC3588/6.2]", ccr.getHeader().isProxiable(), cca.getHeader().isProxiable());
  181. }
  182. @Test
  183. public void hasTFlagSetCCA() throws Exception {
  184. GxCreditControlRequest ccr = gxMessageFactory.createGxCreditControlRequest();
  185. ((DiameterMessageImpl) ccr).getGenericData().setReTransmitted(true);
  186. assertTrue("The 'T' flag should be set in Credit-Control-Request", ccr.getHeader().isPotentiallyRetransmitted());
  187. ((GxServerSessionActivityImpl)gxServerSession).fetchCurrentState(ccr);
  188. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  189. assertFalse("The 'T' flag should not be set in Credit-Control-Answer", cca.getHeader().isPotentiallyRetransmitted());
  190. }
  191. @Test
  192. public void testGettersAndSettersCCA() throws Exception {
  193. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  194. int nFailures = AvpAssistant.testMethods(cca, GxCreditControlAnswer.class);
  195. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  196. }
  197. @Test
  198. public void hasGxApplicationIdCCA() throws Exception {
  199. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  200. assertTrue("Auth-Application-Id AVP in Gx CCA must be 16777224, it is " + cca.getAuthApplicationId(), cca.getAuthApplicationId() == 16777224);
  201. }
  202. @Test
  203. public void hasDestinationHostCCA() throws Exception {
  204. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  205. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", cca.getDestinationHost());
  206. }
  207. @Test
  208. public void hasDestinationRealmCCA() throws Exception {
  209. GxCreditControlAnswer cca = gxServerSession.createGxCreditControlAnswer();
  210. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", cca.getDestinationRealm());
  211. }
  212. @Test
  213. public void isRequestRAR() throws Exception {
  214. GxReAuthRequest rar = gxMessageFactory.createGxReAuthRequest();
  215. assertTrue("Request Flag in Gx Re-Auth-Request is not set.", rar.getHeader().isRequest());
  216. }
  217. @Test
  218. public void isProxiableRAR() throws Exception {
  219. GxReAuthRequest rar = gxMessageFactory.createGxReAuthRequest();
  220. assertTrue("The 'P' bit is not set by default in Re-Auth-Request, it should.", rar.getHeader().isProxiable());
  221. }
  222. @Test
  223. public void testGettersAndSettersRAR() throws Exception {
  224. GxReAuthRequest rar = gxMessageFactory.createGxReAuthRequest();
  225. int nFailures = AvpAssistant.testMethods(rar, GxReAuthRequest.class);
  226. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  227. }
  228. @Test
  229. public void hasGxApplicationIdRAR() throws Exception {
  230. GxReAuthRequest rar = gxMessageFactory.createGxReAuthRequest();
  231. assertTrue("Auth-Application-Id AVP in Gx RAR must be 16777224, it is " + rar.getAuthApplicationId(), rar.getAuthApplicationId() == 16777224);
  232. }
  233. @Test
  234. public void isAnswerRAA() throws Exception {
  235. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  236. assertFalse("Request Flag in Gx Re-Auth-Answer is set.", raa.getHeader().isRequest());
  237. }
  238. @Test
  239. public void isProxiableCopiedRAA() throws Exception {
  240. GxReAuthRequest rar = gxMessageFactory.createGxReAuthRequest();
  241. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(rar);
  242. assertEquals("The 'P' bit is not copied from request in Re-Auth-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  243. // Reverse 'P' bit ...
  244. ((DiameterMessageImpl) rar).getGenericData().setProxiable(!rar.getHeader().isProxiable());
  245. assertTrue("The 'P' bit was not modified in Re-Auth-Request, it should.", rar.getHeader().isProxiable() != raa.getHeader().isProxiable());
  246. raa = gxClientSession.createGxReAuthAnswer(rar);
  247. assertEquals("The 'P' bit is not copied from request in Re-Auth-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  248. }
  249. @Test
  250. public void hasTFlagSetRAA() throws Exception {
  251. GxReAuthRequest rar = gxMessageFactory.createGxReAuthRequest();
  252. ((DiameterMessageImpl) rar).getGenericData().setReTransmitted(true);
  253. assertTrue("The 'T' flag should be set in Re-Auth-Request", rar.getHeader().isPotentiallyRetransmitted());
  254. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(rar);
  255. assertFalse("The 'T' flag should not be set in Re-Auth-Answer", raa.getHeader().isPotentiallyRetransmitted());
  256. }
  257. @Test
  258. public void testGettersAndSettersRAA() throws Exception {
  259. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  260. int nFailures = AvpAssistant.testMethods(raa, GxReAuthAnswer.class);
  261. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  262. }
  263. @Test
  264. public void hasGxApplicationIdRAA() throws Exception {
  265. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  266. assertTrue("Auth-Application-Id AVP in Gx CCA must be 16777224, it is " + raa.getAuthApplicationId(), raa.getAuthApplicationId() == 16777224);
  267. }
  268. @Test
  269. public void hasDestinationHostRAA() throws Exception {
  270. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  271. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", raa.getDestinationHost());
  272. }
  273. @Test
  274. public void hasDestinationRealmRAA() throws Exception {
  275. GxReAuthAnswer raa = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  276. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", raa.getDestinationRealm());
  277. }
  278. @Test
  279. public void testMessageFactoryApplicationIdChangeCCR() throws Exception {
  280. long vendor = 10415L;
  281. ApplicationId originalAppId = ((GxMessageFactoryImpl)gxMessageFactory).getApplicationId();
  282. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  283. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  284. boolean isVendor = originalAppId.getVendorId() != 0L;
  285. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  286. System.out.println("Default VENDOR-ID for Gx is " + originalAppId.getVendorId());
  287. // let's create a message and see how it comes...
  288. GxCreditControlRequest originalCCR = gxMessageFactory.createGxCreditControlRequest();
  289. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalCCR);
  290. // now we switch..
  291. originalCCR = null;
  292. isVendor = !isVendor;
  293. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  294. // create a new message and see how it comes...
  295. GxCreditControlRequest changedCCR = gxMessageFactory.createGxCreditControlRequest();
  296. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedCCR);
  297. // revert back to default
  298. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  299. }
  300. @Test
  301. public void testMessageFactoryApplicationIdChangeRAR() throws Exception {
  302. long vendor = 10415L;
  303. ApplicationId originalAppId = ((GxMessageFactoryImpl)gxMessageFactory).getApplicationId();
  304. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  305. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  306. boolean isVendor = originalAppId.getVendorId() != 0L;
  307. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  308. System.out.println("Default VENDOR-ID for Gx is " + originalAppId.getVendorId());
  309. // let's create a message and see how it comes...
  310. GxReAuthRequest originalRAR = gxMessageFactory.createGxReAuthRequest();
  311. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalRAR);
  312. // now we switch..
  313. originalRAR = null;
  314. isVendor = !isVendor;
  315. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  316. // create a new message and see how it comes...
  317. GxCreditControlRequest changedRAR = gxMessageFactory.createGxCreditControlRequest();
  318. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedRAR);
  319. // revert back to default
  320. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  321. }
  322. @Test
  323. public void testMessageFactoryApplicationIdChangeInClientSessionCCR() throws Exception {
  324. long vendor = 10415L;
  325. ApplicationId originalAppId = ((GxMessageFactoryImpl)gxMessageFactory).getApplicationId();
  326. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  327. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  328. boolean isVendor = originalAppId.getVendorId() != 0L;
  329. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  330. System.out.println("Default VENDOR-ID for Gx is " + originalAppId.getVendorId());
  331. // let's create a message and see how it comes...
  332. GxCreditControlRequest originalCCR = gxClientSession.createGxCreditControlRequest(CcRequestType.EVENT_REQUEST);
  333. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalCCR);
  334. // now we switch..
  335. originalCCR = null;
  336. isVendor = !isVendor;
  337. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  338. // create a new message and see how it comes...
  339. GxCreditControlRequest changedCCR = gxClientSession.createGxCreditControlRequest(CcRequestType.EVENT_REQUEST);
  340. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedCCR);
  341. // revert back to default
  342. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  343. }
  344. @Test
  345. public void testMessageFactoryApplicationIdChangeInClientSessionRAA() throws Exception {
  346. long vendor = 10415L;
  347. ApplicationId originalAppId = ((GxMessageFactoryImpl)gxMessageFactory).getApplicationId();
  348. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  349. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  350. boolean isVendor = originalAppId.getVendorId() != 0L;
  351. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  352. System.out.println("Default VENDOR-ID for Gx is " + originalAppId.getVendorId());
  353. // let's create a message and see how it comes...
  354. GxReAuthAnswer originalRAA = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  355. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalRAA);
  356. // now we switch..
  357. originalRAA = null;
  358. isVendor = !isVendor;
  359. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  360. // create a new message and see how it comes...
  361. GxReAuthAnswer changedRAA = gxClientSession.createGxReAuthAnswer(gxMessageFactory.createGxReAuthRequest());
  362. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedRAA);
  363. // revert back to default
  364. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  365. }
  366. @Test
  367. public void testMessageFactoryApplicationIdChangeInServerSessionCCA() throws Exception {
  368. long vendor = 10415L;
  369. ApplicationId originalAppId = ((GxMessageFactoryImpl)gxMessageFactory).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 Gx is " + originalAppId.getVendorId());
  375. // let's create a message and see how it comes...
  376. GxCreditControlAnswer originalCCA = gxServerSession.createGxCreditControlAnswer();
  377. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalCCA);
  378. // now we switch..
  379. originalCCA = null;
  380. isVendor = !isVendor;
  381. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  382. // create a new message and see how it comes...
  383. GxCreditControlAnswer changedCCA = gxServerSession.createGxCreditControlAnswer();
  384. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedCCA);
  385. // revert back to default
  386. ((GxMessageFactoryImpl)gxMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  387. }
  388. /**
  389. * Class representing the Diameter Configuration
  390. */
  391. public static class MyConfiguration extends EmptyConfiguration {
  392. public MyConfiguration() {
  393. super();
  394. add(Assembler, Assembler.defValue());
  395. add(OwnDiameterURI, clientURI);
  396. add(OwnRealm, realmName);
  397. add(OwnVendorID, 193L);
  398. // Set Ericsson SDK feature
  399. //add(UseUriAsFqdn, true);
  400. // Set Common Applications
  401. add(ApplicationId,
  402. // AppId 1
  403. getInstance().
  404. add(VendorId, 193L).
  405. add(AuthApplId, 0L).
  406. add(AcctApplId, 19302L)
  407. );
  408. // Set peer table
  409. add(PeerTable,
  410. // Peer 1
  411. getInstance().
  412. add(PeerRating, 1).
  413. add(PeerName, serverURI));
  414. // Set realm table
  415. add(RealmTable,
  416. // Realm 1
  417. getInstance().add(RealmEntry, getInstance().
  418. add(RealmName, realmName).
  419. add(ApplicationId, getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L)).
  420. add(RealmHosts, clientHost + ", " + serverHost).
  421. add(RealmLocalAction, "LOCAL").
  422. add(RealmEntryIsDynamic, false).
  423. add(RealmEntryExpTime, 1000L)));
  424. }
  425. }
  426. public org.jdiameter.api.gx.events.GxReAuthAnswer createGxReAuthAnswer(Answer answer) {
  427. // TODO Auto-generated method stub
  428. return null;
  429. }
  430. public org.jdiameter.api.gx.events.GxReAuthRequest createGxReAuthRequest(Request req) {
  431. // TODO Auto-generated method stub
  432. return null;
  433. }
  434. public long[] getApplicationIds() {
  435. return new long[]{GxMessageFactory._GX_AUTH_APP_ID};
  436. }
  437. public void doOtherEvent(AppSession session, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  438. // NO-OP
  439. }
  440. public void doGxReAuthAnswer(ServerGxSession session, org.jdiameter.api.gx.events.GxReAuthRequest request, org.jdiameter.api.gx.events.GxReAuthAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  441. // NO-OP
  442. }
  443. public void doGxReAuthRequest(ClientGxSession session, org.jdiameter.api.gx.events.GxReAuthRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  444. // NO-OP
  445. }
  446. public void doCreditControlRequest(ServerGxSession session, org.jdiameter.api.gx.events.GxCreditControlRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  447. // NO-OP
  448. }
  449. public void doCreditControlAnswer(ClientGxSession session, org.jdiameter.api.gx.events.GxCreditControlRequest request, org.jdiameter.api.gx.events.GxCreditControlAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  450. // NO-OP
  451. }
  452. public org.jdiameter.api.gx.events.GxCreditControlRequest createCreditControlRequest(Request request) {
  453. return null;
  454. }
  455. public org.jdiameter.api.gx.events.GxCreditControlAnswer createCreditControlAnswer(Answer answer) {
  456. return null;
  457. }
  458. @Override
  459. public int getDefaultDDFHValue() {
  460. // TODO Auto-generated method stub
  461. return 0;
  462. }
  463. @Override
  464. public int getDefaultCCFHValue() {
  465. // TODO Auto-generated method stub
  466. return 0;
  467. }
  468. }