EntityManagerClinicTests.java
上传用户:dezhong
上传日期:2022-08-10
资源大小:167k
文件大小:1k
源码类别:

Java编程

开发平台:

Java

  1. package org.springframework.samples.petclinic.jpa;
  2. import java.util.List;
  3. import org.springframework.samples.petclinic.aspects.UsageLogAspect;
  4. /**
  5.  * <p>
  6.  * Tests for the DAO variant based on the shared EntityManager approach. Uses
  7.  * TopLink Essentials (the reference implementation) for testing.
  8.  * </p>
  9.  * <p>
  10.  * Specifically tests usage of an <code>orm.xml</code> file, loaded by the
  11.  * persistence provider through the Spring-provided persistence unit root URL.
  12.  * </p>
  13.  *
  14.  * @author Rod Johnson
  15.  * @author Juergen Hoeller
  16.  */
  17. public class EntityManagerClinicTests extends AbstractJpaClinicTests {
  18. private UsageLogAspect usageLogAspect;
  19. public void setUsageLogAspect(UsageLogAspect usageLogAspect) {
  20. this.usageLogAspect = usageLogAspect;
  21. }
  22. @Override
  23. protected String[] getConfigPaths() {
  24. return new String[] {
  25. "applicationContext-jpaCommon.xml",
  26. "applicationContext-toplinkAdapter.xml",
  27. "applicationContext-entityManager.xml"
  28. };
  29. }
  30. public void testUsageLogAspectIsInvoked() {
  31. String name1 = "Schuurman";
  32. String name2 = "Greenwood";
  33. String name3 = "Leau";
  34. assertTrue(this.clinic.findOwners(name1).isEmpty());
  35. assertTrue(this.clinic.findOwners(name2).isEmpty());
  36. List<String> namesRequested = this.usageLogAspect.getNamesRequested();
  37. assertTrue(namesRequested.contains(name1));
  38. assertTrue(namesRequested.contains(name2));
  39. assertFalse(namesRequested.contains(name3));
  40. }
  41. }