是否有一个java库可以帮助创建用于测试的类的实例?一个检查bean的属性并用随机数据填充它.
我基本上在寻找与C#的Object Hydrator相当的Java .
我想将我的几个SQL Map XML文件使用的sql片段放在一个单独的文件中.目前,<sql>
具有这些片段的元素与其他元素一起位于其中一个元素中<select>
,这使得它们很难找到.
我是否可以使用仅定义几个<sql>
元素的映射器,而不是用于生成接口的实现?这个映射器的正确名称空间是什么?
这是包含framents的SQL Map文件:
<mapper namespace="com.company.project.dao.someDao">
<sql id="whereDate">
WHERE date(`time`) BETWEEN #{startDate} AND #{endDate}
</sql>
<sql id="someOtherSqlFragment">
...
</sql>
<select id="getSomeData"
resultType="SomeClass"
parameterType="DateParam" >
SELECT some_column, another_column
</select>
FROM some_table
<include refid="whereDate"/>
<include refid="otherSqlFragment"/>
</select>
</mapper>
Run Code Online (Sandbox Code Playgroud)
我想分开这样的元素:
第一个Sql Map文件:
<mapper namespace="com.company.project.dao.???">
<sql id="whereDate">
WHERE date(`time`) BETWEEN #{startDate} AND #{endDate}
</sql>
<sql id="someOtherSqlFragment">
...
</sql>
</mapper>
Run Code Online (Sandbox Code Playgroud)
第二个Sql Map文件:
<mapper namespace="com.company.project.dao.someDao">
<select id="getSomeData"
resultType="SomeClass"
parameterType="DateParam" >
SELECT some_column, another_column
</select>
FROM some_table
<include refid="whereDate"/> …
Run Code Online (Sandbox Code Playgroud) 运行单元测试时,我想在记录ERROR级别消息的任何测试中失败.使用SLF4J/Logback实现此目的的最简单方法是什么?我想避免编写自己的ILoggerFactory实现.
我尝试编写自定义Appender,但我不能通过调用Appender的代码传播异常,Appender的所有异常都会被捕获.
我正在使用JUnit Categories将集成测试与单元测试分开.Surefire插件配置有效 - 它会跳过使用我的标记接口IntegrationTest注释的测试.
但是,Failsafe插件不会选择集成测试.我甚至试图指定junit47提供程序,但是在集成测试阶段运行零测试.
这是pom.xml片段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<groups>com.mycompany.test.IntegrationTest</groups>
<excludedGroups>com.mycompany.test.UnitTest</excludedGroups>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这是日志的故障安全部分:
[INFO] --- maven-failsafe-plugin:2.12:integration-test (default) @ MyProject.war ---
[INFO] Failsafe report directory: /home/stoupa/MyProject/war/target/failsafe-reports
[INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='none', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Run Code Online (Sandbox Code Playgroud)
提供者org.apache.maven.surefire.junitcore.JUnitCoreProvider是否可以在日志输出中看到正确的一个?
我正在编写REST客户端,我需要在测试中模拟HTTP服务器.什么是最合适的图书馆?如果我可以创建预期的HTTP请求并将它们与实际进行比较,那将会很棒.
我试图在Spring中实例化一个泛型类,但我得到以下异常:
bean的初始化失败; 嵌套异常是org.springframework.aop.framework.AopConfigException:无法生成类[class football.dao.jpa.GenericJpaDAO]的CGLIB子类:此问题的常见原因包括使用final类或不可见类; 嵌套异常是java.lang.IllegalArgumentException:Superclass没有null构造函数但没有给出参数:
这是Spring容器的XML配置:
<bean id="clubDAO" class="football.dao.jpa.GenericJpaDAO">
<constructor-arg type="EntityManagerFactory" ref="entityManagerFactory"/>
<constructor-arg type="Class" value="football.model.entities.ClubEntity"/>
<constructor-arg type="String" value="ClubEntity"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
这是通用类:
public class GenericJpaDAO <T extends HavingID> {
private EntityManager em;
private Class entityClass;
private String entityName;
public GenericJpaDAO( Class entityClass, String entityName,
EntityManagerFactory emFactory ) {
this.entityClass = entityClass;
this.entityName = entityName;
em = emFactory.createEntityManager();
}
@Transactional
public void create( T entity ) {
em.persist( entity );
}
// more methods
}
Run Code Online (Sandbox Code Playgroud)
我不确定是什么导致了这一点.我很感激任何想法.
是否可以创建一个接受非字符串属性的自定义JSTL标记?
我想创建一个标签,使用Spring MVC中的PagedListHolder来处理分页.
<%@tag body-content="scriptless" description="basic page template" pageEncoding="UTF-8"%>
<%-- The list of normal or fragment attributes can be specified here: --%>
<%@attribute name="pagedList" required="true" %>
<%-- any content can be specified here e.g.: --%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:choose>
<c:when test="${!pagedList.firstPage}">
<a href="
<c:url value="pagedList">
<c:param name="page" value="${pagedList.page - 1}"/>
</c:url>
"><<
</a>
</c:when>
<c:otherwise>
<<
</c:otherwise>
</c:choose>
<%-- ...more --%>
Run Code Online (Sandbox Code Playgroud)
此标记需要PagedListHolder类的实例.
有点像这样,但我意识到这是无效的.
<templ:pagedList pagedList="${players}"/>
Run Code Online (Sandbox Code Playgroud)
我是否需要编写标记处理程序来实现此目的?
以下为什么不工作?(Chrome,所以Arrays.map没有问题)
[" a ", "b", " c", "d "].map(String.prototype.trim)
TypeError: String.prototype.trim called on null or undefined
Run Code Online (Sandbox Code Playgroud)
我想在Spring MVC 3中对"命令对象"使用直接字段访问.对于带注释的控制器,
是否有相当于useDirectFieldAccess()的方法?
我无法在文档中找到任何内容.
Bert Bates和Kathy Sierra的SCJP 6学习指南在第554页(以及其他要求中)指出x.hashCode()!= y.hashCode()要求x.equals(y)== false.
但是Javadoc for Object没有明确提到这样的要求.Quote:
如果两个对象根据equals(Object)方法相等,则在两个对象中的每一个上调用hashCode方法必须产生相同的整数结果.
我应该采用Javadoc所说的物质含义,例如eq - > hc?那么这两个来源之间就不会有冲突.