如何在春季数据Neo4j(SDN5)中加载夹具数据集以进行集成测试

时间:2018-07-27 10:31:46

标签: java spring spring-boot neo4j spring-data-neo4j

我想在一个(非网络)spring boot应用程序的上下文中使用spring数据neo4j版本5(SDN5)的项目中编写集成测试。对于集成测试,我想在每次测试之前导入定义的数据集,以获取graph-db的初始起点(夹具),但是我不知道如何加载它。有人知道怎么做吗?

我正在使用neo4j 3.4.3,SDN5,Spring Boot 2.0,JUnit 5.1。

我通常会通过集成测试来对嵌入式实例运行和执行

@ExtendWith(SpringExtension.class)
@DataNeo4jTest(
    excludeFilters = @ComponentScan.Filter(
        type = FilterType.ASSIGNABLE_TYPE, value = ApplicationRunner.class
    )
)
@ComponentScan(basePackageClasses = {TransformationService.class})
@ActiveProfiles("test")
class Neo4jAgentAutomatonTest {
  @Test
  void getStates() {
    ...
  }
}

1 个答案:

答案 0 :(得分:0)

a)当您还将neo4j-ogm-test添加到项目中时,它会为您提供TestUtils类。 此类具有方法readCQLFile可以解析文件并返回密码查询。

b)您也可以在没有这种依赖性的情况下自行读取文件。

最后,您在类中添加了SessionFactory依赖关系,并自动执行了该查询

class Test {

  @Autowired
  private SessionFactory sessionFactory;

  @Before
  public void setUp() {
    Session session = sessionFactory.openSession();
    session.query(               
         TestUtils.readCQLFile("<filePath>").toString(), emptyMap());
    // ....
  }
}