@Test public void testSDPParseOffer() throws Exception { Exchange ex = new DefaultExchange(new DefaultCamelContext()); ex.getIn().setBody(offerSdp); processor.process(ex); assertEquals(ex.getIn().getBody().getClass(),Offer.class); Offer offer = (Offer)ex.getIn().getBody(); MediaDescription mediaDescription = (MediaDescription) offer.getSdp().getMediaDescriptions(true).get(0); String icePwd = mediaDescription.getAttribute("ice-pwd"); String iceUfrag = mediaDescription.getAttribute("ice-ufrag"); String fingerprint = offer.getSdp().getAttribute("fingerprint"); assertEquals(icePwd,"c490fef46f74bdbe64edd636bc49a259"); assertEquals(iceUfrag,"64dc2277"); assertEquals(fingerprint,"sha-256 99:45:B1:94:7E:97:AE:F2:A5:75:86:89:B5:AD:06:BB:63:02:FA:05:04:B2:83:1B:52:C9:EF:0E:61:8F:38:73"); }
@Test public void testConfirmExist() { // Given for (int i = 1; i < 4; i++) { String key = "Confirm_" + i; Exchange exchange = new DefaultExchange(camelContext); exchange.setExchangeId("Exchange_" + i); aggregationRepository.add(camelContext, key, exchange); assertTrue(exists(key)); } // When aggregationRepository.confirm(camelContext, "Confirm_2"); // Then assertTrue(exists("Confirm_1")); assertFalse(exists("Confirm_2")); assertTrue(exists("Confirm_3")); }
protected void doTestOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception { // START SNIPPET: sending Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); final List<Object> params = new ArrayList<Object>(); Me me = new Me(); me.setFirstName("john"); me.setLastName("Doh"); params.add(me); senderExchange.getIn().setBody(params); senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "outOutOfBandHeader"); Exchange exchange = template.send(producerUri, senderExchange); org.apache.camel.Message out = exchange.getOut(); MessageContentsList result = (MessageContentsList)out.getBody(); assertTrue("Expected the out of band header to propagate but it didn't", result.get(0) != null && ((Me)result.get(0)).getFirstName().equals("pass")); Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT)); assertNotNull(responseContext); validateReturnedOutOfBandHeader(responseContext); }
/** * Evaluates the given xpath using the provided body as a String return type. * * @param context the camel context * @param body the body * @return result of the evaluation */ public String evaluate(CamelContext context, Object body) { ObjectHelper.notNull(context, "CamelContext"); // create a dummy Exchange to use during evaluation Exchange dummy = new DefaultExchange(context); dummy.getIn().setBody(body); setResultQName(XPathConstants.STRING); setResultType(String.class); try { return evaluate(dummy, String.class); } finally { // remove the thread local after usage this.exchange.remove(); } }
public void testXsltOutputFileDelete() throws Exception { URL styleSheet = getClass().getResource("example.xsl"); XsltBuilder builder = XsltBuilder.xslt(styleSheet).outputFile().deleteOutputFile(); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("<hello>world!</hello>"); exchange.getIn().setHeader(Exchange.XSLT_FILE_NAME, "target/xslt/xsltout.xml"); builder.process(exchange); assertIsInstanceOf(File.class, exchange.getOut().getBody()); File file = new File("target/xslt/xsltout.xml"); assertTrue("Output file should exist", file.exists()); String body = exchange.getOut().getBody(String.class); assertTrue(body.endsWith("<goodbye>world!</goodbye>")); // now done the exchange List<Synchronization> onCompletions = exchange.handoverCompletions(); UnitOfWorkHelper.doneSynchronizations(exchange, onCompletions, log); // the file should be deleted assertFalse("Output file should be deleted", file.exists()); }
@Test public void testPopupalteExchangeFromCxfResponseOfNullBody() { DefaultCxfBinding cxfBinding = new DefaultCxfBinding(); cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy()); Exchange exchange = new DefaultExchange(context); org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl(); exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD); Map<String, Object> responseContext = new HashMap<String, Object>(); responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200)); Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers); org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl(); cxfExchange.setInMessage(cxfMessage); cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext); CxfPayload<?> cxfPayload = exchange.getOut().getBody(CxfPayload.class); assertNotNull(cxfPayload); List<?> body = cxfPayload.getBody(); assertNotNull(body); assertEquals(0, body.size()); }
@Test public void testFallbackConverterWithoutObjectFactory() throws Exception { TypeConverter converter = context.getTypeConverter(); Foo foo = converter.convertTo(Foo.class, "<foo><zot name=\"bar1\" value=\"value\" otherValue=\"otherValue\"/></foo>"); assertNotNull("foo should not be null", foo); assertEquals("value", foo.getBarRefs().get(0).getValue()); foo.getBarRefs().clear(); Bar bar = new Bar(); bar.setName("myName"); bar.setValue("myValue"); foo.getBarRefs().add(bar); Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); String value = converter.convertTo(String.class, exchange, foo); assertTrue("Should get a right marshalled string", value.indexOf("<bar name=\"myName\" value=\"myValue\"/>") > 0); }
public void testFailNullBody() throws Exception { URL styleSheet = getClass().getResource("example.xsl"); XsltBuilder builder = XsltBuilder.xslt(styleSheet); builder.setFailOnNullBody(true); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody(null); try { builder.process(exchange); fail("Should thrown an exception"); } catch (ExpectedBodyTypeException e) { // expected } }
@Test public void testExpressionField() throws Exception { Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody(new File("src/test/resources/type.json")); Language lan = context.resolveLanguage("jsonpath"); Expression exp = lan.createExpression("$.kind"); String kind = exp.evaluate(exchange, String.class); assertNotNull(kind); assertEquals("full", kind); exp = lan.createExpression("$.type"); String type = exp.evaluate(exchange, String.class); assertNotNull(type); assertEquals("customer", type); }
@Test public void testmakeAsyncApiCall() { try { getMockEndpoint("mock:seda:start").expectedHeaderReceived("username", "admin123"); getMockEndpoint("mock:seda:start").expectedBodiesReceived("Hello"); DefaultExchange dfex = new DefaultExchange(context); dfex.getIn().setHeader("username", "admin123"); dfex.getIn().setHeader("password", "admin"); dfex.getIn().setBody("Hello"); template.asyncSend("seda:start", dfex); assertMockEndpointsSatisfied(); } catch (Exception e) { e.printStackTrace(); assertTrue("Failed to make async call to api", false); } }
@Test public void execute() throws Exception { Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut); exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm"); exchange.getIn().setHeader(SmppConstants.ID, "1"); exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value()); exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value()); exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818"); exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111)); exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222)); exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value()); exchange.getIn().setBody("new short message body"); session.replaceShortMessage(eq("1"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), eq("-300101001831100+"), eq("-300101003702200+"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq((byte) 0), aryEq("new short message body".getBytes())); replay(session); command.execute(exchange); verify(session); assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID)); }
@Test public void executeWithConfigurationData() throws Exception { Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut); exchange.getIn().setHeader(SmppConstants.COMMAND, "QuerySm"); exchange.getIn().setHeader(SmppConstants.ID, "1"); expect(session.queryShortMessage("1", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1616")) .andReturn(new QuerySmResult("-300101010000004+", MessageState.DELIVERED, (byte) 0)); replay(session); command.execute(exchange); verify(session); assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID)); assertEquals("DELIVERED", exchange.getOut().getHeader(SmppConstants.MESSAGE_STATE)); assertEquals((byte) 0, exchange.getOut().getHeader(SmppConstants.ERROR)); assertNotNull(exchange.getOut().getHeader(SmppConstants.FINAL_DATE)); }
@Test public void testExpressionArray() throws Exception { Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody(new File("src/test/resources/books.json")); Language lan = context.resolveLanguage("jsonpath"); Expression exp = lan.createExpression("$.store.book[*].author"); List<?> authors = exp.evaluate(exchange, List.class); log.debug("Authors {}", authors); assertNotNull(authors); assertEquals(2, authors.size()); assertEquals("Nigel Rees", authors.get(0)); assertEquals("Evelyn Waugh", authors.get(1)); exp = lan.createExpression("$.store.bicycle.price"); String price = exp.evaluate(exchange, String.class); assertEquals("Got a wrong result", "19.95", price); }
public void testHandleErrorsResult() throws Exception { DefaultValidationErrorHandler eh = new DefaultValidationErrorHandler(); eh.error(new SAXParseException("foo", createLocator(3, 5))); eh.error(new SAXParseException("bar", createLocator(9, 12))); assertEquals(false, eh.isValid()); Exchange exchange = new DefaultExchange(context); try { eh.handleErrors(exchange, createScheme(), new SAXResult()); fail("Should have thrown an exception"); } catch (SchemaValidationException e) { assertEquals(2, e.getErrors().size()); assertEquals(0, e.getFatalErrors().size()); assertEquals(0, e.getWarnings().size()); assertNotNull(e.getSchema()); assertNotNull(e.getExchange()); assertTrue(e.getMessage().startsWith("Validation failed for: org.apache.camel.processor.validation.DefaultValidationErrorHandlerTest")); assertTrue(e.getMessage().contains("errors: [")); assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: foo, Line : 3, Column : 5")); assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: bar, Line : 9, Column : 12")); assertTrue(e.getMessage().contains("Exchange[]")); } }
public void testLogStringDurationIsNotZero() throws Exception { CamelContext camel = new DefaultCamelContext(); camel.start(); Logger logger = EasyMock.createMock(Logger.class); logger.isInfoEnabled(); EasyMock.expectLastCall().andReturn(true).atLeastOnce(); logger.info(EasyMock.startsWith("Received: 10")); EasyMock.expectLastCall().once(); logger.info(EasyMock.startsWith("Received: 20")); EasyMock.expectLastCall().once(); EasyMock.replay(logger); ThroughputLogger underTest = new ThroughputLogger(new CamelLogger(logger)); underTest.setGroupSize(10); for (int i = 0; i < 25; i++) { underTest.process(new DefaultExchange(camel)); } EasyMock.verify(logger); camel.stop(); }
@Test public void testConfirmExist() { // Given for (int i = 1; i < 4; i++) { String key = "Confirm_" + i; Exchange exchange = new DefaultExchange(camelContext); exchange.setExchangeId("Exchange_" + i); aggregationRepository.add(camelContext, key, exchange); assertTrue(exists(key)); } // When aggregationRepository.confirm(camelContext, "Exchange_2"); // Then assertTrue(exists("Confirm_1")); assertFalse(exists("Confirm_2")); assertTrue(exists("Confirm_3")); }
@Test public void testWithAlotOfDataSameKey() { LevelDBAggregationRepository repo = new LevelDBAggregationRepository(); repo.setLevelDBFile(levelDBFile); repo.setRepositoryName("repo1"); for (int i = 0; i < 100; i++) { Exchange exchange1 = new DefaultExchange(context); exchange1.getIn().setBody("counter:" + i); repo.add(context, "foo", exchange1); } // Get it back.. Exchange actual = repo.get(context, "foo"); assertEquals("counter:99", actual.getIn().getBody()); }
public void testDumpAsXmlNoBody() throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); message = new DefaultExchange(context).getIn(); // xml message body message.setBody("Hello World"); message.setHeader("foo", 123); String out = MessageHelper.dumpAsXml(message, false); assertEquals("<message exchangeId=\"" + message.getExchange().getExchangeId() + "\">" + "\n <headers>\n <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n </headers>\n</message>", out); context.stop(); }
public void testMessageDump() throws Exception { JAXBContext jaxb = JAXBContext.newInstance(MessageDump.class); Unmarshaller unmarshaller = jaxb.createUnmarshaller(); CamelContext context = new DefaultCamelContext(); context.start(); message = new DefaultExchange(context).getIn(); // xml message body message.setBody("Hello World"); message.setHeader("foo", 123); String out = MessageHelper.dumpAsXml(message, true); MessageDump dump = (MessageDump) unmarshaller.unmarshal(new StringReader(out)); assertNotNull(dump); assertEquals("java.lang.String", dump.getBody().getType()); assertEquals("Hello World", dump.getBody().getValue()); assertEquals(1, dump.getHeaders().size()); assertEquals("foo", dump.getHeaders().get(0).getKey()); assertEquals("java.lang.Integer", dump.getHeaders().get(0).getType()); assertEquals("123", dump.getHeaders().get(0).getValue()); }
@Test public void testPutAndGetNotFound() { LevelDBAggregationRepository repo = new LevelDBAggregationRepository(); repo.setLevelDBFile(levelDBFile); repo.setRepositoryName("repo1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); log.info("Created " + exchange.getExchangeId()); repo.add(context, exchange.getExchangeId(), exchange); Exchange out = repo.get(context, exchange.getExchangeId()); assertNotNull("Should find exchange", out); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); log.info("Created " + exchange2.getExchangeId()); Exchange out2 = repo.get(context, exchange2.getExchangeId()); assertNull("Should not find exchange", out2); }
@Test public void executeWithConfigurationData() throws Exception { Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut); exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm"); expect(session.dataShortMessage(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1717"), eq(new ESMClass()), eq(new RegisteredDelivery((byte) 1)), eq(DataCodings.newInstance((byte) 0)))) .andReturn(new DataSmResult(new MessageId("1"), null)); replay(session); command.execute(exchange); verify(session); assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID)); assertNull(exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS)); }
@Test public void testCandidateParsing() throws Exception { Exchange ex = new DefaultExchange(new DefaultCamelContext()); ex.getIn().setBody(candidate); processor.process(ex); assertEquals(ex.getIn().getBody().getClass(),IceCandidate.class); }
@Test public void testSDPParsing() throws Exception { Exchange ex = new DefaultExchange(new DefaultCamelContext()); ex.getIn().setBody(offerSdp); processor.process(ex); assertEquals(ex.getIn().getBody().getClass(),Offer.class); }
@Test public void testSDPParseAnswer() throws Exception { Exchange ex = new DefaultExchange(new DefaultCamelContext()); ex.getIn().setBody(answerSdp); processor.process(ex); assertEquals(ex.getIn().getBody().getClass(),Answer.class); }
/** * Creates a new {@link Exchange} from <code>packet</code> using the * current {@link CamelContext}. * * @param packet message packet. * @return a new message exchange. */ protected Exchange createExchange(PlatformPacket packet) { DefaultExchange exchange = new DefaultExchange(camelContext); exchange.setUnitOfWork(new DefaultUnitOfWork(exchange)); exchange.setProperties(new HashMap<>(packet.getExchangeProperties())); exchange.getIn().setHeaders(new HashMap<>(packet.getMessageProperties())); setInBody(packet.getMessageBody(), exchange); return exchange; }
private Exchange createExchangeWithOptionalHttpQueryAndHttpMethodHeader(String httpQuery, HttpMethods httpMethod) { CamelContext context = new DefaultCamelContext(); Exchange exchange = new DefaultExchange(context); Message inMsg = exchange.getIn(); if (httpQuery != null) { inMsg.setHeader(Exchange.HTTP_QUERY, httpQuery); } if (httpMethod != null) { inMsg.setHeader(Exchange.HTTP_METHOD, httpMethod); } return exchange; }
private Exchange generateExchange(final String method, final String uri) throws Exception { LOGGER.info("Producer template: {}", super.getProducerTemplate()); Exchange exchange = new DefaultExchange(super.getProducerTemplate().getCamelContext()); exchange.getIn().setHeader(Exchange.HTTP_METHOD, method); exchange.getIn().setHeader(Exchange.HTTP_URI, uri); exchange.getIn().setHeader("stop", "now"); return exchange; }
@Before public void setUp() { sdbClient = new AmazonSDBClientMock(); configuration = new SdbConfiguration(); configuration.setDomainName("DOMAIN1"); exchange = new DefaultExchange(new DefaultCamelContext()); command = new PutAttributesCommand(sdbClient, configuration, exchange); }
@Test public void executeWithValidityPeriodAsString() throws Exception { Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut); exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm"); exchange.getIn().setHeader(SmppConstants.ID, "1"); exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value()); exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value()); exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818"); exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value()); exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value()); exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919"); exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111)); exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, "000003000000000R"); // three days exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1); exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2); exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value()); exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value()); exchange.getIn().setBody("short message body"); expect(session.submitShortMessage(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), eq(TypeOfNumber.INTERNATIONAL), eq(NumberingPlanIndicator.INTERNET), eq("1919"), eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100+"), eq("000003000000000R"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq(ReplaceIfPresentFlag.REPLACE.value()), eq(DataCodings.newInstance((byte) 0)), eq((byte) 0), aryEq("short message body".getBytes()))) .andReturn("1"); replay(session); command.execute(exchange); verify(session); assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID)); assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT)); }
@Test public void testGetNotFound() { LevelDBAggregationRepository repo = new LevelDBAggregationRepository(); repo.setLevelDBFile(levelDBFile); repo.setRepositoryName("repo1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); Exchange out = repo.get(context, exchange.getExchangeId()); assertNull("Should not find exchange", out); }
@Test public void testPopulateCxfRequestFromExchange() { DefaultCxfBinding cxfBinding = new DefaultCxfBinding(); cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy()); Exchange exchange = new DefaultExchange(context); org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl(); exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD); Map<String, Object> requestContext = new HashMap<String, Object>(); exchange.getIn().setHeader("soapAction", "urn:hello:world"); exchange.getIn().setHeader("MyFruitHeader", "peach"); exchange.getIn().setHeader("MyBrewHeader", Arrays.asList("cappuccino", "espresso")); exchange.getIn().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml"))); cxfBinding.populateCxfRequestFromExchange(cxfExchange, exchange, requestContext); // check the protocol headers Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)requestContext.get(Message.PROTOCOL_HEADERS)); assertNotNull(headers); assertEquals(3, headers.size()); verifyHeader(headers, "soapaction", "urn:hello:world"); verifyHeader(headers, "SoapAction", "urn:hello:world"); verifyHeader(headers, "SOAPAction", "urn:hello:world"); verifyHeader(headers, "myfruitheader", "peach"); verifyHeader(headers, "myFruitHeader", "peach"); verifyHeader(headers, "MYFRUITHEADER", "peach"); verifyHeader(headers, "MyBrewHeader", Arrays.asList("cappuccino", "espresso")); Set<Attachment> attachments = CastUtils.cast((Set<?>)requestContext.get(CxfConstants.CAMEL_CXF_ATTACHMENTS)); assertNotNull(attachments); assertNotNull(attachments.size() == 1); Attachment att = attachments.iterator().next(); assertEquals("att-1", att.getId()); }
public void testCollectionProducer() throws Exception { Queue<Exchange> queue = new ArrayBlockingQueue<Exchange>(10); Endpoint endpoint = context.getEndpoint("seda://foo"); MyProducer my = new MyProducer(endpoint, queue); my.start(); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); my.process(exchange); Exchange top = queue.poll(); assertNotNull(top); assertEquals("Hello World", top.getIn().getBody()); }
public void testBeanInfoOverloaded() throws Exception { BeanInfo beanInfo = new BeanInfo(context, Bean.class); Message message = new DefaultMessage(); message.setBody(new RequestB()); Exchange exchange = new DefaultExchange(context); exchange.setIn(message); MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange); Method method = methodInvocation.getMethod(); assertEquals("doSomething", method.getName()); assertEquals(RequestB.class, method.getGenericParameterTypes()[0]); }
protected void setUp() throws Exception { super.setUp(); deleteDirectory("target/cachedir"); createDirectory("target/cachedir"); exchange = new DefaultExchange(context); UnitOfWork uow = new DefaultUnitOfWork(exchange); exchange.setUnitOfWork(uow); }
@Test public void createSmppSubmitMultiCommand() { SMPPSession session = new SMPPSession(); Exchange exchange = new DefaultExchange(new DefaultCamelContext()); exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti"); SmppCommand command = binding.createSmppCommand(session, exchange); assertTrue(command instanceof SmppSubmitMultiCommand); }
private void addExchanges(String... keys) { for (String key : keys) { Exchange exchange = new DefaultExchange(camelContext); exchange.setExchangeId("Exchange-" + key); aggregationRepository.add(camelContext, key, exchange); } }
public void testInstanceMethodConversionWithExchange() throws Exception { String[] values = new String[]{"5", "bar"}; CamelContext camel = new DefaultCamelContext(); Exchange e = new DefaultExchange(camel); e.setProperty("prefix", "foo-"); MyBean bean = converter.convertTo(MyBean.class, e, values); assertEquals("converted using exchange", 5, bean.getFoo(), 5); assertEquals("converted using exchange", "foo-bar", bean.getBar()); }
public void testNoHandlerAmbigious() throws Exception { BeanInfo info = new BeanInfo(context, MyNoHandlerBean.class); Exchange exchange = new DefaultExchange(context); MyNoHandlerBean pojo = new MyNoHandlerBean(); try { info.createInvocation(pojo, exchange); fail("Should throw exception"); } catch (AmbiguousMethodCallException e) { assertEquals(3, e.getMethods().size()); } }
@Before public void setUp() { sdbClient = new AmazonSDBClientMock(); configuration = new SdbConfiguration(); configuration.setDomainName("DOMAIN1"); configuration.setConsistentRead(Boolean.TRUE); exchange = new DefaultExchange(new DefaultCamelContext()); command = new SelectCommand(sdbClient, configuration, exchange); }
@Override @Before public void setUp() throws Exception { exchange = new DefaultExchange(new DefaultCamelContext()); exchange.getIn().setHeader("foo.bar", "cheese"); exchange.getIn().setHeader("name", "James"); }