使用Junit + eclipse将数据持久存储在本地存储Google App引擎中

音调

我的设置:

win 7,eclipse,GAE sdk 1.8.5,objectify 4,junit4

我正在尝试编写Junit测试用例,以保存两个Car实体并检索它们。我为此使用了对象化,并且效果很好。

我的问题是我需要在多次测试用例中保留这些实体,这意味着一旦我在一次运行中使用doSaveCar()保存,在下一次运行中,我应该在运行doListCar()时取回这两个实体。 。如何在Eclipse环境中的各种junit测试运行中保持本地存储

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

public class OFYTest  {

    private final LocalServiceTestHelper helper = new LocalServiceTestHelper(
            new LocalDatastoreServiceTestConfig(),
            new LocalMemcacheServiceTestConfig());

        @Before
        public void setUp() {
            helper.setUp();

        }
        @After
        public void tearDown() {
            helper.tearDown();
        }

        @Test
        public void doSaveCar() {

            new CRUDServiceImpl().save(new Car("Mustang", "green"));
            new CRUDServiceImpl().save(new Car("SRT", "red"));

        }


        @Test
        public void doListCars(){

            new CRUDServiceImpl().list(AbstractEntity.class);


        }

}
塔尔夫科

我通过设置NoStorage标志,使用objectify,junit,mockito和google-app-engine将数据从一次运行转移到另一次运行

dsService.setNoStorage(false);

参考下面的junit测试

private final LocalServiceTestHelper helper =
          new LocalServiceTestHelper(new LocalUserServiceTestConfig())
              .setEnvIsLoggedIn(true)
              .setEnvAuthDomain("localhost")
              .setEnvEmail("test@localhost");

  @Before
  public void setupCustomerServlet() {
    helper.setUp();
    LocalDatastoreService dsService = (LocalDatastoreService)helper.getLocalService(LocalDatastoreService.PACKAGE);
    dsService.setNoStorage(false);
    customerServlet = new CustomerServlet();
  }

  @After
  public void tearDownHelper() {
    helper.tearDown();
  }

  @Test
  public void testDoGet() throws IOException, ServletException {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);

    // A test entry
    Customer customerIn = new Customer();
    customerIn.setName("Felix");
    customerIn.setAddress("Kuestahler");
    String json = (new Gson()).toJson(customerIn);

    StringWriter stringWriter = new StringWriter();

    when(request.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
    when(response.getWriter()).thenReturn(new PrintWriter(stringWriter));

    customerServlet.doPost(request, response);

    Customer customerOut =  (new Gson()).fromJson(stringWriter.toString(), Customer.class);

    assertEquals(customerOut.getName(), customerIn.getName());
    assertEquals(customerOut.get_id() > 0,true);

    stringWriter = new StringWriter();

    when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
    when(response.getWriter()).thenReturn(new PrintWriter(stringWriter));

    customerServlet.doGet(request, response);

    System.out.println("Out: "+stringWriter.toString());

  }

每次mvn测试运行后,我在本地存储的客户列表都在增长。

