1 package org.apache.archiva.redback.struts2.interceptor;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
34 @RunWith( SpringJUnit4ClassRunner.class )
35 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
36 public class SimpleActionInvocationTrackerTest
39 private static final int HISTORY_SIZE = 2;
41 private ActionInvocationTracker tracker;
46 protected String getPlexusConfigLocation()
56 tracker = new SimpleActionInvocationTracker();
60 public void testAddActionInvocation()
63 tracker.setHistorySize( HISTORY_SIZE );
65 tracker.addActionInvocation( new ActionInvocationStub() );
66 assertEquals( 1, tracker.getHistoryCount() );
68 // first entry int the stack
69 SavedActionInvocation actionInvocation = tracker.getActionInvocationAt( 0 );
70 Map<String,Object> parametersMap = actionInvocation.getParametersMap();
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 ) );
78 ActionInvocationStub actionInvocationStub = new ActionInvocationStub();
80 ActionProxyStub proxyStub = (ActionProxyStub) actionInvocationStub.getProxy();
81 proxyStub.setActionName( "new_action" );
82 proxyStub.setMethod( "new_method" );
84 ActionContextStub actionContextStub = (ActionContextStub) actionInvocationStub.getInvocationContext();
85 actionContextStub.getParameters().put( "new_parameter", "new_value" );
87 tracker.addActionInvocation( actionInvocationStub );
88 assertEquals( tracker.getHistoryCount(), HISTORY_SIZE );
90 // second entry in the stack
91 actionInvocation = tracker.getActionInvocationAt( 1 );
92 parametersMap = actionInvocation.getParametersMap();
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" ) );
101 // first entry int the stack
102 actionInvocation = tracker.getActionInvocationAt( 0 );
103 parametersMap = actionInvocation.getParametersMap();
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 ) );
113 public void testHistoryCounter()
116 tracker.setHistorySize( HISTORY_SIZE );
117 tracker.addActionInvocation( new ActionInvocationStub() );
118 assertEquals( 1, tracker.getHistoryCount() );
120 tracker.setHistorySize( HISTORY_SIZE );
121 tracker.addActionInvocation( new ActionInvocationStub() );
122 assertEquals( HISTORY_SIZE, tracker.getHistoryCount() );
124 tracker.addActionInvocation( new ActionInvocationStub() );
125 tracker.addActionInvocation( new ActionInvocationStub() );
126 tracker.addActionInvocation( new ActionInvocationStub() );
127 assertEquals( HISTORY_SIZE, tracker.getHistoryCount() );
129 tracker.addActionInvocation( new ActionInvocationStub() );
130 tracker.addActionInvocation( new ActionInvocationStub() );
131 tracker.addActionInvocation( new ActionInvocationStub() );
132 assertEquals( HISTORY_SIZE, tracker.getHistoryCount() );