Revision: 3307
Author: [email protected]
Date: Thu Feb 18 07:51:21 2010
Log: Added tests for the TableProfileResult class to ensure it can be persisted correctly. Also corrected the annotations on the class and updated the new value maker for the tests.
http://code.google.com/p/power-architect/source/detail?r=3307

Added:
 /trunk/regress/ca/sqlpower/architect/profile/TableProfileResultTest.java
Modified:
 /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
 /trunk/src/ca/sqlpower/architect/profile/TableProfileResult.java

=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/profile/TableProfileResultTest.java Thu Feb 18 07:51:21 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.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 TableProfileResultTest extends PersistedSPObjectTest {
+
+    private TableProfileResult tpr;
+
+    public TableProfileResultTest(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        tpr = (TableProfileResult) new ArchitectNewValueMaker(
+ getRootObject(), getPLIni()).makeNewValue(TableProfileResult.class, null, "");
+    }
+
+    @Override
+    protected Class<? extends SPObject> getChildClassType() {
+        return ColumnProfileResult.class;
+    }
+
+    @Override
+    public SPObject getSPObjectUnderTest() {
+        return tpr;
+    }
+
+    @Override
+    public NewValueMaker createNewValueMaker(SPObject root,
+            DataSourceCollection<SPDataSource> dsCollection) {
+        return new ArchitectNewValueMaker(root, dsCollection);
+    }
+
+}
=======================================
--- /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Wed Feb 17 15:05:17 2010 +++ /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Thu Feb 18 07:51:21 2010
@@ -20,12 +20,14 @@
 package ca.sqlpower.architect.util;

 import ca.sqlpower.architect.ArchitectProject;
+import ca.sqlpower.architect.profile.ColumnProfileResult;
 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.SQLColumn;
 import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.testutil.GenericNewValueMaker;
@@ -53,6 +55,12 @@
(ProfileSettings) makeNewValue(ProfileSettings.class, null, ""));
             getRootObject().addChild(tpr, 0);
             return tpr;
+        } else if (valueType == ColumnProfileResult.class) {
+ TableProfileResult tpr = (TableProfileResult) makeNewValue(TableProfileResult.class, null, "");
+            ColumnProfileResult cpr = new ColumnProfileResult(
+ (SQLColumn) makeNewValue(SQLColumn.class, null, ""), tpr);
+            cpr.setParent(tpr);
+            return cpr;
         } else if (valueType == ColumnValueCount.class) {
ColumnValueCount cvc = new ColumnValueCount(Integer.MAX_VALUE, 2, 42);
             getRootObject().addChild(cvc, 0);
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/TableProfileResult.java Wed Feb 17 14:19:51 2010 +++ /trunk/src/ca/sqlpower/architect/profile/TableProfileResult.java Thu Feb 18 07:51:21 2010
@@ -20,6 +20,7 @@

 import java.text.DateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -30,8 +31,13 @@
 import ca.sqlpower.architect.ddl.DDLGenerator;
 import ca.sqlpower.architect.ddl.DDLUtils;
 import ca.sqlpower.object.SPObject;
+import ca.sqlpower.object.annotation.Accessor;
 import ca.sqlpower.object.annotation.Constructor;
 import ca.sqlpower.object.annotation.ConstructorParameter;
+import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.object.annotation.NonBound;
+import ca.sqlpower.object.annotation.NonProperty;
+import ca.sqlpower.object.annotation.Transient;
 import ca.sqlpower.sql.JDBCDataSource;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLObjectException;
@@ -45,6 +51,14 @@
  * possible to obtain one by using a TableProfileCreator directly.
  */
 public class TableProfileResult extends AbstractProfileResult<SQLTable> {
+
+    /**
+     * Defines an absolute ordering of the child types of this class.
+     */
+    @SuppressWarnings("unchecked")
+    public static List<Class<? extends SPObject>> allowedChildTypes =
+ Collections.unmodifiableList(new ArrayList<Class<? extends SPObject>>(
+                Arrays.asList(ColumnProfileResult.class)));

     @SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(TableProfileResult.class);
@@ -83,6 +97,7 @@
      * of this profile result being populated.  The progress monitor also
* provides the means of canceling the population of this profile result.
      */
+    @Transient @Accessor
     public Monitorable getProgressMonitor() {
         return progressMonitor;
     }
@@ -91,12 +106,16 @@
* Returns the number of rows in this table. This count is not guaranteed to
      * be realistic until this result has been fully profiled.
      */
+    @Accessor
     public int getRowCount() {
         return rowCount;
     }

+    @Mutator
     public void setRowCount(int rowCount) {
+        int oldCount = this.rowCount;
         this.rowCount = rowCount;
+        firePropertyChange("rowCount", oldCount, rowCount);
     }

     /**
@@ -163,6 +182,7 @@
      * Returns an unmodifiable list of columnProfileResults that
      * belong to this table.
      */
+    @NonProperty
     public List<ColumnProfileResult> getColumnProfileResults() {
         return Collections.unmodifiableList(columnProfileResults);
     }
@@ -173,6 +193,7 @@
      * date that they were created. If there are no results found for the
      * given table, an empty collection will be returned.
      */
+    @NonProperty
public Collection<ColumnProfileResult> getColumnProfileResult(SQLColumn c) { Collection<ColumnProfileResult> retCollection = new ArrayList<ColumnProfileResult>();
         for (ColumnProfileResult result : columnProfileResults) {
@@ -191,6 +212,7 @@
      * @return
      * @throws SQLObjectException
      */
+    @Transient @Accessor
     public DDLGenerator getDDLGenerator() throws SQLObjectException {
JDBCDataSource ds = getProfiledObject().getParentDatabase().getDataSource();
         try {
@@ -244,12 +266,12 @@
         }
     }

+    @NonBound
     public List<Class<? extends SPObject>> getAllowedChildTypes() {
- List<Class<? extends SPObject>> types = new ArrayList<Class<? extends SPObject>>();
-        types.add(ColumnProfileResult.class);
-        return types;
+        return allowedChildTypes;
     }

+    @NonProperty
     public List<? extends SPObject> getChildren() {
         List<SPObject> children = new ArrayList<SPObject>();
         children.addAll(columnProfileResults);

Reply via email to