How to use runInitScript method of org.testcontainers.ext.ScriptUtils class

Best Testcontainers-java code snippet using org.testcontainers.ext.ScriptUtils.runInitScript

Source:IntegrationTest.java Github

copy

Full Screen

...35 }36 @Test37 public void transfer() {38 var containerDelegate = new JdbcDatabaseDelegate(postgresDB, "");39 ScriptUtils.runInitScript(containerDelegate, "init-card.sql");40 String body = "{" +41 " \"cardFromNumber\":\"777777777777\"," +42 " \"cardFromValidTill\":\"10-10-2022\"," +43 " \"cardFromCVV\":\"123\"," +44 " \"cardToNumber\":\"88888888888\"," +45 " \"amount\": {" +46 " \"value\":100," +47 " \"currency\":\"RUR\"" +48 " }" +49 "}";50 String excepted = "{" +51 "\"operationId\":\"1\"" +52 "}";53 HttpHeaders headers = new HttpHeaders();54 headers.setContentType(MediaType.APPLICATION_JSON);55 HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);56 ResponseEntity<String> forEntity = restTemplate.postForEntity(57 "/transfer",58 requestEntity,59 String.class60 );61 assertEquals(excepted, forEntity.getBody());62 }63 @Test64 public void confirm() {65 var containerDelegate = new JdbcDatabaseDelegate(postgresDB, "");66 ScriptUtils.runInitScript(containerDelegate, "init-transfer.sql");67 String body = "{" +68 " \"operationId\": \"-1\"," + // указан -1 что бы тесты всегда выполнялись, иначе при совпадении идентификаторов будет ошибка69 " \"code\": \"0000\"" +70 "}";71 String excepted = "{" +72 "\"operationId\":\"-1\"" +73 "}";74 HttpHeaders headers = new HttpHeaders();75 headers.setContentType(MediaType.APPLICATION_JSON);76 HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);77 ResponseEntity<String> forEntity = restTemplate.postForEntity(78 "/confirmOperation",79 requestEntity,80 String.class...

Full Screen

Full Screen

Source:EndToEndTest.java Github

copy

Full Screen

...22 .withNetwork(Network.SHARED)23 .withNetworkAliases("db");24 postgreSQLContainer.start();25 JdbcDatabaseDelegate containerDelegate = new JdbcDatabaseDelegate(postgreSQLContainer, "");26 ScriptUtils.runInitScript(containerDelegate, "data/1-schema.sql");27 ScriptUtils.runInitScript(containerDelegate, "data/2-data.sql");28 String dbJdbcUrl = "jdbc:postgresql://db:5432/integration-tests-db";29 apiContainer = new GenericContainer<>(DockerImageName.parse("demo-api:0.1"));30 apiContainer.withExposedPorts(9000)31 .dependsOn(postgreSQLContainer)32 .withEnv("EXTERNAL_API_URL", "https://reqres.in/api")33 .withEnv("DB_URL", dbJdbcUrl)34 .withEnv("DB_USER", "sa")35 .withEnv("DB_PASSWORD", "sa")36 .withNetwork(Network.SHARED)37 .withNetworkAliases("api");38 apiContainer.start();39 RestAssured.baseURI = "http://" + apiContainer.getHost() + ":" + apiContainer.getMappedPort(9000);40 System.out.println("RestAssured.baseURI : " + RestAssured.baseURI);41 }...

Full Screen

Full Screen

Source:AbstractIntegrationTestConfig.java Github

copy

Full Screen

