]> source.dussan.org Git - archiva.git/blob
a23bcdfce3ef152f8c2c8db346b53dbaaa532182
[archiva.git] /
1 package org.apache.archiva.redback.struts2.interceptor;
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 junit.framework.TestCase;
23 import org.apache.archiva.redback.struts2.ActionContextStub;
24 import org.apache.archiva.redback.struts2.ActionInvocationStub;
25 import org.apache.archiva.redback.struts2.ActionProxyStub;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.springframework.test.context.ContextConfiguration;
30 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31
32 import java.util.Map;
33
34 @RunWith( SpringJUnit4ClassRunner.class )
35 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
36 public class SimpleActionInvocationTrackerTest
37     extends TestCase
38 {
39     private static final int HISTORY_SIZE = 2;
40
41     private ActionInvocationTracker tracker;
42
43     
44     
45
46     protected String getPlexusConfigLocation()
47     {
48         return "plexus.xml";
49     }
50
51     @Before
52     public void setUp()
53         throws Exception
54     {
55         super.setUp();
56         tracker = new SimpleActionInvocationTracker();
57     }
58
59     @Test
60     public void testAddActionInvocation()
61         throws Exception
62     {
63         tracker.setHistorySize( HISTORY_SIZE );
64
65         tracker.addActionInvocation( new ActionInvocationStub() );
66         assertEquals( 1, tracker.getHistoryCount() );
67
68         // first entry int the stack
69         SavedActionInvocation actionInvocation = tracker.getActionInvocationAt( 0 );
70         Map<String,Object> parametersMap = actionInvocation.getParametersMap();
71
72         assertEquals( ActionProxyStub.ACTION_NAME, actionInvocation.getActionName() );
73         assertEquals( ActionProxyStub.METHOD, actionInvocation.getMethodName() );
74         assertEquals( ActionContextStub.VALUE_1, parametersMap.get( ActionContextStub.PARAMETER_1 ) );
75         assertEquals( ActionContextStub.VALUE_2, parametersMap.get( ActionContextStub.PARAMETER_2 ) );
76         assertEquals( ActionContextStub.VALUE_3, parametersMap.get( ActionContextStub.PARAMETER_3 ) );
77
78         ActionInvocationStub actionInvocationStub = new ActionInvocationStub();
79
80         ActionProxyStub proxyStub = (ActionProxyStub) actionInvocationStub.getProxy();
81         proxyStub.setActionName( "new_action" );
82         proxyStub.setMethod( "new_method" );
83
84         ActionContextStub actionContextStub = (ActionContextStub) actionInvocationStub.getInvocationContext();
85         actionContextStub.getParameters().put( "new_parameter", "new_value" );
86
87         tracker.addActionInvocation( actionInvocationStub );
88         assertEquals( tracker.getHistoryCount(), HISTORY_SIZE );
89
90         // second entry in the stack
91         actionInvocation = tracker.getActionInvocationAt( 1 );
92         parametersMap = actionInvocation.getParametersMap();
93
94         assertEquals( "new_action", actionInvocation.getActionName() );
95         assertEquals( "new_method", actionInvocation.getMethodName() );
96         assertEquals( ActionContextStub.VALUE_1, parametersMap.get( ActionContextStub.PARAMETER_1 ) );
97         assertEquals( ActionContextStub.VALUE_2, parametersMap.get( ActionContextStub.PARAMETER_2 ) );
98         assertEquals( ActionContextStub.VALUE_3, parametersMap.get( ActionContextStub.PARAMETER_3 ) );
99         assertEquals( "new_value", parametersMap.get( "new_parameter" ) );
100
101         // first entry int the stack
102         actionInvocation = tracker.getActionInvocationAt( 0 );
103         parametersMap = actionInvocation.getParametersMap();
104
105         assertEquals( ActionProxyStub.ACTION_NAME, actionInvocation.getActionName() );
106         assertEquals( ActionProxyStub.METHOD, actionInvocation.getMethodName() );
107         assertEquals( ActionContextStub.VALUE_1, parametersMap.get( ActionContextStub.PARAMETER_1 ) );
108         assertEquals( ActionContextStub.VALUE_2, parametersMap.get( ActionContextStub.PARAMETER_2 ) );
109         assertEquals( ActionContextStub.VALUE_3, parametersMap.get( ActionContextStub.PARAMETER_3 ) );
110     }
111
112     @Test
113     public void testHistoryCounter()
114         throws Exception
115     {
116         tracker.setHistorySize( HISTORY_SIZE );
117         tracker.addActionInvocation( new ActionInvocationStub() );
118         assertEquals( 1, tracker.getHistoryCount() );
119
120         tracker.setHistorySize( HISTORY_SIZE );
121         tracker.addActionInvocation( new ActionInvocationStub() );
122         assertEquals( HISTORY_SIZE, tracker.getHistoryCount() );
123
124         tracker.addActionInvocation( new ActionInvocationStub() );
125         tracker.addActionInvocation( new ActionInvocationStub() );
126         tracker.addActionInvocation( new ActionInvocationStub() );
127         assertEquals( HISTORY_SIZE, tracker.getHistoryCount() );
128
129         tracker.addActionInvocation( new ActionInvocationStub() );
130         tracker.addActionInvocation( new ActionInvocationStub() );
131         tracker.addActionInvocation( new ActionInvocationStub() );
132         assertEquals( HISTORY_SIZE, tracker.getHistoryCount() );
133     }
134
135 }