PageRenderTime 110ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 1315 lines | 747 code | 339 blank | 229 comment | 57 complexity | 8c9842e166755325bc29b2deae37e9ab MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause

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

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.slee.resources.diameter.tests.factories;
  23. import static org.jdiameter.client.impl.helpers.Parameters.AcctApplId;
  24. import static org.jdiameter.client.impl.helpers.Parameters.ApplicationId;
  25. import static org.jdiameter.client.impl.helpers.Parameters.Assembler;
  26. import static org.jdiameter.client.impl.helpers.Parameters.AuthApplId;
  27. import static org.jdiameter.client.impl.helpers.Parameters.OwnDiameterURI;
  28. import static org.jdiameter.client.impl.helpers.Parameters.OwnRealm;
  29. import static org.jdiameter.client.impl.helpers.Parameters.OwnVendorID;
  30. import static org.jdiameter.client.impl.helpers.Parameters.PeerName;
  31. import static org.jdiameter.client.impl.helpers.Parameters.PeerRating;
  32. import static org.jdiameter.client.impl.helpers.Parameters.PeerTable;
  33. import static org.jdiameter.client.impl.helpers.Parameters.RealmEntry;
  34. import static org.jdiameter.client.impl.helpers.Parameters.RealmTable;
  35. import static org.jdiameter.client.impl.helpers.Parameters.VendorId;
  36. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryExpTime;
  37. import static org.jdiameter.server.impl.helpers.Parameters.RealmEntryIsDynamic;
  38. import static org.jdiameter.server.impl.helpers.Parameters.RealmHosts;
  39. import static org.jdiameter.server.impl.helpers.Parameters.RealmLocalAction;
  40. import static org.jdiameter.server.impl.helpers.Parameters.RealmName;
  41. import static org.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.base.events.avp.IPFilterRule;
  45. import net.java.slee.resource.diameter.gq.GqAvpFactory;
  46. import net.java.slee.resource.diameter.gq.GqMessageFactory;
  47. import net.java.slee.resource.diameter.gq.GqServerSessionActivity;
  48. import net.java.slee.resource.diameter.gq.events.GqAAAnswer;
  49. import net.java.slee.resource.diameter.gq.events.GqAARequest;
  50. import net.java.slee.resource.diameter.gq.events.GqAbortSessionAnswer;
  51. import net.java.slee.resource.diameter.gq.events.GqAbortSessionRequest;
  52. import net.java.slee.resource.diameter.gq.events.GqReAuthAnswer;
  53. import net.java.slee.resource.diameter.gq.events.GqReAuthRequest;
  54. import net.java.slee.resource.diameter.gq.events.GqSessionTerminationAnswer;
  55. import net.java.slee.resource.diameter.gq.events.GqSessionTerminationRequest;
  56. import net.java.slee.resource.diameter.gq.events.avp.BindingInformation;
  57. import net.java.slee.resource.diameter.gq.events.avp.BindingInputList;
  58. import net.java.slee.resource.diameter.gq.events.avp.BindingOutputList;
  59. import net.java.slee.resource.diameter.gq.events.avp.FlowGrouping;
  60. import net.java.slee.resource.diameter.gq.events.avp.FlowStatus;
  61. import net.java.slee.resource.diameter.gq.events.avp.FlowUsage;
  62. import net.java.slee.resource.diameter.gq.events.avp.Flows;
  63. import net.java.slee.resource.diameter.gq.events.avp.GloballyUniqueAddress;
  64. import net.java.slee.resource.diameter.gq.events.avp.MediaComponentDescription;
  65. import net.java.slee.resource.diameter.gq.events.avp.MediaSubComponent;
  66. import net.java.slee.resource.diameter.gq.events.avp.ReservationPriority;
  67. import net.java.slee.resource.diameter.gq.events.avp.V4TransportAddress;
  68. import net.java.slee.resource.diameter.gq.events.avp.V6TransportAddress;
  69. import org.jdiameter.api.Answer;
  70. import org.jdiameter.api.ApplicationId;
  71. import org.jdiameter.api.IllegalDiameterStateException;
  72. import org.jdiameter.api.Request;
  73. import org.jdiameter.api.Stack;
  74. import org.jdiameter.api.auth.events.ReAuthAnswer;
  75. import org.jdiameter.api.auth.events.ReAuthRequest;
  76. import org.jdiameter.api.gq.GqServerSession;
  77. import org.jdiameter.client.api.ISessionFactory;
  78. import org.jdiameter.client.impl.helpers.EmptyConfiguration;
  79. import org.jdiameter.common.impl.app.gq.GqSessionFactoryImpl;
  80. import org.jdiameter.server.impl.app.auth.ServerAuthSessionDataLocalImpl;
  81. import org.jdiameter.server.impl.app.gq.GqServerSessionImpl;
  82. import org.junit.Assert;
  83. import org.junit.Test;
  84. import org.mobicents.diameter.dictionary.AvpDictionary;
  85. import org.mobicents.slee.resource.diameter.base.DiameterAvpFactoryImpl;
  86. import org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl;
  87. import org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl;
  88. import org.mobicents.slee.resource.diameter.gq.GqAvpFactoryImpl;
  89. import org.mobicents.slee.resource.diameter.gq.GqMessageFactoryImpl;
  90. import org.mobicents.slee.resource.diameter.gq.GqServerSessionActivityImpl;
  91. /**
  92. * Test class for JAIN SLEE Diameter Gq' RA Message and AVP Factories
  93. *
  94. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  95. */
  96. public class GqFactoriesTest {
  97. private static String clientHost = "127.0.0.1";
  98. private static String clientPort = "13868";
  99. private static String clientURI = "aaa://" + clientHost + ":" + clientPort;
  100. private static String serverHost = "localhost";
  101. private static String serverPort = "3868";
  102. private static String serverURI = "aaa://" + serverHost + ":" + serverPort;
  103. private static String realmName = "mobicents.org";
  104. private static GqMessageFactory gqMessageFactory;
  105. private static GqAvpFactory gqAvpFactory;
  106. private static Stack stack;
  107. private static GqServerSession serverSession;
  108. //private static GqClientSession clientSession;
  109. static {
  110. stack = new org.jdiameter.client.impl.StackImpl();
  111. try {
  112. stack.init(new MyConfiguration());
  113. }
  114. catch ( Exception e ) {
  115. throw new RuntimeException("Failed to initialize the stack.");
  116. }
  117. DiameterMessageFactoryImpl baseFactory = new DiameterMessageFactoryImpl(stack);
  118. DiameterAvpFactoryImpl baseAvpFactory = new DiameterAvpFactoryImpl();
  119. gqAvpFactory = new GqAvpFactoryImpl(baseAvpFactory);
  120. try {
  121. gqMessageFactory = new GqMessageFactoryImpl(baseFactory, stack.getSessionFactory().getNewSession().getSessionId(), stack);
  122. }
  123. catch ( Exception e ) {
  124. e.printStackTrace();
  125. }
  126. try {
  127. AvpDictionary.INSTANCE.parseDictionary( GqFactoriesTest.class.getClassLoader().getResourceAsStream( "dictionary.xml" ) );
  128. }
  129. catch ( Exception e ) {
  130. throw new RuntimeException("Failed to parse dictionary file.");
  131. }
  132. }
  133. private GqServerSessionActivity gqServerSession = null;
  134. //private GqClientSessionActivity gqClientSession = null;
  135. public GqFactoriesTest() {
  136. try {
  137. GqSessionFactoryImpl gqSessionFactory = new GqSessionFactoryImpl(stack.getSessionFactory());
  138. serverSession = new GqServerSessionImpl(new ServerAuthSessionDataLocalImpl(), (ISessionFactory) stack.getSessionFactory(), gqSessionFactory, gqSessionFactory, gqSessionFactory, gqSessionFactory, 30000L, true);
  139. //clientSession = new GqClientSessionImpl(new ClientAuthSessionDataLocalImpl(), (ISessionFactory) stack.getSessionFactory(), gqSessionFactory, gqSessionFactory, gqSessionFactory, gqSessionFactory, true);
  140. gqServerSession = new GqServerSessionActivityImpl(gqMessageFactory.getBaseMessageFactory(), gqAvpFactory.getBaseFactory(), serverSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack);
  141. //gqClientSession = new GqClientSessionActivityImpl(gqMessageFactory.getBaseMessageFactory(), gqAvpFactory.getBaseFactory(), clientSession, new DiameterIdentity("127.0.0.2"), new DiameterIdentity("mobicents.org"), stack);
  142. //((GqServerSessionActivityImpl)roServerSession).fetchCurrentState(roMessageFactory.createGqAARequest());
  143. }
  144. catch (IllegalDiameterStateException e) {
  145. throw new RuntimeException("Failed to parse dictionary file.");
  146. }
  147. }
  148. // AA-Request
  149. @Test
  150. public void isRequestAAR() throws Exception {
  151. GqAARequest aar = gqMessageFactory.createGqAARequest();
  152. assertTrue("Request Flag in AA-Request is not set.", aar.getHeader().isRequest());
  153. }
  154. @Test
  155. public void isProxiableAAR() throws Exception {
  156. GqAARequest rar = gqMessageFactory.createGqAARequest();
  157. assertTrue("The 'P' bit is not set by default in Gq' AA-Request, it should.", rar.getHeader().isProxiable());
  158. }
  159. @Test
  160. public void testGettersAndSettersAAR() throws Exception {
  161. GqAARequest aar = gqMessageFactory.createGqAARequest();
  162. int nFailures = AvpAssistant.testMethods(aar, GqAARequest.class);
  163. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  164. }
  165. @Test
  166. public void hasGqApplicationIdAAR() throws Exception {
  167. GqAARequest aar = gqMessageFactory.createGqAARequest();
  168. assertTrue("Auth-Application-Id AVP in Gq AAR must be " + GqMessageFactory._GQ_AUTH_APP_ID + ", it is " + aar.getAuthApplicationId(), aar.getAuthApplicationId() == GqMessageFactory._GQ_AUTH_APP_ID);
  169. }
  170. // AA-Answer
  171. @Test
  172. public void isAnswerAAA() throws Exception {
  173. GqAAAnswer aaa = gqServerSession.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  174. assertFalse("Request Flag in AA-Answer is set.", aaa.getHeader().isRequest());
  175. }
  176. @Test
  177. public void isProxiableCopiedAAA() throws Exception {
  178. GqAARequest aar = gqMessageFactory.createGqAARequest();
  179. GqAAAnswer aaa = gqMessageFactory.createGqAAAnswer(aar);
  180. assertEquals("The 'P' bit is not copied from request in Gq' AA-Answer, it should. [RFC3588/6.2]", aar.getHeader().isProxiable(), aaa.getHeader().isProxiable());
  181. // Reverse 'P' bit ...
  182. ((DiameterMessageImpl) aar).getGenericData().setProxiable(!aar.getHeader().isProxiable());
  183. assertTrue("The 'P' bit was not modified in Gq' AA-Request, it should.", aar.getHeader().isProxiable() != aaa.getHeader().isProxiable());
  184. aaa = gqMessageFactory.createGqAAAnswer(aar);
  185. assertEquals("The 'P' bit is not copied from request in Gq' AA-Answer, it should. [RFC3588/6.2]", aar.getHeader().isProxiable(), aaa.getHeader().isProxiable());
  186. }
  187. @Test
  188. public void hasTFlagSetAAA() throws Exception {
  189. GqAARequest aar = gqMessageFactory.createGqAARequest();
  190. ((DiameterMessageImpl) aar).getGenericData().setReTransmitted(true);
  191. assertTrue("The 'T' flag should be set in AA-Request", aar.getHeader().isPotentiallyRetransmitted());
  192. GqAAAnswer aaa = gqMessageFactory.createGqAAAnswer(aar);
  193. assertFalse("The 'T' flag should not be set in AA-Answer", aaa.getHeader().isPotentiallyRetransmitted());
  194. }
  195. @Test
  196. public void testGettersAndSettersAAA() throws Exception {
  197. GqAAAnswer aaa = gqServerSession.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  198. int nFailures = AvpAssistant.testMethods(aaa, GqAAAnswer.class);
  199. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  200. }
  201. @Test
  202. public void hasGqApplicationIdAAA() throws Exception {
  203. GqAAAnswer aaa = gqServerSession.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  204. assertTrue("Auth-Application-Id AVP in Gq AAA must be " + GqMessageFactory._GQ_AUTH_APP_ID + ", it is " + aaa.getAuthApplicationId(), aaa.getAuthApplicationId() == GqMessageFactory._GQ_AUTH_APP_ID);
  205. }
  206. @Test
  207. public void hasDestinationHostAAA() throws Exception {
  208. GqAAAnswer aaa = gqServerSession.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  209. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", aaa.getDestinationHost());
  210. }
  211. @Test
  212. public void hasDestinationRealmAAA() throws Exception {
  213. GqAAAnswer aaa = gqServerSession.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  214. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", aaa.getDestinationRealm());
  215. }
  216. // Abort-Session-Request
  217. @Test
  218. public void isRequestASR() throws Exception {
  219. GqAbortSessionRequest asr = gqMessageFactory.createGqAbortSessionRequest();
  220. assertTrue("Request Flag in Abort-Session-Request is not set.", asr.getHeader().isRequest());
  221. }
  222. @Test
  223. public void isProxiableASR() throws Exception {
  224. GqAbortSessionRequest rar = gqMessageFactory.createGqAbortSessionRequest();
  225. assertTrue("The 'P' bit is not set by default in Gq' Abort-Session-Request, it should.", rar.getHeader().isProxiable());
  226. }
  227. @Test
  228. public void testGettersAndSettersASR() throws Exception {
  229. GqAbortSessionRequest asr = gqMessageFactory.createGqAbortSessionRequest();
  230. int nFailures = AvpAssistant.testMethods(asr, GqAbortSessionRequest.class);
  231. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  232. }
  233. @Test
  234. public void hasGqApplicationIdASR() throws Exception {
  235. GqAbortSessionRequest asr = gqMessageFactory.createGqAbortSessionRequest();
  236. assertTrue("Auth-Application-Id AVP in Gq ASR must be " + GqMessageFactory._GQ_AUTH_APP_ID + ", it is " + asr.getAuthApplicationId(), asr.getAuthApplicationId() == GqMessageFactory._GQ_AUTH_APP_ID);
  237. }
  238. // Abort-Session-Answer
  239. @Test
  240. public void isAnswerASA() throws Exception {
  241. GqAbortSessionAnswer asa = gqMessageFactory.createGqAbortSessionAnswer(gqMessageFactory.createGqAbortSessionRequest());
  242. assertFalse("Request Flag in Abort-Session-Answer is set.", asa.getHeader().isRequest());
  243. }
  244. @Test
  245. public void isProxiableCopiedASA() throws Exception {
  246. GqAbortSessionRequest asr = gqMessageFactory.createGqAbortSessionRequest();
  247. GqAbortSessionAnswer asa = gqMessageFactory.createGqAbortSessionAnswer(asr);
  248. assertEquals("The 'P' bit is not copied from request in Gq' Abort-Session-Answer, it should. [RFC3588/6.2]", asr.getHeader().isProxiable(), asa.getHeader().isProxiable());
  249. // Reverse 'P' bit ...
  250. ((DiameterMessageImpl) asr).getGenericData().setProxiable(!asr.getHeader().isProxiable());
  251. assertTrue("The 'P' bit was not modified in Gq' Abort-Session-Request, it should.", asr.getHeader().isProxiable() != asa.getHeader().isProxiable());
  252. asa = gqMessageFactory.createGqAbortSessionAnswer(asr);
  253. assertEquals("The 'P' bit is not copied from request in Gq' Abort-Session-Answer, it should. [RFC3588/6.2]", asr.getHeader().isProxiable(), asa.getHeader().isProxiable());
  254. }
  255. @Test
  256. public void hasTFlagSetASA() throws Exception {
  257. GqAbortSessionRequest asr = gqMessageFactory.createGqAbortSessionRequest();
  258. ((DiameterMessageImpl) asr).getGenericData().setReTransmitted(true);
  259. assertTrue("The 'T' flag should be set in Abort-Session-Request", asr.getHeader().isPotentiallyRetransmitted());
  260. GqAbortSessionAnswer asa = gqMessageFactory.createGqAbortSessionAnswer(asr);
  261. assertFalse("The 'T' flag should not be set in Abort-Session-Answer", asa.getHeader().isPotentiallyRetransmitted());
  262. }
  263. @Test
  264. public void testGettersAndSettersASA() throws Exception {
  265. GqAbortSessionAnswer asa = gqMessageFactory.createGqAbortSessionAnswer(gqMessageFactory.createGqAbortSessionRequest());
  266. int nFailures = AvpAssistant.testMethods(asa, GqAbortSessionAnswer.class);
  267. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  268. }
  269. @Test
  270. public void hasDestinationHostASA() throws Exception {
  271. GqAbortSessionAnswer asa = gqMessageFactory.createGqAbortSessionAnswer(gqMessageFactory.createGqAbortSessionRequest());
  272. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", asa.getDestinationHost());
  273. }
  274. @Test
  275. public void hasDestinationRealmASA() throws Exception {
  276. GqAbortSessionAnswer asa = gqMessageFactory.createGqAbortSessionAnswer(gqMessageFactory.createGqAbortSessionRequest());
  277. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", asa.getDestinationRealm());
  278. }
  279. // Re-Auth-Request
  280. @Test
  281. public void isRequestRAR() throws Exception {
  282. GqReAuthRequest rar = gqMessageFactory.createGqReAuthRequest();
  283. assertTrue("Request Flag in Re-Auth-Request is not set.", rar.getHeader().isRequest());
  284. }
  285. @Test
  286. public void isProxiableRAR() throws Exception {
  287. GqReAuthRequest rar = gqMessageFactory.createGqReAuthRequest();
  288. assertTrue("The 'P' bit is not set by default in Gq' Re-Auth-Request, it should.", rar.getHeader().isProxiable());
  289. }
  290. @Test
  291. public void testGettersAndSettersRAR() throws Exception {
  292. GqReAuthRequest rar = gqMessageFactory.createGqReAuthRequest();
  293. int nFailures = AvpAssistant.testMethods(rar, GqReAuthRequest.class);
  294. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  295. }
  296. @Test
  297. public void hasGqApplicationIdRAR() throws Exception {
  298. GqReAuthRequest rar = gqMessageFactory.createGqReAuthRequest();
  299. assertTrue("Auth-Application-Id AVP in Gq RAR must be " + GqMessageFactory._GQ_AUTH_APP_ID + ", it is " + rar.getAuthApplicationId(), rar.getAuthApplicationId() == GqMessageFactory._GQ_AUTH_APP_ID);
  300. }
  301. // Re-Auth-Answer
  302. @Test
  303. public void isAnswerRAA() throws Exception {
  304. GqReAuthAnswer raa = gqMessageFactory.createGqReAuthAnswer(gqMessageFactory.createGqReAuthRequest());
  305. assertFalse("Request Flag in Re-Auth-Answer is set.", raa.getHeader().isRequest());
  306. }
  307. @Test
  308. public void isProxiableCopiedRAA() throws Exception {
  309. GqReAuthRequest rar = gqMessageFactory.createGqReAuthRequest();
  310. GqReAuthAnswer raa = gqMessageFactory.createGqReAuthAnswer(rar);
  311. assertEquals("The 'P' bit is not copied from request in Gq' Re-Auth-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  312. // Reverse 'P' bit ...
  313. ((DiameterMessageImpl) rar).getGenericData().setProxiable(!rar.getHeader().isProxiable());
  314. assertTrue("The 'P' bit was not modified in Gq' Re-Auth-Request, it should.", rar.getHeader().isProxiable() != raa.getHeader().isProxiable());
  315. raa = gqMessageFactory.createGqReAuthAnswer(rar);
  316. assertEquals("The 'P' bit is not copied from request in Gq' Re-Auth-Answer, it should. [RFC3588/6.2]", rar.getHeader().isProxiable(), raa.getHeader().isProxiable());
  317. }
  318. @Test
  319. public void hasTFlagSetRAA() throws Exception {
  320. GqReAuthRequest rar = gqMessageFactory.createGqReAuthRequest();
  321. ((DiameterMessageImpl) rar).getGenericData().setReTransmitted(true);
  322. assertTrue("The 'T' flag should be set in Re-Auth-Request", rar.getHeader().isPotentiallyRetransmitted());
  323. GqReAuthAnswer raa = gqMessageFactory.createGqReAuthAnswer(rar);
  324. assertFalse("The 'T' flag should not be set in Re-Auth-Answer", raa.getHeader().isPotentiallyRetransmitted());
  325. }
  326. @Test
  327. public void testGettersAndSettersRAA() throws Exception {
  328. GqReAuthAnswer raa = gqMessageFactory.createGqReAuthAnswer(gqMessageFactory.createGqReAuthRequest());
  329. int nFailures = AvpAssistant.testMethods(raa, GqReAuthAnswer.class);
  330. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  331. }
  332. @Test
  333. public void hasDestinationHostRAA() throws Exception {
  334. GqReAuthAnswer raa = gqMessageFactory.createGqReAuthAnswer(gqMessageFactory.createGqReAuthRequest());
  335. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", raa.getDestinationHost());
  336. }
  337. @Test
  338. public void hasDestinationRealmRAA() throws Exception {
  339. GqReAuthAnswer raa = gqMessageFactory.createGqReAuthAnswer(gqMessageFactory.createGqReAuthRequest());
  340. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", raa.getDestinationRealm());
  341. }
  342. // Session-Termination-Request
  343. @Test
  344. public void isRequestSTR() throws Exception {
  345. GqSessionTerminationRequest str = gqMessageFactory.createGqSessionTerminationRequest();
  346. assertTrue("Request Flag in Session-Termination-Request is not set.", str.getHeader().isRequest());
  347. }
  348. @Test
  349. public void isProxiableSTR() throws Exception {
  350. GqSessionTerminationRequest str = gqMessageFactory.createGqSessionTerminationRequest();
  351. assertTrue("The 'P' bit is not set by default in Session-Termination-Request, it should.", str.getHeader().isProxiable());
  352. }
  353. @Test
  354. public void testGettersAndSettersSTR() throws Exception {
  355. GqSessionTerminationRequest str = gqMessageFactory.createGqSessionTerminationRequest();
  356. int nFailures = AvpAssistant.testMethods(str, GqSessionTerminationRequest.class);
  357. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  358. }
  359. @Test
  360. public void hasGqApplicationIdSTR() throws Exception {
  361. GqSessionTerminationRequest str = gqMessageFactory.createGqSessionTerminationRequest();
  362. assertTrue("Auth-Application-Id AVP in Gq STR must be " + GqMessageFactory._GQ_AUTH_APP_ID + ", it is " + str.getAuthApplicationId(), str.getAuthApplicationId() == GqMessageFactory._GQ_AUTH_APP_ID);
  363. }
  364. // Session-Termination-Answer
  365. @Test
  366. public void isAnswerSTA() throws Exception {
  367. GqSessionTerminationAnswer sta = gqMessageFactory.createGqSessionTerminationAnswer(gqMessageFactory.createGqSessionTerminationRequest());
  368. assertFalse("Request Flag in Re-Auth-Answer is set.", sta.getHeader().isRequest());
  369. }
  370. @Test
  371. public void isProxiableCopiedSTA() throws Exception {
  372. GqSessionTerminationRequest str = gqMessageFactory.createGqSessionTerminationRequest();
  373. GqSessionTerminationAnswer sta = gqMessageFactory.createGqSessionTerminationAnswer(str);
  374. assertEquals("The 'P' bit is not copied from request in Session-Termination-Answer, it should. [RFC3588/6.2]", str.getHeader().isProxiable(), sta.getHeader().isProxiable());
  375. // Reverse 'P' bit ...
  376. ((DiameterMessageImpl) str).getGenericData().setProxiable(!str.getHeader().isProxiable());
  377. assertTrue("The 'P' bit was not modified in Session-Termination-Request, it should.", str.getHeader().isProxiable() != sta.getHeader().isProxiable());
  378. sta = gqMessageFactory.createGqSessionTerminationAnswer(str);
  379. assertEquals("The 'P' bit is not copied from request in Session-Termination-Answer, it should. [RFC3588/6.2]", str.getHeader().isProxiable(), sta.getHeader().isProxiable());
  380. }
  381. @Test
  382. public void hasTFlagSetSTA() throws Exception {
  383. GqSessionTerminationRequest str = gqMessageFactory.createGqSessionTerminationRequest();
  384. ((DiameterMessageImpl) str).getGenericData().setReTransmitted(true);
  385. assertTrue("The 'T' flag should be set in Session-Termination-Request", str.getHeader().isPotentiallyRetransmitted());
  386. GqSessionTerminationAnswer sta = gqMessageFactory.createGqSessionTerminationAnswer(str);
  387. assertFalse("The 'T' flag should not be set in Session-Termination-Answer", sta.getHeader().isPotentiallyRetransmitted());
  388. }
  389. @Test
  390. public void testGettersAndSettersSTA() throws Exception {
  391. GqSessionTerminationAnswer sta = gqMessageFactory.createGqSessionTerminationAnswer(gqMessageFactory.createGqSessionTerminationRequest());
  392. int nFailures = AvpAssistant.testMethods(sta, GqSessionTerminationAnswer.class);
  393. assertEquals("Some methods have failed. See logs for more details.", 0, nFailures);
  394. }
  395. @Test
  396. public void hasDestinationHostSTA() throws Exception {
  397. GqSessionTerminationAnswer sta = gqMessageFactory.createGqSessionTerminationAnswer(gqMessageFactory.createGqSessionTerminationRequest());
  398. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", sta.getDestinationHost());
  399. }
  400. @Test
  401. public void hasDestinationRealmSTA() throws Exception {
  402. GqSessionTerminationAnswer sta = gqMessageFactory.createGqSessionTerminationAnswer(gqMessageFactory.createGqSessionTerminationRequest());
  403. assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", sta.getDestinationRealm());
  404. }
  405. // Gq AVP Factory Tests
  406. private static BindingInformation BI_AVP_DEFAULT = gqAvpFactory.createBindingInformation();
  407. private static BindingInputList BIL_AVP_DEFAULT = gqAvpFactory.createBindingInputList();
  408. private static BindingOutputList BOL_AVP_DEFAULT = gqAvpFactory.createBindingOutputList();
  409. private static FlowGrouping FG_AVP_DEFAULT = gqAvpFactory.createFlowGrouping();
  410. private static Flows F_AVP_DEFAULT = gqAvpFactory.createFlows();
  411. private static GloballyUniqueAddress GUA_AVP_DEFAULT = gqAvpFactory.createGloballyUniqueAddress();
  412. private static MediaComponentDescription MCD_AVP_DEFAULT = gqAvpFactory.createMediaComponentDescription();
  413. private static MediaSubComponent MSC_AVP_DEFAULT = gqAvpFactory.createMediaSubComponent();
  414. private static V4TransportAddress V4TA_AVP_DEFAULT = gqAvpFactory.createV4TransportAddress();
  415. private static V6TransportAddress V6TA_AVP_DEFAULT = gqAvpFactory.createV6TransportAddress();
  416. static {
  417. V4TA_AVP_DEFAULT.setFramedIPAddress("255.255.255.254".getBytes());
  418. V4TA_AVP_DEFAULT.setPortNumber(13579);
  419. V6TA_AVP_DEFAULT.setFramedIPV6Prefix("A123:B456:C789:DE80::/57".getBytes());
  420. V6TA_AVP_DEFAULT.setPortNumber(24680);
  421. BIL_AVP_DEFAULT.setV4TransportAddress(V4TA_AVP_DEFAULT);
  422. BIL_AVP_DEFAULT.setV6TransportAddress(V6TA_AVP_DEFAULT);
  423. BI_AVP_DEFAULT.setBindingInputList(BIL_AVP_DEFAULT);
  424. BI_AVP_DEFAULT.setBindingOutputList(BOL_AVP_DEFAULT);
  425. F_AVP_DEFAULT.setFlowNumber(1);
  426. F_AVP_DEFAULT.setMediaComponentNumber(2);
  427. FG_AVP_DEFAULT.setFlow(F_AVP_DEFAULT);
  428. GUA_AVP_DEFAULT.setAddressRealm("mobicents.org".getBytes());
  429. GUA_AVP_DEFAULT.setFramedIPAddress("255.255.255.254".getBytes());
  430. GUA_AVP_DEFAULT.setFramedIPV6Prefix("A123:B456:C789:DE80::/57".getBytes());
  431. MSC_AVP_DEFAULT.setFlowDescription(new IPFilterRule("deny in ip from 1.2.3.4/24 to any"));
  432. MSC_AVP_DEFAULT.setFlowNumber(7);
  433. MSC_AVP_DEFAULT.setFlowStatus(FlowStatus.ENABLED);
  434. MSC_AVP_DEFAULT.setFlowUsage(FlowUsage.RTCP);
  435. MSC_AVP_DEFAULT.setMaxRequestedBandwidthDL(555);
  436. MSC_AVP_DEFAULT.setMaxRequestedBandwidthUL(222);
  437. MCD_AVP_DEFAULT.setAFApplicationIdentifier("AFApplicationIdentifier".getBytes());
  438. MCD_AVP_DEFAULT.setCodecData("codecData".getBytes());
  439. MCD_AVP_DEFAULT.setFlowStatus(FlowStatus.DISABLED);
  440. MCD_AVP_DEFAULT.setMaxRequestedBandwidthDL(999);
  441. MCD_AVP_DEFAULT.setMaxRequestedBandwidthUL(111);
  442. MCD_AVP_DEFAULT.setMediaAuthorizationContextId("mediaAuthorizationContextId");
  443. MCD_AVP_DEFAULT.setMediaComponentNumber(1);
  444. MCD_AVP_DEFAULT.setMediaSubComponent(MSC_AVP_DEFAULT);
  445. MCD_AVP_DEFAULT.setReservationClass(4);
  446. MCD_AVP_DEFAULT.setReservationPriority(ReservationPriority.PRIORITYSEVEN);
  447. MCD_AVP_DEFAULT.setRRBandwidth(65);
  448. MCD_AVP_DEFAULT.setRSBandwidth(56);
  449. MCD_AVP_DEFAULT.setTransportClass(76576);
  450. }
  451. @Test
  452. public void testAvpFactoryCreateBindingInformation() throws Exception {
  453. String avpName = "Binding-Information";
  454. // Create AVP with mandatory values
  455. BindingInformation biAvp1 = gqAvpFactory.createBindingInformation();
  456. // Make sure it's not null
  457. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", biAvp1);
  458. // Create AVP with default constructor
  459. BindingInformation biAvp2 = gqAvpFactory.createBindingInformation();
  460. // Should not contain mandatory values
  461. // Set mandatory values
  462. // Make sure it's equal to the one created with mandatory values constructor
  463. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", biAvp1, biAvp2);
  464. // Make new copy
  465. biAvp2 = gqAvpFactory.createBindingInformation();
  466. // And set all values using setters
  467. AvpAssistant.testSetters(biAvp2);
  468. // Create empty...
  469. BindingInformation biAvp3 = gqAvpFactory.createBindingInformation();
  470. // Verify that no values have been set
  471. AvpAssistant.testHassers(biAvp3, false);
  472. // Set all previous values
  473. biAvp3.setExtensionAvps(biAvp2.getExtensionAvps());
  474. // Verify if values have been set
  475. AvpAssistant.testHassers(biAvp3, true);
  476. // Verify if values have been correctly set
  477. AvpAssistant.testGetters(biAvp3);
  478. // Make sure they match!
  479. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", biAvp2, biAvp3);
  480. }
  481. @Test
  482. public void testAvpFactoryCreateBindingInputList() throws Exception {
  483. String avpName = "Binding-Input-List";
  484. // Create AVP with mandatory values
  485. BindingInputList bilAvp1 = gqAvpFactory.createBindingInputList();
  486. // Make sure it's not null
  487. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", bilAvp1);
  488. // Create AVP with default constructor
  489. BindingInputList bilAvp2 = gqAvpFactory.createBindingInputList();
  490. // Should not contain mandatory values
  491. // Set mandatory values
  492. // Make sure it's equal to the one created with mandatory values constructor
  493. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", bilAvp1, bilAvp2);
  494. // Make new copy
  495. bilAvp2 = gqAvpFactory.createBindingInputList();
  496. // And set all values using setters
  497. AvpAssistant.testSetters(bilAvp2);
  498. // Create empty...
  499. BindingInputList bilAvp3 = gqAvpFactory.createBindingInputList();
  500. // Verify that no values have been set
  501. AvpAssistant.testHassers(bilAvp3, false);
  502. // Set all previous values
  503. bilAvp3.setExtensionAvps(bilAvp2.getExtensionAvps());
  504. // Verify if values have been set
  505. AvpAssistant.testHassers(bilAvp3, true);
  506. // Verify if values have been correctly set
  507. AvpAssistant.testGetters(bilAvp3);
  508. // Make sure they match!
  509. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", bilAvp2, bilAvp3);
  510. }
  511. @Test
  512. public void testAvpFactoryCreateBindingOutputList() throws Exception {
  513. String avpName = "Binding-Output-List";
  514. // Create AVP with mandatory values
  515. BindingOutputList bolAvp1 = gqAvpFactory.createBindingOutputList();
  516. // Make sure it's not null
  517. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", bolAvp1);
  518. // Create AVP with default constructor
  519. BindingOutputList bolAvp2 = gqAvpFactory.createBindingOutputList();
  520. // Should not contain mandatory values
  521. // Set mandatory values
  522. // Make sure it's equal to the one created with mandatory values constructor
  523. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", bolAvp1, bolAvp2);
  524. // Make new copy
  525. bolAvp2 = gqAvpFactory.createBindingOutputList();
  526. // And set all values using setters
  527. AvpAssistant.testSetters(bolAvp2);
  528. // Create empty...
  529. BindingOutputList bolAvp3 = gqAvpFactory.createBindingOutputList();
  530. // Verify that no values have been set
  531. AvpAssistant.testHassers(bolAvp3, false);
  532. // Set all previous values
  533. bolAvp3.setExtensionAvps(bolAvp2.getExtensionAvps());
  534. // Verify if values have been set
  535. AvpAssistant.testHassers(bolAvp3, true);
  536. // Verify if values have been correctly set
  537. AvpAssistant.testGetters(bolAvp3);
  538. // Make sure they match!
  539. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", bolAvp2, bolAvp3);
  540. }
  541. @Test
  542. public void testAvpFactoryCreateFlowGrouping() throws Exception {
  543. String avpName = "Flow-Grouping";
  544. // Create AVP with mandatory values
  545. FlowGrouping fgAvp1 = gqAvpFactory.createFlowGrouping();
  546. // Make sure it's not null
  547. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", fgAvp1);
  548. // Create AVP with default constructor
  549. FlowGrouping fgAvp2 = gqAvpFactory.createFlowGrouping();
  550. // Should not contain mandatory values
  551. // Set mandatory values
  552. // Make sure it's equal to the one created with mandatory values constructor
  553. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", fgAvp1, fgAvp2);
  554. // Make new copy
  555. fgAvp2 = gqAvpFactory.createFlowGrouping();
  556. // And set all values using setters
  557. AvpAssistant.testSetters(fgAvp2);
  558. // Create empty...
  559. FlowGrouping fgAvp3 = gqAvpFactory.createFlowGrouping();
  560. // Verify that no values have been set
  561. AvpAssistant.testHassers(fgAvp3, false);
  562. // Set all previous values
  563. fgAvp3.setExtensionAvps(fgAvp2.getExtensionAvps());
  564. // Verify if values have been set
  565. AvpAssistant.testHassers(fgAvp3, true);
  566. // Verify if values have been correctly set
  567. AvpAssistant.testGetters(fgAvp3);
  568. // Make sure they match!
  569. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", fgAvp2, fgAvp3);
  570. }
  571. @Test
  572. public void testAvpFactoryCreateFlows() throws Exception {
  573. String avpName = "Flows";
  574. // Create AVP with mandatory values
  575. Flows fAvp1 = gqAvpFactory.createFlows();
  576. // Make sure it's not null
  577. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", fAvp1);
  578. // Create AVP with default constructor
  579. Flows fAvp2 = gqAvpFactory.createFlows();
  580. // Should not contain mandatory values
  581. // Set mandatory values
  582. // Make sure it's equal to the one created with mandatory values constructor
  583. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", fAvp1, fAvp2);
  584. // Make new copy
  585. fAvp2 = gqAvpFactory.createFlows();
  586. // And set all values using setters
  587. AvpAssistant.testSetters(fAvp2);
  588. // Create empty...
  589. Flows fAvp3 = gqAvpFactory.createFlows();
  590. // Verify that no values have been set
  591. AvpAssistant.testHassers(fAvp3, false);
  592. // Set all previous values
  593. fAvp3.setExtensionAvps(fAvp2.getExtensionAvps());
  594. // Verify if values have been set
  595. AvpAssistant.testHassers(fAvp3, true);
  596. // Verify if values have been correctly set
  597. AvpAssistant.testGetters(fAvp3);
  598. // Make sure they match!
  599. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", fAvp2, fAvp3);
  600. }
  601. @Test
  602. public void testAvpFactoryCreateGloballyUniqueAddress() throws Exception {
  603. String avpName = "Globally-Unique-Address";
  604. // Create AVP with mandatory values
  605. GloballyUniqueAddress guaAvp1 = gqAvpFactory.createGloballyUniqueAddress();
  606. // Make sure it's not null
  607. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", guaAvp1);
  608. // Create AVP with default constructor
  609. GloballyUniqueAddress guaAvp2 = gqAvpFactory.createGloballyUniqueAddress();
  610. // Should not contain mandatory values
  611. // Set mandatory values
  612. // Make sure it's equal to the one created with mandatory values constructor
  613. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", guaAvp1, guaAvp2);
  614. // Make new copy
  615. guaAvp2 = gqAvpFactory.createGloballyUniqueAddress();
  616. // And set all values using setters
  617. AvpAssistant.testSetters(guaAvp2);
  618. // Create empty...
  619. GloballyUniqueAddress guaAvp3 = gqAvpFactory.createGloballyUniqueAddress();
  620. // Verify that no values have been set
  621. AvpAssistant.testHassers(guaAvp3, false);
  622. // Set all previous values
  623. guaAvp3.setExtensionAvps(guaAvp2.getExtensionAvps());
  624. // Verify if values have been set
  625. AvpAssistant.testHassers(guaAvp3, true);
  626. // Verify if values have been correctly set
  627. AvpAssistant.testGetters(guaAvp3);
  628. // Make sure they match!
  629. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", guaAvp2, guaAvp3);
  630. }
  631. @Test
  632. public void testAvpFactoryCreateMediaComponentDescription() throws Exception {
  633. String avpName = "Media-Component-Description";
  634. // Create AVP with mandatory values
  635. MediaComponentDescription mcdAvp1 = gqAvpFactory.createMediaComponentDescription();
  636. // Make sure it's not null
  637. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", mcdAvp1);
  638. // Create AVP with default constructor
  639. MediaComponentDescription mcdAvp2 = gqAvpFactory.createMediaComponentDescription();
  640. // Should not contain mandatory values
  641. // Set mandatory values
  642. // Make sure it's equal to the one created with mandatory values constructor
  643. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", mcdAvp1, mcdAvp2);
  644. // Make new copy
  645. mcdAvp2 = gqAvpFactory.createMediaComponentDescription();
  646. // And set all values using setters
  647. AvpAssistant.testSetters(mcdAvp2);
  648. // Create empty...
  649. MediaComponentDescription mcdAvp3 = gqAvpFactory.createMediaComponentDescription();
  650. // Verify that no values have been set
  651. AvpAssistant.testHassers(mcdAvp3, false);
  652. // Set all previous values
  653. mcdAvp3.setExtensionAvps(mcdAvp2.getExtensionAvps());
  654. // Verify if values have been set
  655. AvpAssistant.testHassers(mcdAvp3, true);
  656. // Verify if values have been correctly set
  657. AvpAssistant.testGetters(mcdAvp3);
  658. // Make sure they match!
  659. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", mcdAvp2, mcdAvp3);
  660. }
  661. @Test
  662. public void testAvpFactoryCreateMediaSubComponent() throws Exception {
  663. String avpName = "Media-Sub-Component";
  664. // Create AVP with mandatory values
  665. MediaSubComponent mscAvp1 = gqAvpFactory.createMediaSubComponent();
  666. // Make sure it's not null
  667. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", mscAvp1);
  668. // Create AVP with default constructor
  669. MediaSubComponent mscAvp2 = gqAvpFactory.createMediaSubComponent();
  670. // Should not contain mandatory values
  671. // Set mandatory values
  672. // Make sure it's equal to the one created with mandatory values constructor
  673. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", mscAvp1, mscAvp2);
  674. // Make new copy
  675. mscAvp2 = gqAvpFactory.createMediaSubComponent();
  676. // And set all values using setters
  677. AvpAssistant.testSetters(mscAvp2);
  678. // Create empty...
  679. MediaSubComponent mscAvp3 = gqAvpFactory.createMediaSubComponent();
  680. // Verify that no values have been set
  681. AvpAssistant.testHassers(mscAvp3, false);
  682. // Set all previous values
  683. mscAvp3.setExtensionAvps(mscAvp2.getExtensionAvps());
  684. // Verify if values have been set
  685. AvpAssistant.testHassers(mscAvp3, true);
  686. // Verify if values have been correctly set
  687. AvpAssistant.testGetters(mscAvp3);
  688. // Make sure they match!
  689. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", mscAvp2, mscAvp3);
  690. }
  691. @Test
  692. public void testAvpFactoryCreateV4TransportAddress() throws Exception {
  693. String avpName = "V4-Transport-Address";
  694. // Create AVP with mandatory values
  695. V4TransportAddress v4taAvp1 = gqAvpFactory.createV4TransportAddress();
  696. // Make sure it's not null
  697. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", v4taAvp1);
  698. // Create AVP with default constructor
  699. V4TransportAddress v4taAvp2 = gqAvpFactory.createV4TransportAddress();
  700. // Should not contain mandatory values
  701. // Set mandatory values
  702. // Make sure it's equal to the one created with mandatory values constructor
  703. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", v4taAvp1, v4taAvp2);
  704. // Make new copy
  705. v4taAvp2 = gqAvpFactory.createV4TransportAddress();
  706. // And set all values using setters
  707. AvpAssistant.testSetters(v4taAvp2);
  708. // Create empty...
  709. V4TransportAddress v4taAvp3 = gqAvpFactory.createV4TransportAddress();
  710. // Verify that no values have been set
  711. AvpAssistant.testHassers(v4taAvp3, false);
  712. // Set all previous values
  713. v4taAvp3.setExtensionAvps(v4taAvp2.getExtensionAvps());
  714. // Verify if values have been set
  715. AvpAssistant.testHassers(v4taAvp3, true);
  716. // Verify if values have been correctly set
  717. AvpAssistant.testGetters(v4taAvp3);
  718. // Make sure they match!
  719. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", v4taAvp2, v4taAvp3);
  720. }
  721. @Test
  722. public void testAvpFactoryCreateV6TransportAddress() throws Exception {
  723. String avpName = "V6-Transport-Address";
  724. // Create AVP with mandatory values
  725. V6TransportAddress v6taAvp1 = gqAvpFactory.createV6TransportAddress();
  726. // Make sure it's not null
  727. Assert.assertNotNull("Created " + avpName + " AVP from objects should not be null.", v6taAvp1);
  728. // Create AVP with default constructor
  729. V6TransportAddress v6taAvp2 = gqAvpFactory.createV6TransportAddress();
  730. // Should not contain mandatory values
  731. // Set mandatory values
  732. // Make sure it's equal to the one created with mandatory values constructor
  733. Assert.assertEquals("Created " + avpName + " AVP from default constructor + set<Mandatory-AVPs> should be equal to original.", v6taAvp1, v6taAvp2);
  734. // Make new copy
  735. v6taAvp2 = gqAvpFactory.createV6TransportAddress();
  736. // And set all values using setters
  737. AvpAssistant.testSetters(v6taAvp2);
  738. // Create empty...
  739. V6TransportAddress v6taAvp3 = gqAvpFactory.createV6TransportAddress();
  740. // Verify that no values have been set
  741. AvpAssistant.testHassers(v6taAvp3, false);
  742. // Set all previous values
  743. v6taAvp3.setExtensionAvps(v6taAvp2.getExtensionAvps());
  744. // Verify if values have been set
  745. AvpAssistant.testHassers(v6taAvp3, true);
  746. // Verify if values have been correctly set
  747. AvpAssistant.testGetters(v6taAvp3);
  748. // Make sure they match!
  749. Assert.assertEquals("Created " + avpName + " AVP from default constructor + setExtensionAvps should be equal to original.", v6taAvp2, v6taAvp3);
  750. }
  751. /**
  752. * Class representing the Diameter Configuration
  753. */
  754. public static class MyConfiguration extends EmptyConfiguration {
  755. public MyConfiguration() {
  756. super();
  757. add(Assembler, Assembler.defValue());
  758. add(OwnDiameterURI, clientURI);
  759. add(OwnRealm, realmName);
  760. add(OwnVendorID, 193L);
  761. // Set Ericsson SDK feature
  762. //add(UseUriAsFqdn, true);
  763. // Set Common Applications
  764. add(ApplicationId,
  765. // AppId 1
  766. getInstance().
  767. add(VendorId, 193L).
  768. add(AuthApplId, 0L).
  769. add(AcctApplId, 19302L)
  770. );
  771. // Set peer table
  772. add(PeerTable,
  773. // Peer 1
  774. getInstance().
  775. add(PeerRating, 1).
  776. add(PeerName, serverURI));
  777. // Set realm table
  778. add(RealmTable,
  779. // Realm 1
  780. getInstance().add(RealmEntry, getInstance().
  781. add(RealmName, realmName).
  782. add(ApplicationId, getInstance().add(VendorId, 193L).add(AuthApplId, 0L).add(AcctApplId, 19302L)).
  783. add(RealmHosts, clientHost + ", " + serverHost).
  784. add(RealmLocalAction, "LOCAL").
  785. add(RealmEntryIsDynamic, false).
  786. add(RealmEntryExpTime, 1000L)));
  787. }
  788. }
  789. public ReAuthAnswer createReAuthAnswer( Answer answer ) {
  790. // TODO Auto-generated method stub
  791. return null;
  792. }
  793. public ReAuthRequest createReAuthRequest( Request req ) {
  794. // TODO Auto-generated method stub
  795. return null;
  796. }
  797. public long[] getApplicationIds() {
  798. return new long[]{GqMessageFactory._GQ_AUTH_APP_ID};
  799. }
  800. @Test
  801. public void testMessageFactoryApplicationIdChangeAAR() throws Exception {
  802. long vendor = 10415L;
  803. ApplicationId originalAppId = ((GqMessageFactoryImpl)gqMessageFactory).getApplicationId();
  804. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  805. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  806. boolean isVendor = originalAppId.getVendorId() != 0L;
  807. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  808. System.out.println("Default VENDOR-ID for Gq is " + originalAppId.getVendorId());
  809. // let's create a message and see how it comes...
  810. GqAARequest originalAAR = gqMessageFactory.createGqAARequest();
  811. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalAAR);
  812. // now we switch..
  813. originalAAR = null;
  814. isVendor = !isVendor;
  815. ((GqMessageFactoryImpl)gqMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  816. // create a new message and see how it comes...
  817. GqAARequest changedAAR = gqMessageFactory.createGqAARequest();
  818. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedAAR);
  819. // revert back to default
  820. ((GqMessageFactoryImpl)gqMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  821. }
  822. @Test
  823. public void testMessageFactoryApplicationIdChangeAAA() throws Exception {
  824. long vendor = 10415L;
  825. ApplicationId originalAppId = ((GqMessageFactoryImpl)gqMessageFactory).getApplicationId();
  826. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  827. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  828. boolean isVendor = originalAppId.getVendorId() != 0L;
  829. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  830. System.out.println("Default VENDOR-ID for Gq is " + originalAppId.getVendorId());
  831. // let's create a message and see how it comes...
  832. GqAAAnswer originalAAA = gqMessageFactory.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  833. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalAAA);
  834. // now we switch..
  835. originalAAA = null;
  836. isVendor = !isVendor;
  837. ((GqMessageFactoryImpl)gqMessageFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  838. // create a new message and see how it comes...
  839. GqAAAnswer changedAAA = gqMessageFactory.createGqAAAnswer(gqMessageFactory.createGqAARequest());
  840. checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedAAA);
  841. // revert back to default
  842. ((GqMessageFactoryImpl)gqMessageFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
  843. }
  844. @Test
  845. public void testMessageFactoryApplicationIdChangeASR() throws Exception {
  846. long vendor = 10415L;
  847. ApplicationId originalAppId = ((GqMessageFactoryImpl)gqMessageFactory).getApplicationId();
  848. boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  849. boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
  850. boolean isVendor = originalAppId.getVendorId() != 0L;
  851. assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
  852. System.out.println("Default VENDOR-ID for Gq is " + originalAppId.getVendorId());
  853. // let's create a message and see how it comes...
  854. GqAbortSessionRequest originalASR = gqMessageFactory.crea

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