...22 .withPassword("")23 .withReuse(true);24 mysql.start();25 JdbcDatabaseDelegate jdbcDatabaseDelegate = new JdbcDatabaseDelegate(mysql, "");26 ScriptUtils.runInitScript(jdbcDatabaseDelegate,"data/create-db.sql");27 ScriptUtils.runInitScript(jdbcDatabaseDelegate,"data/truncate-db.sql");28 ScriptUtils.runInitScript(jdbcDatabaseDelegate, "data/insert-data.sql");29 }30 @DynamicPropertySource31 public static void setDatasourceProperties(final DynamicPropertyRegistry registry)32 {33 registry.add("spring.datasource.url", mysql::getJdbcUrl);34 registry.add("spring.datasource.password", mysql::getPassword);35 registry.add("spring.datasource.username", mysql::getUsername);36 }37}...

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PostgreSQLContainer;2import org.testcontainers.ext.ScriptUtils;3public class Main {4 public static void main(String[] args) {5 PostgreSQLContainer container = new PostgreSQLContainer();6 container.start();7 ScriptUtils.runInitScript(container, "init.sql");8 }9}10import org.testcontainers.containers.PostgreSQLContainer;11import org.testcontainers.ext.ScriptUtils;12public class Main {13 public static void main(String[] args) {14 PostgreSQLContainer container = new PostgreSQLContainer();15 container.start();16 ScriptUtils.runInitScript(container, "init.sql");17 }18}19import org.testcontainers.containers.PostgreSQLContainer;20import org.testcontainers.ext.ScriptUtils;21public class Main {22 public static void main(String[] args) {23 PostgreSQLContainer container = new PostgreSQLContainer();24 container.start();25 ScriptUtils.runInitScript(container, "init.sql");26 }27}28import org.testcontainers.containers.PostgreSQLContainer;29import org.testcontainers.ext.ScriptUtils;30public class Main {31 public static void main(String[] args) {32 PostgreSQLContainer container = new PostgreSQLContainer();33 container.start();34 ScriptUtils.runInitScript(container, "init.sql");35 }36}37import org.testcontainers.containers.PostgreSQLContainer;38import org.testcontainers.ext.ScriptUtils;39public class Main {40 public static void main(String[] args) {41 PostgreSQLContainer container = new PostgreSQLContainer();42 container.start();43 ScriptUtils.runInitScript(container, "init.sql");44 }45}46import org.testcontainers.containers.PostgreSQLContainer;47import org.testcontainers.ext.ScriptUtils;48public class Main {49 public static void main(String[] args) {50 PostgreSQLContainer container = new PostgreSQLContainer();51 container.start();52 ScriptUtils.runInitScript(container, "init.sql");53 }54}

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PostgreSQLContainer;2import org.testcontainers.ext.ScriptUtils;3public class TestPostgreSQLContainer extends PostgreSQLContainer<TestPostgreSQLContainer> {4 private static final String IMAGE_VERSION = "postgres:9.6.8";5 private static TestPostgreSQLContainer container;6 private TestPostgreSQLContainer() {7 super(IMAGE_VERSION);8 }9 public static TestPostgreSQLContainer getInstance() {10 if (container == null) {11 container = new TestPostgreSQLContainer();12 }13 return container;14 }15 public void start() {16 super.start();17 ScriptUtils.runInitScript(getJdbcUrl(), "postgres", "postgres",18 "/scripts/init.sql", false);19 }20 public void stop() {21 }22}23import org.testcontainers.containers.PostgreSQLContainer;24import org.testcontainers.jdbc.JdbcDatabaseDelegate;25public class TestPostgreSQLContainer extends PostgreSQLContainer<TestPostgreSQLContainer> {26 private static final String IMAGE_VERSION = "postgres:9.6.8";27 private static TestPostgreSQLContainer container;28 private TestPostgreSQLContainer() {29 super(IMAGE_VERSION);30 }31 public static TestPostgreSQLContainer getInstance() {32 if (container == null) {33 container = new TestPostgreSQLContainer();34 }35 return container;36 }37 public void start() {38 super.start();39 JdbcDatabaseDelegate delegate = new JdbcDatabaseDelegate(getJdbcUrl(), "postgres",40 "postgres");41 delegate.runInitScript("/scripts/init.sql");42 }43 public void stop() {44 }45}46import org.testcontainers.containers.PostgreSQLContainer;47import org.testcontainers.jdbc.JdbcDatabaseDelegate;48public class TestPostgreSQLContainer extends PostgreSQLContainer<TestPostgreSQLContainer> {49 private static final String IMAGE_VERSION = "postgres:9.6.8";50 private static TestPostgreSQLContainer container;51 private TestPostgreSQLContainer() {52 super(IMAGE_VERSION);53 }54 public static TestPostgreSQLContainer getInstance() {

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PostgreSQLContainer;2import org.testcontainers.ext.ScriptUtils;3public class TestContainersDemo {4 public static void main(String[] args) {5 PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer();6 postgreSQLContainer.start();7 ScriptUtils.runInitScript(postgreSQLContainer, "1.sql");8 postgreSQLContainer.stop();9 }10}

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.MySQLContainer;2import org.testcontainers.ext.ScriptUtils;3{4 public static void main( String[] args )5 {6 try (MySQLContainer mySQLContainer = new MySQLContainer()) {7 mySQLContainer.start();8 ScriptUtils.runInitScript(mySQLContainer, "create.sql");9 }10 }11}12CREATE TABLE `test` (13 `id` int(11) NOT NULL AUTO_INCREMENT,14 `name` varchar(255) NOT NULL,15 PRIMARY KEY (`id`)16plugins {17}18repositories {19 mavenCentral()20}21dependencies {22}23test {24 useJUnit()25}

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PostgreSQLContainer;2import org.testcontainers.ext.ScriptUtils;3public class TestPostgresContainer extends PostgreSQLContainer<TestPostgresContainer> {4 public static final String IMAGE_VERSION = "postgres:9.6";5 private String initScriptPath;6 public TestPostgresContainer(String initScriptPath) {7 super(IMAGE_VERSION);8 this.initScriptPath = initScriptPath;9 }10 public void start() {11 super.start();12 ScriptUtils.runInitScript(getJdbcUrl(), getUsername(), getPassword(), initScriptPath, false);13 }14}15public class TestPostgresContainer extends PostgreSQLContainer<TestPostgresContainer> {16 public static final String IMAGE_VERSION = "postgres:9.6";17 private String initScriptPath;18 public TestPostgresContainer(String initScriptPath) {19 super(IMAGE_VERSION);20 this.initScriptPath = initScriptPath;21 }22 public void start() {23 super.start();24 ScriptUtils.runInitScript(getJdbcUrl(), getUsername(), getPassword(), initScriptPath, false);25 }26}27public class TestPostgresContainer extends PostgreSQLContainer<TestPostgresContainer> {28 public static final String IMAGE_VERSION = "postgres:9.6";29 private String initScriptPath;30 public TestPostgresContainer(String initScriptPath) {31 super(IMAGE_VERSION);32 this.initScriptPath = initScriptPath;33 }34 public void start() {35 super.start();36 ScriptUtils.runInitScript(getJdbcUrl(), getUsername(), getPassword(), initScriptPath, false);37 }38}39public class TestPostgresContainer extends PostgreSQLContainer<TestPostgresContainer> {40 public static final String IMAGE_VERSION = "postgres:9.6";41 private String initScriptPath;42 public TestPostgresContainer(String initScriptPath) {43 super(IMAGE_VERSION);44 this.initScriptPath = initScriptPath;45 }46 public void start() {47 super.start();48 ScriptUtils.runInitScript(getJdbcUrl(), getUsername(), getPassword(), initScriptPath

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.ext;2import java.io.IOException;3import java.nio.file.Files;4import java.nio.file.Path;5import java.nio.file.Paths;6import java.sql.Connection;7import java.sql.DriverManager;8import java.sql.SQLException;9import java.util.Properties;10import org.junit.Test;11import org.testcontainers.containers.JdbcDatabaseContainer;12import org.testcontainers.containers.PostgreSQLContainer;13public class ScriptUtilsTest {14 public void testRunInitScript() throws IOException, SQLException {15 JdbcDatabaseContainer<?> container = new PostgreSQLContainer<>()16 .withDatabaseName("test")17 .withUsername("test")18 .withPassword("test");19 container.start();20 Connection connection = DriverManager.getConnection(container.getJdbcUrl(),21 container.getUsername(),22 container.getPassword());23 Path filePath = Paths.get("src", "test", "resources", "test.sql");24 String sqlScript = new String(Files.readAllBytes(filePath));25 ScriptUtils.runInitScript(connection, sqlScript);26 container.stop();27 }28}29package org.testcontainers.ext;30import java.io.IOException;31import java.nio.file.Files;32import java.nio.file.Path;33import java.nio.file.Paths;34import java.sql.Connection;35import java.sql.DriverManager;36import java.sql.SQLException;37import java.util.Properties;38import org.junit.Test;39import org.testcontainers.containers.JdbcDatabaseContainer;40import org.testcontainers.containers.PostgreSQLContainer;41public class ScriptUtilsTest {42 public void testRunInitScript() throws IOException, SQLException {43 JdbcDatabaseContainer<?> container = new PostgreSQLContainer<>()44 .withDatabaseName("test")45 .withUsername("test")46 .withPassword("test");47 container.start();48 Connection connection = DriverManager.getConnection(container.getJdbcUrl(),49 container.getUsername(),50 container.getPassword());51 Path filePath = Paths.get("src", "test

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.GenericContainer;2import org.testcontainers.containers.output.Slf4jLogConsumer;3import org.testcontainers.containers.output.ToStringConsumer;4import org.testcontainers.ext.ScriptUtils;5import org.testcontainers.utility.MountableFile;6import java.io.IOException;7public class ExampleScriptUtils {8 public static void main(String[] args) throws IOException, InterruptedException {9 GenericContainer container = new GenericContainer("postgres:9.6.2")10 .withExposedPorts(5432)11 .withLogConsumer(new Slf4jLogConsumer(org.slf4j.LoggerFactory.getLogger("example")))12 .withLogConsumer(new ToStringConsumer());13 container.start();14 ScriptUtils.runInitScript(container, MountableFile.forClasspathResource("init.sql"));15 container.stop();16 }17}18import org.testcontainers.containers.GenericContainer;19import org.testcontainers.containers.output.Slf4jLogConsumer;20import org.testcontainers.containers.output.ToStringConsumer;21import org.testcontainers.ext.ScriptUtils;22import org.testcontainers.utility.MountableFile;23import java.io.IOException;24public class ExampleScriptUtils {25 public static void main(String[] args) throws IOException, InterruptedException {26 GenericContainer container = new GenericContainer("postgres:9.6.2")27 .withExposedPorts(5432)28 .withLogConsumer(new Slf4jLogConsumer(org.slf4j.LoggerFactory.getLogger("example")))29 .withLogConsumer(new ToStringConsumer());30 container.start();31 ScriptUtils.runInitScript(container, MountableFile.forClasspathResource("init.sql"));32 container.stop();33 }34}35import org.testcontainers.containers.GenericContainer;36import org.testcontainers.containers.output.Slf4jLogConsumer;37import org.testcontainers.containers.output.ToStringConsumer;38import org.testcontainers.ext.ScriptUtils;39import org.testcontainers.utility.MountableFile;40import java.io.IOException;41public class ExampleScriptUtils {42 public static void main(String[] args) throws IOException, InterruptedException {43 GenericContainer container = new GenericContainer("postgres:9.6.2")44 .withExposedPorts(5432)

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.ext;2import org.testcontainers.containers.GenericContainer;3public class RunInitScript {4 public static void main(String[] args) {5 GenericContainer container = new GenericContainer("mysql:latest").withExposedPorts(3306);6 container.start();7 ScriptUtils.runInitScript(container, "/tmp/init.sql");8 container.stop();9 }10}11package org.testcontainers.ext;12import org.testcontainers.containers.GenericContainer;13public class RunInitScript {14 public static void main(String[] args) {15 GenericContainer container = new GenericContainer("mysql:latest").withExposedPorts(3306);16 container.start();17 ScriptUtils.runInitScript(container, "/tmp/init.sql", "UTF-8");18 container.stop();19 }20}21package org.testcontainers.ext;22import org.testcontainers.containers.GenericContainer;23public class RunInitScript {24 public static void main(String[] args) {25 GenericContainer container = new GenericContainer("mysql:latest").withExposedPorts(3306);26 container.start();27 ScriptUtils.runInitScript(container, "/tmp/init.sql", "UTF-8", true);28 container.stop();29 }30}31package org.testcontainers.ext;32import org.testcontainers.containers.GenericContainer;33public class RunInitScript {34 public static void main(String[] args) {35 GenericContainer container = new GenericContainer("mysql:latest").withExposedPorts(3306);36 container.start();37 ScriptUtils.runInitScript(container, "/tmp/init.sql", "UTF-8", true, true);38 container.stop();

Full Screen

Full Screen

runInitScript

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.JdbcDatabaseContainer;2import org.testcontainers.ext.ScriptUtils;3public class TestContainerInitScriptExample {4 public static void main(String[] args) throws Exception {5 JdbcDatabaseContainer container = new JdbcDatabaseContainer("mysql:5.7.21");6 container.start();7 ScriptUtils.runInitScript(container, "classpath:db/init.sql");8 }9}10import org.testcontainers.containers.JdbcDatabaseContainer;11import org.testcontainers.ext.ScriptUtils;12public class TestContainerInitScriptExample {13 public static void main(String[] args) throws Exception {14 JdbcDatabaseContainer container = new JdbcDatabaseContainer("mysql:5.7.21");15 container.start();16 ScriptUtils.runInitScript(container, "classpath:db/init.sql");17 }18}19import org.testcontainers.containers.JdbcDatabaseContainer;20import org.testcontainers.ext.ScriptUtils;21public class TestContainerInitScriptExample {22 public static void main(String[] args) throws Exception {23 JdbcDatabaseContainer container = new JdbcDatabaseContainer("mysql:5.7.21");24 container.start();25 ScriptUtils.runInitScript(container, "classpath:db/init.sql");26 }27}28import org.testcontainers.containers.JdbcDatabaseContainer;29import org.testcontainers.ext.ScriptUtils;30public class TestContainerInitScriptExample {31 public static void main(String[] args) throws Exception {32 JdbcDatabaseContainer container = new JdbcDatabaseContainer("mysql:5.7.21");33 container.start();34 ScriptUtils.runInitScript(container, "classpath:db/init.sql");35 }36}37import org.testcontainers.containers.JdbcDatabaseContainer;38import org.testcontainers.ext.ScriptUtils;39public class TestContainerInitScriptExample {40 public static void main(String[]

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful