- 男士护肤品哪个牌子好?十大男士护肤品排行榜
高省APP珊珊
很多男生意识到护肤的必要性,开始着手护肤,但不知道该选哪个男士护肤品品牌使用好。目前市面上很多男士护肤品品牌,可谓琳琅满目,让人眼花缭乱。男士挑选护肤品时,根据自己皮肤需求去正规渠道挑选合适的知名护肤品比较放心靠谱。高省APP,是2021年推出的平台,0投资,0风险、高省APP佣金更高,模式更好,终端用户不流失。【高省】是一个自用省钱佣金高,分享推广赚钱多的平台,百度有几百万篇报道,也期待你的加入
- 2022-10-20
体力劳动者
不因感觉稍纵即逝就不加记录。在女儿睡觉后我记下今天的小故事。接手新班级后,今天是第二次收到家长的感谢信(微信)。是我表扬次数最多的两位学生家长致来的感谢,他们明显感受到孩子自信、阳光了不少,写作业由被动变为了主动,家庭氛围也由鸡飞狗跳变成了其乐融融。在被顽皮的学生气得头晕之后,我感到了久违的价值感,责任感甚至使命感,我回复家长这样一句话:我们也需要家长的反馈好让我们的教育工作更有劲头。我也认识到,
- 程翔授《评价一篇记叙文》
行吟斯基
桂林十一中高一2中学生自读程老师学生文章板书课题师巡看。看完举手。问:它是记叙文。不商量。独立打分。学生评价打分。师:高低都正常,不受干扰。师巡,略评。打完举手。调查:分层次举手——高分先举手。最低分。最高95分。最低45分。女:差距太大!师:同一篇,相差55分。若是你的文章,愿落谁手?男:身临其境感觉。师:你有此经历?没也没关系。女:不优美……,结尾无升华……无感悟……师:辞藻不美?(师追问)男
- 日更006 终极训练营day3
懒cici
人生创业课(2)今天的主题:学习方法一:遇到有用的书,反复读,然后结合自身实际,列践行清单,不要再写读书笔记思考这本书与我有什么关系,我在哪些地方能用到,之后我该怎么用方法二:读完书没映像怎么办?训练你的大脑,方法:每读完一遍书,立马合上书,做一场分享,几分钟都行对自己的学习要求太低,要逼自己方法三:学习深度不够怎么办?找到细分领域的榜样,把他们的文章、书籍、产品都体验一遍,成为他们的超级用户,向
- 9、汇编语言编程入门:从环境搭建到简单程序实现
神经网络酱
汇编语言MEPISGNU工具链
汇编语言编程入门:从环境搭建到简单程序实现1.数据存储介质问题解决在处理数据存储时,若要使用MEPIS系统,需确保有其可访问的存储介质。目前,MEPIS无法向采用NTFS格式(常用于Windows2000和XP工作站)的硬盘写入数据。不过,若硬盘采用FAT32格式,MEPIS就能进行写入操作。此外,MEPIS还能将文件写入软盘和大多数USB闪存驱动器。若工作站连接到局域网,还可通过FTP协议或挂载
- day15|前端框架学习和算法
universe_01
前端算法笔记
T22括号生成先把所有情况都画出来,然后(在满足什么情况下)把不符合条件的删除。T78子集要画树状图,把思路清晰。可以用暴力法、回溯法和DFS做这个题DFS深度搜索:每个边都走完,再回溯应用:二叉树搜索,图搜索回溯算法=DFS+剪枝T200岛屿数量(非常经典BFS宽度把树状转化成队列形式,lambda匿名函数“一次性的小函数,没有名字”setup语法糖:让代码更简洁好写的语法ref创建:基本类型的
- 贝多芬诞辰250周年纪念
万千星河赴远方
就算不是古典音乐爱好者,你也一定听说过贝多芬。作为古典音乐史上最伟大的音乐家之一,他不仅是古典主义风格的集大成者,同时也是浪漫主义风格的开创者。贝多芬肖像画(1813年)贝多芬的一生共创作了9部交响曲、36首钢琴奏鸣曲、10部小提琴奏鸣曲、16首弦乐四重奏、1部歌剧及2部弥撒曲等等。数量虽然不及前辈海顿、莫扎特多,但他几乎改造了当时所有的音乐表达形式,赋予了它们全新的价值,对后世音乐的发展产生了极
- 三件事—小白猫·雨天·八段锦
咸鱼月亮
1.最近楼下出现一只非常漂亮的粘人小白猫,看着不像是流浪猫,非常亲人。眼睛比蓝球的还大,而且是绿色的,很漂亮。第一次遇到它,它就跟我到电梯口,如果我稍微招招手,肯定就跟我进电梯了。后来我喂过它几次,好可惜不能养它,一只蓝球就是我的极限了。2.下雨天就心烦,好奇怪。明明以前我超爱看窗外的雨和听雨声,看来近来的心情不够宁静了。3.最近在练八段锦,从第一次就爱上了这个运动,很轻松缓慢,但是却出汗。感觉可
- 25-1-2019
树藤与海岛呢
hello八月来报道了今天看到了一篇文章就只想记下那两句话:良田千顷不过一日三餐广夏万间只睡卧榻三尺大概的意思就是要珍惜当下不要等来不及的时候才珍惜分享今天的两餐最近没有时间运动呢下个月补回好了说完了哈哈goodnight图片发自App图片发自App
- 力扣热题100-------54. 螺旋矩阵
海航Java之路
力扣leetcode矩阵java
给你一个m行n列的矩阵matrix,请按照顺时针螺旋顺序,返回矩阵中的所有元素。示例1:输入:matrix=[[1,2,3],[4,5,6],[7,8,9]]输出:[1,2,3,6,9,8,7,4,5]示例2:输入:matrix=[[1,2,3,4],[5,6,7,8],[9,10,11,12]]输出:[1,2,3,4,8,12,11,10,9,5,6,7]提示:m==matrix.lengthn
- 你要记住,最重要的是:随时做好准备,为了你可能成为更好的自己,放弃现在的自己。
霖霖z
打卡人:周云日期:2018年11月09日【日精进打卡第180天】【知~学习】《六项精进》0遍共214遍《通篇》1遍共106遍《大学》2遍共347遍《坚强工作,温柔生活》ok《不抱怨的世界》104-108页《经典名句》你要记住,最重要的是:随时做好准备,为了你可能成为更好的自己,放弃现在的自己。【行~实践】一、修身:(对自己个人)1、坚持打卡二、齐家:(对家庭和家人)打扫卫生,接送孩子,洗衣做饭,陪
- SpringMVC执行流程(原理),通俗易懂
国服冰
SpringMVCspringmvc
SpringMVC执行流程(原理),通俗易懂一、图解SpringMVC流程二、进一步理解Springmvc的执行流程1、导入依赖2、建立展示的视图3、web.xml4、spring配置文件springmvc-servlet5、Controller6、tomcat配置7、访问的url8、视图页面一、图解SpringMVC流程图为SpringMVC的一个较完整的流程图,实线表示SpringMVC框架提
- C++ 计数排序、归并排序、快速排序
每天搬一点点砖
c++数据结构算法
计数排序:是一种基于哈希的排序算法。他的基本思想是通过统计每个元素的出现次数,然后根据统计结果将元素依次放入排序后的序列中。这种排序算法适用于范围较小的情况,例如整数范围在0到k之间计数排序步骤:1初始化一个长度为最大元素值加1的计数数组,所有元素初始化为02遍历原始数组,将每个元素值作为索引,在计数数组中对应位置加13将数组清空4遍历计数器数组,按照数组中的元素个数放回到元数组中计数排序的优点和
- 2023-11-02
一帆f
发现浸润心田的感觉:今天一个机缘之下突然想分享我的婆媳关系,我一边分享一边回忆我之前和儿媳妇关系的微妙变化,特别是分享到我能感受到儿媳妇的各种美好,现在也能心平气和的和老公平等对话,看到自己看到老公,以己推人以人推己自然而然的换位思考,心中有一种美好的能量在涌动,一种浸润心田的感觉从心胸向全身扩散,美好极了……我很想记住这种感觉,赶紧把它写下来以留纪念,也就是当我看见他人的美好,美好的美妙的浸润心
- 48. 旋转图像 - 力扣(LeetCode)
Fiee-77
#数组leetcode算法python数据结构数组
题目:给定一个n×n的二维矩阵matrix表示一个图像。请你将图像顺时针旋转90度。你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。示例1:输入:matrix=[[1,2,3],[4,5,6],[7,8,9]]输出:[[7,4,1],[8,5,2],[9,6,3]]示例2:输入:matrix=[[5,1,9,11],[2,4,8,10],[13,3,6,
- Git 与 GitHub 的对比与使用指南
一念&
其它gitgithub
Git与GitHub的对比与使用指南在软件开发中,Git和GitHub是两个密切相关但本质不同的工具。下面我将逐步解释它们的定义、区别、核心概念以及如何协同使用,确保内容真实可靠,基于广泛的技术实践。1.什么是Git?Git是一个分布式版本控制系统,由LinusTorvalds于2005年创建。它的核心功能是跟踪代码文件的变化,帮助开发者管理项目历史记录、协作和回滚错误。Git是开源的,可以在本地
- Spring进阶 - SpringMVC实现原理之DispatcherServlet处理请求的过程
倾听铃的声
后端springjavamvc开发语言分布式
前文我们有了IOC的源码基础以及SpringMVC的基础,我们便可以进一步深入理解SpringMVC主要实现原理,包含DispatcherServlet的初始化过程和DispatcherServlet处理请求的过程的源码解析。本文是第二篇:DispatcherServlet处理请求的过程的源码解析。@pdaiSpring进阶-SpringMVC实现原理之DispatcherServlet处理请求的
- 2019-06-05
第十七把巴鲁克
今天去实验田里实习,见到了福寿螺真的可怕且牛皮,六级也快来了,说实话还是害怕。我昨天考了环工原理,真的太难了,太烦了,理工科真的难,烦。实验报告还是没写,要抓紧速度抓紧时间,还是应该学会努力学习,远离一些不上进的事物。
- Linux系统配置(应用程序)
1风天云月
Linuxlinux应用程序编译安装rpmhttp
目录前言一、应用程序概述1、命令与程序的关系2、程序的组成3、软件包封装类型二、RPM1、RPM概述2、RPM用法三、编译安装1、解包2、配置3、编译4、安装5、启用httpd服务结语前言在Linux中的应用程序被视为将软件包安装到系统中后产生的各种文档,其中包括可执行文件、配置文件、用户手册等内容,这些文档被组织为一个有机的整体,为用户提供特定的功能,因此对于“安装软件包”与“安装应用程序”这两
- 第28章 汇编语言--- 异常处理
hummhumm
汇编算法开发语言程序设计高级语言异常处理汇编语言
在汇编语言中,异常处理是一个重要的概念,它涉及到处理器如何响应和处理程序运行时发生的非正常情况。异常可以是硬件错误(例如除零错误、非法指令)或者软件触发的中断(例如系统调用)。当发生异常时,处理器会暂停当前正在执行的程序,并转移到一个预先定义好的位置来处理这个异常。为了详细阐述第28章关于汇编语言中的异常处理,我们可以考虑一个简化的例子,展示异常处理的基本结构。请注意,实际的代码将取决于具体的处理
- 【C++算法】76.优先级队列_前 K 个高频单词
流星白龙
优选算法C++c++算法开发语言
文章目录题目链接:题目描述:解法C++算法代码:题目链接:692.前K个高频单词题目描述:解法利用堆来解决TopK问题预处理一下原始的字符串数组,用一个哈希表统计一下每一个单词出现的频次。创建一个大小为k的堆频次:小根堆字典序(频次相同的时候):大根堆循环让元素依次进堆判断提取结果C++算法代码:classSolution{//定义类型别名,PSI表示对typedefpairPSI;//自定义比较
- 中原焦点团队吴瑕瑜焦点解决初级第18期坚持分享第695天 2021年12月6号
卿安
中原焦点团队吴瑕瑜焦点解决初级第18期坚持分享第695天2021年12月6号相信相信的力量。很多时候我们忽视了相信的力量,当看到孩子遇到困难、挫折,或者可能犯错时,我们急于去帮忙,这至少部分暗含不相信孩子有能力自己解决,“等不及”,少了对孩子有权决定是否需要帮忙的尊重,缺乏界限,容易引起冲突,并影响孩子的独立能力。对孩子的成长,很多时候,家长的相信比具体帮助更重要。
- Flowable 高级扩展:自定义元素与性能优化实战
练习时长两年半的程序员小胡
Flowable流程引擎实战指南流程图flowableBPMN流程引擎java
在前五篇文章中,我们从基础概念、流程设计、API实战、SpringBoot集成,到外部系统协同,逐步构建了Flowable的应用体系。但企业级复杂场景中,原生功能往往难以满足定制化需求——比如需要特殊的审批规则网关、与决策引擎联动实现动态路由,或是在高并发场景下优化流程引擎性能。本文将聚焦Flowable的高级扩展能力,详解如何自定义流程元素、集成规则引擎,并掌握大型系统中的性能调优策略。一、自定
- 2022-04-07
上善若水1979527
昨天苏阿姨来给我送普门品!和她一块来的还有另外一个阿姨!我下去拿时!那阿姨说你不是干房产的小赵!帮我租房的!我说你认识我?对啊!你帮我租的房子!我没印象了!我和保红一块!我说我想起来了阿姨!你这运动服一换!小电车一骑!一下年轻十岁我早记不得了!我只记得一九年五一带看了河滨美航还有德胜的好多套房子!你都不当意!你告诉我你每晚拜观音菩萨说快让小赵普萨帮我找套合适的房子吧!我把本子上记得半年内的德胜房源
- Java | 多线程经典问题 - 售票
Ada54
一、售票需求1)同一个票池2)多个窗口卖票,不能出售同一张票二、售票问题代码实现(线程与进程小总结,请戳:Java|线程和进程,创建线程)step1:定义SaleWindow类实现Runnable接口,覆盖run方法step2:实例化SaleWindow对象,创建Thread对象,将SaleWindow作为参数传给Thread类的构造函数,然后通过Thread.start()方法启动线程step3
- 2021-会说话的人运气都不会太差-会说话的人更善于倾听(5)沉默、留白
12_德德
21、说话时,如想强调某一部分,一个有效方法是,以沉默留出空白。留出多大空白才好呢?7秒。22、沉默所营造的“空白”长度,说的人感觉到的,是实际长度的3倍,而听的人感觉到的,则只有实际长度的1/3。23、只要善于用“一直”来表达,就不会给人以不过是一时任性之感。能说“一直”的人,会得到周围的支持,在合适的时候想到你。24、要得到“是把好手”的高度评价,就要展示你对公司的热爱。特别是,如能对上司或公
- SpringMVC的执行流程
1、什么是MVCMVC是一种设计模式。MVC的原理图如下所示M-Model模型(完成业务逻辑:有javaBean构成,service+dao+entity)V-View视图(做界面的展示jsp,html……)C-Controller控制器(接收请求—>调用模型—>根据结果派发页面2、SpringMVC是什么SpringMVC是一个MVC的开源框架,SpringMVC=Struts2+Spring,
- 企业级区块链平台Hyperchain核心原理剖析
boyedu
区块链区块链企业级区块链平台Hyperchain
Hyperchain作为国产自主可控的企业级联盟区块链平台,其核心原理围绕高性能共识、隐私保护、智能合约引擎及可扩展架构展开,通过多模块协同实现企业级区块链网络的高效部署与安全运行。以下从核心架构、关键技术、性能优化、安全机制、应用场景五个维度展开剖析:一、核心架构:分层解耦与模块化设计Hyperchain采用分层架构,将区块链功能解耦为独立模块,支持灵活组合与扩展:P2P网络层由验证节点(VP)
- 力扣面试题07 - 旋转矩阵
茶猫_
leetcode矩阵算法c语言
题目:给你一幅由N×N矩阵表示的图像,其中每个像素的大小为4字节。请你设计一种算法,将图像旋转90度。不占用额外内存空间能否做到?示例1:给定matrix=[[1,2,3],[4,5,6],[7,8,9]],原地旋转输入矩阵,使其变为:[[7,4,1],[8,5,2],[9,6,3]]示例2:给定matrix=[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,
- 2019-07-30
西域社群
天地之间,分外热闹。望热浪涛涛,引无数帅哥竞开撩,夕窈窕淑女皆露腰。一代天骄,群里热闹。不见美女露妖娆,唯见帅哥手机忙,唐诗宋词,广为流传,惜字如金,声情并茂。君悉吾析,今日之局有套路,昨日之生惹人恋。聚往矣,数风流人物还看今朝!!
- sql统计相同项个数并按名次显示
朱辉辉33
javaoracle
现在有如下这样一个表:
A表
ID Name time
------------------------------
0001 aaa 2006-11-18
0002 ccc 2006-11-18
0003 eee 2006-11-18
0004 aaa 2006-11-18
0005 eee 2006-11-18
0004 aaa 2006-11-18
0002 ccc 20
- Android+Jquery Mobile学习系列-目录
白糖_
JQuery Mobile
最近在研究学习基于Android的移动应用开发,准备给家里人做一个应用程序用用。向公司手机移动团队咨询了下,觉得使用Android的WebView上手最快,因为WebView等于是一个内置浏览器,可以基于html页面开发,不用去学习Android自带的七七八八的控件。然后加上Jquery mobile的样式渲染和事件等,就能非常方便的做动态应用了。
从现在起,往后一段时间,我打算
- 如何给线程池命名
daysinsun
线程池
在系统运行后,在线程快照里总是看到线程池的名字为pool-xx,这样导致很不好定位,怎么给线程池一个有意义的名字呢。参照ThreadPoolExecutor类的ThreadFactory,自己实现ThreadFactory接口,重写newThread方法即可。参考代码如下:
public class Named
- IE 中"HTML Parsing Error:Unable to modify the parent container element before the
周凡杨
html解析errorreadyState
错误: IE 中"HTML Parsing Error:Unable to modify the parent container element before the child element is closed"
现象: 同事之间几个IE 测试情况下,有的报这个错,有的不报。经查询资料后,可归纳以下原因。
- java上传
g21121
java
我们在做web项目中通常会遇到上传文件的情况,用struts等框架的会直接用的自带的标签和组件,今天说的是利用servlet来完成上传。
我们这里利用到commons-fileupload组件,相关jar包可以取apache官网下载:http://commons.apache.org/
下面是servlet的代码:
//定义一个磁盘文件工厂
DiskFileItemFactory fact
- SpringMVC配置学习
510888780
springmvc
spring MVC配置详解
现在主流的Web MVC框架除了Struts这个主力 外,其次就是Spring MVC了,因此这也是作为一名程序员需要掌握的主流框架,框架选择多了,应对多变的需求和业务时,可实行的方案自然就多了。不过要想灵活运用Spring MVC来应对大多数的Web开发,就必须要掌握它的配置及原理。
一、Spring MVC环境搭建:(Spring 2.5.6 + Hi
- spring mvc-jfreeChart 柱图(1)
布衣凌宇
jfreechart
第一步:下载jfreeChart包,注意是jfreeChart文件lib目录下的,jcommon-1.0.23.jar和jfreechart-1.0.19.jar两个包即可;
第二步:配置web.xml;
web.xml代码如下
<servlet>
<servlet-name>jfreechart</servlet-nam
- 我的spring学习笔记13-容器扩展点之PropertyPlaceholderConfigurer
aijuans
Spring3
PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFactoryPostProcessor接口的一个实现。关于BeanFactoryPostProcessor和BeanPostProcessor类似。我会在其他地方介绍。PropertyPlaceholderConfigurer可以将上下文(配置文件)中的属性值放在另一个单独的标准java P
- java 线程池使用 Runnable&Callable&Future
antlove
javathreadRunnablecallablefuture
1. 创建线程池
ExecutorService executorService = Executors.newCachedThreadPool();
2. 执行一次线程,调用Runnable接口实现
Future<?> future = executorService.submit(new DefaultRunnable());
System.out.prin
- XML语法元素结构的总结
百合不是茶
xml树结构
1.XML介绍1969年 gml (主要目的是要在不同的机器进行通信的数据规范)1985年 sgml standard generralized markup language1993年 html(www网)1998年 xml extensible markup language
- 改变eclipse编码格式
bijian1013
eclipse编码格式
1.改变整个工作空间的编码格式
改变整个工作空间的编码格式,这样以后新建的文件也是新设置的编码格式。
Eclipse->window->preferences->General->workspace-
- javascript中return的设计缺陷
bijian1013
JavaScriptAngularJS
代码1:
<script>
var gisService = (function(window)
{
return
{
name:function ()
{
alert(1);
}
};
})(this);
gisService.name();
&l
- 【持久化框架MyBatis3八】Spring集成MyBatis3
bit1129
Mybatis3
pom.xml配置
Maven的pom中主要包括:
MyBatis
MyBatis-Spring
Spring
MySQL-Connector-Java
Druid
applicationContext.xml配置
<?xml version="1.0" encoding="UTF-8"?>
&
- java web项目启动时自动加载自定义properties文件
bitray
javaWeb监听器相对路径
创建一个类
public class ContextInitListener implements ServletContextListener
使得该类成为一个监听器。用于监听整个容器生命周期的,主要是初始化和销毁的。
类创建后要在web.xml配置文件中增加一个简单的监听器配置,即刚才我们定义的类。
<listener>
<des
- 用nginx区分文件大小做出不同响应
ronin47
昨晚和前21v的同事聊天,说到我离职后一些技术上的更新。其中有个给某大客户(游戏下载类)的特殊需求设计,因为文件大小差距很大——估计是大版本和补丁的区别——又走的是同一个域名,而squid在响应比较大的文件时,尤其是初次下载的时候,性能比较差,所以拆成两组服务器,squid服务于较小的文件,通过pull方式从peer层获取,nginx服务于较大的文件,通过push方式由peer层分发同步。外部发布
- java-67-扑克牌的顺子.从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的.2-10为数字本身,A为1,J为11,Q为12,K为13,而大
bylijinnan
java
package com.ljn.base;
import java.util.Arrays;
import java.util.Random;
public class ContinuousPoker {
/**
* Q67 扑克牌的顺子 从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的。
* 2-10为数字本身,A为1,J为1
- 翟鸿燊老师语录
ccii
翟鸿燊
一、国学应用智慧TAT之亮剑精神A
1. 角色就是人格
就像你一回家的时候,你一进屋里面,你已经是儿子,是姑娘啦,给老爸老妈倒怀水吧,你还觉得你是老总呢?还拿派呢?就像今天一样,你们往这儿一坐,你们之间是什么,同学,是朋友。
还有下属最忌讳的就是领导向他询问情况的时候,什么我不知道,我不清楚,该你知道的你凭什么不知道
- [光速与宇宙]进行光速飞行的一些问题
comsci
问题
在人类整体进入宇宙时代,即将开展深空宇宙探索之前,我有几个猜想想告诉大家
仅仅是猜想。。。未经官方证实
1:要在宇宙中进行光速飞行,必须首先获得宇宙中的航行通行证,而这个航行通行证并不是我们平常认为的那种带钢印的证书,是什么呢? 下面我来告诉
- oracle undo解析
cwqcwqmax9
oracle
oracle undo解析2012-09-24 09:02:01 我来说两句 作者:虫师收藏 我要投稿
Undo是干嘛用的? &nb
- java中各种集合的详细介绍
dashuaifu
java集合
一,java中各种集合的关系图 Collection 接口的接口 对象的集合 ├ List 子接口 &n
- 卸载windows服务的方法
dcj3sjt126com
windowsservice
卸载Windows服务的方法
在Windows中,有一类程序称为服务,在操作系统内核加载完成后就开始加载。这里程序往往运行在操作系统的底层,因此资源占用比较大、执行效率比较高,比较有代表性的就是杀毒软件。但是一旦因为特殊原因不能正确卸载这些程序了,其加载在Windows内的服务就不容易删除了。即便是删除注册表中的相 应项目,虽然不启动了,但是系统中仍然存在此项服务,只是没有加载而已。如果安装其他
- Warning: The Copy Bundle Resources build phase contains this target's Info.plist
dcj3sjt126com
iosxcode
http://developer.apple.com/iphone/library/qa/qa2009/qa1649.html
Excerpt:
You are getting this warning because you probably added your Info.plist file to your Copy Bundle
- 2014之C++学习笔记(一)
Etwo
C++EtwoEtwoiterator迭代器
已经有很长一段时间没有写博客了,可能大家已经淡忘了Etwo这个人的存在,这一年多以来,本人从事了AS的相关开发工作,但最近一段时间,AS在天朝的没落,相信有很多码农也都清楚,现在的页游基本上达到饱和,手机上的游戏基本被unity3D与cocos占据,AS基本没有容身之处。so。。。最近我并不打算直接转型
- js跨越获取数据问题记录
haifengwuch
jsonpjsonAjax
js的跨越问题,普通的ajax无法获取服务器返回的值。
第一种解决方案,通过getson,后台配合方式,实现。
Java后台代码:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String ca
- 蓝色jQuery导航条
ini
JavaScripthtmljqueryWebhtml5
效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/39.htmHTML文件代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery鼠标悬停上下滑动导航条 - 柯乐义<
- linux部署jdk,tomcat,mysql
kerryg
jdktomcatlinuxmysql
1、安装java环境jdk:
一般系统都会默认自带的JDK,但是不太好用,都会卸载了,然后重新安装。
1.1)、卸载:
(rpm -qa :查询已经安装哪些软件包;
rmp -q 软件包:查询指定包是否已
- DOMContentLoaded VS onload VS onreadystatechange
mutongwu
jqueryjs
1. DOMContentLoaded 在页面html、script、style加载完毕即可触发,无需等待所有资源(image/iframe)加载完毕。(IE9+)
2. onload是最早支持的事件,要求所有资源加载完毕触发。
3. onreadystatechange 开始在IE引入,后来其它浏览器也有一定的实现。涉及以下 document , applet, embed, fra
- sql批量插入数据
qifeifei
批量插入
hi,
自己在做工程的时候,遇到批量插入数据的数据修复场景。我的思路是在插入前准备一个临时表,临时表的整理就看当时的选择条件了,临时表就是要插入的数据集,最后再批量插入到数据库中。
WITH tempT AS (
SELECT
item_id AS combo_id,
item_id,
now() AS create_date
FROM
a
- log4j打印日志文件 如何实现相对路径到 项目工程下
thinkfreer
Weblog4j应用服务器日志
最近为了实现统计一个网站的访问量,记录用户的登录信息,以方便站长实时了解自己网站的访问情况,选择了Apache 的log4j,但是在选择相对路径那块 卡主了,X度了好多方法(其实大多都是一样的内用,还一个字都不差的),都没有能解决问题,无奈搞了2天终于解决了,与大家分享一下
需求:
用户登录该网站时,把用户的登录名,ip,时间。统计到一个txt文档里,以方便其他系统调用此txt。项目名
- linux下mysql-5.6.23.tar.gz安装与配置
笑我痴狂
mysqllinuxunix
1.卸载系统默认的mysql
[root@localhost ~]# rpm -qa | grep mysql
mysql-libs-5.1.66-2.el6_3.x86_64
mysql-devel-5.1.66-2.el6_3.x86_64
mysql-5.1.66-2.el6_3.x86_64
[root@localhost ~]# rpm -e mysql-libs-5.1
151 Comments
Thanks for the code, it works nicely.
That is nice, very useful.
Any chance of it being submitted as a patch to the S2 team so that it can be ‘polished’ (Javadoc’ced and suchlike) and included in the core, similar to the way that Spring provides integration test support classes in the spring-mock.jar library?
Cheers
Rick
Pretty nice. I do believe this is one of the places where Struts 2.0 could offer a lot more developer support. I have been tackling this issue for sometime and written also some utility classes to simplify Struts 2.0 + Spring unit testing…
Here’s my take on it:
http://fassisrosa.blogspot.com/2007/03/unit-testing-struts-20-part-2.html
Thank you, it works great. You can also set the session into invocationContext:
protected static HashMap session = new HashMap();
// …
protected Object createAction(Class clazz, String namespace, String name)
throws Exception {
// …
proxy.getInvocation().getInvocationContext().setParameters(new HashMap());
proxy.getInvocation().getInvocationContext().setSession(session);
//…
}
This code has helped me a lot to get my action tests up and running. Thank you very much. A little problem remains, though, as we are using tiles too. When ever I try to execute an action that has as result type “tiles” I get an NPE in org.apache.struts2.view.tiles.TileResult.doExecute. It looks like the tiles listener (configured in web.xml) is not loaded. How does your code load web.xml actually (if at all)?
Mike, the web.xml is not being loaded at all. I didn’t find the need for it in my test cases but that would be an excellent feature. If I have some time I’ll see where/how it can be loaded, if you figure it out, please post the solution…
have you got any solution for loading web.xml??
This code is very helpful! It is exactly what I was looking for. However, I also have the same problem with tiles (as Mike above). If someone discovers the solution please post. I was going down the route of putting the tiles.xml in the ConfigurationManager, but I think this is the wrong path.
This is great thankyou!
My web application uses a servlet filter to maintain my jpa entity manager open in my views (org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter). I’m new to unit testing and wondered how i could modify your base class so that my filter gets inluded before calling the struts dispatcher. I am guessing that this is a similar problem to the tiles problem that is described in a previous post, ie the need to load web.xml.
I’m using Struts2 without Spring. And I would like to know how can I do a junit test using struts2??
Thanks in advance
Very good tutorial and it was very useful for me to test the complete flow in my application Thanks a lot.
I cannot find an invoke() method on the proxy reference in your testValidation()example. Also, I had to modify the method signature of protected T createAction(Class clazz, String namespace, String name) as follows protected T createAction(Class clazz, String namespace, String name)
Can you explain please?
Thanks and great work!
I see what happened to your source code now! the got sripped down on account of the HTML symbols! I have wrapped the method signature inside tags and it looks fine
protected createAction(Class clazz, String namespace, String name)
Now then, can you tell me why I am unable to find the invoke method on my proxy reference in the validation test code?
Sweet examples brother,
Scott
Hello Scott
I am getting a compile error on the method signature can you post the correct method signature plz?
— Error (T) cannot be resolved :
protected T createAction(Class clazz, String namespace, String name)
— Error (T) cannot be resolved :
return (T) proxy.getAction();
Can you tell me how to get around the error caused by this jndi snafu? This is being thrown from the setUp() at appContext.refresh();
Hi Scott, that should read proxy.execute(), not invoke(). I’ve fixed the example. Thanks for pointing out the error.
Sweet! Is there a way to get the model from the action post execute method call?
What do you mean? The return value of createAction() is the action class. Whatever public methods are available in your action are available during the tests. Just have a method which returns a model object in your action..
Consider the following test:
PayrollUpdateAction action = createAction(PayrollUpdateAction.class,
“/pr”, “PayrollUpdate_notes”);
action.setId(123L);
String result = proxy.execute();
PayrollUpdateTO model = action.getModel();
System.out.println(model);
assertEquals(“notes”,result );
The model that prints is null! Spring injected the model and it was a live reference during the execute() behavior! I guess my question is one of accessing the action before it has wound it’s way through the interceptors during the return cycle
My bad! I did not have Spring injecting the model. Sorry if you looked into this already.
Peace,
Scott
createAction(PayrollUpdateAction.class,“/pr”, “PayrollUpdate_notes”);
Are you only requiring the class name because Java Generics require it?
Yup, only reason. Just to avoid a cast in the code that calls createAction(), it’s a little neater (I think).
I agree this makes your factory method much cleaner! I really appreciate you offering up this solution. It is easy to see you are a very sharp cat.
I have an Action that extends a parent who implements SessionAware. When I pass my subclass to the createAction and use the proxy to invoke it, I am getting a null pointer on the session Map. Should the setSession()be getting called if it is in the interceptor stack?
Scott
I haven’t worked with SessionAware so I’m not sure when it gets invoked, I just use the org.apache.struts2.ServletActionContext class to get hold of the request/response objects.
All the interceptors are being called, however, since we are using a MockServletContext, naturally the request and session are Mocks too. I am trying to test an Action that implements these *aware* interfaces and of course the request and session maps are null. What would be the most natural way to push my own maps into these variables? Does it seem okay to simply call the setters on the action itself?
Thanks,
Scott
One more comment on the interceptor invocation. I have the following test running:
MemberMaintenance action = createAction(MemberMaintenance.class,”/member”, “MemberMaintenance_add”);
(MemberMaintenance) proxy.getAction()).setSession(new HashMap());
Map p = new HashMap();
p.put(“id”, “1″);
proxy.getInvocation().getInvocationContext().setParameters(p);
String nextStep = proxy.execute();
(ActionSupport) proxy.getAction()).getFieldErrors();
and when the SessionAware interceptor is invoked, it is “resetting” my session Map to null! I have fixed it for the moment by changing the setSession(Map session) to check for a null Map being passed in. This really calls into question the advantage of having the interceptors included on the proxy.execute() test though. Comments?
Scott
Hello,
I’m completely new to unit testing with struts and I’m having difficulty getting this example to work… Is this designed to run in the container or not? I thought not, but now I’m unsure. If it’s in container, can anyone point me to some examples of setting up container testing with junit?
I’m also seeing an error saying either my applicationContext.xml cannot be found, or there’s a connection timeout parsing the xml. The file not found is fair enough, but can anyone suggest a reason for a connection timeout?
Jason, this is not designed to run in a container. I don’t think running unit tests in a container is the way to go, you’re testing discrete action functionality, not how the container might behave.
As for the appplicationContext.xml not being found, remember that they’re being loaded from the classpath using XmlWebApplicationContext so make sure your application context configuration is in your classpath and referenced correctly in config[]. If you prefer to load them from the file system instead, you can just override XmlWebApplicationContext.getResource().
Thanks for your help. I seem to be locating the appContext ok now, but I have another question: No where in the code do you specify the location of the struts.xml. Is this also assumed to be on the classpath? Is there a way to load this from the filesystem if necessary?
I’m getting an error now where none of my action mappings can be resolved, so I assume struts.xml to not being picked up.
Do you have the link to the source code?
It doesn’t seem to work with Struts 2.0.9. Thanks really.
It’s working fine with 2.0.9 for me, might want to post the error you’re getting.
Get this error:
Unable to create SAX parser – Class: org.gjt.xpp.jaxp11.SAXParserFactoryImpl
etc etc etc
Caused by: javax.xml.parsers.ParserConfigurationException: validation is not supported
at org.gjt.xpp.jaxp11.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:100)
at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:109)
… 21 more
The app code works on the server. Is some jar missing to my local test?
The line:
StrutsSpringObjectFactory.setObjectFactory(ssf);
Does not works in struts 2.1 snapshot.
I trace the code and find out that ObjectFactory in xworks 2.1 drop the singleton pattern. Would you mind giving me any suggestion to do the right same things in struts 2.1 (+ xworks 2.1)
I’ve updated the source code to make it a little simpler, you don’t need StrutsSpringObjectFactory anymore. Try it again and let me know.
Your sample is different from my case. Since I have other types of test that use spring, and I don’t want to startup more than one spring application context. In short, I wish to have a way that put a spring application context into struts context by hand when test setup, just as your previous sample that I can put the application context in a new StrutsSpringObjectFactory and assign the object factory to struts context. Is there any other way to do that? Thanks for your help.
What changes would need to be made if I’m not using Spring? Thanks guys, tons of help!
Hi there
I have recently started developing Struts 2 and I am enjoying it, thanks to articles like these. I have used the base class and I am getting a NPE when it comes to tiles..and i see people have posted about this before and I was wondering if someone has done a solution and if so is there any sample code I could have a look at?
Thanks
I am also having the same problem…Can anyone pls help me?…
Hi, thanks for this nice article. It helped me a lot.
Maybe you can fix the typo(?) in PersonActionTest line 12 (pa->action).
I am using Struts 2.0.11 with Tiles 2.0.4 (TilesDecorationFilter) and I am not facing the problems stated above. But I am extremely new to all the stuff ^^ so don’t trust me too much
Thanks Felix, I’ve fixed the typo.
I am also struggling to get this to work without Springs (just struts2). I know that isn’t the purpose of this article, but its so close
Hi there
I am trying this out for a project that uses freemarker and I am getting a ton of warning messages – I am testing it in intellij idea
…
java.io.FileNotFoundException: class path resource [template/simple/common-attributes_en_US.ftl] cannot be resolved to URL because it does not exist
…
2007-11-28 16:45:10,546 WARN [org.springframework.mock.web.MockServletContext:MockServletContext.java:264] : Couldn’t determine real path of resource class path resource [template/xhtml/form-close-validate.ftl]
java.io.FileNotFoundException: class path resource [template/xhtml/form-close-validate.ftl] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/Documents%20and%20Settings/jon/.m2/repository/org/apache/struts/struts2-core/2.0.11/struts2-core-2.0.11.jar!/template/xhtml/form-close-validate.ftl
…
any tips?
Hi
I am learning struts2. this is realy good artical for me.
if you have more artical related to struts2,Spring and hibernate published it.
Rishi
Hi,
Really good example. Had a quick (and probably stupid) question though. How do you invoke a method in the action other than “execute”? I have an action class with all my CRUD methods in there and want to test each one with the full interceptor stack etc.
Thanks,
Mohammed
Mohammed, you can define the configuration in your struts.xml:
<action name="myAction" class="MyClass" method="myMethod"/>
or you can just invoke myAction like this: myAction!myMethod.action and myMethod will be called.
can you pls tell me what to do when action returns a tiles type result??
Thanks,
Do you, or anyone else have this working with Maven 2?
I’m having problems…
(NB, my other unit tests work fine – just cant test action classes at the moment).
I wasnt sure how to get the XML files (Spring, Struts etc) onto the test classpath, so ended up copying them to src/test/resources (there has to be a better way!)
After doing that, i’m getting the following error
Unable to load bean: type:org.apache.struts2.components.template.TemplateEngine class:org.apache.struts2.components.template.JspTemplateEngine – bean – jar:file:/C:/Documents%20and%20Settings/abdealim/.m2/repository/org/apache/struts2/struts2-core/2.0.9/struts2-core-2.0.9.jar!/struts-default.xml:34:150
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208)
…
Add the struts2-core-2.0.9.jar in your pom file and test once ,
Also you can add the same in properties-> Javabuild path-> add external jars-> add this jar and test.
Hey,
I tried running the test customized to my application, but I am encountering an issue of Infinite Recursion Detected. I guess its something related to auto chaining not working, but am not sure. Appreciate your help in this regard
I am getting the same error when running the junit test.
Infinite recursion detected: [/login!input, /exceptionHandler, /exceptionHandler] – [unknown location]
at com.opensymphony.xwork2.ActionChainResult.execute(ActionChainResult.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at com.opensymphony.xwork2.ActionChainResult.execute(ActionChainResult.java:229)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at gov.glin.web.struts.action.LoginActionTest.testValidLogin(LoginActionTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
here is the entry in the struts.xml
{ “input”, “login” }
/login/login.ftl
/home.action
/changePassword.action?user=${user.userId}
Re: 45.
src/test/resources and src/main/resources is the best way to put stuff in your classpath, not sure why you don’t like that. You can also define additional resources location in Maven if you need to.
Hi,
I’m very new to java, struts, spring, etc..
And i’m getting trouble to get this test working with my struts actions. I’m using eclipse and when I run the test I see from the Junit tab this error:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:99)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:317)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:125)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:141)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:123)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:91)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:292)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at com.aix2.test.BaseStrutsTestCase.setUp(BaseStrutsTestCase.java:117)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I tryed to test if I was pointing to the right file and if it is readable putting this code snipet in my class constructor:
File f = new File("WEB-INF/applicationContext.xml");
if (f.exists() && f.isFile()) {
try {
System.out.println("file exists: " + f.getCanonicalPath());
} catch (Exception e) {
e.printStackTrace();
}
if (f.canRead()) {
System.out.println("readable archive.");
}
}
which prints:
“file exists.
readable archive”
and then:
web-15:23:54,968 DEBUG com.aix.estagio.AtividadesEstagioAction:41 - AtividadesEstagioActionTest() - start
web-15:23:54,984 DEBUG com.aix2.test.BaseStrutsTestCase:88 - createAction(Class, String, String) - Erro ao criar ActionProxy: java.lang.NullPointerException
web-15:23:54,984 ERROR com.aix2.test.BaseStrutsTestCase:90 - createAction(Class, String, String)
java.lang.NullPointerException
at com.aix2.test.BaseStrutsTestCase.createAction(BaseStrutsTestCase.java:76)
at com.aix.test.webgiz.AtividadesEstagioActionTest.(AtividadesEstagioActionTest.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at junit.framework.TestSuite.createTest(TestSuite.java:131)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
at junit.framework.TestSuite.(TestSuite.java:75)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
after debugging I’ve found that the dispatcher object is null when in the createAction method.
When is this object instantiated?
Do you have any ideas on how to get this working for my case?
Many thanks and sorry for the bad english.
use like this:
CONFIG_LOCATIONS = “file:D:\\开发中项目\\dsunit\\WebRoot\\WEB-INF\\classes\\applicationContext.xml”;
Hope you success.
dalto, you’re having a classpath issue. Just make sure your tests can find the application context at /WEB-INF/applicationContext.xml. Or you can tell Spring where to look for the files as shown in the example.
Hi arsenalist,
appreciate your inputs on issue 46 pls.
Sri, that to me looks like something wrong with your action configuration which is causing a recursion between the login!input action and your exceptionHandler. Is your exception handler by any chance redirecting to login!input and in turn login!input is throwing n exception thus causing the recursion?
I believe the action is being invoked correctly which indicates that the test is setup fine, it’s just what happens after that is the problem.
here is my struts entry
{ “input”, “login” }
/login/login.ftl
/home.action
/changePassword.action?user=${user.userId}
and my applicationContext entry
I dont know from where the input method is invoked, and why my action fails which in turn calls exceptionHandler. frustrated with this.
applicationContext
struts entry
{ “input”, “login” }
/login/login.ftl
/home.action
/changePassword.action?user=${user.userId}
am not sure why my application entry and struts entry is cropped
This blog has some trouble dealing with XML, you’ll have to escape it when posting code. I think the “input” method is automatically invoked by Struts at some point (I could be wrong), you should try renaming the input method to something more precise and see what the behavior is.
thanks for the reply!
i’m new to java and i can’t understand what the classpath have to do with this issue.. do i have to add my project directory to the classpath?
i already tried to fix this by specifying to where the file is like the exemple and it keep throwing the same error.. by the way, i only have the applicationContext.xml file and not the security one, can this cause any problem?
i’ve added the MockServletContext package directory to the classpath, keeps throwing the same error in the setUp() method.
i solved it by referencing the file this way:
file///c:/workpath/project/WEB-INF/applicationContext.xml
nice article, btw
hi arsenalist,
Issue 46 I could resolve that issue now, the problem was there was an NPE which was thrown in ContextInterceptor because I didnt set the Session in the BaseTestCase
proxy.getInvocation().getInvocationContext().setSession(sessionMap);
and hence the infinite recursion. Good Lord I spent lot of time debugging for this. My bad.
Thanks for your help arsenal.
Thanks for posting this, in an ocean of mediocrity it is nice to stumble across the odd pearl.
I’m prototyping my first struts2 app right now and having successfully configured actions/results using annotations I would like to be able to test them. Unfortunately as it stands and using your base test class I am unable to do that. Everything works as expected if I add the actions/results into struts.xml. I have already spent some time wading through the Dispatcher source and find myself very little the wiser. I thought perhaps by loading actionPackages in the initParams parameter of the Dispatcher constructor it might all magically start working. Unfortunately I’m still relatively new to java (from c#) and I really want to understand what I’m doing rather than rely on magic. I would really appreciate a few pointers.
David, what’s the problem?
Well, I would like to know how to enable your BaseStrutsTestCase class to work with action/result annotations.
I also develop an application using Tiles. It would be really neccessary to mock out the TilesResult because these would be tested independently.
I would also like to test Preparer classes, but my preparers could do nothing but return action results so that they can be tested.
Hi,
I’m getting this error, and have no idea where to even start looking for the problem. I’m using Maven 2, JUnit 4, Struts 2 + Spring.
Unable to load bean: type:org.apache.struts2.components.template.TemplateEngine class:org.apache.struts2.components.template.JspTemplateEngine – bean – jar:file:/C:/Documents%20and%20Settings/abdealim/.m2/repository/org/apache/struts2/struts2-core/2.0.9/struts2-core-2.0.9.jar!/struts-default.xml:34:150
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:131)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
at com.sentaca.telusreporting.web.BaseStrutsTestCase.setUp(BaseStrutsTestCase.java:95)
at com.sentaca.telusreporting.web.UserManagementActionTestCase.setUp(UserManagementActionTestCase.java:12)
at junit.framework.TestCase.runBare(TestCase.java:132)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/jsp/JspWriter
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getDeclaredConstructors(Class.java:1808)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:198)
… 25 more
Hey there – I guess your attention is currently elsewhere. I am wondering if you have had any opportunity to think about how your BaseStrutsTestCase could be made annotation-aware. I realise this may not be high on your list of priorities but I would certainly appreciate some pointers as to how I might go about this. I’m currently in the middle of a prototype exercise and I will need to revisit this soonish. Being able to test my actions is higher on my list of priorities than using annotations so I may need to revert to the xml-style configuration if I can’t get this working.
It is actually quite easy to make this base class annotation aware. Just add this before line 86 (in setUp()) in BaseStrutsTestCase:
HashMap params = new HashMap();
params.put("actionPackages", "your.action.package1,your.action.package1");
and then modify line 86 to read:
dispatcher = new Dispatcher(servletContext, params);
You basically need to tell the dispatcher to scan your classpath. actionPackages is the parameter which makes this happen in web.xml. If you want to understand why and how this works check out the Dispatcher code at Krugle:
http://www.krugle.org/kse/files/svn/svn.apache.org/struts/current/struts2/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Thank you Hardy for that! I’ve updated the post.
Thanks Hardy, that would be worth a woot! Your timing is impeccable.
I’m getting this error when I run my JUnit Test class
java.lang.SecurityException: class “junit.framework.JUnit4TestCaseFacade”‘s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(Unknown Source)
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at org.junit.internal.runners.OldTestClassRunner$OldTestClassAdaptingListener.asDescription(OldTestClassRunner.java:41)
at org.junit.internal.runners.OldTestClassRunner$OldTestClassAdaptingListener.startTest(OldTestClassRunner.java:31)
at junit.framework.TestResult.startTest(TestResult.java:151)
at junit.framework.TestResult.run(TestResult.java:103)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Any idea on what this means ? Thanks !
Ismath
Hi, just one idea to improve the code. In class PersonActionTest you use
assertEquals(result, “success”);
which will result in some misleading error messages by JUnit on failure, like
[junit] junit.framework.ComparisonFailure: expected: but was:
The JUnit API documentation states:
assertEquals(java.lang.String expected, java.lang.String actual)
So just flipping the variables will make things clearer.
Greets, Felix
This really works well, but I have an obstacle. We have custom validators and have placed the validators.xml file in the /WEB-INF/classes/ directory as prescribed. The site works fine, however, the test case for the action does not. Running against the action produces the exception: java.lang.IllegalArgumentException: There is no validator class mapped to the name myCustomValidator.
I’m not sure how to incorporate this into the above test configuration. Do you have a suggestion? Thanks!
Actually, I just figured it out, but perhaps you know a better way. I added:
ValidatorFactory.registerValidator(“myCustomValidator”, “x.y.z.web.validators.MyCustomValidator”);
as the first line in my unit test and it works. By the way, I’m also using your base test to get an action so that I can set up the validator context in other tests that test validators independently. It really made it easy. Thanks again.
good
Hi, thanks for this post. My colleagues and I are finding it very helpful.
Just one nit-picking I couldn’t resist though.
It seems you are using assert…() method’s parameters in reverse order. According to the API doc, ‘expected’ value should come first, then ‘actual’. I don’t think this would degrade the quality of tests in terms of accuracy, but for the people reading the tests (and adopting these in their own projects), it may be confusing at times since it goes against the usual convention.
Anyways, cheers for the Arsenal!
Hi,I am having struts2 + hibernate application no spring configuration.
I used the same abstract BaseStrutsTestCase class with only change to commented out this code from setUp() method
/*
if( applicationContext == null ) {
// this is the first time so initialize Spring context
servletContext = new MockServletContext();
servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
CONFIG_LOCATIONS);
applicationContext = (new ContextLoader()).initWebApplica
*/
Test cases works fine with struts2 application only.
But the only problem is that i am not able to pass the request parameters to the action class while able to pass the
params by SettingDomainObjects.
It means testInterceptorsBySettingDomainObjects() this is working fine while this is not testInterceptorsBySettingRequestParameters() from the above example.
Can anybody tell me what is the problem here ?
If we want to use a different struts xml than the default one (say, struts-test.xml) , it can be specified as :
params.put(“config”,”struts-default.xml,struts-plugin.xml,struts-test.xml”);
somebody copied your article word by word here http://itefforts.blogspot.com/2007/08/struts2-spring-junit.html
Hi all,
I´ve read the posts, and someone has the need to put in the CONFIG_LOCATIONS the web-xml?
I´ve there de JNDI datasources needed by Spring.
How, based in the example, could i load to the classpath the web.xml??
cheers
Bigster, to load config locations, you can just specify it using the way it’s shown in Line 75 of the setUp() method.
servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, CONFIG_LOCATIONS);
arsenalist,
That´s what i´ve tried :
private static final String CONFIG_LOCATIONS =
“WEB-INF/web.xml,”+ “hibernate.cfg.xml,” + “aplicationContext-dao.xml,” + “applicationContext-resources.xml,” + “applicationContext-service.xml,” + “applicationContext-struts.xml”;
it throws a FileNotfoundExecption, it don´t find tha web.xml in the WEB-INF folder.
any help?
use like this:
private static final String CONFIG_LOCATIONS =
“/WEB-INF/web.xml,”+ “/hibernate.cfg.xml,” + “/aplicationContext-dao.xml,” + “/applicationContext-resources.xml,” + “/applicationContext-service.xml,” + “/applicationContext-struts.xml”;
Hi. I’m trying to implement this solution, but i have problem with the import
“import org.springframework.mock.web.MockHttpServletRequest;”, don’t recognises and don’t exist in spring 2.0.4 jar file. Any idea?. Congratulations Arsenal and thank you for your article.
Resolved. The spring jar file does’n contain the mock jar, is only the core. Must be include the mock jar file in the classpath. Now i’m trying the test my classes. Thks.
Hi I am very new to struts2. I am using tiles and like to use your code to develop some test cases for my application. The problem is I was using any namespace tag before in the package area.
So when I use namespace tag and put some value in it, the body jsp displayed but not the left menu, top menu and etc.
Why other jsp are not getting displayed?
—Struts.xml———————————————–
myTest
Error
————————————————————
Tiles.xml
Hi I am very new to struts2. I am using tiles and like to use your code to develop some test cases for my application. The problem is I was using any namespace tag before in the package area.
So when I use namespace tag and put some value in it, the body jsp displayed but not the left menu, top menu and etc.
Why other jsp are not getting displayed?
—Struts.xml———————————————–
myTest
Error
————————————————————
Tiles.xml
---Struts.xml-----------------------------------------------
myTest
Error
------------------------------------------------------------
Tiles.xml
—Struts.xml———————————————–
package name=”vd” namespace=”/vd” extends=”something”
action name=”vdTest” class=”vdAction”
result type=”tiles” myTest result
result name=”error” type=”tiles” Error result
action>
package
————————————————————
Tiles.xml
definition name=”default” template=”/WEB-INF/jsp/default.jsp”
put-attribute name=”title” value=”Management System”
put-attribute name=”header” value=”/html/header.html”
put-attribute name=”menu” value=”/WEB-INF/jsp/menu.jsp”
put-attribute name=”footer” value=”/html/footer.html”
put-attribute name=”body” value=”/html/main.html”
definition>
definition name=”myTest” extends=”default”
put-attribute name=”body” value=”/WEB-INF/jsp/vdTest.jsp”
definition
Hi,
I’m trying to test Struts actions following this example and I’m getting type cast exception in the line:
PersonAction action = createAction(PersonAction.class, “/site”, “deletePerson”);
Exception message says “ActionSupport” cannot be cast to PersonAction.
Hi everyone,
I’m also running “testInterceptorsBySettingRequestParameters()” with no success. I’m using ognl expressions in the request parameter like “person.name”, “person.description” and the action is getting a null reference to the Person object.
I have the getter and setter for the person object. While debugging I found the request parameters are null.
Any help will be very much appreciated,
Thanks in advance
Karel, for #87 make sure your PersonAction class extends ActionSupport. I suspect #88 might be related too.
Hi,
The class in fact extends ActionSupport and I’m still getting the error.
The other thing is that the Person object doesn’t get populated in the PersonAction class after setting request parameter “person.name” and “person.description” parameters in the request.
I’m following this example line by line with the modification of having a Person object that gets populated from the request in the Action bean.
Thanks for your quick feedback.
Cheers,
Karel
Karen – make sure you have the proper interceptors in your stack. This example is working fine for me using the default struts.xml configuration. Maybe its time to whip out the debugger and see what interceptors are being invoked.
So, I am seeing the same issue with MockHttpServletRequest parameters not making it through the Parameters interceptor. I have traced the code pretty deep and it looks like the InvocationContext does not get a copy of the MockHttpServletRequest parameters. There is some interesting comments in ActionContext for setParameters(Map param), where it says “in a Servlet Environment this returns the HttpRequest parameters, otherwise it returns a Map” (paraphrase). So I trying to figure out where this all gets determined. My guess is the Dispatcher so I am headed in that direction.
While I am doing that, it sounds like people are getting this (request.addParameter(…)) to work. Mike, what version of Struts are you using? What plugins? How are you executing your unit tests? Anything else about your Struts/Testing environment that is not likely to be shared by others?
Ok, so I did not figure out why the parameters are not getting copied from the ServletRequest to the InvocationContext, but I have a workaround I think.
Try replacing:
request.addParameter(“id”,”1″)
with
Map params = new HashMap();
params.put(“id”,”1″);
proxy.getInvocation().getInvocationContext().setParameters(params);
java.lang.NullPointerException at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:104)at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
-
-
- at
vms.junit.test.LoginActionTest.testInterceptorsBySettingDomainObjects(LoginActionTest.java:29)
My LoginActionTest is——————-
package vms.junit.test;
import java.util.Map;
import vms.action.LoginAction;
import vms.model.User;
public class LoginActionTest extends BaseStrutsTestCase {
public LoginActionTest(String name) {
super(name);
}
public void testInterceptorsBySettingDomainObjects() throws Exception {
LoginAction action = createAction(LoginAction.class,
“/”, “Login”);
User user = new User();
user.setFirstName(“vidit”);
user.setLastName(“kumar”);
action.setUser(user);
String result = proxy.execute();
assertEquals(result, “success”);
}
}
I have tiles listener in my web.xml…I dont know why I am getting this error.
Any help will be much appreciated.
Some people have reported success using that with Tiles, others have not. The issue here is that the tiles config isn’t being read because it can’t find it in the classpath…
Sorry, I stopped using Tiles a long time ago in favor of Sitemesh.
Hi Arsenalist
thanks for the quick reply. I am loading tiles config in the same way I am loading application-Context and dataAccessContext
private static final String CONFIG_LOCATIONS = “classpath:/WEB-INF/applicationContext.xml”
+ “, classpath:/WEB-INF/dataAccessContext.xml”
+ “, classpath:/WEB-INF/tiles.xml ” ;
Is there any other way to load tiles config file.
Some time ago now but…
For issues 45 & 64 – the JspTemplateEngine is dependant on the jsp-api.jar
Make sure this is available on the class path.
I have a problem with applicationContext.xml file’s configuration. My applicationContext.xml file is not under META-INF, so I change this part :
private static final String CONFIG_LOCATIONS = “META-INF/applicationContext-app.xml,” +”META-INF/applicationContext-security.xml”;
to
private static final String CONFIG_LOCATIONS = “WEB-INF/applicationContext.xml”;
The error is :
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml] at
Moreover, I don’t have a file named applicationContext-security.xml.
I am sure that applicationContext.xml is in the correct place, so what is the problem? Should I do some change on it?
The applicationContext.xml file :
I have solved my problem
I just wrote :
private static final String CONFIG_LOCATIONS = “file:WebContent/WEB-INF/applicationContext.xml”;
But I couldn’t understand the difference.
After I have solve the configuration problem, there is another problem about tiles. As some peope mentioned that the tiles integration causes NPE, I have the same problem, ant the trace is the same.. I have set the configuration file to
private static final String CONFIG_LOCATIONS = “file:src/struts.xml,file:WebContent/WEB-INF/tiles.xml” ; this, as suggested, but it did not work. How can I solve this problem ?
I do not have applicationContext file, I use struts.xml instead of it.
struts.xml :
tvq.NameCollector
tvq.ListTasks
/error.jsp
tvq.addTask
web.xml :
TVQ
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
org.springframework.web.context.ContextLoaderListener
Tiles_Filter
org.apache.tiles.web.startup.TilesFilter
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
/WEB-INF/tiles.xml
Tiles_Filter
/*
REQUEST
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
I have modified BaseStrutsTestCase.createAction to include request and response objects
protected T createAction(Class clazz,String namespace, String name, MockHttpServletRequest request,MockHttpServletResponse response)
Modified the following lines in the method
Map extraContext = dispatcher.createContextMap(request, response, null, servletContext);
ActionProxy proxy = dispatcher.getContainer().getInstance(
ActionProxyFactory.class).createActionProxy(namespace, name,
extraContext, true, false);
dropped these lines
proxy.getInvocation().getInvocationContext().
setParameters(new HashMap());
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
ServletActionContext.setRequest(request);
ServletActionContext.setResponse(response);
This will make sure whatever parameter is added to servlet request using addParameter method will end up in the Action domain objects.
I hope this solves Dusty’s problem
For the ones who want to integrate this unit test with tiles, I have found a tutorial-like post :
http://www.soft-gems.net/index.php?option=com_content&task=view&id=48&Itemid=33
However, It gave an exception like that:
org.apache.tiles.definition.NoSuchDefinitionException: tvq.ListTasks
The program works correctly, but I can not test it
I found a similar code sample to this at http://www.soft-gems.net/index.php?option=com_content&task=view&id=48, which included tiles support. I found that by adding the tiles config from the other example to the code on this page I stopped getting NPE’s in Tiles, although I’m still working through my tests to see if it breaks anything else.
To add tiles support, find this line in the existing code (currently line 80 in the listing above but it might change) :-
new JspSupportServlet().init(new MockServletConfig(servletContext));
and add the following code to define the location of your tiles.xml and sets up a Tile listener
servletContext.addInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG, “WEB-INF/tiles.xml”);
final StrutsTilesListener tilesListener = new StrutsTilesListener();
final ServletContextEvent event = new ServletContextEvent(servletContext);
tilesListener.contextInitialized(event);
I cant claim any credit for the above, other than finding it and posting it here
Thanks for posting it. I was breaking my head on why tiles not getting initialized. Tried several configuration option in struts2 but nothing worked.
I am thinking of posting the same in several other places where people posted this issue. I saw several people had problems on the same lines.
Thanks.
Why we need to load tiles.xml for JUnit, are you trying to execute results? This is to know the requirement.
Thanks
Thank you so much!
This is exactly what I’ve been searching for hours.
It also serves as a good example to load any other ServletContextListener classes.
We are trying to use this to test action classes in an Struts/Spring/Hibernate application.
DriverManagerDataSource and LocalSessionFactoryBean are used.
I am receiving HibernateException that there is no active transaction. Any idea?
cat7,
I tried what you have suggested but It gave an error as I mentioned before:
org.apache.tiles.definition.NoSuchDefinitionException: tvq.ListTasks
What can be the problem?
Line 57-58
//do not execute the result after executing the action
proxy.setExecuteResult(true);
there is a bug inside this code
hi,
my StrutsActionTestCase is virtually a copy of your BaseStrutsTestCase. I use it first in TestLogin where everything works fine and than in TestRegister where this strange assertion error is thrown:
java.lang.AssertionError:
Unexpected method call put(“configurationReload-struts-default.xml”, true):
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:29)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:56)
at org.easymock.classextension.internal.ClassProxyFactory$1.intercept(ClassProxyFactory.java:74)
at com.opensymphony.xwork2.ActionContext$$EnhancerByCGLIB$$8aa46a90.put()
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:110)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:152)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
at test.actions.StrutsActionTestCase.setUp(StrutsActionTestCase.java:94)
at test.actions.security.TestRegister.setUp(TestRegister.java:27)
StrutsActionTestCase.java:94 coresponds to BaseStrutsTestCase.java:90 which is the line with
dispatcher.init().
Why is the ActionContext an EasyMock-Mock-class???
the quickfix seems to be to reset the ActionContext in BaseStrutsTestCase.setUp() between line 71 and line 72:
protected void setUp() throws Exception
{
ActionContext.setContext( new ActionContext(new TreeMap()) );
if( applicationContext == null ) {
….
But there seems to be a bug somewhere!?
I am trying to unit test one action class which returns sucess…
I am getting this error…
-Info — Initializing Tiles2 container. . .
-WARN [org.apache.tiles.impl.BasicTilesContainer] – Unable to find configured definition ‘/WEB-INF/tiles.xml’
2008-08-07 13:51:19,583 INFO [org.apache.tiles.impl.BasicTilesContainer] – Tiles2 container initialization complete.
PS. session and request are *local* variable. Do not use the member variable of the same name.
I’m having the same Classpath problems that some have found (46).
On my setup, I have a unittests source folder (separate from both the src and WebContent).
String CONFIG_LOCATIONS = “WEB-INF/applicationContext.xml”;
doesn’t find the file (nor tiles.xml, for example). “WebContent/WEB-INF/…” doesn’t find it either.
I’ve also tried the full system path without any luck.
Everything works great if I copy-paste the xml files to the unittests source folder. But how can I reference the files in the WEB-INF folder?
Is Junit support Struts 2.0?
I am trying to write Junit Test Case for DAO’s but Objects are not created.
Thank you for this great post !
I’m new to this these technologies. so while I copied this class to run in my eclipse it is giving me 2 errors which is in “T” -no class exit..
how to resolve this.
I’ve been successfully using your BaseStrutsTestCase under TestNG with Struts-2.1.2 and Spring-2.5.6.
Pretty nice, thanks!
I was wondering how you handle the fact the service layer problem. In order to test your actions, you need to provide some persistent entity, right? If you want to keep away from the container, you’ve got to mock the Service layer in some ways so as to be able to return expected entity for your action.
How do you mock them? Do you use a specific tool?
My DAOs implement interfaces and I have a “real” implementation and a test implementation which I use during testing. I use XStream and a bunch of XML files to mock data coming from a database during testing.
Nice article, I tried the same but facing following issue when I try to run the JUnits
[junit] Running com.pg.site.actions.about.AboutUsActionTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test com.pg.site.actions.about.AboutUsActionTest FAILED (crashed)
The message in the log is
junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
If any of you faced such issue, can you please help me.
I implemented SessionAware interface in Action class and i just set the session using,
….
ServletActionContext.getContext().setSession(session);
ServletActionContext.setServletContext(servletContext);
……
and it works like magic
Hi Arsenalist, nice job!
I’ve implemented your framework and it’s been incredibly helpful. One question though: I’ve not been able to get it to add request parameters using your method in the example (request.addParameter(“id”, “123″)). The values just don’t get noticed by the interceptors. So, I’ve been doing it using the method that the base action uses (proxy.getInvocation().getInvocationContext().getParameters().put( …. ) ).
That works well, but it’s a little messy, because that particular parameters map requires all parameter values to be String[]s, not Strings, so i have to add extra lines into the code. Any idea what I might be doing wrong?
Cheers.
Just an extra note on my last post: I tried Girih’s method from 7/2/08, but I wasn’t able to get it work…
In the method definition:
protected T createAction(Class clazz, String namespace, String name)
For the class ‘T’ should i import the following class
import org.apache.poi.hssf.record.formula.functions.T;
In the method definition:
protected T createAction(Class clazz, String namespace, String name)
For the class ‘T’ should i import the following class
import org.apache.poi.hssf.record.formula.functions.T;
is this correct import?
T is a reference to any class in Java 1.5 generics. You don’t need to import anything.
Hi
I am trying to use your framework and is really usefull, in my case I am using struts2-rest-struts-plugin, and it use RestActionProxyFactory instead of ActionProxyFactory
I modify the code..like follow but I get a null action Proxy.. any ideas?
RestActionProxyFactory actionProxy = dispatcher.getContainer().getInstance(RestActionProxyFactory.class, “rest”);
proxy = actionProxy.createActionProxy(namespace, name, null, true, false);
Got an error with:
private static final String CONFIG_LOCATIONS = “file:WebContent/WEB-INF/applicationContext.xml”;
at
applicationContext = (new ContextLoader()).initWebApplicationContext(servletContext);
with:
Caused by: java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.properties()[Ljavax/persistence/PersistenceProperty;
Can someone refer to the xml documents? is the security.xml necessary? sorry i am kinda new to this
Thx, Jorgan
You can load xml documents, but ensure you get the absolute path or relative path from the classpath to load them.
Hi,
It’s very helpful. But I’ve an problem.
I’ve an action implement Preparable. When I run the proxy.execute(), the EntityManager is opened/closed twice. This causes a problem that an entity feched in prepare() becomes detached.
Any solution?
Thanks,
For those of you who are using this base class to unit test your Struts 2 apps, have you encountered this requirement?
I have a web.xml listener placing an object in application scope using servletContext.setAttribute(foo,engine) and an interceptor expecting to locate it using actionInvocation.getStack().findValue(“#attr.foo”).
In my unit test which subclasses BaseStrutsTestCase I am putting the engine in scope using proxy.getInvocation().getStack().set(“foo”, engine), however my interceptor is finding a null when it attempts to fetch it from the stack. Is there something weird concerning the OgnlValueStack in this context?
Peace,
Scott
I was wondering if the problem with the aware interface (SessionAware) as described in comments 24 & 25 was ever resolved.
I have recently started experimenting with this very helpful unit testing code and facing same issue.
Looks like the framework isn’t setting a session object to my class implementing SessionAware. So, I call the setSession() method to set it myself. That happens before proxy.execute(), but when the time comes for proxy.execute(0 to run, it resets the session map to null.
The test passes with the option to by-pass the framework and test the action in an isolated function.
Not sure if this discussion is still active, but if anyone has any advice or solution on this issue, I would very interested in hearing it.
Many thanks.
Zarar – I modified your BaseStrutsTestCase class so that it works for testing a Struts 2 Action class that doesn’t use Spring. I’d like to publish this code along with an example of how to use it on my blog (http://www.brucephillips.name/blog). I’ve cited your name and blog article in the code comments and also will cite your orignal work in the blog article.
Is is OK with you if I publish on my blog the modified BaseStrutsTestCase class I created based on your work?
Bruce Phillips
Sure Bruce, no problem.
I am getting the following error:
java.lang.NullPointerException
at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:104)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at gc.test.unittest.testaction.TestLoginActionUsingBaseStrutsTestCase.testInterceptorsBySettingRequestParameters(TestLoginActionUsingBaseStrutsTestCase.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:91)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I have got the answer.
Complete BaseStrutsTestCase is like following:
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
import junit.framework.TestCase;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.tiles.StrutsTilesListener;
import org.apache.struts2.views.JspSupportServlet;
import org.apache.tiles.impl.BasicTilesContainer;
import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.ContextLoader;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContextEvent;
/**
* @author Arindam Ray
*/
@SuppressWarnings(“unchecked”)
public abstract class BaseStrutsTestCase extends TestCase {
private static final String CONTEXT_CONFIG_LOCATION = “/WEB-INF/applicationContext.xml,” +
“/WEB-INF/dataAccessContext.xml”;
private static final String TILES_DEFINITIONS = “/WEB-INF/tiles.xml”;
private static ApplicationContext applicationContext;
private Dispatcher dispatcher;
protected ActionProxy proxy;
protected static MockServletContext servletContext;
protected MockHttpServletRequest request;
protected MockHttpServletResponse response;
public BaseStrutsTestCase(String name) {
super(name);
}
/**
* Created action class based on namespace and name
* @param clazz Class for which to create Action
* @param namespace Namespace of action
* @param name Action name
* @param parameters Request parameters
* @param session Session map
* @return Action class
* @throws Exception Catch-all exception
*/
protected Object createAction(Class clazz, String namespace, String name, Map parameters, Map session)
throws Exception {
// create a proxy class which is just a wrapper around the action call.
// The proxy is created by checking the namespace and name against the
// struts.xml configuration
proxy = dispatcher.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(namespace, name, null, true, false);
ActionContext actionContext = proxy.getInvocation().getInvocationContext();
if(parameters == null) {
// by default, don’t pass in any request parameters
actionContext.setParameters(new HashMap());
}
else {
//set the parameters
actionContext.setParameters(parameters);
}
if(session == null) {
actionContext.setSession(new HashMap());
}
else {
//set the session
actionContext.setSession(session);
}
// do not execute the result after executing the action
proxy.setExecuteResult(true);
// set the actions context to the one which the proxy is using
ServletActionContext.setContext(actionContext);
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
ServletActionContext.setRequest(request);
ServletActionContext.setResponse(response);
ServletActionContext.setServletContext(servletContext);
return proxy.getAction();
}
protected void setUp() throws Exception {
if( applicationContext == null ) {
// this is the first time so initialize Spring context
servletContext = new MockServletContext();
servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, CONTEXT_CONFIG_LOCATION);
applicationContext = (new ContextLoader()).initWebApplicationContext(servletContext);
// Struts JSP support servlet (for Freemarker)
new JspSupportServlet().init(new MockServletConfig(servletContext));
//for tiles
servletContext.addInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG, TILES_DEFINITIONS);
final StrutsTilesListener tilesListener = new StrutsTilesListener();
final ServletContextEvent event = new ServletContextEvent(servletContext);
tilesListener.contextInitialized(event);
}
// Dispatcher is the guy that actually handles all requests. Pass in
// an empty. Map as the parameters but if you want to change stuff like
// what config files to read, you need to specify them here. Here’s how to
// scan packages for actions (thanks to Hardy Ferentschik – Comment 66)
// (see Dispatcher’s source code)
HashMap params = new HashMap();
params.put(“actionPackages”, “gc.action”);
dispatcher = new Dispatcher(servletContext, params);
dispatcher.init();
Dispatcher.setInstance(dispatcher);
}
}
Thanks Arsenalist for the code.
Has anybody got the above code to run by setting request parameters? The method testInterceptorsBySettingRequestParameters() doesnot work for me. There were quite few queries on this. Has anyone got it to work?
I used the approach here until I recently upgraded Struts and came up with an alternative:
http://www.digitalsanctum.com/2010/01/25/how-to-test-struts-2-actions-without-a-container/
My approach uses a combination of Struts and Spring to achieve transactional tests without the use of a container.
Thank for your post! Great work!
One question is: when I run testInterceptorsBySettingDomainObjects(), it works, but can
not invoke the interceptor. I’m using struts2+spring2+tiles
Thank You!
After a few hours of debugging I got this code to work perfectly! Thank you so much for not only posting the code, but revising it and helping with other users. This post makes it easy to set this up and troubleshoot.
A small change is needed for Struts 2.1.6. The createActionProxy() method of ActionProxyFactory needs an additional parameter for the action’s ‘method’.
To set the Action’s domain objects through request parameter, the suggested approach will not work. i.e.
request.setParameter(“id”, “123″) will not set the Id field of the action class. That has to be done in the following way –
Map params = new HashMap();
params.put(“id”, “123″);
proxy.getInvocation().getInvocationContext().setParameters(params);
how to solve this problem
There is no Action mapped for namespace / and action name createaccount. – [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:177)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at net.action.StrutsTestCase.getActionProxy(StrutsTestCase.java:84)
at net.action.NewTest.testUserName(NewTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
this one is very helpful example
how to solve this problem
There is no Action mapped for namespace / and action name createaccount. – [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:177)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at net.action.StrutsTestCase.getActionProxy(StrutsTestCase.java:84)
at net.action.NewTest.testUserName(NewTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
There was something wrong with the usage of “assertEquals(result, “success”);”
The actual API is: assertEquals(Object expected, Object actual)
One Trackback
[...] Later on, I found a wise solution to this problem by searching and trying new possibilities. This blog was a helper for [...]