[hg] main-silver: issue api tests

  • From: Tomas Stupka < >
  • To:
  • Subject: [hg] main-silver: issue api tests
  • Date: Sat, 02 Mar 2013 03:35:47 -0800

changeset d2295b552e71 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/d2295b552e71
description:
        issue api tests

diffstat:

 bugtracking/src/org/netbeans/modules/bugtracking/IssueImpl.java              
      |    5 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestIssue.java
   |   74 ++-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java 
     |  231 ++++++++++
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryTest.java
 |   10 +-
 4 files changed, 301 insertions(+), 19 deletions(-)

diffs (427 lines):

diff --git a/bugtracking/src/org/netbeans/modules/bugtracking/IssueImpl.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/IssueImpl.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/IssueImpl.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/IssueImpl.java
@@ -56,7 +56,10 @@
  * @author Tomas Stupka
  */
 public final class IssueImpl<I> {
-    private static final int SHORT_DISP_NAME_LENGTH = 15;
+    /** 
+     * public for testing purposes
+     */
+    public static final int SHORT_DISP_NAME_LENGTH = 15;
     
     private Issue issue;
     private final RepositoryImpl repo;
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestIssue.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestIssue.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestIssue.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestIssue.java
@@ -42,9 +42,15 @@
 package org.netbeans.modules.bugtracking.api;
 
 import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
 import java.io.File;
+import java.io.IOException;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
 import org.netbeans.modules.bugtracking.TestIssue;
 import org.netbeans.modules.bugtracking.spi.BugtrackingController;
+import org.netbeans.modules.bugtracking.spi.IssueProvider;
+import org.openide.util.HelpCtx;
 
 /**
  *
@@ -54,20 +60,37 @@
     static final String ID_1 = "1";
     static final String ID_2 = "2";
 
+    static final String SUMMARY_SUF = " - summary";
+    static final String TOOLTIP_SUF = " - tooltip";
+    
     private final String id;
+    private final boolean isNew;
+    boolean wasOpened;
+    boolean wasRefreshed;
+    boolean wasClosedOnComment;
+    String addedComment;
+    String attachedPatchDesc;
+    boolean idFinished;
+    File attachedFile;
+    private BugtrackingController controller;
 
     public APITestIssue(String id) {
+        this(id, false);
+    }
+    
+    public APITestIssue(String id, boolean isNew) {
         this.id = id;
+        this.isNew = isNew;
     }
     
     @Override
     public String getDisplayName() {
-        return "Issue : " + id;
+        return "Issue : " + id + getSummary();
     }
 
     @Override
     public String getTooltip() {
-        return getDisplayName() + " tooltip";
+        return id + TOOLTIP_SUF;
     }
 
     @Override
@@ -77,47 +100,66 @@
 
     @Override
     public String getSummary() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        return id + SUMMARY_SUF;
     }
 
     @Override
     public boolean isNew() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        return isNew;
     }
 
     @Override
     public boolean refresh() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public TestIssue createFor(String id) {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        wasRefreshed = true;
+        support.firePropertyChange(IssueProvider.EVENT_ISSUE_REFRESHED, 
null, null);
+        return true;
     }
 
     @Override
     public void addComment(String comment, boolean closeAsFixed) {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        wasClosedOnComment = closeAsFixed;
+        addedComment = comment;
     }
 
     @Override
     public void attachPatch(File file, String description) {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        attachedPatchDesc = description;
+        attachedFile = file;
     }
 
     @Override
     public BugtrackingController getController() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        if(controller == null) {
+            controller = new BugtrackingController() {
+                @Override
+                public void opened() {
+                    wasOpened = true;
+                }
+                private JPanel panel;
+                @Override
+                public JComponent getComponent() {
+                    if(panel == null) {
+                        panel = new JPanel();
+                    }
+                    return panel;
+                }
+                @Override public HelpCtx getHelpCtx() { return null; }
+                @Override public boolean isValid() { return true; }
+                @Override public void applyChanges() throws IOException { }
+            };
+        }
+        return controller;
     }
 
+    private final PropertyChangeSupport support = new 
PropertyChangeSupport(this);
     @Override
     public void removePropertyChangeListener(PropertyChangeListener 
listener) {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        support.removePropertyChangeListener(listener);
     }
 
     @Override
     public void addPropertyChangeListener(PropertyChangeListener listener) {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        support.addPropertyChangeListener(listener);
     }
 
     @Override
@@ -127,7 +169,7 @@
 
     @Override
     public boolean isFinished() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        return idFinished;
     }
     
 }
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java
new file mode 100644
--- /dev/null
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java
@@ -0,0 +1,231 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ * 
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ * 
+ * Contributor(s):
+ * 
+ * Portions Copyrighted 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.bugtracking.api;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.logging.Level;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNull;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.bugtracking.APIAccessor;
+import org.netbeans.modules.bugtracking.IssueImpl;
+import org.netbeans.modules.bugtracking.ui.issue.IssueTopComponent;
+import org.openide.util.test.MockLookup;
+
+/**
+ *
+ * @author tomas
+ */
+public class IssueTest extends NbTestCase {
+
+    public IssueTest(String arg0) {
+        super(arg0);
+    }
+
+    @Override
+    protected Level logLevel() {
+        return Level.ALL;
+    }   
+    
+    @Override
+    protected void setUp() throws Exception {    
+        MockLookup.setLayersAndInstances();
+        APITestConnector.init();
+    }
+
+    @Override
+    protected void tearDown() throws Exception { }
+
+    public void testGetAttributes() {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        assertEquals(apiIssue.getID(), issue.getID());
+        assertEquals(apiIssue.getDisplayName(), issue.getDisplayName());
+        assertEquals(apiIssue.getTooltip(), issue.getTooltip());
+        assertEquals(apiIssue.getSummary(), issue.getSummary());
+    }
+    
+    public void testGetShortenedDisplayName() {
+        Issue issue = getIssue();
+        
+        assertEquals(IssueImpl.SHORT_DISP_NAME_LENGTH + 3, 
issue.getShortenedDisplayName().length());
+        assertTrue(issue.getShortenedDisplayName().endsWith("..."));
+    }
+    
+    public void testGetRepository() {
+        assertEquals(getRepo(), getIssue().getRepository());
+    }
+    
+    public void testIsFinished() {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        assertFalse(issue.isFinished());
+        apiIssue.idFinished = true;
+        assertTrue(issue.isFinished());
+    }
+    
+    public void testRefresh() {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        assertFalse(apiIssue.wasRefreshed);
+        issue.refresh();
+        assertTrue(apiIssue.wasRefreshed);
+    }
+    
+    public void testOpen() throws InterruptedException {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        assertFalse(apiIssue.wasOpened);
+        issue.open();
+        assertOpened(apiIssue);
+        
+        IssueTopComponent tc = 
IssueTopComponent.find(APIAccessor.IMPL.getImpl(issue));
+        assertNotNull(tc);
+        tc.close();
+        
+        apiIssue.wasRefreshed = false;
+        apiIssue.wasOpened = false;
+        issue.open(true);
+        assertOpened(apiIssue);
+        assertTrue(apiIssue.wasRefreshed);
+    }
+    
+    public void testAddedComment() {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        
+        assertFalse(apiIssue.wasClosedOnComment);
+        assertNull(apiIssue.addedComment);
+        
+        String comment = "cmt";
+        boolean refresh = true;
+        issue.addComment(comment, refresh);
+        assertTrue(apiIssue.wasClosedOnComment);
+        assertEquals(comment, apiIssue.addedComment);
+        
+        comment = "cmt2";
+        refresh = false;
+        issue.addComment(comment, refresh);
+        assertFalse(apiIssue.wasClosedOnComment);
+        assertEquals(comment, apiIssue.addedComment);
+    }
+    
+    public void testAttachPatch() {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        assertNull(apiIssue.attachedFile);
+        assertNull(apiIssue.attachedPatchDesc);
+        
+        String desc = "desc";
+        File file = new File("somefile");
+        issue.attachPatch(file, desc);
+        assertEquals(desc, apiIssue.attachedPatchDesc);
+        assertEquals(file, apiIssue.attachedFile);
+        
+        desc = "desc2";
+        file = new File("somefile2");
+        issue.attachPatch(file, desc);
+        assertEquals(desc, apiIssue.attachedPatchDesc);
+        assertEquals(file, apiIssue.attachedFile);
+    }
+    
+    public void testPCL() {
+        APITestIssue apiIssue = getAPIIssue();
+        Issue issue = getIssue();
+        
+        final boolean refreshed[] = new boolean[] {false};
+        PropertyChangeListener l = new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                refreshed[0] = true;
+            }
+        };
+        
+        issue.addPropertyChangeListener(l);
+        apiIssue.wasRefreshed = false;
+        issue.refresh();
+        assertTrue(apiIssue.wasRefreshed);
+        assertTrue(refreshed[0]);
+        
+        refreshed[0] = false;
+        issue.removePropertyChangeListener(l);
+        assertFalse(refreshed[0]);
+    }
+    
+    private APITestRepository getApiRepo() {
+        return APITestKit.getAPIRepo(APITestRepository.ID);
+    }
+
+    private Repository getRepo() {
+        return APITestKit.getRepo(APITestRepository.ID);
+    }
+
+    private APITestIssue getAPIIssue() {
+        return getApiRepo().getIssues(new String[] {APITestIssue.ID_1})[0];
+    }
+    
+    private Issue getIssue() {
+        return getRepo().getIssues(APITestIssue.ID_1)[0];
+    }
+
+    private void assertOpened(APITestIssue apiIssue) throws 
InterruptedException {
+        long t = System.currentTimeMillis();
+        while(!apiIssue.wasOpened) {
+            Thread.currentThread().sleep(200);
+            if(System.currentTimeMillis() - t > 5000) {
+                // timeout
+                fail("issue wasn't opened");
+            }
+        }
+    }
+    
+}
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryTest.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryTest.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryTest.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryTest.java
@@ -115,16 +115,22 @@
         APITestRepository apiTestRepo = getApiRepo();
         
         final boolean[] received = new boolean[] {false};
-        repo.addPropertyChangeListener(new PropertyChangeListener() {
+        final PropertyChangeListener l = new PropertyChangeListener() {
             @Override
             public void propertyChange(PropertyChangeEvent pce) {
                 
if(Repository.EVENT_QUERY_LIST_CHANGED.equals(pce.getPropertyName())) {
                     received[0] = true;
                 }
             }
-        });
+          };
+        repo.addPropertyChangeListener(l);
         apiTestRepo.fireQueryChangeEvent();
         assertTrue(received[0]);
+        
+        repo.removePropertyChangeListener(l);
+        received[0] = false;
+        apiTestRepo.fireQueryChangeEvent();
+        assertFalse(received[0]);
     }
 
     public void testDisplayNameChanged() throws IOException {

[hg] main-silver: issue api tests

Tomas Stupka 03/02/2013

Project Features

About this Project

ConnectedDeveloper was started in November 2009, is owned by tpavek, and has 66 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close