In my spring boot application, I have the following class that calls a stored procedure
public class FmTrfUtil {
static int returnVal;
public static int insertFmTrfs(List<String> trfs, String source) {
EntityManager em = Persistence.createEntityManagerFactory("RIStore_FM").createEntityManager();
Session session = em.unwrap( Session.class );
final String[] trfArray = trfs.toArray(new String[trfs.size()]);
final String src = source;
session.doWork( new Work(){
public void execute(Connection conn) throws SQLException {
CallableStatement stmt = null;
OracleConnection oraCon = conn.unwrap(OracleConnection.class);
Array array = oraCon.createARRAY("VARCHAR2_TAB_T", trfArray);
stmt = conn.prepareCall("{? = call FM_TRF_UTIL.process_fm_trf(?,?)}");
stmt.registerOutParameter(1, Types.INTEGER);
stmt.setArray(2, array);
stmt.setString(3, src);
stmt.execute();
returnVal = stmt.getInt(1);
}
});
return returnVal;
}
}
Now I would like to run integration test on this class using spring test following example in Integration Testing a Spring Boot Application.
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = RistoreWebApplication.class)
@WebAppConfiguration
public class FmTrfUtilTest {
static EntityManagerFactory factory = null;
static EntityManager manager = null;
@Test
public void test() {
List<String> trfs = new ArrayList<String>();
trfs.add("TRF000001");
trfs.add("TRF000002");
int ret = FmTrfUtil.insertFmTrfs(trfs, "SARC");
assertTrue(ret > 0);
}
}
Here RistoreWebApplication
is the name of the main app class which is the entry point of the api. According to that web page, "The @SpringApplicationConfiguration
annotation will trigger logic for reading Spring Boot specific configurations, properties, and so on." My understanding is this will load database connection information in my application.properties as well:
spring.datasource.url=jdbc:oracle:thin:@ldap://xxx:389/risdev3, cn=OracleContext,dc=yyy,dc=com
spring.datasource.username=rowner
spring.datasource.password=rowner987
spring.datasource.driverClassName=oracle.jdbc.OracleDriver
However, when I run this test, I got UnsupportedOperationException: The application must supply JDBC connections
. How exactly do I load the db connection config running the test? I am using spring boot 1.3
EDIT
since application.properties lives in src/main/resources while my test classes are in src/test/java, I figured I'd have another property file under src/test/resources
based on the answer to Spring jUnit Testing properties file. So I did that and added annotation @PropertySource("classpath:application-test.properties")
in my test class, but still getting the same error. Is there a way to know whether the property file is being read and/or what is the current classpath?