Coverage Report - org.apache.camel.component.mock.AssertionClause
 
Classes in this File Line Coverage Branch Coverage Complexity
AssertionClause
62% 
100% 
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 org.apache.camel.component.mock;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.camel.Exchange;
 23  
 import org.apache.camel.Expression;
 24  
 import org.apache.camel.Predicate;
 25  
 import org.apache.camel.builder.ValueBuilder;
 26  
 
 27  
 import static org.apache.camel.builder.ExpressionBuilder.bodyExpression;
 28  
 import static org.apache.camel.builder.ExpressionBuilder.headerExpression;
 29  
 
 30  
 /**
 31  
  * A builder of assertions on message exchanges
 32  
  * 
 33  
  * @version $Revision: 1.1 $
 34  
  */
 35  12
 public abstract class AssertionClause<E extends Exchange> implements Runnable {
 36  
 
 37  12
     private List<Predicate<E>> predicates = new ArrayList<Predicate<E>>();
 38  
 
 39  
     // Builder methods
 40  
     // -------------------------------------------------------------------------
 41  
 
 42  
     /**
 43  
      * Adds the given predicate to this assertion clause
 44  
      */
 45  
     public AssertionClause<E> predicate(Predicate<E> predicate) {
 46  0
         addPredicate(predicate);
 47  0
         return this;
 48  
     }
 49  
 
 50  
     /**
 51  
      * Returns a predicate and value builder for headers on an exchange
 52  
      */
 53  
 
 54  
     public ValueBuilder<E> header(String name) {
 55  12
         Expression<E> expression = headerExpression(name);
 56  12
         return new PredicateValueBuilder(expression);
 57  
     }
 58  
 
 59  
     /**
 60  
      * Returns a predicate and value builder for the inbound body on an exchange
 61  
      */
 62  
 
 63  
     public PredicateValueBuilder body() {
 64  0
         Expression<E> expression = bodyExpression();
 65  0
         return new PredicateValueBuilder(expression);
 66  
     }
 67  
 
 68  
     /**
 69  
      * Returns a predicate and value builder for the inbound message body as a
 70  
      * specific type
 71  
      */
 72  
 
 73  
     public <T> PredicateValueBuilder bodyAs(Class<T> type) {
 74  0
         Expression<E> expression = bodyExpression(type);
 75  0
         return new PredicateValueBuilder(expression);
 76  
     }
 77  
 
 78  
     /**
 79  
      * Returns a predicate and value builder for the outbound body on an
 80  
      * exchange
 81  
      */
 82  
 
 83  
     public PredicateValueBuilder outBody() {
 84  0
         Expression<E> expression = bodyExpression();
 85  0
         return new PredicateValueBuilder(expression);
 86  
     }
 87  
 
 88  
     /**
 89  
      * Returns a predicate and value builder for the outbound message body as a
 90  
      * specific type
 91  
      */
 92  
 
 93  
     public <T> PredicateValueBuilder outBody(Class<T> type) {
 94  0
         Expression<E> expression = bodyExpression(type);
 95  0
         return new PredicateValueBuilder(expression);
 96  
     }
 97  
 
 98  
     /**
 99  
      * Performs any assertions on the given exchange
 100  
      */
 101  
     protected void applyAssertionOn(MockEndpoint endpoint, int index, E exchange) {
 102  12
         for (Predicate<E> predicate : predicates) {
 103  12
             predicate.assertMatches(endpoint.getEndpointUri() + " ", exchange);
 104  12
         }
 105  12
     }
 106  
 
 107  
     protected void addPredicate(Predicate<E> predicate) {
 108  12
         predicates.add(predicate);
 109  12
     }
 110  
 
 111  12
     public class PredicateValueBuilder extends ValueBuilder<E> {
 112  
 
 113  12
         public PredicateValueBuilder(Expression<E> expression) {
 114  12
             super(expression);
 115  12
         }
 116  
 
 117  
         protected Predicate<E> onNewPredicate(Predicate<E> predicate) {
 118  12
             addPredicate(predicate);
 119  12
             return predicate;
 120  
         }
 121  
     }
 122  
 }