NamedConfigurationDAOMysqlImpl extends AbstractTableCreatingDAOImpl implements NamedConfigurationDAO { public int createConfiguration(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()); if (namedConfiguration.isActive()) updateAllInactive.update(namedConfiguration.getTenantId(), namedConfiguration.getAssocTypeId()); namedConfiguration.getConfiguration().setConfigurationName(namedConfiguration.getName()); return createConfiguration.update(namedConfiguration.getTenantId(), namedConfiguration.getAssocTypeId(), namedConfiguration.getPluginId().getUri().toASCIIString(), namedConfiguration.getPluginId().getVersion().toString(), namedConfiguration.getName(), namedConfiguration.getConfiguration().marshal(false), namedConfiguration.isActive()); } 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+saved.xml") public void createConfiguration_shouldSave() { NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 3", CONFIG_1_1_3, false); int rowsAffected = namedConfigurationDAO.createConfiguration(namedConfiguration); assertThat(rowsAffected, is(1)); }
@Test @ExpectedDataSet("/dbunit/pluginContainer/plugin_configuration+saved_active.xml") public void createConfiguration_shouldUpdateActive() { NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 3", CONFIG_1_1_3, true); int rowsAffected = namedConfigurationDAO.createConfiguration(namedConfiguration); assertThat(rowsAffected, is(1)); }
@Test @ExpectedDataSet("/dbunit/pluginContainer/plugin_configuration+saved.xml") public void createConfiguration_shouldOverwriteConfigurationName() { WaitingGeneratorConfiguration config_1_1_3 = new WaitingGeneratorConfiguration(); config_1_1_3.setConfigurationName("BOGUS NAME"); config_1_1_3.setAssociationType("1-1-3"); config_1_1_3.setTimeout(3000); NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 3", config_1_1_3, false); int rowsAffected = namedConfigurationDAO.createConfiguration(namedConfiguration); assertThat(rowsAffected, is(1)); }
@Test(expected = NullPointerException.class) public void createConfiguration_shouldThrowOnNullNamedConfiguration() { namedConfigurationDAO.createConfiguration(null); }
@Test(expected = NullPointerException.class) public void createConfiguration_shouldThrowOnNullPluginId() { NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, null, "Configuration 3", CONFIG_1_1_3, false); namedConfigurationDAO.createConfiguration(namedConfiguration); }
@Test(expected = NullPointerException.class) public void createConfiguration_shouldThrowOnNullName() { NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, waitingGenerator.getId(), null, CONFIG_1_1_3, false); namedConfigurationDAO.createConfiguration(namedConfiguration); }
@Test(expected = NullPointerException.class) public void createConfiguration_shouldThrowOnNullConfiguration() { NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 3", null, false); namedConfigurationDAO.createConfiguration(namedConfiguration); }
@Test(expected = DuplicateKeyException.class) public void createConfiguration_shouldThrowOnDuplicateName() { NamedConfiguration namedConfiguration = new NamedConfiguration(1, 1, waitingGenerator.getId(), "Configuration 2", CONFIG_1_1_2, false); namedConfigurationDAO.createConfiguration(namedConfiguration); }