1

我使用 Spring Roo,并依赖 Roo 的按需数据进行集成测试

我最近意识到,当我从 Maven 运行它们时,在 Eclipse 中顺利运行的相同集成测试会中断

问题似乎来自 Spring Roo 的按需数据。例如,我收到诸如...之类的错误

testFindPlisByMultiFieldWithNothingSet(trc.suivi.core.repository.PliRepositoryTest):预期:<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:我刚刚从 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());
}
4

2 回答 2

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>

来源:aspectj-maven-plugin

于 2013-09-22T15:29:42.953 回答
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 fromthis affected type is not exposed to the weaver.

更新 2http://www.eclipse.org/articles/Article-Introducing-AJDT/article.html
阅读。尝试使用或参数 http://mojo.codehaus.org/aspectj-maven-plugin/compile-mojo.html#weaveDependencies进行配置。Managing multiple projectsaspectj-maven-pluginweaveDependenciesweaveDirectories

于 2012-10-29T11:26:20.093 回答