PageRenderTime 52ms CodeModel.GetById 30ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 0ms

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

http://thoughtsite.googlecode.com/
Java | 64 lines | 42 code | 11 blank | 11 comment | 0 complexity | 7c43a9745bb43733f4e2fe902b9fc2c2 MD5 | raw file
 1package com.google.ie.test;
 2
 3import com.google.appengine.api.datastore.dev.LocalDatastoreService;
 4import com.google.appengine.tools.development.ApiProxyLocalImpl;
 5import com.google.apphosting.api.ApiProxy;
 6import com.google.ie.dto.RetrievalInfo;
 7
 8import org.junit.After;
 9import org.junit.Before;
10import org.springframework.test.context.ContextConfiguration;
11import org.springframework.test.context.TestExecutionListeners;
12import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
13import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
14import org.springframework.transaction.annotation.Transactional;
15
16import java.io.File;
17
18import javax.jdo.JDOHelper;
19
20/**
21 * Base class for testing all data access classes.
22 * 
23 * @author abraina
24 * 
25 */
26@ContextConfiguration(locations = { "test-app-context.xml" })
27@TestExecutionListeners(TransactionalTestExecutionListener.class)
28@Transactional
29public class DatastoreTest extends AbstractJUnit4SpringContextTests {
30
31    /** Persistence manager factory to be used in tests */
32    protected static javax.jdo.PersistenceManagerFactory pmf = JDOHelper
33                    .getPersistenceManagerFactory("transactions-optional");
34
35    @Before
36    public void setUp() {
37
38        // Set test environment
39        ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment());
40        ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")) {
41        });
42        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
43        // Local datastore should not save test objects to file
44        proxy.setProperty(LocalDatastoreService.NO_STORAGE_PROPERTY, Boolean.TRUE.toString());
45
46    }
47
48    @After
49    public void tearDown() {
50        // Set environment as test environment
51        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
52        LocalDatastoreService datastoreService =
53                        (LocalDatastoreService) proxy.getService(LocalDatastoreService.PACKAGE);
54        datastoreService.clearProfiles();
55        // Setting api proxy to null. Not necessary but a good practice.
56        ApiProxy.setDelegate(null);
57        ApiProxy.setEnvironmentForCurrentThread(null);
58    }
59
60    protected RetrievalInfo createDummyRetrievalParam(int startindex, int noOfRecords,
61                    String orderOn, String orderBy) {
62        return new RetrievalInfo(startindex, noOfRecords, orderOn, orderBy);
63    }
64}