use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class KnownConfigurationsTest method testKnownConfigurations.
@Test
public void testKnownConfigurations() {
KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
ConsoleConfiguration[] configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(0, configurations.length);
CCListener listener = new CCListener();
try {
knownConfigurations.addConsoleConfigurationListener(listener);
Assert.assertEquals(0, listener.added.size());
ConsoleConfigurationPreferences preferences = new ConsoleConfigurationPreferences() {
public void setName(String name) {
}
public void readStateFrom(Element element) {
}
public void writeStateTo(Element node) {
}
public File getPropertyFile() {
return null;
}
public File getConfigXMLFile() {
return null;
}
public Properties getProperties() {
return null;
}
public File[] getMappingFiles() {
return null;
}
public URL[] getCustomClassPathURLS() {
return null;
}
public String getName() {
return TestConsoleMessages.KnownConfigurationsTest_fake_prefs;
}
public String getEntityResolverName() {
return null;
}
public ConfigurationMode getConfigurationMode() {
return null;
}
public String getNamingStrategy() {
return null;
}
public String getPersistenceUnitName() {
return null;
}
public String getConnectionProfileName() {
return null;
}
public String getDialectName() {
return null;
}
public String getHibernateVersion() {
return null;
}
};
ConsoleConfigurationPreferences preferences2 = new ConsoleConfigurationPreferences() {
String name = TestConsoleMessages.KnownConfigurationsTest_new_test;
public void setName(String name) {
this.name = name;
}
public void readStateFrom(Element element) {
}
public void writeStateTo(Element node) {
}
public File getPropertyFile() {
return null;
}
public File getConfigXMLFile() {
return null;
}
public Properties getProperties() {
return null;
}
public File[] getMappingFiles() {
return null;
}
public URL[] getCustomClassPathURLS() {
return null;
}
public String getName() {
return name;
}
public String getEntityResolverName() {
return null;
}
public ConfigurationMode getConfigurationMode() {
return null;
}
public String getNamingStrategy() {
return null;
}
public String getPersistenceUnitName() {
return null;
}
public String getConnectionProfileName() {
return null;
}
public String getDialectName() {
return null;
}
public String getHibernateVersion() {
return null;
}
};
ConsoleConfiguration configuration = new ConsoleConfiguration(preferences);
ConsoleConfiguration configuration2 = new ConsoleConfiguration(preferences2);
knownConfigurations.addConfiguration(configuration, false);
knownConfigurations.addConfiguration(configuration2, false);
configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(2, configurations.length);
Assert.assertEquals(listener.added.size(), 0);
knownConfigurations.addConfiguration(configuration, true);
knownConfigurations.addConfiguration(configuration2, true);
configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(2, configurations.length);
Assert.assertEquals(listener.added.size(), 2);
knownConfigurations.removeConfiguration(configuration, false);
knownConfigurations.removeConfiguration(configuration2, false);
configurations = knownConfigurations.getConfigurations();
Assert.assertEquals(0, configurations.length);
Assert.assertEquals(listener.added.size(), 0);
} finally {
KnownConfigurations.getInstance().removeConfigurationListener(listener);
}
}
use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class KnownConfigurationsProvider method inputChanged.
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
super.inputChanged(v, oldInput, newInput);
tv = (TreeViewer) v;
if (oldInput != null && oldInput instanceof KnownConfigurations) {
KnownConfigurations old = (KnownConfigurations) oldInput;
if (old != null) {
old.removeConfigurationListener(this);
}
}
if (newInput != null && newInput instanceof KnownConfigurations) {
KnownConfigurations newz = (KnownConfigurations) newInput;
if (newz != null) {
newz.addConsoleConfigurationListener(this);
}
}
}
Aggregations