Revision: 3305
Author: [email protected]
Date: Wed Feb 17 15:05:17 2010
Log: Added a test for the ProfileManagerImpl to confirm the profile manager
is persisted with its children.
http://code.google.com/p/power-architect/source/detail?r=3305
Added:
/trunk/regress/ca/sqlpower/architect/profile/ProfileManagerImplTest.java
Modified:
/trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
/trunk/src/ca/sqlpower/architect/profile/ProfileManagerImpl.java
=======================================
--- /dev/null
+++
/trunk/regress/ca/sqlpower/architect/profile/ProfileManagerImplTest.java
Wed Feb 17 15:05:17 2010
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of Power*Architect.
+ *
+ * Power*Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Power*Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.profile;
+
+import ca.sqlpower.architect.ArchitectProject;
+import ca.sqlpower.architect.StubArchitectSession;
+import ca.sqlpower.architect.util.ArchitectNewValueMaker;
+import ca.sqlpower.object.PersistedSPObjectTest;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.testutil.NewValueMaker;
+
+public class ProfileManagerImplTest extends PersistedSPObjectTest {
+
+ private ProfileManagerImpl profileManager;
+
+ public ProfileManagerImplTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ profileManager = new ProfileManagerImpl();
+ ArchitectProject project = (ArchitectProject) new
ArchitectNewValueMaker(
+ getRootObject(),
getPLIni()).makeNewValue(ArchitectProject.class, null, "");
+ project.init(new StubArchitectSession());
+ project.setProfileManager(profileManager);
+
+ getRootObject().addChild(project, 0);
+ }
+
+ @Override
+ public NewValueMaker createNewValueMaker(SPObject root,
DataSourceCollection<SPDataSource> dsCollection) {
+ return new ArchitectNewValueMaker(root, dsCollection);
+ }
+
+ @Override
+ protected Class<? extends SPObject> getChildClassType() {
+ return TableProfileResult.class;
+ }
+
+ @Override
+ public SPObject getSPObjectUnderTest() {
+ return profileManager;
+ }
+
+}
=======================================
--- /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
Wed Feb 17 14:19:51 2010
+++ /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
Wed Feb 17 15:05:17 2010
@@ -19,14 +19,17 @@
package ca.sqlpower.architect.util;
+import ca.sqlpower.architect.ArchitectProject;
import ca.sqlpower.architect.profile.ColumnValueCount;
import ca.sqlpower.architect.profile.ProfileSettings;
import ca.sqlpower.architect.profile.TableProfileResult;
import ca.sqlpower.object.SPObject;
import ca.sqlpower.sql.DataSourceCollection;
import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLTable;
import ca.sqlpower.testutil.GenericNewValueMaker;
+import ca.sqlpower.util.SPSession;
public class ArchitectNewValueMaker extends GenericNewValueMaker {
@@ -54,6 +57,21 @@
ColumnValueCount cvc = new ColumnValueCount(Integer.MAX_VALUE,
2, 42);
getRootObject().addChild(cvc, 0);
return cvc;
+ } else if (ArchitectProject.class.isAssignableFrom(valueType)) {
+ ArchitectProject project;
+ final SPObject rootObject = getRootObject();
+ try {
+ project = new ArchitectProject() {
+ @Override
+ public SPSession getSession() {
+ return rootObject.getSession();
+ }
+ };
+ } catch (SQLObjectException e) {
+ throw new RuntimeException(e);
+ }
+ getRootObject().addChild(project, 0);
+ return project;
} else {
return super.makeNewValue(valueType, oldVal, propName);
}
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/ProfileManagerImpl.java Tue
Feb 16 14:02:41 2010
+++ /trunk/src/ca/sqlpower/architect/profile/ProfileManagerImpl.java Wed
Feb 17 15:05:17 2010
@@ -210,6 +210,7 @@
@Override @Mutator
public void setParent(SPObject parent) {
+ SPObject oldParent = getParent();
if (getParent() != null) {
((ArchitectProject)
getParent()).getRootObject().removeSQLObjectPreEventListener(databaseRemovalWatcher);
}
@@ -217,6 +218,7 @@
if (parent != null && ((ArchitectProject)
parent).getRootObject() != null) {
((ArchitectProject)
parent).getRootObject().addSQLObjectPreEventListener(databaseRemovalWatcher);
}
+ firePropertyChange("parent", oldParent, parent);
}
@Override @Accessor
@@ -398,6 +400,9 @@
*/
private void fireProfilesAdded(List<TableProfileResult> results) {
if (results == null) throw new NullPointerException("Can't fire
event for null profile list");
+ for (TableProfileResult tpr : results) {
+ fireChildAdded(TableProfileResult.class, tpr,
results.indexOf(tpr));
+ }
ProfileChangeEvent e = new ProfileChangeEvent(this, results);
for (int i = profileChangeListeners.size() - 1; i >= 0; i--) {
profileChangeListeners.get(i).profilesAdded(e);