我正在尝试对我的DAO进行单元测试(使用Spring和Hibernate).我在本教程中使用的是HSQLDB .该教程指出可以使用SQL脚本初始化内存中的HSQLDB数据库,但是我无法在Spring中找到有关如何执行此操作的信息.这是相关的Spring上下文配置:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:mydb" />
<property name="username" value="sa" />
<property name="password" value="" />
<property name="initialSize" value="5" />
<property name="maxActive" value="10" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="10" />
</bean>
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢.
我需要一个方法,在测试期间调用时返回一些什么都不做,拥有该方法的类实例作为间谍实现.
我知道doNothing()方法只适用于void方法.有没有办法通过返回某些东西的方法获得相同的行为?
谢谢!
好的,所以我知道这里的第一个答案/评论将是"使用一个ExecutorService并使用invokeAll".但是,有一个很好的理由(我不会让人厌烦)让我们保持线程池分离.
所以我有一个线程池(ExecutorServices)列表,我需要做的是Callable在每个线程池上调用一个不同的submit(没有问题).现在我有了这个Future实例集合,每个实例都是单独创建的ExecutorService,我想等待所有这些实例完成(并且能够提供一个超时,任何未完成的操作都会被取消).
是否存在将执行此操作的现有类(包装Future实例列表并允许等待直到完成所有操作)?如果没有,将赞赏有效机制的建议.
正在考虑get为每个呼叫设置超时,但必须计算每次呼叫的总时间.
我看到这篇帖子等到任何未来完成但这延伸Future而不是包装它们的列表.
我正在使用Spring MVC编写Rest服务.以下是该课程的大纲:
@Controller
public class MyController{
@RequestMapping(..)
public void myMethod(...) throws NotAuthorizedException{...}
@ExceptionHandler(NotAuthorizedException.class)
@ResponseStatus(value=HttpStatus.UNAUTHORIZED, reason="blah")
public void handler(...){...}
}
Run Code Online (Sandbox Code Playgroud)
我使用此处发布的设计编写了单元测试.测试基本如下:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(....)
public class mytest{
MockHttpServletRequest requestMock;
MockHttpServletResponse responseMock;
AnnotationMethodHandlerAdapter handlerAdapter;
@Before
public void setUp() {
requestMock = new MockHttpServletRequest();
requestMock.setContentType(MediaType.APPLICATION_JSON_VALUE);
requestMock.addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
responseMock = new MockHttpServletResponse();
handlerAdapter = new AnnotationMethodHandlerAdapter();
}
@Test
public void testExceptionHandler(){
// setup ....
handlerAdapter.handle(...);
// verify
// I would like to do the following
assertThat(responseMock.getStatus(), is(HttpStatus.UNAUTHORIZED.value()));
}
}
Run Code Online (Sandbox Code Playgroud)
然而,召唤handle是扔了NotAuthorizedException …
根据SXSSF(Streaming Usermodel API)文档:
SXSSF(package :)
org.apache.poi.xssf.streaming是XSSF 的API兼容流式扩展,用于在必须生成非常大的电子表格时使用,并且堆空间有限.SXSSF通过限制对滑动窗口内行的访问来实现其低内存占用,而XSSF允许访问文档中的所有行.不再在窗口中的旧行变得不可访问,因为它们被写入磁盘.
但是,在提供的示例中,刷新发生在工作簿被赋予写入文件的文件位置之前.
public static void main(String[] args) throws Throwable {
Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
Sheet sh = wb.createSheet();
for(int rownum = 0; rownum < 1000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
String address = new CellReference(cell).formatAsString();
cell.setCellValue(address);
}
}
// Rows with rownum < 900 are …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行xml验证.我在运行时获得了一个模式列表(可能包含在jar中).验证根据我向SchemaFactory提供模式的顺序传递或失败.
这是我在做的事情:
private void validateXml(String xml, List<URI> schemas){
Source[] source = new StreamSource[schemas.size()];
int i=0;
for (URI f : schemas){
source[i++] = new StreamSource(f.openStream());
}
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NA_URI);
sf.setResourceResolver(new MyClassPathResourceResolver());
Schema schema = schemaFactory.newSchema(source);
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes()));
Run Code Online (Sandbox Code Playgroud)
再次,如果传递的模式集不是以xml的根元素引用的模式开始,则会失败.有没有解决这个问题或者我做错了什么?
我使用eclipse kepler并下载eclipseLink 2.5.0并添加到库中.还可以从Marketplace下载JPA Diagram Editor.
但是,当右键单击JPA内容时,不存在任何项目,并且,当右键单击项目并从"JPA工具"菜单中单击"打开图表"时,不会发生任何事情.
此外,当在项目的属性中单击JPA Diagram Editor时,显示错误.
为什么?
我有以下脚本有效:
x=10
echo $x
now=$(date +'%Y-%m-%d')
echo $now
Run Code Online (Sandbox Code Playgroud)
但是,当我在开头添加注释行时:
# comment
x=10
echo $x
now=$(date +'%Y-%m-%d')
echo $now
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
x=10: command not found
x: undefined variable
Run Code Online (Sandbox Code Playgroud)
为什么添加导致脚本失败的注释?
如果我做以下工作它是有效的:
x=10
echo $x
now=$(date +'%Y-%m-%d')
# comment here
echo $now
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个树,每个节点有六个孩子.我为生成树而编写的方法genB导致堆栈溢出.
public class TreeTest
{
public static void main(String Args[])
{
sBNode bTree;
sWNode wTree;
bTree = new sBNode();
wTree = new sWNode();
TreeTest ai = new TreeTest();
bTree.depth = 0;
System.out.println(bTree.depth);
ai.genB(bTree, 2);
ai.printTree(bTree);
}
public Treetest()
{
}
public boolean leaf(sBNode node)
{
if(node.pe1==null && node.pe2==null && node.pe3==null && node.ee1==null && node.ee2==null && node.ee3==null)
return true;
else
return false;
}
public void genB(sBNode parent, int ddepth)
{
int pdepth;
if(parent.depth != ddepth)
{
System.out.println(parent.depth);
pdepth = parent.depth++;
sBNode …Run Code Online (Sandbox Code Playgroud) java ×9
junit ×2
spring ×2
apache-poi ×1
concurrency ×1
dali ×1
eclipse ×1
future ×1
hsqldb ×1
jpa ×1
mockito ×1
powermock ×1
recursion ×1
rest ×1
shell ×1
spring-mvc ×1
sxssf ×1
tree ×1
unit-testing ×1
xml ×1