PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/bpel.model/test/unit/src/org/netbeans/modules/bpel/model/xam/ProcessTest.java

https://bitbucket.org/openesb/netbeans-soa
Java | 1312 lines | 768 code | 313 blank | 231 comment | 143 complexity | 23fa1b9952ef6eba17d6c9584d95853a MD5 | raw file
  1. /*
  2. * The contents of this file are subject to the terms of the Common Development
  3. * and Distribution License (the License). You may not use this file except in
  4. * compliance with the License.
  5. *
  6. * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
  7. * or http://www.netbeans.org/cddl.txt.
  8. *
  9. * When distributing Covered Code, include this CDDL Header Notice in each file
  10. * and include the License file at http://www.netbeans.org/cddl.txt.
  11. * If applicable, add the following below the CDDL Header, with the fields
  12. * enclosed by brackets [] replaced by your own identifying information:
  13. * "Portions Copyrighted [year] [name of copyright owner]"
  14. *
  15. * The Original Software is NetBeans. The Initial Developer of the Original
  16. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  17. * Microsystems, Inc. All Rights Reserved.
  18. */
  19. package org.netbeans.modules.bpel.model.xam;
  20. import java.util.HashSet;
  21. import java.util.LinkedList;
  22. import java.util.List;
  23. import java.util.Set;
  24. import junit.framework.Test;
  25. import junit.framework.TestCase;
  26. import junit.framework.TestSuite;
  27. import org.netbeans.modules.bpel.model.api.BpelEntity;
  28. import org.netbeans.modules.bpel.model.api.CorrelationSetContainer;
  29. import org.netbeans.modules.bpel.model.api.Documentation;
  30. import org.netbeans.modules.bpel.model.api.EventHandlers;
  31. import org.netbeans.modules.bpel.model.api.ExtendableActivity;
  32. import org.netbeans.modules.bpel.model.api.ExtensionContainer;
  33. import org.netbeans.modules.bpel.model.api.FaultHandlers;
  34. import org.netbeans.modules.bpel.model.api.Import;
  35. import org.netbeans.modules.bpel.model.api.PartnerLinkContainer;
  36. import org.netbeans.modules.bpel.model.api.Process;
  37. import org.netbeans.modules.bpel.model.api.Sequence;
  38. import org.netbeans.modules.bpel.model.api.VariableContainer;
  39. import org.netbeans.modules.bpel.model.api.support.ActivityDescriptor;
  40. import org.netbeans.modules.bpel.model.api.support.ActivityDescriptor.ActivityType;
  41. import org.netbeans.modules.bpel.model.impl.BpelModelImpl;
  42. import org.w3c.dom.Document;
  43. import org.w3c.dom.Element;
  44. import org.w3c.dom.Node;
  45. import org.w3c.dom.NodeList;
  46. /**
  47. *
  48. * @author ads
  49. */
  50. public class ProcessTest extends TestCase {
  51. static final String D1 = "d1";
  52. static final String D2 = "d2";
  53. static final String NEW = "new";
  54. public ProcessTest(String testName) {
  55. super(testName);
  56. }
  57. protected void setUp() throws Exception {
  58. }
  59. protected void tearDown() throws Exception {
  60. }
  61. public static Test suite() {
  62. TestSuite suite = new TestSuite(ProcessTest.class);
  63. return suite;
  64. }
  65. /**
  66. * Test method for getActivity with preexisted Activity in xml file.
  67. * @throws Exception
  68. */
  69. public void testGetActivity() throws Exception{
  70. Util.createData();
  71. BpelModelImpl model = Util.loadModel();
  72. ExtendableActivity activity = model.getProcess().getActivity();
  73. assert activity instanceof Sequence;
  74. }
  75. /**
  76. * Test method setActivity with preexisted Activity in xml file.
  77. * @throws Exception
  78. */
  79. public void testSetActivity() throws Exception {
  80. Util.createData();
  81. BpelModelImpl model = Util.loadModel();
  82. setActivityTest( model );
  83. }
  84. /**
  85. * This method tests removeActivity method.
  86. * @throws Exception
  87. */
  88. public void testRemoveActivity() throws Exception {
  89. Util.createData();
  90. BpelModelImpl model = Util.loadModel();
  91. removeActivityTest( model );
  92. }
  93. /**
  94. * This method test how setActivity will behave when it absent
  95. * initially in XML file.
  96. * @throws Exception
  97. */
  98. public void testSetActivityAbsentInProcess() throws Exception{
  99. Util.createData();
  100. BpelModelImpl model = Util.loadModel();
  101. removeActivityTest( model );
  102. // first test - how model will behave after deletion
  103. // activity via modle method.
  104. setActivityTest( model );
  105. // second - we remove activity once again and load result
  106. // document as new and once again test setting activity.
  107. model = removeActivityTest( model );
  108. assertNull( model.getProcess().getActivity() );
  109. setActivityTest( model );
  110. }
  111. /**
  112. * Test of getPartnerLinkContainer method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  113. * @throws Exception
  114. */
  115. public void testGetPartnerLinkContainer() throws Exception {
  116. Util.createData();
  117. BpelModelImpl model = Util.loadModel();
  118. assertNotNull( model.getProcess().getPartnerLinkContainer() );
  119. }
  120. /**
  121. * Test of setPartnerLinkContainer method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  122. * @throws Exception
  123. */
  124. public void testSetPartnerLinkContainer() throws Exception {
  125. Util.createData();
  126. BpelModelImpl model = Util.loadModel();
  127. setPartnerLinkContainerTest(model);
  128. }
  129. public void testSetExtensionContainer() throws Exception {
  130. Util.createData();
  131. BpelModelImpl model = Util.loadModel();
  132. setExtensionContainerTest( model );
  133. }
  134. public void testRemoveExtensionContainer() throws Exception {
  135. Util.createData();
  136. BpelModelImpl model = Util.loadModel();
  137. removeExtensionContainerTest( model );
  138. }
  139. public void testSetExtensionContainerAbsentInProcess() throws Exception{
  140. Util.createData();
  141. BpelModelImpl model = Util.loadModel();
  142. removeExtensionContainerTest( model );
  143. // first test - how model will behave after deletion
  144. // ExtensionContainer via modle method.
  145. setExtensionContainerTest( model );
  146. // second - we remove ExtensionContainer once again and load result
  147. // document as new and once again test setting ExtensionContainer.
  148. model = removeExtensionContainerTest( model );
  149. assertNull( model.getProcess().getExtensionContainer() );
  150. setExtensionContainerTest( model );
  151. }
  152. public void testGetVariableContainer() throws Exception {
  153. Util.createData();
  154. BpelModelImpl model = Util.loadModel();
  155. assertNotNull( model.getProcess().getVariableContainer() );
  156. }
  157. public void testSetVariableContainer() throws Exception {
  158. Util.createData();
  159. BpelModelImpl model = Util.loadModel();
  160. setVariableContainerTest( model );
  161. }
  162. public void testRemoveVariableContainer() throws Exception {
  163. Util.createData();
  164. BpelModelImpl model = Util.loadModel();
  165. removeVariableContainerTest( model );
  166. }
  167. public void testSetVariableContainerAbsentInProcess() throws Exception{
  168. Util.createData();
  169. BpelModelImpl model = Util.loadModel();
  170. removeVariableContainerTest( model );
  171. // first test - how model will behave after deletion
  172. // PartnerLinkContainer via modle method.
  173. setVariableContainerTest( model );
  174. // second - we remove PartnerLinkContainer once again and load result
  175. // document as new and once again test setting PartnerLinkContainer.
  176. model = removeVariableContainerTest( model );
  177. assertNull( model.getProcess().getVariableContainer() );
  178. setVariableContainerTest( model );
  179. }
  180. public void testGetCorrelationSetContainer() throws Exception {
  181. Util.createData();
  182. BpelModelImpl model = Util.loadModel();
  183. assertNotNull( model.getProcess().getCorrelationSetContainer() );
  184. }
  185. public void testGetDocumentation() throws Exception {
  186. Util.createData();
  187. BpelModelImpl model = Util.loadModel();
  188. assertTrue( model.getProcess().getDocumentations().length==2);
  189. assertTrue( model.getProcess().sizeOfDocumentations()==2);
  190. assertNotNull( model.getProcess().getDocumentation(0));
  191. assertNotNull( model.getProcess().getDocumentation(1));
  192. }
  193. public void testGetExtensionContainer() throws Exception {
  194. Util.createData();
  195. BpelModelImpl model = Util.loadModel();
  196. assertNotNull( model.getProcess().getExtensionContainer() );
  197. }
  198. public void testGetImport() throws Exception {
  199. Util.createData();
  200. BpelModelImpl model = Util.loadModel();
  201. assertTrue( model.getProcess().getImports().length ==3 );
  202. assertTrue( model.getProcess().sizeOfImports() == 3) ;
  203. for ( int i =0 ; i<3 ; i++ ) {
  204. assertNotNull( model.getProcess().getImport(i ));
  205. }
  206. }
  207. public void testRemoveDocumentation() throws Exception {
  208. Util.createData();
  209. BpelModelImpl model = Util.loadModel();
  210. removeDocumentationTest( model , 1 );
  211. }
  212. public void testAddDocumentation() throws Exception {
  213. Util.createData();
  214. BpelModelImpl model = Util.loadModel();
  215. addDocumentationTest( model );
  216. }
  217. public void testAddDocumentationAbsentInProcess() throws Exception {
  218. Util.createData();
  219. BpelModelImpl model = Util.loadModel();
  220. // remove both documenation from model.
  221. removeDocumentationTest( model , 0 );
  222. model = removeDocumentationTest( model , 0 );
  223. assertTrue( model.getProcess().sizeOfDocumentations() == 0 );
  224. addDocumentationTest( model );
  225. }
  226. public void testSetCorrelationSetContainer() throws Exception {
  227. Util.createData();
  228. BpelModelImpl model = Util.loadModel();
  229. setCorrelationSetContainerTest( model );
  230. }
  231. public void testRemoveCorrelationSetContainer() throws Exception{
  232. Util.createData();
  233. BpelModelImpl model = Util.loadModel();
  234. removeCorrelationSetContainerTest( model );
  235. }
  236. public void testSetCorrelationSetContainerAbsentInProcess() throws Exception{
  237. Util.createData();
  238. BpelModelImpl model = Util.loadModel();
  239. removeCorrelationSetContainerTest( model );
  240. // first test - how model will behave after deletion
  241. // CorrelationSetContainer via modle method.
  242. setCorrelationSetContainerTest( model );
  243. // second - we remove CorrelationSetContainer once again and load result
  244. // document as new and once again test setting CorrelationSetContainer.
  245. model = removeCorrelationSetContainerTest( model );
  246. assertNull( model.getProcess().getCorrelationSetContainer() );
  247. setCorrelationSetContainerTest( model );
  248. }
  249. public void testGetFaultHandlers() throws Exception {
  250. Util.createData();
  251. BpelModelImpl model = Util.loadModel();
  252. assertNotNull( model.getProcess().getFaultHandlers() );
  253. }
  254. public void testSetFaultHandlers() throws Exception {
  255. Util.createData();
  256. BpelModelImpl model = Util.loadModel();
  257. setFaultHandlersTest( model );
  258. }
  259. public void testRemoveFaultHandlers() throws Exception {
  260. Util.createData();
  261. BpelModelImpl model = Util.loadModel();
  262. removeFaultHandlersTest( model );
  263. }
  264. public void testSetFaultHandlersAbsentInProcess() throws Exception{
  265. Util.createData();
  266. BpelModelImpl model = Util.loadModel();
  267. removeFaultHandlersTest( model );
  268. // first test - how model will behave after deletion
  269. // FaultHandlers via modle method.
  270. setFaultHandlersTest( model );
  271. // second - we remove FaultHandlers once again and load result
  272. // document as new and once again test setting FaultHandlers.
  273. model = removeFaultHandlersTest( model );
  274. assertNull( model.getProcess().getFaultHandlers() );
  275. setFaultHandlersTest( model );
  276. }
  277. public void testGetEventHandlers() throws Exception{
  278. Util.createData();
  279. BpelModelImpl model = Util.loadModel();
  280. assertNotNull( model.getProcess().getEventHandlers() );
  281. }
  282. public void testSetEventHandlers() throws Exception{
  283. Util.createData();
  284. BpelModelImpl model = Util.loadModel();
  285. setEventHandlersTest( model );
  286. }
  287. public void testRemoveEventHandlers() throws Exception{
  288. Util.createData();
  289. BpelModelImpl model = Util.loadModel();
  290. removeEventHandlersTest( model );
  291. }
  292. public void testSetEventHandlersAbsentInProcess() throws Exception{
  293. Util.createData();
  294. BpelModelImpl model = Util.loadModel();
  295. removeEventHandlersTest( model );
  296. // first test - how model will behave after deletion
  297. // EventHandlers via modle method.
  298. setEventHandlersTest( model );
  299. // second - we remove EventHandlers once again and load result
  300. // document as new and once again test setting EventHandlers.
  301. model = removeEventHandlersTest( model );
  302. assertNull( model.getProcess().getEventHandlers() );
  303. setEventHandlersTest( model );
  304. }
  305. //
  306. // /**
  307. // * Test of getAbstractProcess method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  308. // */
  309. // public void testGetAbstractProcess() {
  310. // // TODO : test attribute access
  311. // }
  312. //
  313. //
  314. // /**
  315. // * Test of setAbstractProcess method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  316. // */
  317. // public void testSetAbstractProcess() {
  318. // // TODO : test attribute access
  319. // }
  320. //
  321. // /**
  322. // * Test of getEnableInstanceCompensation method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  323. // */
  324. // public void testGetEnableInstanceCompensation() {
  325. //// TODO : test attribute access
  326. // }
  327. //
  328. //
  329. // /**
  330. // * Test of setEnableInstanceCompensation method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  331. // */
  332. // public void testSetEnableInstanceCompensation() {
  333. //// TODO : test attribute access
  334. // }
  335. //
  336. // /**
  337. // * Test of getExpressionLanguage method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  338. // */
  339. // public void testGetExpressionLanguage() {
  340. //// TODO : test attribute access
  341. // }
  342. //
  343. // /**
  344. // * Test of setExpressionLanguage method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  345. // */
  346. // public void testSetExpressionLanguage() throws Exception {
  347. //// TODO : test attribute access
  348. // }
  349. //
  350. // /**
  351. // * Test of getQueryLanguage method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  352. // */
  353. // public void testGetQueryLanguage() {
  354. //// TODO : test attribute access
  355. // }
  356. //
  357. // /**
  358. // * Test of setQueryLanguage method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  359. // */
  360. // public void testSetQueryLanguage() throws Exception {
  361. //// TODO : test attribute access
  362. // }
  363. //
  364. // /**
  365. // * Test of getTargetNamespace method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  366. // */
  367. // public void testGetTargetNamespace() {
  368. //// TODO : test attribute access
  369. // }
  370. //
  371. // /**
  372. // * Test of setTargetNamespace method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  373. // */
  374. // public void testSetTargetNamespace() throws Exception {
  375. //// TODO : test attribute access
  376. // }
  377. //
  378. // /**
  379. // * Test of removeAbstractProcess method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  380. // */
  381. // public void testRemoveAbstractProcess() {
  382. //// TODO : test attribute access
  383. // }
  384. //
  385. // /**
  386. // * Test of removeQueryLanguage method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  387. // */
  388. // public void testRemoveQueryLanguage() {
  389. //// TODO : test attribute access
  390. // }
  391. //
  392. // /**
  393. // * Test of removeExpressionLanguage method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  394. // */
  395. // public void testRemoveExpressionLanguage() {
  396. //// TODO : test attribute access
  397. // }
  398. //
  399. // /**
  400. // * Test of removeEnableInstanceCompensation method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  401. // */
  402. // public void testRemoveEnableInstanceCompensation() {
  403. //// TODO : test attribute access
  404. // }
  405. /**
  406. * Test of removePartnerLinkContainer method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  407. * @throws Exception
  408. */
  409. public void testRemovePartnerLinkContainer() throws Exception {
  410. Util.createData();
  411. BpelModelImpl model = Util.loadModel();
  412. removePartnerLinkContainerTest( model );
  413. }
  414. public void testSetPartnerLinkContainerAbsentInProcess() throws Exception{
  415. Util.createData();
  416. BpelModelImpl model = Util.loadModel();
  417. removePartnerLinkContainerTest( model );
  418. // first test - how model will behave after deletion
  419. // PartnerLinkContainer via modle method.
  420. setPartnerLinkContainerTest( model );
  421. // second - we remove PartnerLinkContainer once again and load result
  422. // document as new and once again test setting PartnerLinkContainer.
  423. model = removePartnerLinkContainerTest( model );
  424. assertNull( model.getProcess().getPartnerLinkContainer() );
  425. setPartnerLinkContainerTest( model );
  426. }
  427. // /**
  428. // * Test of accept method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  429. // */
  430. // public void testAccept() {
  431. // TODO : is this need to test ?
  432. // }
  433. /**
  434. * Test of getElementType method, of class org.netbeans.modules.soa.model.bpel.xdm.impl.ProcessImpl.
  435. * @throws Exception
  436. */
  437. public void testGetElementType() throws Exception {
  438. Util.createData();
  439. BpelModelImpl model = Util.loadModel();
  440. assertTrue( model.getProcess().getElementType().
  441. equals( Process.class ) );
  442. }
  443. private void setActivityTest( BpelModelImpl model ){
  444. Process process = model.getProcess();
  445. Documentation[] docs = process.getDocumentations();
  446. ExtensionContainer extensionContainer = process.getExtensionContainer();
  447. Import[] imports = process.getImports();
  448. PartnerLinkContainer container = process.getPartnerLinkContainer();
  449. VariableContainer variableContainer = process.getVariableContainer();
  450. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  451. FaultHandlers faultHandlers = process.getFaultHandlers();
  452. EventHandlers eventHandlers = process.getEventHandlers();
  453. List<? extends BpelEntity> entities = process.getChildren();
  454. for( ActivityType type : ActivityType.values())
  455. {
  456. List<String> tagList = new LinkedList<String>();
  457. for (BpelEntity entity : entities) {
  458. tagList.add( Util.getTagName( entity ).intern() );
  459. }
  460. // when we call this method in test method that don't have
  461. // activity as child, we have less children then need in list
  462. if ( process.getActivity()== null ) {
  463. tagList.add( null );
  464. }
  465. if ( type.equals( ActivityType.COMPENSATE )){
  466. continue;
  467. }
  468. ExtendableActivity activity = model.getBuilder().createActivity(
  469. new ActivityDescriptor( type ) );
  470. // HERE SET new activity.
  471. model.getProcess().setActivity( activity );
  472. ExtendableActivity act = model.getProcess().getActivity();
  473. assertTrue( model.getProcess() == process );
  474. assertTrue( activity == act );
  475. assertTrue( container == process.getPartnerLinkContainer() );
  476. assertTrue( variableContainer == process.getVariableContainer());
  477. assertTrue( setContainer == process.getCorrelationSetContainer());
  478. assertTrue( faultHandlers == process.getFaultHandlers());
  479. assertTrue( eventHandlers == process.getEventHandlers());
  480. assertTrue( extensionContainer == process.getExtensionContainer() );
  481. assertTrue( process.getDocumentations().length == docs.length );
  482. int i = 0 ;
  483. for( Documentation doc : process.getDocumentations() ){
  484. assertTrue( doc == docs[i] );
  485. i++;
  486. }
  487. assertTrue( process.sizeOfImports() == imports.length );
  488. i=0;
  489. for( Import imp : process.getImports() ){
  490. assertTrue( imp == imports[i]);
  491. i++;
  492. }
  493. tagList.set( tagList.size()-1 , Util.getTagName( activity).intern() );
  494. checkOrderAndPresence(model, tagList );
  495. }
  496. Document doc = Util.flush( model );
  497. NodeList list =
  498. doc.getElementsByTagName( "nb:insidesequence" );
  499. assertEquals( list.getLength() , 0 );
  500. }
  501. /**
  502. * This method checks that each tag in <code>tagList</code>
  503. * present as child tag in root of document.
  504. * They have correct order. They are single.
  505. */
  506. private void checkOrderAndPresence(BpelModelImpl model, List<String> tagList ) {
  507. Document document = Util.flush( model );
  508. Set<String> foundTags = new HashSet<String>();
  509. Element root = document.getDocumentElement();
  510. NodeList list = root.getChildNodes();
  511. /* walk through all nodes in list and check
  512. * that all of them in correct order and no other
  513. * elements appear.
  514. */
  515. String lastTag = null;
  516. for( int i=0; i<list.getLength(); i++ ){
  517. Node node = list.item( i );
  518. String name = node.getNodeName();
  519. if ( tagList.size() == 0 ){
  520. if ( name!= null ) {
  521. // if there some more bpel tags in XML then this incorrect
  522. assertFalse( foundTags.contains( name.intern()));
  523. }
  524. continue;
  525. }
  526. if ( tagList.get(0).equals( name ) ){
  527. tagList.remove( 0 );
  528. // only one such tag could be present in XML
  529. if ( !name.equals( lastTag) ){
  530. assertFalse( foundTags.contains( name.intern()));
  531. foundTags.add( name.intern() );
  532. }
  533. lastTag = name.intern();
  534. }
  535. }
  536. // if order was wrong this list will not null.
  537. if ( tagList.size()>0 ) {
  538. Util.debug( tagList.get(0)) ;
  539. }
  540. assertTrue( tagList.size() == 0 );
  541. }
  542. private BpelModelImpl removeActivityTest(BpelModelImpl model) throws Exception {
  543. Process process = model.getProcess();
  544. // initial suggestion about nonempty Activity in process.
  545. assert process.getActivity()!= null;
  546. String tagName = Util.getTagName( process.getActivity() );
  547. List<String> tagList = getChildrenTagList(process);
  548. tagList.remove( tagList.size() - 1);
  549. process.removeActivity();
  550. assertNull( process.getActivity() );
  551. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList, 0 );
  552. }
  553. /**
  554. * Method returns list of tag names that correspond order
  555. * children in <code>process</code>.
  556. */
  557. private List<String> getChildrenTagList(Process process) {
  558. List<? extends BpelEntity> entities = process.getChildren();
  559. List<String> tagList = new LinkedList<String>();
  560. for (BpelEntity entity : entities) {
  561. tagList.add( Util.getTagName( entity ).intern() );
  562. }
  563. return tagList;
  564. }
  565. private void setPartnerLinkContainerTest(BpelModelImpl model) {
  566. Process process = model.getProcess();
  567. PartnerLinkContainer container =
  568. model.getBuilder().createPartnerLinkContainer();
  569. Documentation[] docs = process.getDocumentations();
  570. ExtensionContainer extensionContainer = process.getExtensionContainer();
  571. Import[] imports = process.getImports();
  572. VariableContainer variableContainer = process.getVariableContainer();
  573. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  574. FaultHandlers faultHandlers = process.getFaultHandlers();
  575. EventHandlers eventHandlers = process.getEventHandlers();
  576. ExtendableActivity activity = process.getActivity();
  577. List<String> tagList = getChildrenTagList(process);
  578. if ( process.getPartnerLinkContainer()== null ) {
  579. tagList.add( 6, Util.getTagName( container ) );
  580. }
  581. // HERE SET new PartnerLinkContainer
  582. process.setPartnerLinkContainer( container );
  583. assertTrue( model.getProcess() == process );
  584. assertTrue( extensionContainer == process.getExtensionContainer() );
  585. assertTrue( variableContainer == process.getVariableContainer());
  586. assertTrue( setContainer == process.getCorrelationSetContainer());
  587. assertTrue( faultHandlers == process.getFaultHandlers());
  588. assertTrue( eventHandlers == process.getEventHandlers());
  589. assertTrue( activity == process.getActivity() );
  590. assertTrue( process.getDocumentations().length == docs.length );
  591. int i = 0 ;
  592. for( Documentation doc : process.getDocumentations() ){
  593. assertTrue( doc == docs[i] );
  594. i++;
  595. }
  596. assertTrue( process.sizeOfImports() == imports.length );
  597. i=0;
  598. for( Import imp : process.getImports() ){
  599. assertTrue( imp == imports[i]);
  600. i++;
  601. }
  602. checkOrderAndPresence( model , tagList );
  603. Document doc = Util.flush( model );
  604. String tagName = Util.getTagName( container );
  605. NodeList list =
  606. doc.getElementsByTagName( tagName.substring( 0, tagName.length() -1 ));
  607. assertEquals( list.getLength() , 0 );
  608. }
  609. private void setExtensionContainerTest(BpelModelImpl model) {
  610. Process process = model.getProcess();
  611. ExtensionContainer container = model.getBuilder().
  612. createExtensionContainer();
  613. Documentation[] docs = process.getDocumentations();
  614. Import[] imports = process.getImports();
  615. PartnerLinkContainer plnkContainer = process.getPartnerLinkContainer();
  616. VariableContainer variableContainer = process.getVariableContainer();
  617. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  618. FaultHandlers faultHandlers = process.getFaultHandlers();
  619. EventHandlers eventHandlers = process.getEventHandlers();
  620. ExtendableActivity activity = process.getActivity();
  621. List<String> tagList = getChildrenTagList(process);
  622. if ( process.getPartnerLinkContainer()== null ) {
  623. tagList.add( 2, Util.getTagName( container ) );
  624. }
  625. // HERE SET new ExtensionContainer
  626. process.setExtensionContainer( container );
  627. assertTrue( model.getProcess() == process );
  628. assertTrue( container == process.getExtensionContainer() );
  629. assertTrue( plnkContainer == process.getPartnerLinkContainer());
  630. assertTrue( variableContainer == process.getVariableContainer());
  631. assertTrue( setContainer == process.getCorrelationSetContainer());
  632. assertTrue( faultHandlers == process.getFaultHandlers());
  633. assertTrue( eventHandlers == process.getEventHandlers());
  634. assertTrue( activity == process.getActivity() );
  635. assertTrue( process.getDocumentations().length == docs.length );
  636. int i = 0 ;
  637. for( Documentation doc : process.getDocumentations() ){
  638. assertTrue( doc == docs[i] );
  639. i++;
  640. }
  641. assertTrue( process.sizeOfImports() == imports.length );
  642. i=0;
  643. for( Import imp : process.getImports() ){
  644. assertTrue( imp == imports[i]);
  645. i++;
  646. }
  647. checkOrderAndPresence( model , tagList );
  648. Document doc = Util.flush( model );
  649. String tagName = Util.getTagName( container );
  650. NodeList list =
  651. doc.getElementsByTagName( tagName.substring( 0, tagName.length() -1 ));
  652. assertEquals( list.getLength() , 0 );
  653. }
  654. private void addDocumentationTest(BpelModelImpl model) {
  655. Process process = model.getProcess();
  656. Documentation doc = model.getBuilder().createDocumentation();
  657. Documentation[] docs = process.getDocumentations();
  658. ExtensionContainer extensionContainer = process.getExtensionContainer();
  659. Import[] imports = process.getImports();
  660. PartnerLinkContainer plnkContainer = process.getPartnerLinkContainer();
  661. VariableContainer variableContainer = process.getVariableContainer();
  662. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  663. FaultHandlers faultHandlers = process.getFaultHandlers();
  664. EventHandlers eventHandlers = process.getEventHandlers();
  665. ExtendableActivity activity = process.getActivity();
  666. List<String> tagList = getChildrenTagList(process);
  667. if ( process.sizeOfDocumentations()== 0 ) {
  668. tagList.add( 0, Util.getTagName( doc ) );
  669. }
  670. // HERE SET add new Documentation
  671. process.addDocumentation( doc );
  672. assertTrue( model.getProcess() == process );
  673. assertTrue( plnkContainer == process.getPartnerLinkContainer() );
  674. assertTrue( extensionContainer == process.getExtensionContainer() );
  675. assertTrue( variableContainer == process.getVariableContainer());
  676. assertTrue( setContainer == process.getCorrelationSetContainer());
  677. assertTrue( faultHandlers == process.getFaultHandlers());
  678. assertTrue( eventHandlers == process.getEventHandlers());
  679. assertTrue( activity == process.getActivity() );
  680. assertTrue( process.getDocumentations().length == docs.length +1);
  681. int i = 0 ;
  682. for( Documentation doc1 : docs) {
  683. assertTrue( doc1 == process.getDocumentation(i) );
  684. i++;
  685. }
  686. assertTrue( doc == process.getDocumentation( docs.length ));
  687. assertTrue( process.sizeOfImports() == imports.length );
  688. i=0;
  689. for( Import imp : process.getImports() ){
  690. assertTrue( imp == imports[i]);
  691. i++;
  692. }
  693. checkOrderAndPresence( model , tagList );
  694. Document domDoc = Util.flush( model );
  695. String tagName = Util.getTagName( doc );
  696. NodeList list = domDoc.getElementsByTagName( tagName );
  697. assertTrue(list.item( docs.length ).getChildNodes().getLength()==0);
  698. assertTrue( doc.getContent().length()==0);
  699. }
  700. private void setEventHandlersTest( BpelModelImpl model ) {
  701. Process process = model.getProcess();
  702. EventHandlers eventHandlers =
  703. model.getBuilder().createEventHandlers();
  704. Documentation[] docs = process.getDocumentations();
  705. ExtensionContainer extensionContainer = process.getExtensionContainer();
  706. Import[] imports = process.getImports();
  707. PartnerLinkContainer pContainer = process.getPartnerLinkContainer();
  708. VariableContainer variableContainer = process.getVariableContainer();
  709. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  710. FaultHandlers faultHandlers = process.getFaultHandlers();
  711. ExtendableActivity activity = process.getActivity();
  712. List<String> tagList = getChildrenTagList(process);
  713. if ( process.getEventHandlers()== null ) {
  714. tagList.add( 10, Util.getTagName( eventHandlers ) );
  715. }
  716. // HERE SET new EventHandlers
  717. process.setEventHandlers( eventHandlers );
  718. assertTrue( model.getProcess() == process );
  719. assertTrue( pContainer == process.getPartnerLinkContainer());
  720. assertTrue( variableContainer == process.getVariableContainer());
  721. assertTrue( faultHandlers == process.getFaultHandlers() );
  722. assertTrue( setContainer == process.getCorrelationSetContainer());
  723. assertTrue( activity == process.getActivity() );
  724. assert( extensionContainer == process.getExtensionContainer() );
  725. assertTrue( process.getDocumentations().length == docs.length );
  726. int i = 0 ;
  727. for( Documentation doc : process.getDocumentations() ){
  728. assertTrue( doc == docs[i] );
  729. i++;
  730. }
  731. assertTrue( process.sizeOfImports() == imports.length );
  732. i=0;
  733. for( Import imp : process.getImports() ){
  734. assertTrue( imp == imports[i]);
  735. i++;
  736. }
  737. checkOrderAndPresence( model , tagList );
  738. Document doc = Util.flush( model );
  739. NodeList list =
  740. doc.getElementsByTagName( "nb:insideeventHandlers" );
  741. assertEquals( list.getLength() , 0 );
  742. }
  743. private void setFaultHandlersTest(BpelModelImpl model) {
  744. Process process = model.getProcess();
  745. FaultHandlers faultHandlers =
  746. model.getBuilder().createFaultHandlers();
  747. Documentation[] docs = process.getDocumentations();
  748. ExtensionContainer extensionContainer = process.getExtensionContainer();
  749. Import[] imports = process.getImports();
  750. PartnerLinkContainer pContainer = process.getPartnerLinkContainer();
  751. VariableContainer variableContainer = process.getVariableContainer();
  752. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  753. EventHandlers eventHandlers = process.getEventHandlers();
  754. ExtendableActivity activity = process.getActivity();
  755. List<String> tagList = getChildrenTagList(process);
  756. if ( process.getFaultHandlers()== null ) {
  757. tagList.add( 9, Util.getTagName( faultHandlers ) );
  758. }
  759. // HERE SET new FaultHandlers
  760. process.setFaultHandlers( faultHandlers );
  761. assertTrue( model.getProcess() == process );
  762. assertTrue( pContainer == process.getPartnerLinkContainer());
  763. assertTrue( variableContainer == process.getVariableContainer());
  764. assertTrue( setContainer == process.getCorrelationSetContainer());
  765. assertTrue( eventHandlers == process.getEventHandlers());
  766. assertTrue( activity == process.getActivity() );
  767. assertTrue( extensionContainer == process.getExtensionContainer() );
  768. assertTrue( process.getDocumentations().length == docs.length );
  769. int i = 0 ;
  770. for( Documentation doc : process.getDocumentations() ){
  771. assertTrue( doc == docs[i] );
  772. i++;
  773. }
  774. assertTrue( process.sizeOfImports() == imports.length );
  775. i=0;
  776. for( Import imp : process.getImports() ){
  777. assertTrue( imp == imports[i]);
  778. i++;
  779. }
  780. checkOrderAndPresence( model , tagList );
  781. Document doc = Util.flush( model );
  782. NodeList list =
  783. doc.getElementsByTagName( "nb:insidefaultHandler" );
  784. assertEquals( list.getLength() , 0 );
  785. }
  786. private void setCorrelationSetContainerTest(BpelModelImpl model) {
  787. Process process = model.getProcess();
  788. CorrelationSetContainer container =
  789. model.getBuilder().createCorrelationSetContainer();
  790. Documentation[] docs = process.getDocumentations();
  791. ExtensionContainer extensionContainer = process.getExtensionContainer();
  792. Import[] imports = process.getImports();
  793. PartnerLinkContainer pContainer = process.getPartnerLinkContainer();
  794. VariableContainer variableContainer = process.getVariableContainer();
  795. FaultHandlers faultHandlers = process.getFaultHandlers();
  796. EventHandlers eventHandlers = process.getEventHandlers();
  797. ExtendableActivity activity = process.getActivity();
  798. List<String> tagList = getChildrenTagList(process);
  799. if ( process.getVariableContainer()== null ) {
  800. tagList.add( 8, Util.getTagName( container ) );
  801. }
  802. // HERE SET new CorrelationSetContainer
  803. process.setCorrelationSetContainer( container );
  804. assertTrue( model.getProcess() == process );
  805. assertTrue( pContainer == process.getPartnerLinkContainer());
  806. assertTrue( variableContainer == process.getVariableContainer());
  807. assertTrue( faultHandlers == process.getFaultHandlers());
  808. assertTrue( eventHandlers == process.getEventHandlers());
  809. assertTrue( activity == process.getActivity() );
  810. assertTrue( extensionContainer == process.getExtensionContainer() );
  811. assertTrue( process.getDocumentations().length == docs.length );
  812. int i = 0 ;
  813. for( Documentation doc : process.getDocumentations() ){
  814. assertTrue( doc == docs[i] );
  815. i++;
  816. }
  817. assertTrue( process.sizeOfImports() == imports.length );
  818. i=0;
  819. for( Import imp : process.getImports() ){
  820. assertTrue( imp == imports[i]);
  821. i++;
  822. }
  823. checkOrderAndPresence( model , tagList );
  824. Document doc = Util.flush( model );
  825. String tagName = Util.getTagName( container );
  826. NodeList list =
  827. doc.getElementsByTagName( tagName.substring( 0, tagName.length() -1 ));
  828. assertEquals( list.getLength() , 0 );
  829. }
  830. private void setVariableContainerTest(BpelModelImpl model) {
  831. Process process = model.getProcess();
  832. VariableContainer container =
  833. model.getBuilder().createVariableContainer();
  834. Documentation[] docs = process.getDocumentations();
  835. ExtensionContainer extensionContainer = process.getExtensionContainer();
  836. Import[] imports = process.getImports();
  837. PartnerLinkContainer pContainer = process.getPartnerLinkContainer();
  838. CorrelationSetContainer setContainer = process.getCorrelationSetContainer();
  839. FaultHandlers faultHandlers = process.getFaultHandlers();
  840. EventHandlers eventHandlers = process.getEventHandlers();
  841. ExtendableActivity activity = process.getActivity();
  842. List<String> tagList = getChildrenTagList(process);
  843. if ( process.getVariableContainer()== null ) {
  844. tagList.add( 7, Util.getTagName( container ) );
  845. }
  846. // HERE SET new VariableContainer
  847. process.setVariableContainer( container );
  848. assertTrue( model.getProcess() == process );
  849. assertTrue( extensionContainer == process.getExtensionContainer() );
  850. assertTrue( pContainer == process.getPartnerLinkContainer());
  851. assertTrue( setContainer == process.getCorrelationSetContainer());
  852. assertTrue( faultHandlers == process.getFaultHandlers());
  853. assertTrue( eventHandlers == process.getEventHandlers());
  854. assertTrue( activity == process.getActivity() );
  855. assertTrue( process.getDocumentations().length == docs.length );
  856. int i = 0 ;
  857. for( Documentation doc : process.getDocumentations() ){
  858. assertTrue( doc == docs[i] );
  859. i++;
  860. }
  861. assertTrue( process.sizeOfImports() == imports.length );
  862. i=0;
  863. for( Import imp : process.getImports() ){
  864. assertTrue( imp == imports[i]);
  865. i++;
  866. }
  867. checkOrderAndPresence( model , tagList );
  868. Document doc = Util.flush( model );
  869. NodeList list =
  870. doc.getElementsByTagName( "nb:insidevariables");
  871. assertEquals( list.getLength() , 0 );
  872. }
  873. private BpelModelImpl removePartnerLinkContainerTest(BpelModelImpl model)
  874. throws Exception
  875. {
  876. Process process = model.getProcess();
  877. // initial suggestion about nonempty PartnerContainer in process.
  878. assert process.getPartnerLinkContainer() != null;
  879. String tagName = Util.getTagName(process.getPartnerLinkContainer());
  880. List<String> tagList = getChildrenTagList(process);
  881. tagList.remove( 6 );
  882. process.removePartnerLinkContainer();
  883. assertNull(process.getPartnerLinkContainer());
  884. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList, 0 );
  885. }
  886. private BpelModelImpl removeDocumentationTest(BpelModelImpl model , int i )
  887. throws Exception
  888. {
  889. Process process = model.getProcess();
  890. String presentTag = D1;
  891. // initial suggestion about nonempty PartnerContainer in process.
  892. assert process.getDocumentation( i ) != null;
  893. if ( process.getDocumentation(i).getContent().equals( presentTag )){
  894. presentTag = D2;
  895. }
  896. String tagName = Util.getTagName(process.getDocumentation(i));
  897. List<String> tagList = getChildrenTagList(process);
  898. tagList.remove( 0 );
  899. int size = process.sizeOfDocumentations();
  900. process.removeDocumentation( i );
  901. assertTrue(process.sizeOfDocumentations() == size -1 );
  902. assertTrue(process.getDocumentations().length == size -1 );
  903. if ( process.sizeOfDocumentations() >0 ){
  904. process.getDocumentation( 0 ).getContent().equals( presentTag );
  905. }
  906. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList, 1 );
  907. }
  908. private BpelModelImpl removeVariableContainerTest( BpelModelImpl model)
  909. throws Exception
  910. {
  911. Process process = model.getProcess();
  912. // initial suggestion about nonempty VariableContainer in process.
  913. assert process.getVariableContainer() != null;
  914. String tagName = Util.getTagName(process.getVariableContainer());
  915. List<String> tagList = getChildrenTagList(process);
  916. tagList.remove( 7);
  917. process.removeVariableContainer();
  918. assertNull(process.getVariableContainer());
  919. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList, 0 );
  920. }
  921. private BpelModelImpl removeExtensionContainerTest( BpelModelImpl model )
  922. throws Exception
  923. {
  924. Process process = model.getProcess();
  925. // initial suggestion about nonempty ExtensionContainer in process.
  926. assertNotNull(process.getVariableContainer());
  927. String tagName = Util.getTagName(process.getExtensionContainer());
  928. List<String> tagList = getChildrenTagList(process);
  929. tagList.remove(2);
  930. process.removeExtensionContainer();
  931. assertNull(process.getExtensionContainer());
  932. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList, 0);
  933. }
  934. private BpelModelImpl removeEventHandlersTest( BpelModelImpl model)
  935. throws Exception
  936. {
  937. Process process = model.getProcess();
  938. // initial suggestion about nonempty EventHandlers in process.
  939. assert process.getEventHandlers() != null;
  940. String tagName = Util.getTagName(process.getEventHandlers());
  941. List<String> tagList = getChildrenTagList(process);
  942. tagList.remove( 10 );
  943. process.removeEventHandlers();
  944. assertNull(process.getEventHandlers());
  945. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList , 0);
  946. }
  947. private BpelModelImpl removeFaultHandlersTest( BpelModelImpl model)
  948. throws Exception
  949. {
  950. Process process = model.getProcess();
  951. // initial suggestion about nonempty FaultHandlers in process.
  952. assert process.getFaultHandlers() != null;
  953. String tagName = Util.getTagName(process.getFaultHandlers());
  954. List<String> tagList = getChildrenTagList(process);
  955. tagList.remove( 9 );
  956. process.removeFaultHandlers();
  957. assertNull(process.getFaultHandlers());
  958. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList , 0);
  959. }
  960. private BpelModelImpl removeCorrelationSetContainerTest( BpelModelImpl model)
  961. throws Exception
  962. {
  963. Process process = model.getProcess();
  964. // initial suggestion about nonempty CorrelationSetContainer in process.
  965. assert process.getCorrelationSetContainer() != null;
  966. String tagName = Util.getTagName(process.getCorrelationSetContainer());
  967. List<String> tagList = getChildrenTagList(process);
  968. tagList.remove( 8 );
  969. process.removeCorrelationSetContainer();
  970. assertNull(process.getCorrelationSetContainer());
  971. return checkAbsenceOfTagAndLoadModel(model, tagName, tagList , 0);
  972. }
  973. /**
  974. * This method check for absence <code>tagName</code> in root children and
  975. * returns new model that built on XML without tagName.
  976. * Also it checks that order of elements in XML correspond to
  977. * order in <code>tagList</code>.
  978. *
  979. */
  980. private BpelModelImpl checkAbsenceOfTagAndLoadModel(BpelModelImpl model,
  981. String tagName, List<String> tagList, int countOfPresence )
  982. throws Exception
  983. {
  984. int count = 0;
  985. StringBuilder builder = new StringBuilder();
  986. Document document = Util.flush( model , builder );
  987. Element root = document.getDocumentElement();
  988. NodeList list = root.getChildNodes();
  989. for( int i=0 ; i<list.getLength(); i++ ){
  990. Node node = list.item( i );
  991. if ( tagName.equals( node.getNodeName() )){
  992. count++;
  993. assertTrue( count <=countOfPresence );
  994. }
  995. }
  996. checkOrderAndPresence( model , tagList );
  997. return Util.loadModel( builder.toString() );
  998. }
  999. }