View Javadoc
1   package org.apache.onami.lifecycle.core;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  import java.util.ArrayList;
26  import java.util.Arrays;
27  import java.util.List;
28  
29  public class StagingOrderTestCase
30  {
31      @Test
32      public void testFifo()
33      {
34          List<Integer> order = new ArrayList<Integer>();
35          DefaultStager<TestAnnotationA> stager = makeStager( order, DefaultStager.Order.FIRST_IN_FIRST_OUT );
36          stager.stage();
37  
38          Assert.assertEquals( Arrays.asList( 1, 2, 3 ), order );
39      }
40  
41      @Test
42      public void testFilo()
43      {
44          List<Integer> order = new ArrayList<Integer>();
45          DefaultStager<TestAnnotationA> stager = makeStager( order, DefaultStager.Order.FIRST_IN_LAST_OUT );
46          stager.stage();
47  
48          Assert.assertEquals( Arrays.asList( 3, 2, 1 ), order );
49      }
50  
51      private DefaultStager<TestAnnotationA> makeStager( final List<Integer> order, DefaultStager.Order stagingOrder )
52      {
53          Stageable stageable1 = new Stageable()
54          {
55              @Override
56              public void stage( StageHandler stageHandler )
57              {
58                  order.add( 1 );
59              }
60          };
61          Stageable stageable2 = new Stageable()
62          {
63              @Override
64              public void stage( StageHandler stageHandler )
65              {
66                  order.add( 2 );
67              }
68          };
69          Stageable stageable3 = new Stageable()
70          {
71              @Override
72              public void stage( StageHandler stageHandler )
73              {
74                  order.add( 3 );
75              }
76          };
77  
78          DefaultStager<TestAnnotationA> stager =
79              new DefaultStager<TestAnnotationA>( TestAnnotationA.class, stagingOrder );
80          stager.register( stageable1 );
81          stager.register( stageable2 );
82          stager.register( stageable3 );
83          return stager;
84      }
85  }