@Override public void value(DbEnvironment dbEnvironment) { dbEnvironment.buildAppContext() .setupEnvInfra().cleanEnvironment() .deploy(); } });
@Override public DbEnvironment getEnvironment() { return delegate.getEnvironment(); }
@Override public DataSource getDataSource() { return delegate.getDataSource(); }
public DbDeployerAppContext buildAppContext(Credential credential) { return this.getAppContextBuilder().setCredential(credential).build(); }
@Test public void testAseDeploy() throws Exception { DbDeployerAppContext step1Context = getAppContext.valueOf(1); step1Context .setupEnvInfra() .cleanEnvironment() .deploy(); String physicalSchemaStr = step1Context.getEnvironment().getPlatform().getSchemaPrefix(step1Context.getEnvironment().getPhysicalSchema("oats")); this.validateStep1(step1Context.getDataSource(), physicalSchemaStr, new JdbcHelper()); DbDeployerAppContext step2Context = getAppContext.valueOf(2); step2Context .setupEnvInfra() .deploy(); this.validateStep2(step2Context.getDataSource(), physicalSchemaStr, new JdbcHelper()); }
public ImmutableSet<CompareBreak> calculateBaselineBreaks(DbDeployerAppContext appContext) { appContext.setupEnvInfra(); final ImmutableSet<PhysicalSchema> physicalSchemas = appContext.getEnvironment().getPhysicalSchemas(); final DbMetadataManager metadataManager = appContext.getDbMetadataManager(); appContext.cleanAndDeploy(); appContext.cleanEnvironment(); appContext.deploy(new MainDeployerArgs().useBaseline(true));
.setCredential(new Credential("sa", "")) .build(); context.setupEnvInfra(); LOG.info("Step 1 - Clean Environment"); context.cleanEnvironment(); LOG.info("Step 1 - Deploy"); context.deploy(); LOG.info("Step 1- Re-deploy (should be no-op)"); context.deploy(); this.conn = context.getDataSource().getConnection(); .setCredential(new Credential("sa", "")) .build(); context.deploy();
@Test public void testUnitTestDeploy() throws Exception { DbDeployerAppContext builder = new UnitTestDbBuilder() .setReferenceEnvName("test") .setSourcePath("./src/test/resources/platforms/h2/step1") .setDbPlatform(new H2DbPlatform()) .setDbServer("MYCUSTOMDB") .buildContext(); builder.setupEnvInfra(); builder.cleanAndDeploy(); DbDeployerAppContext context = builder.cleanAndDeploy();// run it twice to ensure clean ability DbEnvironment env = builder.getEnvironment(); this.setupVerification(builder); int result; this.conn = context.getDataSource().getConnection(); result = this.jdbc.queryForInt(conn, "select count(*) from bogusSchema.TABLE_A"); assertEquals(4, result); result = this.jdbc.queryForInt(conn, "select count(*) from bogusSchema.VIEW1"); assertEquals(4, result); }
.setDbServer("mytest") .buildContext() .setupEnvInfra() .deploy() .setupAndCleanAndDeploy() .getEnvironment(); .setDbPlatform(new H2DbPlatform()) .setDbServer("mytest") .buildContext().setupAndCleanAndDeploy();
@Before public void setup() throws Exception { DbDeployerAppContext context = getAppContext.valueOf(1); context.setupEnvInfra(); this.logicalSchema1 = context.getEnvironment().getSchemas().getFirst().getName(); // pick one from the environment at random as our logical schema so that we can test the retrieval logic this.logicalSchema2 = "MYSCHEMA2"; // this is just for testing in this DAO, no need to tie to the actual logical schema this.testSchema = context.getEnvironment().getPhysicalSchema(this.logicalSchema1); this.platform = context.getEnvironment().getPlatform(); this.conn = context.getDataSource().getConnection(); this.jdbcHelper = ((AbstractSqlExecutor) context.getSqlExecutor()).createJdbcHelper(context.getDataSource()); this.artifactDeployerDao = (SameSchemaChangeAuditDao) ((DbDeployerAppContextImpl) context).getArtifactDeployerDao(); this.deployExecutionDao = (SameSchemaDeployExecutionDao) context.getDeployExecutionDao(); }
.setDbServer("mytest") .buildContext() .setupEnvInfra() .cleanAndDeploy() .setupAndCleanAndDeploy() .getEnvironment(); .setDbPlatform(new HsqlDbPlatform()) .setDbServer("mytest") .buildContext().setupAndCleanAndDeploy();
@Test @Ignore("Ignoring re-deploy in the flow") public void testRedeploy() { File outputDir = new File("./target/outputReveng/final"); DbEnvironment prod = DbEnvironmentFactory.getInstance().readOneFromSourcePath(outputDir.getPath(), "prod"); prod.setCleanBuildAllowed(true); prod.buildAppContext("deploybuilddbo", "deploybuilddb0") .cleanEnvironment() .deploy(); } }
@Test public void testCrossDbJoin() throws Exception { Set<String> tables = new HashSet<String>(); Set<String> views = new HashSet<String>(); tables.add("TABLE_C"); tables.add("PRODUCT"); // run it twice to ensure that we can drop the schema DbDeployerAppContext dbDeployerAppContext = new UnitTestDbBuilder() .setReferenceEnvName("test") .setDbServer("crossDbJoin") .setSourcePath("platforms/h2/step1") .setDbPlatform(new H2DbPlatform()) .setTables(tables) .setViews(views) .buildContext(); dbDeployerAppContext.setupAndCleanAndDeploy().getEnvironment(); this.setupVerification(dbDeployerAppContext); int result; this.conn = dbDeployerAppContext.getDataSource().getConnection(); result = this.jdbc .queryForInt(conn, "select count(p.*) from bogusSchema.TABLE_C a, SCHEMA2.PRODUCT p where a.PRODUCT_ID = p.PRODUCT_ID "); assertEquals(3, result); }
/** * non-delegate method; calls deploy w/ the passed-in args. */ @Override public DbDeployerAppContext deploy() { return delegate.deploy(defaultArgs); }
@Test public void testInMemoryH2() { DbDeployerAppContext context = UnitTestDbBuilder.newBuilder() .setSourcePath("platforms/db2/step1/system-config-inmem.xml") .setReferenceEnvName("unittestrefh2") .setDbPlatform(new H2DbPlatform()) .setDbServer("mydb2testH2") .buildContext(); context.setupEnvInfra(); context.cleanAndDeploy(); // TODO add assertions }
@Test public void testHsqlConversion() { DbDeployerAppContext builder = UnitTestDbBuilder.newBuilder() .setSourcePath("platforms/sybaseiq/system-config-inmem.xml") .setReferenceEnvName("hsqltest") .setDbPlatform(new H2DbPlatform()) .setDbServer("iqhsqltest") .buildContext(); builder.setupEnvInfra(); builder.build(); } }
@Test public void testUnitTestWithFile() throws Exception { DataSource ds = JdbcDataSourceFactory.createFromJdbcUrl(org.h2.Driver.class, H2JdbcDataSourceFactory.getUrl("fileTest", true), new Credential("sa", "")); this.jdbc = new JdbcHelper(); // run it twice to ensure that we can drop the schema DbDeployerAppContext builder = new UnitTestDbBuilder() .setEnvName("unittest-file") .setDbServer("fileTest") .setSourcePath("platforms/h2/step1") .setDbPlatform(new H2DbPlatform()) .setPersistToFile(true) .buildContext(); builder.setupEnvInfra(); builder.setupEnvInfra(); builder.setupEnvInfra(); builder.cleanAndDeploy(); DbDeployerAppContext dbDeployerAppContext = builder.cleanAndDeploy(); int result; this.conn = dbDeployerAppContext.getDataSource().getConnection(); result = this.jdbc.queryForInt(conn, "select count(*) from bogusSchema.TABLE_A"); assertEquals(4, result); result = this.jdbc.queryForInt(conn, "select count(*) from bogusSchema.VIEW1"); assertEquals(4, result); } }
@Override public DbDeployerAppContext setupEnvInfra(boolean strictSetupEnvInfra) { return delegate.setupEnvInfra(strictSetupEnvInfra); }
@Override public DbDeployerAppContext cleanEnvironment() { return delegate.cleanEnvironment(); }
/** * Builds the deployer context. See the class Javadoc for more information */ private DbDeployerAppContext buildContextUncached() { validateBuilder(); String[] envsToRequest = this.referenceEnvName != null ? new String[] { this.referenceEnvName } : new String[0]; DbEnvironment referenceEnv = DbEnvironmentFactory.getInstance().readFromSourcePath(this.sourcePath, envsToRequest) .getFirst(); DbEnvironment env = referenceEnv.createCopy(); if (this.envName != null) { env.setName(this.envName); } env.setDisableAuditTracking(true); env.setPersistToFile(this.isPersistToFile()); if (this.dbPlatform != null) { env.setPlatform(this.dbPlatform); } if (this.dbServer != null) { env.setDbServer(this.dbServer); } if (this.grantsDisabled) { env.setPermissions(Lists.immutable.<Permission>empty()); } env.setDefaultUserId(credential.getUsername()); env.setDefaultPassword(credential.getPassword()); return env.getAppContextBuilder() .setWorkDir(workDir) .build(); }