我一直在关注使用它进行单元测试DAO类的EasyMock和教程/示例,用于"外部容器"测试.但是,我认为他们中的大多数都在谈论测试服务层,而不是模拟DAO类.我有点困惑,你真的是如何对DAO层进行单元测试吗?
有人会说,与DB和EJB交互的测试实际上是集成测试而不是单元测试,但是你怎么知道你的SQL是否正确(假设没有ORM)并且你的DAO插入/查询真实的正确数据(读取,本地数据库与生产中的数据库类似?
我读到DBUnit是这种情况的解决方案.但我的问题是使用像DBUnit这样的框架"外部容器".如果DAO依赖于某些EJB,我们如何处理事务,如果有更新其他表的触发器会发生什么?
仅对具有此类依赖性的DAO进行单元测试的最佳方法是什么?
这个问题与逻辑比任何编程语言更相关.如果问题不适合论坛,请告诉我,我会删除它.
我必须编写一个逻辑来计算博客奖励网站的博客分数.博客可能会被提名为多个奖项类别,并由评审团进行同行评审或评级为-1至5级(-1表示他们完全不喜欢的博客).现在,一个或多个陪审员可以对博客进行评级.计算博客最终得分时的一个标准是,如果博客被更多人评为肯定,那么它应该获得更多的权重(反之亦然).类似地,即使是一个陪审员,评分为-1的博客也应该影响其得分(-1在这里是一种否决权).最后,我还希望根据博客的Technorati等级获得额外的分数(以便最终得分基于陪审员评级+ Technorati排名的组合).
示例:博客在A类中被评为6位陪审员.2分为3分,3分为2分,1分为4分.(我曾将得分计算为(2*3 + 3*2 + 1*4)/ 6 = 16/6 = 2.67得到加权平均但我对此不满意,主要是因为当陪审员评级为-1时它不能很好地工作.此外,我还需要添加Technorati排名等级标准.
你能帮我决定计算最终得分的最佳方法(保持评级方法与上面相同,现在不能改变)?
我想在某些情况下绕过Spring webflow(Spring 2.0.5)应用程序的登录表单(因此登录表单是为普通用户提供的,但是当URL就像http://server.com/myspringapp/fakelogin?username = FakeUser&password = FakePassword然后不应该向用户显示登录表单,而是根据请求参数在内部进行身份验证,然后将其带到安全页面.
所以我不想要Preauthenticastion,而是特殊场合的透明身份验证(当URL如上所述).我看到了诸如http://forum.springsource.org/showthread.php?t=59108之类的线程,但没有提到解决方案的地方.我尝试实现AuthenticationProcessingFilter但不太确定如何实现requiresAuthentication()方法.
以下是我当前的安全性XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
<bean id="customAuthenticationProvider" class="com.myco.jsf.spring.security.MyAuthenticationProvider">
<security:custom-authentication-provider/>
<constructor-arg>
<ref bean="webSessionFactory"/>
</constructor-arg>
<constructor-arg>
<ref bean="authenticationBridge"/>
</constructor-arg>
</bean>
<bean id="myEntryPoint" class="com.myco.web.filter.CustomAuthenticationEntryPoint">
<property name="loginFormUrl" value="/spring/login" />
</bean>
<bean id="myProcessingFilter" class="com.myco.web.filter.CustomAuthenticationProcessingFilter">
<security:custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />
<property name="defaultTargetUrl" value="/spring/secure" />
<property name="authenticationFailureUrl" value="/spring/login" />
<property name="alwaysUseDefaultTargetUrl" value="false" />
<property name="filterProcessesUrl" value="/spring/j_spring_security_check" />
<property name="authenticationManager" ref="authenticationManager" />
<!--
<property name="allowSessionCreation" value="true" />
-->
</bean>
<security:authentication-manager alias="authenticationManager"/> …
Run Code Online (Sandbox Code Playgroud) 我几乎没有看到任何与Hibernate相关的问题的指针.这适用于使用具有父子关系的单个数据库表来实现继承.例如:
CREATE TABLE Employee (
empId BIGINT NOT NULL AUTO_INCREMENT,
empName VARCHAR(100) NOT NULL,
managerId BIGINT,
CONSTRAINT pk_employee PRIMARY KEY (empId)
)
Run Code Online (Sandbox Code Playgroud)
这里,managerId列可以为null,也可以指向Employee表的另一行.业务规则要求员工了解他的所有报告人,并让他了解他/她的经理.业务规则还允许行具有null managerId(组织的CEO没有经理).
我们如何在Hibernate中映射这种关系,标准的多对一关系在这里不起作用?特别是,如果我想实现我的实体不仅作为相应的"Employee"实体类,而且实现多个类,例如"Manager","Assistant Manager","Engineer"等,每个类都继承自"Employee"超级实体类,某些实体具有实际上并不适用于所有的属性,例如"Manager"获取Perks,其他实体则不获取(相应的表列当然会接受null).
示例代码将不胜感激(我打算使用Hibernate 3注释).
我厌倦了搜索在Sybase ASE上进行不区分大小写搜索的解决方案(Sybase数据/列名称区分大小写).Sybase文档自豪地说只有一种方法可以使用Upper和Lower函数进行搜索,但是谚语说,它存在性能问题.并且相信我他们是对的,如果你的桌子有巨大的数据表现如此尴尬,你永远不会再使用上下.我向其他开发者提出的问题是:你们怎么解决这个问题?
PS请不要建议更改排序顺序或移动到任何其他数据库,在现实世界中开发人员不控制数据库.
这似乎是一个愚蠢的问题.我正在尝试为Spring Batch Job Repository(Spring Batch 2.1.7)配置Oracle10g数据库,我能够使用org/springframework/batch/core/schema-oracle10g.sql核心中提供的脚本创建表.我还将属性batch.data.source.init设置为false.
在干净的数据库上,我的批处理程序运行正常,成功创建所有批处理表/序列,并使用批处理结果的详细信息填充它们.但是,当我再次运行它时,Spring Batch会再次尝试创建这些表并抛出"ORA-00955:名称已被现有对象使用"异常.我究竟做错了什么?
# For Oracle
batch.jdbc.driver=oracle.jdbc.driver.OracleDriver
batch.jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl
batch.jdbc.user=****
batch.jdbc.password=****
batch.schema=****
batch.schema.script=classpath:/org/springframework/batch/core/schema-oracle10g.sql
batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-oracle10g.sql
batch.jdbc.testWhileIdle=true
batch.data.source.init=false
Run Code Online (Sandbox Code Playgroud)
以下是我的上下文文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder location="classpath:batch.properties" />
<context:component-scan base-package="com.myco.mypack" />
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
<import resource="classpath:/META-INF/spring/module-context.xml" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property …
Run Code Online (Sandbox Code Playgroud) 我正在使用maven的声纳:声纳目标在我的Jenkins工作中生成Sonar报告.
我的Jenkins主机名是:jenhost.tst.com,My Sonar主机是sonhost.tst.com,My Sonar jdbc url是:jdbc:mysql://sonhost.tst.com:3306/sonar,这个数据库有一个用户名使用适当的权限创建的声纳.
现在,在运行Maven目标时,我收到错误:
无法打开与数据库的连接:用户'sonar'@jenhost.tst.xxxx.com'拒绝访问(使用密码:YES)
上述错误中的奇怪之处在于声纳用户正在尝试访问我的Jenkins主机作为数据库名称而不是声纳主机.
我已经检查了我的Maven settings.xml,并且在那里正确地提到了Sonar的数据库URL,并且在Jenkins中也正确地提到了它.
有人对这个有任何线索吗?
blogs ×1
dao ×1
dbunit ×1
easymock ×1
hibernate ×1
java ×1
jenkins ×1
logic ×1
maven ×1
orm ×1
performance ×1
sonarqube ×1
spring ×1
spring-batch ×1
sybase-ase ×1
unit-testing ×1