UpgradeCatalog221 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { dbAccessor.createIndex("idx_stage_request_id", "stage", "request_id"); dbAccessor.createIndex("idx_hrc_request_id", "host_role_command", "request_id"); dbAccessor.createIndex("idx_rsc_request_id", "role_success_criteria", "request_id"); executeBlueprintProvisionActionDDLUpdates(); dbAccessor.addColumn(TOPOLOGY_HOST_INFO_TABLE, new DBAccessor.DBColumnInfo(TOPOLOGY_HOST_INFO_RACK_INFO_COLUMN, String.class, 255)); } @Inject  UpgradeCatalog221(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }
@Test public void testExecuteDDLUpdates() throws Exception{ final DBAccessor dbAccessor = createNiceMock(DBAccessor.class); dbAccessor.createIndex(eq("idx_stage_request_id"), eq("stage"), eq("request_id")); expectLastCall().once(); dbAccessor.createIndex(eq("idx_hrc_request_id"), eq("host_role_command"), eq("request_id")); expectLastCall().once(); dbAccessor.createIndex(eq("idx_rsc_request_id"), eq("role_success_criteria"), eq("request_id")); expectLastCall().once(); Capture<DBAccessor.DBColumnInfo> capturedHostGroupComponentProvisionColumn = EasyMock.newCapture(); dbAccessor.addColumn(eq("hostgroup_component"), capture(capturedHostGroupComponentProvisionColumn)); expectLastCall().once(); replay(dbAccessor); Module module = new Module() { @Override public void configure(Binder binder) { binder.bind(DBAccessor.class).toInstance(dbAccessor); binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); binder.bind(EntityManager.class).toInstance(entityManager); } }; Injector injector = Guice.createInjector(module); UpgradeCatalog221 upgradeCatalog221 = injector.getInstance(UpgradeCatalog221.class); upgradeCatalog221.executeDDLUpdates(); assertEquals("Incorrect column name added", "provision_action", capturedHostGroupComponentProvisionColumn.getValue().getName()); assertNull("Incorrect default value added", capturedHostGroupComponentProvisionColumn.getValue().getDefaultValue()); assertEquals("Incorrect column type added", String.class, capturedHostGroupComponentProvisionColumn.getValue().getType()); assertEquals("Incorrect column length added", 255, capturedHostGroupComponentProvisionColumn.getValue().getLength().intValue()); assertTrue("Incorrect column nullable state added", capturedHostGroupComponentProvisionColumn.getValue().isNullable()); verify(dbAccessor); }