Revision: 3674
Author: [email protected]
Date: Mon Jul  5 15:06:27 2010
Log: NEW - bug 2458: Create Critic Manager
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2458

Added in persistence tests for the critic settings and added missing annotations.
http://code.google.com/p/power-architect/source/detail?r=3674

Added:
 /trunk/regress/ca/sqlpower/architect/ddl/critic
 /trunk/regress/ca/sqlpower/architect/ddl/critic/CriticAndSettingsTest.java
 /trunk/regress/ca/sqlpower/architect/ddl/critic/CriticGroupingTest.java
 /trunk/regress/ca/sqlpower/architect/ddl/critic/CriticManagerTest.java
Modified:
 /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticGrouping.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java

=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/ddl/critic/CriticAndSettingsTest.java Mon Jul 5 15:06:27 2010
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL 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.
+ *
+ * SQL 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.ddl.critic;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.List;
+
+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 CriticAndSettingsTest extends PersistedSPObjectTest {
+
+    private SPObject critic;
+
+    public CriticAndSettingsTest(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+ critic = (SPObject) createNewValueMaker(getRootObject(), getPLIni()). + makeNewValue(CriticAndSettings.class, null, "Object under test");
+    }
+
+    @Override
+    public SPObject getSPObjectUnderTest() {
+        return critic;
+    }
+
+    @Override
+    public NewValueMaker createNewValueMaker(SPObject root,
+            DataSourceCollection<SPDataSource> dsCollection) {
+        return new ArchitectNewValueMaker(root, dsCollection);
+    }
+
+    @Override
+    protected Class<? extends SPObject> getChildClassType() {
+        return null;
+    }
+
+    /**
+ * A different implementation of the allowed child types since this is an abstract class.
+     */
+    @Override
+    public void testAllowedChildTypesField() throws Exception {
+        Class<? extends SPObject> classUnderTest = CriticAndSettings.class;
+        Field childOrderField;
+        try {
+ childOrderField = classUnderTest.getDeclaredField("allowedChildTypes");
+        } catch (NoSuchFieldException ex) {
+ fail("Persistent " + classUnderTest + " must have a static final field called allowedChildTypes");
+            throw new AssertionError(); // NOTREACHED
+        }
+
+        assertEquals("The allowedChildTypes field must be final",
+                true, Modifier.isFinal(childOrderField.getModifiers()));
+
+        assertEquals("The allowedChildTypes field must be static",
+                true, Modifier.isStatic(childOrderField.getModifiers()));
+
+ // Note: in the future, we will change this to require that the field is private
+        assertEquals("The allowedChildTypes field must be public",
+                true, Modifier.isPublic(childOrderField.getModifiers()));
+
+        List<Class<? extends SPObject>> allowedChildTypes =
+            (List<Class<? extends SPObject>>) childOrderField.get(null);
+        assertTrue(allowedChildTypes.isEmpty());
+    }
+}
=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/ddl/critic/CriticGroupingTest.java Mon Jul 5 15:06:27 2010
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL 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.
+ *
+ * SQL 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.ddl.critic;
+
+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 CriticGroupingTest extends PersistedSPObjectTest {
+
+    private SPObject group;
+
+    public CriticGroupingTest(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+ group = (SPObject) createNewValueMaker(getRootObject(), getPLIni()).
+            makeNewValue(CriticGrouping.class, null, "Object under test");
+    }
+
+    @Override
+    protected Class<? extends SPObject> getChildClassType() {
+        return CriticAndSettings.class;
+    }
+
+    @Override
+    public SPObject getSPObjectUnderTest() {
+        return group;
+    }
+
+    @Override
+    public NewValueMaker createNewValueMaker(SPObject root,
+            DataSourceCollection<SPDataSource> dsCollection) {
+        return new ArchitectNewValueMaker(root, dsCollection);
+    }
+}
=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/ddl/critic/CriticManagerTest.java Mon Jul 5 15:06:27 2010
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL 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.
+ *
+ * SQL 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.ddl.critic;
+
+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;
+
+/**
+ * A simple test case of the critic manager. Future tests can be added here.
+ */
+public class CriticManagerTest extends PersistedSPObjectTest {
+
+    private CriticManager manager;
+
+    public CriticManagerTest(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+ manager = (CriticManager) createNewValueMaker(getRootObject(), getPLIni()).
+            makeNewValue(CriticManager.class, null, "Object under test");
+    }
+
+    @Override
+    protected Class<? extends SPObject> getChildClassType() {
+        return CriticGrouping.class;
+    }
+
+    @Override
+    public SPObject getSPObjectUnderTest() {
+        return manager;
+    }
+
+    @Override
+ public NewValueMaker createNewValueMaker(SPObject root, DataSourceCollection<SPDataSource> dsCollection) {
+        return new ArchitectNewValueMaker(root, dsCollection);
+    }
+
+    @Override
+    public void testPersisterCreatesNewObjects() throws Exception {
+ // The CriticManager object is a final field of the ArchitectProject, and as such, cannot
+        // be created by persist calls. It must instead be updated.
+ // See "ArchitectSessionPersisterTest.testRefreshRootNodeWithJSONPersister()"
+    }
+}
=======================================
--- /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Mon Jun 28 12:33:39 2010 +++ /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Mon Jul 5 15:06:27 2010
@@ -20,9 +20,14 @@
 package ca.sqlpower.architect.util;

 import ca.sqlpower.architect.ArchitectProject;
