Coverage Report - org.apache.commons.pipeline.testFramework.TestStage
 
Classes in this File Line Coverage Branch Coverage Complexity
TestStage
100%
24/24
N/A
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  
 
 18  
 package org.apache.commons.pipeline.testFramework;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collections;
 22  
 import java.util.List;
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 import org.apache.commons.pipeline.Stage;
 26  
 import org.apache.commons.pipeline.StageContext;
 27  
 import org.apache.commons.pipeline.StageException;
 28  
 import org.apache.commons.pipeline.validation.ConsumedTypes;
 29  
 import org.apache.commons.pipeline.validation.ProducesConsumed;
 30  
 
 31  
 @ConsumedTypes(Object.class)
 32  
 @ProducesConsumed
 33  
 public class TestStage implements Stage {
 34  37
     private Log log = LogFactory.getLog(TestStage.class);
 35  
     private int index;
 36  
     private StageContext context;
 37  
 
 38  37
     public List<Object> processedObjects = Collections.synchronizedList(new ArrayList<Object>());
 39  37
     public boolean initialized = false;
 40  37
     public boolean preprocessed = false;
 41  37
     public boolean postprocessed = false;
 42  37
     public boolean released = false;
 43  
     
 44  
     /**
 45  
      * Construct a TestStage with a numeric index used to easily identify this stage. 
 46  
      * The {@link getIndex} and {@link toString} methods use this index.
 47  
      * @param index acts as an identification number
 48  
      */
 49  37
     public TestStage(int index) {
 50  37
         this.index = index;
 51  37
     }
 52  
     
 53  
     public int getIndex() {
 54  2
         return this.index;
 55  
     }
 56  
 
 57  
     public void init(StageContext context) {        
 58  35
         this.context = context;
 59  35
         this.initialized = true;
 60  35
     }
 61  
     
 62  
     public void preprocess() throws StageException {
 63  21
         this.preprocessed = true;
 64  21
     }
 65  
 
 66  
     public void process(Object obj) throws StageException {
 67  38
         log.info(this + " is processing object " + obj);
 68  38
         this.processedObjects.add(obj);
 69  38
         this.context.getDownstreamFeeder(this).feed(obj);
 70  38
     }
 71  
     
 72  
     public void postprocess() throws StageException {
 73  21
         this.postprocessed = true;
 74  21
     }
 75  
 
 76  
     public void release() {
 77  21
         this.released = true;
 78  21
     }
 79  
 
 80  
     public String toString() {
 81  252
         return "TEST STAGE (" + this.index + ")";
 82  
     }
 83  
 }