Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SpringBootApplication(scanBasePackages= "pl.netsprint.bt.rest")
- public class Application {
- private Log log = LogFactory.getLog(Application.class);
- public static void main(String[] args){
- Application app = new Application();
- app.start(args);
- }
- public void start(String[] args){
- log.info("Starting SpringBoot application :) ");
- log.debug(Arrays.asList(args).toString().replace(",","").replace("[","").replace("]",""));
- SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
- builder.logStartupInfo(true);
- builder.headless(true);
- builder.registerShutdownHook(true);
- builder.application();
- ConfigurableApplicationContext ctx = builder.run(args);
- Environment env = ctx.getEnvironment();
- String port = env.getProperty("server.port");
- log.info("Started SpringBoot application running on port: " + port);
- }
- }
- @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
- @ActiveProfiles("test")
- public class ApplicationTest {
- public Log log = LogFactory.getLog(this.getClass());
- @Autowired
- private Environment env;
- @LocalServerPort
- private int port;
- public void setPort(int port){
- this.port = port;
- }
- public int getPort(){
- return port;
- }
- @Test
- public void testContext(){
- Assert.assertNotNull(getPort());
- Assert.assertNotNull(env);
- }
- }
- application-test.properties
- #DataSource
- spring.datasource.type=org.h2.jdbcx.JdbcDataSource
- spring.datasource.platform=H2
- spring.datasource.driver-class-name=org.h2.Driver
- spring.datasource.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1
- spring.datasource.username=sa
- spring.datasource.password=
- #JPA/Hibernate
- spring.jpa.properties.hibernate.show_sql=true
- spring.jpa.properties.hibernate.use_sql_comments=true
- spring.jpa.properties.hibernate.format_sql=false
- spring.jpa.hibernate.ddl-auto=create
- spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
- spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
- logging.level.org.hibernate.SQL=DEBUG
- logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
- @Repository
- public interface ClientJpaRepository extends JpaRepository<Client,Long>{
- }
- public class ClientJpaRepositoryTest extends ApplicationTest {
- @Autowired
- private ClientJpaRepository repoClient;
- @Test
- public void test() throws Exception {
- Client clientTvn = new Client("Client Tvn");
- repoClient.save(clientTvn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement