我使用Spring Roo和我依赖Roo的数据按需集成测试。
我最近意识到,当我从Maven运行时,在Eclipse中顺利运行的集成测试会中断。
问题似乎来自Spring Roo的需求数据。例如,我得到的错误如......
testFindPlisByMultiFieldWithNothingSet(trc.suivi.core.repository.PliRepositoryTest): 预期:其中10 -10但是:< 0>
...进行以下测试...
@Test
public void testFindPlisByMultiFieldWithNothingSet() {
PliDataOnDemand dod = new PliDataOnDemand();
dod.init();
PliQueryInfo pliQueryInfo = new PliQueryInfo();
List<Pli> plis = pliRepository.findPlisByMultiField(pliQueryInfo, null, null, null, null);
assertEquals(10, plis.size());
}
...表示 dod.init()
未填充我的内存数据库 ...
仅供参考,PliDataOnDemand是我们的一个名为Pli的实体的按需数据类。
有人可以帮忙吗?
编辑:
从命令行:我运行了“mvn test”
来自eclipse:我刚刚从日食菜单中运行了测试
Maven版本: 3.0.4
编辑2:
aspectJ maven插件的输出:
[INFO] 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java:8) is annotated with @Component type annotation from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:26)
[INFO] 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java:8) is annotated with @Configurable type annotation from 'trc.suivi.core.domain.PliDataOnDemand_Roo_Configurable' (PliDataOnDemand_Roo_Configurable.aj:11)
[INFO] Extending interface set for type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) to include 'org.springframework.beans.factory.aspectj.ConfigurableObject' (AnnotationBeanConfigurerAspect.aj)
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped field from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'java.util.Random trc.suivi.core.domain.PliDataOnDemand.rnd')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped field from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'java.util.List<trc.suivi.core.domain.Pli> trc.suivi.core.domain.PliDataOnDemand.data')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped field from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'trc.suivi.core.domain.UtilisateurDataOnDemand trc.suivi.core.domain.PliDataOnDemand.utilisateurDataOnDemand')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'trc.suivi.core.domain.Pli trc.suivi.core.domain.PliDataOnDemand.getNewTransientPli(int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setDateAnnulation(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setDateCreation(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setDateModification(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setDateReception(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setFDV(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setIdentifiant(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setNbPlisFDVEstime(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setNumeroPli(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setPaiement(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setStatut(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.setTypePli(trc.suivi.core.domain.Pli, int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'trc.suivi.core.domain.Pli trc.suivi.core.domain.PliDataOnDemand.getSpecificPli(int)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'trc.suivi.core.domain.Pli trc.suivi.core.domain.PliDataOnDemand.getRandomPli()')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'boolean trc.suivi.core.domain.PliDataOnDemand.modifyPli(trc.suivi.core.domain.Pli)')
[INFO] Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java) has intertyped method from 'trc.suivi.core.domain.PliDataOnDemand_Roo_DataOnDemand' (PliDataOnDemand_Roo_DataOnDemand.aj:'void trc.suivi.core.domain.PliDataOnDemand.init()')
[INFO] Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java:8) advised by before advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (spring-aspects-3.1.1.RELEASE.jar!AbstractDependencyInjectionAspect.class:78(from AbstractDependencyInjectionAspect.aj)) [with runtime test]
[INFO] Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java:8) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (spring-aspects-3.1.1.RELEASE.jar!AbstractDependencyInjectionAspect.class:87(from AbstractDependencyInjectionAspect.aj)) [with runtime test]
[INFO] Join point 'initialization(void trc.suivi.core.domain.PliDataOnDemand.<init>())' in Type 'trc.suivi.core.domain.PliDataOnDemand' (PliDataOnDemand.java:8) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (spring-aspects-3.1.1.RELEASE.jar!AbstractDependencyInjectionAspect.class:87(from AbstractDependencyInjectionAspect.aj)) [with runtime test]
编辑3:
我明白了:
testFindPlisByMultiFieldWithIdentifiantSet(trc.suivi.core.repository.PliRepositoryTest): Unable to find trc.suivi.core.domain.Utilisateur with id 1; nested exception is javax.persistence.EntityNotFoundException: Unable to find trc.suivi.core.domain.Utilisateur with id 1
进行以下测试:
@Test
public void testFindPlisByMultiFieldWithIdentifiantSet() {
PliDataOnDemand dod = new PliDataOnDemand();
Pli pli = dod.getSpecificPli(0);
pli.setIdentifiant("theIdentifiant");
pliRepository.save(pli);
PliQueryInfo pliQueryInfo = new PliQueryInfo();
pliQueryInfo.setIdentifiant("theIdentifiant");
List<Pli> plis = pliRepository.findPlisByMultiField(pliQueryInfo, null, null, "identifiant", "desc");
assertEquals(1, plis.size());
}
答案 0 :(得分:5)
这是将依赖关系jar暴露给maven和aspectj weaver的方法:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.agroup</groupId>
<artifactId>to-weave</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.anothergroup</groupId>
<artifactId>gen</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<weaveDependencies>
<weaveDependency>
<groupId>org.agroup</groupId>
<artifactId>to-weave</artifactId>
</weaveDependency>
<weaveDependency>
<groupId>org.anothergroup</groupId>
<artifactId>gen</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>
...
</project>
答案 1 :(得分:3)
为什么你自己打电话给dod.init()
?您可以按需自动发送数据。不要忘记使用@RunWith(SpringJUnit4ClassRunner.class)
注释您的测试类。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
@Transactional
public class PliTest {
@Autowired
private PliDataOnDemand dod;
// your tests
}
<强>更新强>
看到你的maven输出我会说aspect
编织有问题。
从您的输出has intertyped method from
和this affected type is not exposed to the weaver
。
更新2
从中了解Managing multiple projects
http://www.eclipse.org/articles/Article-Introducing-AJDT/article.html。
尝试使用aspectj-maven-plugin
或weaveDependencies
参数配置weaveDirectories
http://mojo.codehaus.org/aspectj-maven-plugin/compile-mojo.html#weaveDependencies