At line 15 added 1 line. |
* [6] Test that it all works |
At line 170 changed 1 line. |
You can see that I added those comment tags so we can remove the method security during the unit tests. |
You can see the comment tags surrounding the interceptor so we can remove the method security during the unit tests. |
At line 173 changed 1 line. |
Now we need to modify {{build.xml}} so the Method Security interceptor will be removed during the unit tests. |
Now we need to modify {{build.xml}} to take advantage of those comment tags we just added to {{applicationContext-security.xml}}. In the {{test-module}} target we need to add a regular expression replace task to remove the XML between out comment tags. I changed the beginning of {{test-module}} target to look like this: |
{{{ <target name="test-module"> |
<!-- Inputs: module, test.classpath --> |
<echo level="info">Testing ${module}...</echo> |
<mkdir dir="${test.dir}/data"/> |
<propertycopy name="testcase" from="${module}-testcase" silent="true"/> |
<!-- Replace tokens in test properties files --> |
<copy todir="${test.dir}/${module}/classes"> |
<fileset dir="test/${module}" excludes="**/*.java"/> |
<filterset refid="variables.to.replace"/> |
</copy> |
<!-- Use test-specific XML files --> |
<copy todir="${webapp.target}/WEB-INF" overwrite="true"> |
<fileset dir="test" includes="*.xml"/> |
</copy> |
<!-- Remove configurations that should not be enabled during testing --> |
<replaceregexp file="${webapp.target}/WEB-INF/applicationContext-service.xml" |
flags="sg"> |
<regexp pattern="REMOVE DURING TEST: Start.*REMOVE DURING TEST: End" /> |
<substitution expression="REMOVED DURING TESTING" /> |
</replaceregexp> |
<property name="additional.src.dirs" value=""/> |
<junit ... }}} |
|
!!Test that it all works [#6] |
At this point we should be able to successfully run an {{ant test-all}}. The unit tests will not use the security, but the web tests will. So if you want to make sure a user cannot do something they should not be allowed to you can add a test to web-tests.xml. But if you want to see that the security works, log in as user "tomcat" and try to access [http://localhost:8080/appfuse/editProfile.html?method=search]. Because we reqire an {{admin}} role to access {{UserManager.getUsers}} you should now get a 403 Access Denied error. |