PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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