/src/test/java/com/google/ie/test/TransactionalServiceTest.java

http://thoughtsite.googlecode.com/ · Java · 47 lines · 27 code · 7 blank · 13 comment · 0 complexity · cb31b43f2f5d66ce179e442a4e5ed2e5 MD5 · raw file

  1. // Copyright 2009 Google Inc. All Rights Reserved.
  2. /**
  3. *
  4. */
  5. package com.google.ie.test;
  6. import com.google.appengine.tools.development.ApiProxyLocalImpl;
  7. import com.google.apphosting.api.ApiProxy;
  8. import org.junit.After;
  9. import org.junit.Before;
  10. import org.springframework.test.context.ContextConfiguration;
  11. import org.springframework.test.context.TestExecutionListeners;
  12. import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
  13. import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import java.io.File;
  16. /**
  17. * Base test class for all service method tests that need spring transactions.
  18. * The setUp() and tearDown() methods defined below are responsible for creating
  19. * and resetting the test environment.
  20. *
  21. * @author Akhil
  22. */
  23. @ContextConfiguration(locations = { "test-app-context.xml" })
  24. @TestExecutionListeners(TransactionalTestExecutionListener.class)
  25. @Transactional
  26. public class TransactionalServiceTest extends AbstractJUnit4SpringContextTests {
  27. @Before
  28. public void setUp() {
  29. // Set environment as test environment
  30. ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment());
  31. ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")) {
  32. });
  33. }
  34. @After
  35. public void tearDown() {
  36. // Setting api proxy to null. Not necessary but a good practice.
  37. ApiProxy.setDelegate(null);
  38. ApiProxy.setEnvironmentForCurrentThread(null);
  39. }
  40. }