Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

See https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html#testcontext-executing-sql-declaratively

Test class example

Below is the example of test class which can be used as a template/reference for database tests being added to CPS project.

Code Block
languagejava
package org.onap.cps.spi.impl;

import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.cps.DatabaseTestContainer;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.SchemaSetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class CpsAdminPersistenceServiceTest {

    private static final String CLEAR_DATA = "/data/clear-all.sql";
    private static final String SET_DATA = "/data/anchor.sql";

    @ClassRule
    public static DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance();

    @Autowired
    private CpsAdminPersistenceService cpsAdminPersistenceService;

    @Autowired
    private DataspaceRepository dataspaceRepository;

    @Autowired
    private SchemaSetRepository schemaSetRepository;

    @Test
    @Sql({CLEAR_DATA, SET_DATA})
    public void testCreateAnchor() {
        // test
    }
}



Resources

Frameworks and libraries:

...