播放测试对象Yaml的框架图像BLOB文件 [英] Play Framework Image BLOB File for Test Object Yaml

查看:99
本文介绍了播放测试对象Yaml的框架图像BLOB文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用yaml结构设置测试Blob图片?

How do you set up a Test Blob Image using the yaml structure?

此外,BLOB文件的数据库结构是什么? (MySQL)

Also, what is the database structure for a BLOB file? (MySQL)

推荐答案

前一段时间,我在一个项目上遇到了同样的问题.但是,由于找不到用夹具解决此问题的方法(因为数据库将blob对象存储为字符串,如上文Pere所述),因此我创建了一种解决方法,至少可以在测试用例场景中解决此问题.我创建了以下文件/app/job/Bootstrap.java:

I have experienced the same kind of problem a while ago on a project. However as I could not find a way to solve this with the fixtures (as the database stores the blob object as a string as Pere explained above), I created a workaround to at least solve this problem in a test-case-scenario. I created the following file /app/job/Bootstrap.java:

import play.test.*;
import play.jobs.*;
import play.db.DB;
import models.*;

import java.util.List;

@OnApplicationStart
public class Bootstrap extends Job {
     public void doJob() {
        // Load default data if the database is empty
        if(Item.count() == 0) {
            Fixtures.loadModels("my_fixtures.yml");
            List<Item> allItems = Item.findAll();
            for (Item a: allItems){
                DB.execute("UPDATE `Item` SET image='item_" + a.name.toLowerCase() + ".png|image/png' WHERE id=" + a.getId());
            }
        }
    }
}

我要做的第一件事是如果数据库中没有存储"Item",则用初始数据填充数据库.
第二件事是遍历所有播放的物品"!只是存储在数据库中,可以从"my_fixtures.yml"文件中读取.如上例所示,这里的每个项目的字符串字段都会更新.

The first thing I do is filling the database with initial data if there are no 'Item' already stored in the database.
The second thing is iterating over all the 'Item' which play! just stored in the database, which are read from the "my_fixtures.yml" file. Here for each item the string field will get updated as shown in the example above.

我知道这并不是OP中问题的完全答案,但是它提供了一些解决此问题的方法.

I know this is not exactly the answer to question in the OP, but it gives some kind idea to work around this issue..

在上面给出的示例中,我假定按照 application.conf 中的说明,将图片手动上传到附件文件夹,并且每个图片名称都类似于:"item_< ; item_name_in_lowercase>带有".png"扩展名

In the example given above I assume that the pictures are uploaded manually to your attachment folder as given in your application.conf, and that each image name is like: "item_<item_name_in_lowercase>" with a ".png" extension

这篇关于播放测试对象Yaml的框架图像BLOB文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