NamedConfigurationDAOMysqlImpl extends AbstractTableCreatingDAOImpl implements NamedConfigurationDAO { public int updateConfiguration(NamedConfiguration namedConfiguration) { Preconditions.checkNotNull(namedConfiguration); Preconditions.checkNotNull(namedConfiguration.getPluginId()); Preconditions.checkNotNull(namedConfiguration.getPluginId().getUri()); Preconditions.checkNotNull(namedConfiguration.getPluginId().getVersion()); Preconditions.checkNotNull(namedConfiguration.getName()); Preconditions.checkNotNull(namedConfiguration.getConfiguration()); Preconditions.checkNotNull(namedConfiguration.getConfiguration().getConfigurationName()); String oldName = namedConfiguration.getName(); String newName = namedConfiguration.getConfiguration().getConfigurationName(); int rowsAffected; if (namedConfiguration.isActive()) { updateAllInactive.update(namedConfiguration.getTenantId(), namedConfiguration.getAssocTypeId()); rowsAffected = updateConfigurationActive.update(newName, namedConfiguration.getConfiguration().marshal(false), namedConfiguration.getTenantId(), namedConfiguration.getAssocTypeId(), namedConfiguration.getPluginId().getUri(), namedConfiguration.getPluginId().getVersion(), oldName); } else rowsAffected = updateConfigurationInactive.update(newName, namedConfiguration.getConfiguration().marshal(false), namedConfiguration.getTenantId(), namedConfiguration.getAssocTypeId(), namedConfiguration.getPluginId().getUri(), namedConfiguration.getPluginId().getVersion(), oldName); namedConfiguration.setName(newName); return rowsAffected; } NamedConfigurationDAOMysqlImpl(DataSource dataSource, SqlScriptService sqlScriptService,
                                          PluginRegistry pluginRegistry); @Override String getDefaultTableName(); @Override String getTableCreatingSQLScriptName(); int updateConfiguration(NamedConfiguration namedConfiguration); int createConfiguration(NamedConfiguration namedConfiguration); int deleteConfiguration(NamedConfiguration namedConfiguration); NamedConfiguration readConfiguration(int tenantId, int assocTypeId, PluginId pluginId, String name); List<NamedConfiguration> readConfigurations(int tenantId, int assocTypeId, PluginId pluginId); NamedConfiguration readActiveConfiguration(int tenantId, int assocTypeId); int deactivateByPlugin(PluginId pluginId); int deactivateByAssocType(Integer tenantId, Integer assocTypeId);  }
@Test @ExpectedDataSet("/dbunit/pluginContainer/plugin_configuration+updated_active.xml") public void updateConfiguration_updatesActive() { int rowsModified; NamedConfiguration config; config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 2", CONFIG_1_1_2, true); rowsModified = namedConfigurationDAO.updateConfiguration(config); assertThat(rowsModified, is(1)); }
@Test @ExpectedDataSet("/dbunit/pluginContainer/plugin_configuration+renamed.xml") public void updateConfiguration_renamesConfiguration() { int rowsModified; NamedConfiguration config; config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 1", CONFIG_1_1_1, false); config.getConfiguration().setConfigurationName("Configuration 1 RENAMED"); rowsModified = namedConfigurationDAO.updateConfiguration(config); assertThat(rowsModified, is(1)); config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 2", CONFIG_1_1_2, false); config.getConfiguration().setConfigurationName("Configuration 2 RENAMED"); rowsModified = namedConfigurationDAO.updateConfiguration(config); assertThat(rowsModified, is(1)); config = new NamedConfiguration(1, 2, waitingGenerator.getId(), "Configuration 1", CONFIG_1_2_1, false); config.getConfiguration().setConfigurationName("Configuration 1 RENAMED"); rowsModified = namedConfigurationDAO.updateConfiguration(config); assertThat(rowsModified, is(1)); config = new NamedConfiguration(2, 1, waitingGenerator.getId(), "Configuration 1", CONFIG_2_1_1, false); config.getConfiguration().setConfigurationName("Configuration 1 RENAMED"); rowsModified = namedConfigurationDAO.updateConfiguration(config); assertThat(rowsModified, is(1)); }
@Test @ExpectedDataSet("/dbunit/pluginContainer/plugin_configuration.xml") public void updateConfiguration_shouldIgnoreWhenNotFound() { NamedConfiguration config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 3", CONFIG_1_1_3, false); int rowsModified = namedConfigurationDAO.updateConfiguration(config); assertThat(rowsModified, is(0)); }
@Test(expected = DuplicateKeyException.class) @ExpectedDataSet("/dbunit/pluginContainer/plugin_configuration.xml") public void updateConfiguration_shouldThrowOnExistingName() { WaitingGeneratorConfiguration config_1_1_2 = new WaitingGeneratorConfiguration(); config_1_1_2.setConfigurationName("Configuration 2"); config_1_1_2.setAssociationType("1-1-2"); config_1_1_2.setTimeout(2000); NamedConfiguration config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 1", config_1_1_2, false); namedConfigurationDAO.updateConfiguration(config); }
@Test(expected = NullPointerException.class) public void updateConfiguration_shouldThrowOnNullNamedConfiguration() { namedConfigurationDAO.updateConfiguration(null); }
@Test(expected = NullPointerException.class) public void updateConfiguration_shouldThrowOnNullPluginId() { NamedConfiguration config = new NamedConfiguration(1, 1, null, "Configuration 2", CONFIG_1_1_2, false); namedConfigurationDAO.updateConfiguration(config); }
@Test(expected = NullPointerException.class) public void updateConfiguration_shouldThrowOnNullName() { NamedConfiguration config = new NamedConfiguration(1, 1, waitingGenerator.getId(), null, CONFIG_1_1_1, false); namedConfigurationDAO.updateConfiguration(config); }
@Test(expected = NullPointerException.class) public void updateConfiguration_shouldThrowOnNullConfiguration() { NamedConfiguration config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 1", null, false); namedConfigurationDAO.updateConfiguration(config); }
@Test(expected = NullPointerException.class) public void updateConfiguration_shouldThrowOnNullConfigurationName() { NamedConfiguration config = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 1", CONFIG_NULL_NAME, false); namedConfigurationDAO.updateConfiguration(config); }