|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 3 | + * the License. You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 8 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 9 | + * specific language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * Copyright 2021-2021 the original author or authors. |
| 12 | + */ |
| 13 | + |
| 14 | +package org.stdg.test; |
| 15 | + |
| 16 | +import org.junit.jupiter.api.AfterAll; |
| 17 | +import org.junit.jupiter.api.BeforeAll; |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.stdg.DatasetRow; |
| 20 | +import org.stdg.SqlTestDataGenerator; |
| 21 | +import org.testcontainers.containers.OracleContainer; |
| 22 | + |
| 23 | +import javax.sql.DataSource; |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +import static org.stdg.test.TestTable.*; |
| 27 | +import static org.stdg.test.TestTable.TestTableAssert.assertThat; |
| 28 | + |
| 29 | +public class OracleTest { |
| 30 | + |
| 31 | + private static DataSource DATA_SOURCE; |
| 32 | + |
| 33 | + private static final OracleContainer ORACLE_CONTAINER |
| 34 | + = new OracleContainer("gvenzl/oracle-xe") |
| 35 | + .withEnv("ORACLE_PASSWORD", "oracle"); |
| 36 | + |
| 37 | + private static SqlExecutor SQL_EXECUTOR; |
| 38 | + |
| 39 | + @BeforeAll |
| 40 | + public static void beforeAll() { |
| 41 | + ORACLE_CONTAINER.start(); |
| 42 | + String jdbcUrl = ORACLE_CONTAINER.getJdbcUrl(); |
| 43 | + DATA_SOURCE = DataSourceBuilder.INSTANCE.build(jdbcUrl |
| 44 | + , ORACLE_CONTAINER.getUsername() |
| 45 | + , ORACLE_CONTAINER.getPassword()); |
| 46 | + SQL_EXECUTOR = new SqlExecutor(DATA_SOURCE); |
| 47 | + } |
| 48 | + |
| 49 | + @AfterAll |
| 50 | + public static void stopContainer() { |
| 51 | + ORACLE_CONTAINER.stop(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void should_generate_working_insert() { |
| 56 | + |
| 57 | + // GIVEN |
| 58 | + TestTable table = |
| 59 | + buildUniqueTable(DATA_SOURCE |
| 60 | + , "TABLE_NAME" |
| 61 | + , "col1 NUMBER" |
| 62 | + + ", col2 varchar(25)" |
| 63 | + + ", col3 varchar(25)") |
| 64 | + .create() |
| 65 | + .insertValues("1, 'col2_val', 'col3_val'"); |
| 66 | + |
| 67 | + String tableName = table.getTableName(); |
| 68 | + DatasetRow datasetRow = |
| 69 | + DatasetRow.ofTable(tableName) |
| 70 | + .addColumnValue("col1", 1) |
| 71 | + .addColumnValue("col2", "col2_val") |
| 72 | + .addColumnValue("col3", "col3_val"); |
| 73 | + |
| 74 | + //WHEN |
| 75 | + SqlTestDataGenerator sqlTestDataGenerator = SqlTestDataGenerator.buildFrom(DATA_SOURCE); |
| 76 | + |
| 77 | + List<String> insertStatements = sqlTestDataGenerator.generateInsertListFor(datasetRow); |
| 78 | + |
| 79 | + // THEN |
| 80 | + table.recreate(); |
| 81 | + |
| 82 | + SQL_EXECUTOR.execute(insertStatements); |
| 83 | + assertThat(table) |
| 84 | + .withGeneratedInserts(insertStatements) |
| 85 | + .hasNumberOfRows(1) |
| 86 | + .row(0).hasValues(1, "col2_val", "col3_val"); |
| 87 | + |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments