1 package org.jbpm.bpel.bar; 2 3 import java.io.StringReader ; 4 import java.util.Map ; 5 6 import org.xml.sax.InputSource ; 7 8 import junit.framework.TestCase; 9 10 import org.jbpm.bpel.bar.BarApplication; 11 import org.jbpm.bpel.bar.BarScope; 12 import org.jbpm.bpel.bar.ScopeMatcher; 13 import org.jbpm.bpel.def.BpelDefinition; 14 import org.jbpm.bpel.def.Scope; 15 import org.jbpm.bpel.def.Sequence; 16 import org.jbpm.bpel.xml.BpelException; 17 import org.jbpm.bpel.xml.BpelReader; 18 import org.jbpm.bpel.xml.BarDescriptorReader; 19 20 public class ScopeMatcherTest extends TestCase { 21 22 private ScopeMatcher binder; 23 private BarDescriptorReader barReader = BarDescriptorReader.getInstance(); 24 private BpelDefinition process; 25 26 public void setUp() throws BpelException { 27 process = new BpelDefinition(); 28 InputSource input = new InputSource (getClass().getResource("definition.xml").toString()); 29 BpelReader.getInstance().read(process, input); 30 binder = new ScopeMatcher(); 31 } 32 33 public void testMatchProcessConfig() throws Exception { 34 String text = 35 "<bpelApplication xmlns='http://jbpm.org/bpel'>" + 36 "<connectionFactory name='CF'/>" + 37 "<partnerLinks>" + 38 "<partnerLink name='schedulingPL'>" + 39 "<destination name='queue/scheduling'/>" + 40 "</partnerLink>" + 41 "</partnerLinks>" + 42 "</bpelApplication>"; 43 44 BarApplication application = new BarApplication(); 45 barReader.read(application, new InputSource ( new StringReader (text)) ); 46 Map configurations = binder.match(process, application); 47 BarScope scopeConfig = (BarScope) configurations.get(process.getScope()); 48 assertSame(application, configurations.get(process.getScope())); 49 assertEquals(1, scopeConfig.getPartnerLinks().size()); 50 } 51 52 public void testMatchScopeConfig() throws Exception { 53 String text = 54 "<bpelApplication xmlns='http://jbpm.org/bpel'>" + 55 "<connectionFactory name='CF'/>" + 56 "<scopes>" + 57 "<scope name='s1'>" + 58 "<scopes>" + 59 "<scope name='s1.1'>" + 60 "<destination name='s1Destination'/>" + 61 "</scope>" + 62 "</scopes>" + 63 "</scope>" + 64 "</scopes>" + 65 "</bpelApplication>"; 66 67 BarApplication application = new BarApplication(); 68 barReader.read(application, new InputSource ( new StringReader (text)) ); 69 Scope s1Def = (Scope) ((Sequence)process.getRoot()).getNodes().get(1); 70 BarScope s1Config = (BarScope) application.getScopes().iterator().next(); 71 Scope s11Def = (Scope) s1Def.getRoot(); 72 BarScope s11Config = (BarScope) s1Config.getScopes().iterator().next(); 73 74 Map configurations = binder.match(process, application); 75 76 assertSame(s1Config, configurations.get(s1Def)); 77 assertSame(s11Config, configurations.get(s11Def)); 78 } 79 80 public void testMatchUnnamedScopeConfig() throws Exception { 81 String text = 82 "<bpelApplication xmlns='http://jbpm.org/bpel'>" + 83 "<connectionFactory name='CF'/>" + 84 "<scopes>" + 85 "<scope>" + 86 "<destination name='s1Destination'/>" + 87 "</scope>" + 88 "</scopes>" + 89 "</bpelApplication>"; 90 91 BarApplication application = new BarApplication(); 92 barReader.read(application, new InputSource ( new StringReader (text)) ); 93 Scope s1Def = (Scope) ((Sequence)process.getRoot()).getNodes().get(2); 94 BarScope s1Config = (BarScope) application.getScopes().iterator().next(); 95 Map configurations = binder.match(process, application); 96 97 assertSame(s1Config, configurations.get(s1Def)); 98 } 99 100 public void testConflictingScopeConfig() throws Exception { 101 String text = 102 "<bpelApplication xmlns='http://jbpm.org/bpel'>" + 103 "<connectionFactory name='CF'/>" + 104 "<scopes>" + 105 "<scope name='conflictingName'>" + 106 "<destination name='s1Destination'/>" + 107 "</scope>" + 108 "</scopes>" + 109 "</bpelApplication>"; 110 111 BarApplication application = new BarApplication(); 112 barReader.read(application, new InputSource ( new StringReader (text)) ); 113 try { 114 binder.match(process, application); 115 fail("conflicting name resolution must fail"); 116 } 117 catch (RuntimeException e) { 118 } 120 } 121 } 122 | Popular Tags |