UpgradeCatalog211 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { executeHostComponentStateDDLUpdates(); dbAccessor.setColumnNullable("viewinstanceproperty", "value", true); dbAccessor.setColumnNullable("viewinstancedata", "value", true); } @Inject  UpgradeCatalog211(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }
@Test public void testExecuteDDLUpdates() throws Exception { Injector injector = initInjector(); try { Provider<EntityManager> entityManagerProvider = initEntityManagerProvider(); final DBAccessor dbAccessor = createNiceMock(DBAccessor.class); final OsFamily osFamily = createNiceMock(OsFamily.class); Configuration configuration = createNiceMock(Configuration.class); Connection connection = createNiceMock(Connection.class); Statement statement = createNiceMock(Statement.class); ResultSet resultSet = createNiceMock(ResultSet.class); expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes(); expect(configuration.getDatabaseType()).andReturn(DatabaseType.DERBY).anyTimes(); dbAccessor.getConnection(); expectLastCall().andReturn(connection).anyTimes(); connection.createStatement(); expectLastCall().andReturn(statement).anyTimes(); statement.executeQuery("SELECT COUNT(*) from ambari_sequences where sequence_name='hostcomponentstate_id_seq'"); expectLastCall().andReturn(resultSet).atLeastOnce(); ResultSet rs1 = createNiceMock(ResultSet.class); expect(rs1.next()).andReturn(Boolean.TRUE).once(); statement.executeQuery(anyObject(String.class)); expectLastCall().andReturn(rs1).anyTimes(); Capture<String> queryCapture = EasyMock.newCapture(); dbAccessor.executeQuery(capture(queryCapture)); expectLastCall().once(); dbAccessor.setColumnNullable("viewinstanceproperty", "value", true); expectLastCall().once(); dbAccessor.setColumnNullable("viewinstancedata", "value", true); expectLastCall().once(); replayAll(); AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor, osFamily, entityManagerProvider.get()); Class<?> c = AbstractUpgradeCatalog.class; Field f = c.getDeclaredField("configuration"); f.setAccessible(true); f.set(upgradeCatalog, configuration); f = UpgradeCatalog211.class.getDeclaredField("m_hcsId"); f.setAccessible(true); f.set(upgradeCatalog, new AtomicLong(1001)); upgradeCatalog.executeDDLUpdates(); verifyAll(); Assert.assertTrue(queryCapture.hasCaptured()); Assert.assertTrue(queryCapture.getValue().contains("1001")); } finally { destroyInjector(injector); } }