Status returns 200 but when i checked the logs cannot see any H2 logs for creating tables or inserting data. So, what do you suggest me to do.
Another thing I want to mention is that while testing the Repository, I was able to do my Repository tests with h2 using the @DataJpaTest annotation. Below you can see my sample properties file and controllertest file.
@RunWith(SpringRunner.class)
@WebMvcTest(VehicleController.class)
@ContextConfiguration(classes=DemoApplication.class)
@AutoConfigureMockMvc
public class VehicleControllerTest {
@Autowired
private WebApplicationContext context;
@Autowired
private MockMvc mvc;
@MockBean
private VehicleService vehicleService;
@Before
public void setup() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
}
@Test
public void RetrieveAllVehicles() throws Exception {
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/api/vehicle").content("application/json");
MvcResult result = this.mvc.perform(requestBuilder).andExpect(status().isOk())
.andReturn();
assertEquals(12 , 12);
}
Application Properties file like that for in memory database with H2.
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.jpa.show-sql=true
spring.datasource.initialization-mode=always