001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.web;
018:
019: import org.bpmscript.web.SourceHighLighter;
020:
021: import junit.framework.TestCase;
022:
023: public class SourceHighLighterTest extends TestCase {
024: public void testHighlight() throws Exception {
025: // script.pause(classpath:/org/bpmscript/jbi/bpmscriptlibrary.js:2)
026: // script.(classpath:/org/bpmscript/jbi/bpmscriptlibrary.js:86)
027: // script.(classpath:/org/bpmscript/jbi/bpmscriptlibrary.js:107)
028: // script.main(main.js:141)
029: StackTraceElement[] elements = new StackTraceElement[] {
030: new StackTraceElement(
031: "script",
032: "pause",
033: "classpath:/org/bpmscript/jbi/bpmscriptlibrary.js",
034: 2),
035: new StackTraceElement(
036: "script",
037: "",
038: "classpath:/org/bpmscript/jbi/bpmscriptlibrary.js",
039: 86),
040: new StackTraceElement(
041: "script",
042: "",
043: "classpath:/org/bpmscript/jbi/bpmscriptlibrary.js",
044: 107),
045: new StackTraceElement("script", "main", "main.js", 141) };
046:
047: SourceHighLighter highLighter = new SourceHighLighter();
048: highLighter.highlight("main.js", source, elements);
049:
050: }
051:
052: private String source = "function ServiceSupport(interfaceName, namespace, localPart, sender) {\n"
053: + "\n"
054: + " this.interfaceName = interfaceName;\n"
055: + " this.namespace = namespace;\n"
056: + " this.localPart = localPart;\n"
057: + " this.sender = sender;\n"
058: + "\n"
059: + " this.call = function(operation, message, timeout) {\n"
060: + " var future = this.sender.send(this.namespace, \n"
061: + " this.localPart, \n"
062: + " message,\n"
063: + " {'interface':this.interfaceName, 'operation':operation}, \n"
064: + " timeout);\n"
065: + " out.println(\">>>>>>>>>>>>>>>>>>>>> \" + operation + \" >>>>>>>>>>>>>>>>>>>\");\n"
066: + " out.println(message);\n"
067: + " var result = future.get();\n"
068: + " var resultContent = result.getOutMessage().getContent();\n"
069: + " if(resultContent != null) {\n"
070: + " var content = sourceToXml(resultContent);\n"
071: + " out.println(\"<<<<<<<<<<<<<<<<<<<<< \" + operation + \" <<<<<<<<<<<<<<<<<<<\");\n"
072: + " out.println(content.toString());\n"
073: + " if(content.stackTrace.toString() != '') {\n"
074: + " throw content.name().toString();\n"
075: + " }\n"
076: + " return content;\n"
077: + " }\n"
078: + " }\n"
079: + "}\n"
080: + "\n"
081: + "function ReconcilliationFacade(sender) {\n"
082: + "\n"
083: + " this.serviceSupport = new ServiceSupport(\"com.vnocore.payment.facade.IReconcilliationFacade\", \n"
084: + " \"http://www.vnocore.com/jbi\", \"rpc-component\", sender);\n"
085: + "\n"
086: + " this.createPaymentId = function(accountId, paymentCard, amount, timeout) {\n"
087: + " var content = this.serviceSupport.call(\"createPaymentId\",\n"
088: + " <object-array>\n"
089: + " <string>{accountId}</string>\n"
090: + " <com.vnocore.payment.model.PaymentCard>\n"
091: + " <cardNumber>{paymentCard.cardNumber}</cardNumber>\n"
092: + " </com.vnocore.payment.model.PaymentCard>\n"
093: + " <big-decimal>{amount}</big-decimal>\n"
094: + " </object-array>.toXMLString(), timeout);\n"
095: + " return content.text().toString();\n"
096: + " }\n"
097: + "}\n"
098: + "\n"
099: + "function CardPaymentFacade(sender) {\n"
100: + "\n"
101: + " this.serviceSupport = new ServiceSupport(\"com.vnocore.payment.facade.ICardPaymentFacade\", \n"
102: + " \"http://www.vnocore.com/jbi\", \"rpc-component\", sender);\n"
103: + "\n"
104: + " this.authorise = function(paymentId, paymentCard, amount, cvv2, timeout) {\n"
105: + " this.serviceSupport.call(\"authorise\",\n"
106: + " <object-array>\n"
107: + " <string>{paymentId}</string>\n"
108: + " <com.vnocore.payment.model.PaymentCard>\n"
109: + " <cardNumber>{paymentCard.cardNumber}</cardNumber>\n"
110: + " </com.vnocore.payment.model.PaymentCard>\n"
111: + " <big-decimal>{amount}</big-decimal>\n"
112: + " <string>{cvv2}</string>\n"
113: + " </object-array>.toXMLString(), timeout);\n"
114: + " }\n"
115: + " this.commit = function(paymentId, timeout) {\n"
116: + " this.serviceSupport.call(\"commit\",\n"
117: + " <object-array>\n"
118: + " <string>{paymentId}</string>\n"
119: + " </object-array>.toXMLString(), timeout);\n"
120: + " }\n"
121: + "}\n"
122: + "\n"
123: + "function BillingFacade(sender) {\n"
124: + "\n"
125: + " this.serviceSupport = new ServiceSupport(\"com.vnocore.billing.facade.IBillingFacade\", \n"
126: + " \"http://www.vnocore.com/jbi\", \"rpc-component\", sender);\n"
127: + "\n"
128: + " this.postPayment = function(paymentId, accountId, invoiceId, amount, timeout) {\n"
129: + " this.serviceSupport.call(\"postPayment\",\n"
130: + " \"<object-array>\" +\n"
131: + " (paymentId != null ? \"<string>\" + paymentId + \"</string>\" : \"<null/>\") +\n"
132: + " (accountId != null ? \"<string>\" + accountId + \"</string>\" : \"<null/>\") +\n"
133: + " (invoiceId != null ? \"<string>\" + invoiceId + \"</string>\" : \"<null/>\") +\n"
134: + " \"<big-decimal>\" + amount + \"</big-decimal>\" +\n"
135: + " \"</object-array>\", timeout);\n"
136: + " }\n"
137: + "}\n"
138: + "\n"
139: + "/**\n"
140: + " \"<string>accountId</string>\" +\n"
141: + " \"<string>invoiceId</string>\" +\n"
142: + " \"<com.vnocore.payment.model.PaymentCard>\" +\n"
143: + " \" <cardNumber>1234</cardNumber>\" +\n"
144: + " \"</com.vnocore.payment.model.PaymentCard>\" +\n"
145: + " \"<string>cvv</string>\" +\n"
146: + " \"<big-decimal>10</big-decimal>\" +\n"
147: + "**/\n"
148: + "\n"
149: + "function decodeRequest(input) {\n"
150: + " var request = new Object();\n"
151: + " var xml = sourceToXml(input.getInMessage().getContent());\n"
152: + " request.accountId = xml.*[0].text().toString();\n"
153: + " request.invoiceId = xml.*[1].text().toString();\n"
154: + " \n"
155: + " var paymentCard = new Object();\n"
156: + " var paymentCardXml = xml.*[2];\n"
157: + " paymentCard.cardNumber = paymentCardXml.cardNumber.text().toString();\n"
158: + " request.paymentCard = paymentCard;\n"
159: + "\n"
160: + " request.cvv2 = xml.*[3].text().toString();\n"
161: + " request.amount = xml.*[4].text().toString();\n"
162: + " return request;\n"
163: + "}\n"
164: + "\n"
165: + "function main(processInstanceId, input, processInstanceIdStack) {\n"
166: + "\n"
167: + " var sender = new SyncSender(processInstanceId, input, processInstanceIdStack);\n"
168: + " var reconcilliationFacade = new ReconcilliationFacade(sender);\n"
169: + " var cardPaymentFacade = new CardPaymentFacade(sender);\n"
170: + " var billingFacade = new BillingFacade(sender);\n"
171: + "\n"
172: + " var request = decodeRequest(input);\n"
173: + "\n"
174: + " var future = sender.send(\"http://bpmscript.org/jbi\", \n"
175: + " \"bpmscript\", \n"
176: + " \"<hello>world!</hello>\",\n"
177: + " {'process':'echo'}, \n"
178: + " 1000);\n"
179: + " \n"
180: + " out.println(sourceToString(future.get().getOutMessage().getContent()));\n"
181: + " \n"
182: + " var taskService = new TaskService(processInstanceId, sender);\n"
183: + "\n"
184: + " var taskRequest = taskService.taskRequest(\"What should I do next\");\n"
185: + " taskRequest.response(\"Skip\", \"Please enter the partyId:\").integer();\n"
186: + " taskRequest.response(\"Retry\", \"Retry\");\n"
187: + " var complexType = taskRequest.response(\"AddPerson\", \"Please enter the person details:\").complexType(\"person\");\n"
188: + " complexType.field(\"firstName\").string();\n"
189: + " complexType.field(\"surname\").string();\n"
190: + " taskRequest.setRole(\"ANONYMOUS\");\n"
191: + " \n"
192: + " out.println(taskService.request(taskRequest, 1000).getPath());\n"
193: + "\n"
194: + " var paymentId = reconcilliationFacade.createPaymentId(request.accountId, request.paymentCard, request.amount, 1000);\n"
195: + " cardPaymentFacade.authorise(paymentId, request.paymentCard, request.amount, 123, 1000);\n"
196: + " cardPaymentFacade.commit(paymentId);\n"
197: + " sender.reply(\"success\");\n"
198: + " billingFacade.postPayment(paymentId, request.accountId, request.invoiceId, request.amount);\n"
199: + "\n" + " return \"done\";\n" + "\n" + "}\n";
200:
201: }
|