我有几个DAO对象用于从数据库中检索信息,我真的想为它们编写一些自动化测试,但我很难弄清楚如何去做.
我正在使用Spring JdbcTemplate来运行实际查询(通过预准备语句)并将结果映射到模型对象(通过RowMapper类).
如果我要编写单元测试,我不确定如何/应该模拟对象.例如,由于只有读取,我会使用实际的数据库连接而不是模拟jdbcTemplate,但我不确定是否正确.
这是批次中最简单的DAO的(简化)代码:
/**
* Implementation of the {@link BusinessSegmentDAO} interface using JDBC.
*/
public class GPLBusinessSegmentDAO implements BusinessSegmentDAO {
private JdbcTemplate jdbcTemplate;
private static class BusinessSegmentRowMapper implements RowMapper<BusinessSegment> {
public BusinessSegment mapRow(ResultSet rs, int arg1) throws SQLException {
try {
return new BusinessSegment(rs.getString(...));
} catch (SQLException e) {
return null;
}
}
}
private static class GetBusinessSegmentsPreparedStatementCreator
implements PreparedStatementCreator {
private String region, cc, ll;
private int regionId;
private GetBusinessSegmentsPreparedStatementCreator(String cc, String …Run Code Online (Sandbox Code Playgroud) 如何在VIEW上创建放置在远程服务器上的FEDERATED?我正在使用MySQL.
mysql view federated-table federated federated-storage-engine
我正在使用mapview的自定义版本(OSMDroid版本).我在其中使用自定义图块,我只希望用户能够查看我有自定义图块的区域.有没有办法设置边界lat long,所以当它们平移地图时它不会超过这些边界?
这是两个文件
Calling.php
<html>
<body>
<form action="Called.php" method="get">
<input type="button" name="B1" value="B1">
<input type="button" name="B2" value="B2">
<input type="Submit" name="Submit1"/>
<!-- <a href="http://www.google.com?act=google">Google</a>
<a href="http://www.yahoo.com?act=yahoo">yahoo</a>
-->
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和Called.php
<?php
if(isset($_GET("Submit1")))
{
echo("<script>location.href = 'http://stackoverflow.com';</script>");
}
if(isset($_GET["B1"]))
{
echo("<script>location.href = 'http://google.com/';</script>");
exit();
}
if(isset($_GET["B2"]))
- List item
{
echo "<meta http-equiv='refresh' content='0;url=http://www.yahoo.com'>";
exit();
}
?>
Run Code Online (Sandbox Code Playgroud)
当我点击按钮"B1"和"B2"时,页面将闪烁,但现在重定向和第三个"提交"按钮将重定向到新页面,我在那里得到输出为"Called.php".
请花几秒钟为这个php初学者.
我正在使用open_workbook()函数打开一个excel文件.但我找不到任何函数来稍后在xlrd模块中关闭该文件.有没有办法使用xlrd关闭xls文件?或者根本不需要?
在iPhone上运行应用程序时(例如,当您可以通过其他方式测试某些GPS或相机功能时),我在哪里可以找到并检查NSUserDefaults创建的文件以保存standardUserDefaults?我正在运行XCode 4.
所以即时生成2048 RSA密钥对.但是当我查看私钥时,长度只有1232字节.这与2048有什么关系,还是2048只是模数大小?
由于QObject,我遇到了关于多重继承的QT问题.我知道其他很多人都有同样的问题,但我不知道应该怎么解决.
class NavigatableItem : public QObject
{
Q_OBJECT
signals:
void deselected();
void selected();
void activated();
};
class Button : public NavigatableItem, public QToolButton
{
Q_OBJECT
...
}
class MainMenuOption : public Button
{
Q_OBJECT
...
}
Run Code Online (Sandbox Code Playgroud)
当我这样做
MainMenuOption* messages = new MainMenuOption();
connect(messages, SIGNAL(selected()), SLOT(onMenuOptionSelected()))
Run Code Online (Sandbox Code Playgroud)
我会得到错误:
QObject'是'MainMenuOption'的模糊基础
之所以我让NavigatableItem因为信号而来自QObject.有没有办法做到这一点?
编辑:
为每个继承声明添加虚拟,仍然给我同样的错误:
class NavigatableItem : public virtual QObject
class Button : public virtual NavigatableItem, public virtual QToolButton
class MainMenuOption : public virtual Button
Run Code Online (Sandbox Code Playgroud)
即使在'全部清洁'之后,'运行qmake'和'全部建立'.
可能重复:
Android中的上下文是什么?
我想知道Android的Context是什么,以及为什么需要它.我知道它与课程有关,每个班级都有独特的背景.我在一些代码中看到,在调用另一个类的方法时会传递一个Context.我不明白为什么需要它.请帮忙.
我在Spring MVC Controller中定义了这个方法:
@RequestMapping(value = "{id}/content", method=RequestMethod.POST)
@PreAuthorize("principal.user.userAccount instanceof T(com.anonym.model.identity.PedagoAccount) AND principal.user.userAccount.userId == #object.pedago.userId AND #form.id == #object.id")
public String modifyContent(@PathVariable("id") Project object, @Valid @ModelAttribute("form") ProjectContentForm form) {
....
}
Run Code Online (Sandbox Code Playgroud)
然后在我的JUnit测试中,我想调用此方法并确保验证PreAuthorize条件.但是当我在JUnit测试中使用错误帐户设置用户主体时,没有错误,方法完成.似乎绕过了注释.
但是当我以正常方式调用此方法(而不是测试)时,将验证PreAuthorize.
如果可能的话,如何在junit测试中测试这个注释以及如果它抛出一个异常如何捕获它?
谢谢,
尼古拉斯
android ×2
c++ ×1
controller ×1
cryptography ×1
dao ×1
federated ×1
google-maps ×1
ios ×1
java ×1
jdbctemplate ×1
junit ×1
key ×1
mysql ×1
osmdroid ×1
php ×1
private ×1
python ×1
qt ×1
qt-signals ×1
rsa ×1
spring ×1
spring-el ×1
spring-mvc ×1
testing ×1
view ×1
xlrd ×1