View Javadoc
1   package org.codehaus.plexus.test;
2   
3   import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
4   import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
5   import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException;
6   import junit.framework.Assert;
7   import static junit.framework.Assert.assertTrue;
8   
9   public class AbstractStartableComponent
10      implements StartableComponent, Startable
11  {
12      public int startOrder;
13  
14      public int stopOrder;
15  
16      public AbstractStartableComponent component1;
17  
18      public AbstractStartableComponent component2;
19  
20      public void start()
21          throws StartingException
22      {
23          startOrder = startGenerator.getAndIncrement();
24      }
25  
26      public void stop()
27          throws StoppingException
28      {
29          stopOrder = stopGenerator.getAndIncrement();
30      }
31  
32      public void assertStartOrderCorrect()
33      {
34          if ( component1 != null )
35          {
36              assertTrue( "This component started before injected component1", startOrder > component1.startOrder );
37          }
38          if ( component2 != null )
39          {
40              assertTrue( "This component started before injected component2", startOrder > component2.startOrder );
41          }
42  
43          // assert children are correct
44          if ( component1 != null )
45          {
46              component1.assertStartOrderCorrect();
47          }
48          if ( component2 != null )
49          {
50              component2.assertStartOrderCorrect();
51          }
52      }
53  
54      public void assertStopOrderCorrect()
55      {
56          if ( component1 != null )
57          {
58              assertTrue( "This component stopped after injected component1", stopOrder < component1.stopOrder );
59          }
60          if ( component2 != null )
61          {
62              assertTrue( "This component stopped after injected component2", stopOrder < component2.stopOrder );
63          }
64  
65          // assert children are correct
66          if ( component1 != null )
67          {
68              component1.assertStopOrderCorrect();
69          }
70          if ( component2 != null )
71          {
72              component2.assertStopOrderCorrect();
73          }
74      }
75  }