SORU
22 Aralık 2008, PAZARTESİ


Nasıl JPA yapılandırmak için Maven test için

Bir şekilde Maven projesi dağıtımı için kullanılan normal bir yerine test etmek için kullanılır bu tür ikinci persistence.xml bir dosyası var mı?

Denedim koyarak bir persistence.xml içine src/test/resources/META-INF alır, hangi kopyalanan erek/test-dersleri/META-INF, ama görünüşe göre hedef/sınıfları/META-INF (kopyadan src/main/resources) alır tercih rağmen mvn -X test listesi sınıf girdiler hemen sipariş:

[DEBUG] Test Classpath :
[DEBUG]   /home/uqpbecke/dev/NetBeansProjects/UserManager/target/test-classes
[DEBUG]   /home/uqpbecke/dev/NetBeansProjects/UserManager/target/classes
[DEBUG]   /home/uqpbecke/.m2/repository/junit/junit/4.5/junit-4.5.jar
...

JPA yapılandırma dağıtım sürümü değiştirmek zorunda kalmadan basit hsqldb bir yapılandırma karşı testler yapmak mümkün, ideal olarak düz projesi ödeme sonra yerel verdiği için herhangi bir ihtiyaç olmadan istiyorum.

CEVAP
24 Temmuz 2009, Cuma


Aşağıdaki Maven 2.1 (infaz bağlama verebilecek test ve paketi arasında bir faz yok önce) için çalışacak.

Maven-antrun-eklenti testler süresince test sürümü ile persistence.xml bakın, proje paketlenmiş önce doğru sürümü geri yükleyebilirsiniz.

Bu örnek üretim versiyonu src/main/resources/meta-inf/persistence.xml ve test sürümü, META-INF ve hedef//-sınıflar test META-INF sırasıyla//sınıfları hedef kopyalanmış olacaktır src/test/resources/meta-inf/persistence.xml olduğunu varsayar.

Bir mojo içine saklanması için daha şık olurdu, ama sadece bir dosya kopyalama konum olarak, overkill gibi görünüyor.

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.3</version>
  <executions>
    <execution>
      <id>copy-test-persistence</id>
      <phase>process-test-resources</phase>
      <configuration>
        <tasks>
          <!--backup the "proper" persistence.xml-->
          <copy file="${project.build.outputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml.proper"/>
          <!--replace the "proper" persistence.xml with the "test" version-->
          <copy file="${project.build.testOutputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml"/>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
    <execution>
      <id>restore-persistence</id>
      <phase>prepare-package</phase>
      <configuration>
        <tasks>
          <!--restore the "proper" persistence.xml-->
          <copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" tofile="${project.build.outputDirectory}/META-INF/persistence.xml"/>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ArkticPlanet

    ArkticPlanet

    9 ŞUBAT 2010
  • jonathepianist

    jonathepiani

    31 Temmuz 2008
  • Rayone GB

    Rayone GB

    14 Temmuz 2007