Некоторые из моих фрагментов кода написаны ниже .. Я думаю, что я напутал с аннотациями. Также использование xls и xml, и Entity не связаны должным образом. Как протестировать базу данных в Springit с помощью Junit с аннотациями @ExpectedDatabase и @DatabaseSetup?
@ContextConfiguration(classes = {TestConfig.class}, initializers = {ConfigFileApplicationContextInitializer.class} )
public class ClassTest extends TestBase{
@Test
@DatabaseSetups({@DatabaseSetup(connection = "conection-name", value = "classpath:/path..xls/" )}){
@ExpectedDatabase(connection = "conection-name", value = "classpath:/path..xls/")
void test01(){
// set of operations to set values and enter in method
autowiredClass.methodName1(parameterName1);
}
}
// We enter into autowiredClass.methodName1
@Override
protected ObjectClass methodName1(Objectname parameterName1){
// set of operations to perform and take the parameter
EntityClass dataEntity = service.getInfo(parameters);
// Note that we are getting correct parameter required.
// We enter into getInfo method
@Transactional
public EntityClass getInfo(parameters){
// check parameters are not null they are not null
// below line returns null --> working of annotations and whole process is unclear..
List<EntityClass> xyz = dao.selectquery(parameters);
}
// Dao layer
@Dao
@ConfigAutowireable
public interface dao {
@Select
List<EntityClass> selectquery(parameter);
}
// a simple select query
select * from TableName;
// EntityClass
@Entity
@Table(name = "TableName")
public class EntityClass{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "colName1")
private Integer colName1;
@Column(name = "colName2")
private Integer colName2;
}
// xls file
col1 col2
data1 data2
// TestBase
@ExtendWith(SpringExtention.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class, TransactionaDbUnitTestExecutionListener.class)
@ImportResources({"Classpath:/path..xml/"})
public class TestBase{
@BeforeEach
public void setup(TestInfo testinfo){
}
}