+import ca.sqlpower.architect.ArchitectSessionContextImpl;
 import ca.sqlpower.architect.ProjectSettings;
 import ca.sqlpower.architect.ProjectSettings.ColumnVisibility;
+import ca.sqlpower.architect.ddl.critic.CriticAndSettings;
+import ca.sqlpower.architect.ddl.critic.CriticGrouping;
 import ca.sqlpower.architect.ddl.critic.CriticManager;
+import ca.sqlpower.architect.ddl.critic.CriticAndSettings.Severity;
+import ca.sqlpower.architect.ddl.critic.impl.AlphaNumericNameCritic;
 import ca.sqlpower.architect.etl.kettle.KettleSettings;
 import ca.sqlpower.architect.olap.OLAPObject;
 import ca.sqlpower.architect.olap.OLAPRootObject;
@@ -48,7 +53,6 @@
 import ca.sqlpower.sql.SPDataSource;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLDatabase;
-import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.testutil.GenericNewValueMaker;

@@ -111,7 +115,8 @@
             ArchitectSwingProject project;
             try {
                 project = new ArchitectSwingProject();
-            } catch (SQLObjectException e) {
+ project.setSession(new ArchitectSessionContextImpl(false).createSession());
+            } catch (Exception e) {
                 throw new RuntimeException(e);
             }
             getRootObject().addChild(project, 0);
@@ -157,6 +162,22 @@
return ((ArchitectSwingProject) makeNewValue(ArchitectSwingProject.class, null, null)).getOlapRootObject();
         } else if (OLAPObject.class.isAssignableFrom(valueType)) {
return mondrianValueMaker.makeNewValue(valueType, oldVal, propName);
+        } else if (valueType == CriticGrouping.class) {
+ CriticGrouping group = new CriticGrouping(CriticAndSettings.StarterPlatformTypes.GENERIC.getName()); + CriticManager manager = (CriticManager) makeNewValue(CriticManager.class, null, "parent of group");
+            manager.addChild(group, 0);
+            return group;
+        } else if (CriticAndSettings.class.isAssignableFrom(valueType)) {
+            CriticAndSettings critic = new AlphaNumericNameCritic();
+ CriticGrouping group = (CriticGrouping) makeNewValue(CriticGrouping.class, null, "group for critic");
+            group.addChild(critic, 0);
+            return critic;
+        } else if (valueType == Severity.class) {
+            if (Severity.ERROR.equals(oldVal)) {
+                return Severity.WARNING;
+            } else {
+                return Severity.ERROR;
+            }
         } else {
             return super.makeNewValue(valueType, oldVal, propName);
         }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticGrouping.java Tue Jun 29 09:19:15 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticGrouping.java Mon Jul 5 15:06:27 2010
@@ -29,7 +29,9 @@
 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;

 /**
* Critics can be grouped and enabled or disabled as a group. This gives the
@@ -111,14 +113,17 @@
         return 0;
     }

+    @Transient @Accessor
     public List<Class<? extends SPObject>> getAllowedChildTypes() {
         return allowedChildTypes;
     }

+    @NonProperty
     public List<? extends SPObject> getChildren() {
         return Collections.unmodifiableList(settings);
     }

+    @NonBound
     public List<? extends SPObject> getDependencies() {
         return Collections.emptyList();
     }
@@ -152,11 +157,13 @@
     }

     @Override
+    @Accessor
     public CriticManager getParent() {
         return (CriticManager) super.getParent();
     }

     @Override
+    @Mutator
     public void setParent(SPObject parent) {
         if (!(parent instanceof CriticManager)) {
throw new IllegalArgumentException("Critic groups must be a child of a critic manager.");
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java Wed Jun 30 14:35:34 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java Mon Jul 5 15:06:27 2010
@@ -55,7 +55,9 @@
 import ca.sqlpower.object.annotation.Accessor;
 import ca.sqlpower.object.annotation.Constructor;
 import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.object.annotation.NonBound;
 import ca.sqlpower.object.annotation.NonProperty;
+import ca.sqlpower.object.annotation.Transient;

 /**
* A collection of settings that defines what critics are enabled in the system
@@ -124,6 +126,7 @@
* Returns the list of starting critics. This list is final and will always
      * return the critics in the same order.
      */
+    @Transient @Accessor
     public List<CriticAndSettings> getStartingCritics() {
         return STARTING_CRITICS;
     }
@@ -234,14 +237,17 @@
         return 0;
     }

+    @Transient @Accessor
     public List<Class<? extends SPObject>> getAllowedChildTypes() {
         return allowedChildTypes;
     }

+    @NonProperty
     public List<? extends SPObject> getChildren() {
         return Collections.unmodifiableList(criticGroupings);
     }

+    @NonBound
     public List<? extends SPObject> getDependencies() {
         return Collections.emptyList();
     }

Reply via email to