imac:~ Felix$ ls -l /Users/Felix/Development/workspace-clb/clb-appEngine/./WEB-  INF/appengine-generated/
total 32
-rw-r--r--  1 Felix  Felix     81 22 Okt 22:00 datastore-indexes-auto.xml
-rw-r--r--  1 Felix  Felix  10068 22 Okt 22:00 local_db.bin
imac:~ Felix$ ls -l /Users/Felix/Development/workspace-clb/clb-appEngine/./WEB-INF/appengine-generated/
total 32
-rw-r--r--  1 Felix  Felix     81 22 Okt 22:08 datastore-indexes-auto.xml
-rw-r--r--  1 Felix  Felix  11265 22 Okt 22:08 local_db.bin`

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Cassandra在JanusGraph中持久存储

来自分类Dev

使用OS.File在文件中持久存储JSON

来自分类Dev

使用docker-entrypoint-initdb.d创建的Mongodb用户不会持久存储在数据库中

来自分类Dev

Cordova:将数据持久存储在数据库中

来自分类Dev

使用Google App引擎,云存储和数据存储的Apps在中国如何运作?

来自分类Dev

使用TTL最好的海量数据持久存储?

来自分类Dev

使用Java将JSONObject存储在Google数据存储中

来自分类Dev

使用flume将数据存储在linux本地目录中

来自分类Dev

不使用SQLite在Android中持久存储数组的最佳方法

来自分类Dev

在不使用SQLite的情况下在Android中持久存储数组的最佳方法

来自分类Dev

google app引擎数据存储区使用“ in”运算符进行查询

来自分类Dev

如何使用JPA在Google App引擎中建立多对多关系

来自分类Dev

如何从使用开放ID Google App引擎登录的用户中获取唯一身份

来自分类Dev

Python中的共享持久存储

来自分类Dev

Swift中的简单持久存储

来自分类Dev

持久存储在kubernetes容器中

来自分类Dev

在Swift中持久存储对象数组

来自分类Dev

持久存储html中的值(javascript)

来自分类Dev

在Swift中持久存储对象数组

来自分类Dev

在Jena TDB三重存储中持久存储数据

来自分类Dev

创建搜索“引擎”以使用python从Google数据存储中获取信息

来自分类Dev

是否可以将密码以纯文本形式存储在内存中,而不能持久存储在数据库,文件等中?

来自分类Dev

在python中解析google app引擎对象

来自分类Dev

使用Scikit学习Google App引擎

来自分类Dev

无法在Google App引擎中使用TfidfVectorizer

来自分类Dev

如何使用本地存储中的数据初始化存储?

来自分类Dev

使用Java将元数据存储在Google App Engine内存缓存中

来自分类Dev

NDB数据存储中的Google App引擎重命名字段

来自分类Dev

使用Cygnus将Orion ContextBroker中的历史数据存储在本地Hadoop数据库中

Related 相关文章

  1. 1

    使用Cassandra在JanusGraph中持久存储

  2. 2

    使用OS.File在文件中持久存储JSON

  3. 3

    使用docker-entrypoint-initdb.d创建的Mongodb用户不会持久存储在数据库中

  4. 4

    Cordova:将数据持久存储在数据库中

  5. 5

    使用Google App引擎,云存储和数据存储的Apps在中国如何运作?

  6. 6

    使用TTL最好的海量数据持久存储?

  7. 7

    使用Java将JSONObject存储在Google数据存储中

  8. 8

    使用flume将数据存储在linux本地目录中

  9. 9

    不使用SQLite在Android中持久存储数组的最佳方法

  10. 10

    在不使用SQLite的情况下在Android中持久存储数组的最佳方法

  11. 11

    google app引擎数据存储区使用“ in”运算符进行查询

  12. 12

    如何使用JPA在Google App引擎中建立多对多关系

  13. 13

    如何从使用开放ID Google App引擎登录的用户中获取唯一身份

  14. 14

    Python中的共享持久存储

  15. 15

    Swift中的简单持久存储

  16. 16

    持久存储在kubernetes容器中

  17. 17

    在Swift中持久存储对象数组

  18. 18

    持久存储html中的值(javascript)

  19. 19

    在Swift中持久存储对象数组

  20. 20

    在Jena TDB三重存储中持久存储数据

  21. 21

    创建搜索“引擎”以使用python从Google数据存储中获取信息

  22. 22

    是否可以将密码以纯文本形式存储在内存中,而不能持久存储在数据库,文件等中?

  23. 23

    在python中解析google app引擎对象

  24. 24

    使用Scikit学习Google App引擎

  25. 25

    无法在Google App引擎中使用TfidfVectorizer

  26. 26

    如何使用本地存储中的数据初始化存储?

  27. 27

    使用Java将元数据存储在Google App Engine内存缓存中

  28. 28

    NDB数据存储中的Google App引擎重命名字段

  29. 29

    使用Cygnus将Orion ContextBroker中的历史数据存储在本地Hadoop数据库中

热门标签

归档