我有一个方法我想要存根但它有很多参数.我怎样才能避免模拟所有参数但仍然存根方法.
例如:
//Method to stub
public void myMethod(Bar bar, Foo foo, FooBar fooBar, BarFoo barFoo, .....endless list of parameters..);
Run Code Online (Sandbox Code Playgroud) 我有一个无状态的EJB加入我的数据库.我需要在JSF 2转换器中使用此bean来从String值参数中检索实体对象.我正在使用JEE6和Glassfish V3.
@EJB 注释不起作用并获得NPE,因为它位于faces上下文中,并且它无法访问EJB上下文.
我的问题是:是否仍然可以使用@Resource其他注释或JNDI查找来注入此bean ,还是需要解决方法?
解
像这样执行JNDI查找:
try {
ic = new InitialContext();
myejb= (MyEJB) ic
.lookup("java:global/xxxx/MyEJB");
} catch (NamingException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我是模拟测试的新手.
我想测试我的Service方法CorrectionService.correctPerson(Long personId).该实现尚未编写,但它将如何做:
CorrectionService将调用的方法AddressDAO,将删除一些的Adress一个Person了.其中Person有许多AddressES
我不确定我的基本结构是什么CorrectionServiceTest.testCorrectPerson.
另外请确认/不确认在此测试中我不需要测试地址是否实际被删除(应该在a中完成AddressDaoTest),只是调用了DAO方法.
谢谢
我想在我的数据库中复制一组实体.我用以下方式检索了这个系列:
CategoryHistory chNew = new CategoryHistory();
CategoryHistory chLast = (CategoryHistory)em.createQuery("SELECT ch from CategoryHistory ch WHERE ch.date = MAX(date)").getSingleResult;
List<Category> categories = chLast.getCategories();
chNew.addCategories(categories)// Should be a copy of the categories: OneToMany
Run Code Online (Sandbox Code Playgroud)
现在我想复制一个'类别'列表并用EntityManager保存它.我正在使用JPA/Hibernate. UPDATE
在知道如何分离我的实体之后,我需要知道要分离的内容:当前代码:
CategoryHistory chLast = (CategoryHistory)em.createQuery("SELECT ch from CategoryHistory ch WHERE ch.date=(SELECT MAX(date) from CategoryHistory)").getSingleResult();
Set<Category> categories =chLast.getCategories();
//detach
org.hibernate.Session session = ((org.hibernate.ejb.EntityManagerImpl) em.getDelegate()).getSession();
session.evict(chLast);//detaches also its child-entities?
//set the realations
chNew.setCategories(categories);
for (Category category : categories) {
category.setCategoryHistory(chNew);
}
//set now create date
chNew.setDate(Calendar.getInstance().getTime());
//persist
em.persist(chNew);
Run Code Online (Sandbox Code Playgroud)
这会引发 …
是否有可能确保只有 spring可以实例化一个类,而不是new在编译时通过关键字?(避免意外实例化)
谢谢!
基本问题:
包含一个页面,其中包含具有组件ID的组件,多次无法完成.但是,我如何能够在包含页面的情况下引用该组件?
例:
included.xhtml
....
<h:form id="foo"/>
....
<!-- here i need reference to foo component of this page -->
Run Code Online (Sandbox Code Playgroud)
的index.xhtml
....
<ui:include src="included.xhtml" />
<ui:include src="included.xhtml" />
<ui:include src="included.xhtml" />
Run Code Online (Sandbox Code Playgroud) 因为我想在文本框上设置Extender(来自AJAX Controls工具包的日历),我必须更改代码
<%= Html.TextBox("name") %>
Run Code Online (Sandbox Code Playgroud)
至
<asp:TextBox ...>
但是如何在元素上绑定属性"name"?
谢谢