Advertisement
Guest User

Untitled

a guest
Dec 13th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package copyFromCamel;
  18.  
  19. import org.apache.camel.builder.AdviceWithRouteBuilder;
  20. import org.apache.camel.builder.RouteBuilder;
  21. import org.apache.camel.test.junit4.CamelTestSupport;
  22. import org.junit.Test;
  23.  
  24. /**
  25. * Advice with tests
  26. */
  27. public class AdviceWithWeaveFirstLastTest extends CamelTestSupport {
  28.  
  29. @Override
  30. public boolean isUseAdviceWith() {
  31. return true;
  32. }
  33.  
  34. @Test
  35. public void testWeaveAddFirst() throws Exception {
  36. // START SNIPPET: e1
  37. context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
  38. @Override
  39. public void configure() throws Exception {
  40. // insert at first the given piece of route to the existing route
  41. weaveAddFirst().to("mock:a").transform(constant("Bye World"));
  42. }
  43. });
  44. // END SNIPPET: e1
  45.  
  46. context.start();
  47.  
  48. getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
  49. getMockEndpoint("mock:foo").expectedBodiesReceived("Bye World");
  50. getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
  51. getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
  52.  
  53. template.sendBody("direct:start", "Hello World");
  54.  
  55. assertMockEndpointsSatisfied();
  56. }
  57.  
  58. @Test
  59. public void testWeaveAddLast() throws Exception {
  60. // START SNIPPET: e2
  61. context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
  62. @Override
  63. public void configure() throws Exception {
  64. // insert at the end of the existing route, the given piece of route
  65. weaveAddLast().to("mock:a").transform(constant("Bye World"));
  66. }
  67. });
  68. // END SNIPPET: e2
  69.  
  70. context.start();
  71.  
  72. getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
  73. getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
  74. getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
  75. getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
  76.  
  77. Object out = template.requestBody("direct:start", "Hello World");
  78. assertEquals("Bye World", out);
  79.  
  80. assertMockEndpointsSatisfied();
  81. }
  82.  
  83. @Override
  84. protected RouteBuilder createRouteBuilder() throws Exception {
  85. return new RouteBuilder() {
  86. @Override
  87. public void configure() throws Exception {
  88. // START SNIPPET: e5
  89. from("direct:start")
  90. .to("mock:foo")
  91. .to("mock:bar").id("bar")
  92. .to("mock:result");
  93. // END SNIPPET: e5
  94. }
  95. };
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement