Author: schof
Date: Wed Aug  2 15:51:09 2006
New Revision: 428182

URL: http://svn.apache.org/viewvc?rev=428182&view=rev
Log:
modifications to allow pet quantity and price to appear in an eventual tooltip 
over the tree nodes.

Added:
    
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/PetTreeNode.java
    
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/PetTreeNodeTest.java
Modified:
    
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/domain/Pet.java
    
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/TreeBacker.java

Modified: 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/domain/Pet.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/domain/Pet.java?rev=428182&r1=428181&r2=428182&view=diff
==============================================================================
--- 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/domain/Pet.java
 (original)
+++ 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/domain/Pet.java
 Wed Aug  2 15:51:09 2006
@@ -39,18 +39,26 @@
      */
     public Pet(String productId, String description) {
         this(null, productId, description);
-//        this.productId = productId;
-//        this.description = description;
     }
 
-    public Pet(Category category, String productId, String description) {
+    public Pet(String productId, String description, double price, int 
quantity) {
+        this(null, productId, description, price, quantity);
+    }
+
+    public Pet(Category category, String productId, String description, double 
price, int quantity) {
         this.category = category;
         this.productId = productId;
         this.description = description;
+        this.price = price;
+        this.quantity = quantity;
+    }
+
+    public Pet(Category category, String productId, String description) {
+        this(category, productId, description, 0, 0);
     }
 
-    /** No arg constructor.  Should only be used by Hibernate. */
-    Pet() {}
+    /** No arg constructor.  Should only be used by Hibernate and JMock. */
+    public Pet() {}
 
     private void setCategory(Category category) {
         this.category = category;

Added: 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/PetTreeNode.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/PetTreeNode.java?rev=428182&view=auto
==============================================================================
--- 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/PetTreeNode.java
 (added)
+++ 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/PetTreeNode.java
 Wed Aug  2 15:51:09 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.petstore.view.backing;
+
+import org.apache.myfaces.custom.tree2.TreeNodeBase;
+import org.apache.shale.petstore.domain.Pet;
+
+/**
+ * Custom implementation of the Tomahawk TreeNode interface.  It contains 
information specific
+ * to Pets that is needed for display purposes.
+ *
+ * @author Sean Schofield
+ */
+public class PetTreeNode extends TreeNodeBase {
+
+    private int quantity;
+    private double price;
+
+    public PetTreeNode(Pet pet) {
+        super("pet", pet.getDescription(), pet.getProductId(), true);
+        this.quantity = pet.getQuantity();
+        this.price = pet.getPrice();
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public double getPrice() {
+        return price;
+    }
+
+    public boolean isOutOfStock() {
+        return (quantity == 0);
+    }
+
+}

Modified: 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/TreeBacker.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/TreeBacker.java?rev=428182&r1=428181&r2=428182&view=diff
==============================================================================
--- 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/TreeBacker.java
 (original)
+++ 
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/view/backing/TreeBacker.java
 Wed Aug  2 15:51:09 2006
@@ -97,10 +97,12 @@
         Set<Pet> pets = category.getPets();
 
         for (Pet pet : pets) {
-            TreeNode petNode = new TreeNodeBase("pet", pet.getDescription(), 
true);
+            //TreeNode petNode = new TreeNodeBase("pet", pet.getDescription(), 
true);
+            PetTreeNode petNode = new PetTreeNode(pet);
             children.add(petNode);
         }
 
         return treeNode;
     }
+
 }

Added: 
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/PetTreeNodeTest.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/PetTreeNodeTest.java?rev=428182&view=auto
==============================================================================
--- 
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/PetTreeNodeTest.java
 (added)
+++ 
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/PetTreeNodeTest.java
 Wed Aug  2 15:51:09 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.petstore.view.backing;
+
+import junit.framework.TestCase;
+import org.apache.shale.petstore.domain.Pet;
+
+/**
+ * @author Sean Schofield
+ */
+public class PetTreeNodeTest extends TestCase {
+
+    private static final Pet BOSTON_TERRIER = new Pet("1001", "boton terrier", 
1000.00, 10);
+    private static final Pet WHEATON_TERRIER = new Pet("1002", "wheaton 
terrier", 850.00, 0);
+
+    /**
+     * Tests the getQuantity functionality of the inner class.
+     */
+    public void testGetQuantity() {
+        PetTreeNode petTreeNode = new PetTreeNode(BOSTON_TERRIER);
+        assertTrue("unexpected quantity", petTreeNode.getQuantity() == 
BOSTON_TERRIER.getQuantity());
+    }
+
+    /**
+     * Tests the getPrice functionality of the inner class.
+     */
+    public void testGetPrice() {
+        PetTreeNode petTreeNode = new PetTreeNode(BOSTON_TERRIER);
+        assertTrue("unexpected price", petTreeNode.getPrice() == 
BOSTON_TERRIER.getPrice());
+    }
+
+    /**
+     * Tests the isOutOfStock functionality of the inner class.
+     */
+    public void testIsOutOfStock() {
+        PetTreeNode petTreeNode = new PetTreeNode(BOSTON_TERRIER);
+        assertFalse("unexpected outOfStock value", petTreeNode.isOutOfStock());
+
+        petTreeNode = new PetTreeNode(WHEATON_TERRIER);
+        assertTrue("unexpected outOfStock value", petTreeNode.isOutOfStock());
+    }
+
+}


Reply via email to