[hg] main-silver: added api util tests

  • From: Tomas Stupka < >
  • To:
  • Subject: [hg] main-silver: added api util tests
  • Date: Tue, 05 Mar 2013 08:40:26 -0800

changeset 733dee87ae40 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/733dee87ae40
description:
        added api util tests

diffstat:

 bugtracking/src/org/netbeans/modules/bugtracking/IssueImpl.java              
         |    4 +
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestConnector.java
  |    4 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestIssue.java
      |    1 +
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
      |    1 +
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestRepository.java
 |   14 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java 
        |  192 +++------
 6 files changed, 88 insertions(+), 128 deletions(-)

diffs (351 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
@@ -190,4 +190,8 @@
     public BugtrackingController getController() {
         return issueProvider.getController(data);
     }    
+    
+    public boolean isData(Object obj) {
+        return data == obj;
 }
+}
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestConnector.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestConnector.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestConnector.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestConnector.java
@@ -231,12 +231,12 @@
 
         @Override
         public APITestQuery createQuery(APITestRepository r) {
-            throw new UnsupportedOperationException("Not supported yet."); 
//To change body of generated methods, choose Tools | Templates.
+            return r.createQuery();
         }
 
         @Override
         public APITestIssue createIssue(APITestRepository r) {
-            throw new UnsupportedOperationException("Not supported yet."); 
//To change body of generated methods, choose Tools | Templates.
+            return r.createIssue();
         }
 
         @Override
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
@@ -60,6 +60,7 @@
     static final String ID_1 = "1";
     static final String ID_2 = "2";
     static final String ID_SUB_3 = "3";
+    static final String ID_NEW = "1000";
 
     static final String SUMMARY_SUF = " - summary";
     static final String TOOLTIP_SUF = " - tooltip";
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
@@ -77,6 +77,7 @@
     public APITestQuery(String name, APITestRepository repo) {
         this.name = name;
         this.repo = repo;
+        this.isSaved = name != null;
     }
     
     @Override
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestRepository.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestRepository.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestRepository.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestRepository.java
@@ -53,8 +53,6 @@
 import java.util.List;
 import javax.swing.JComponent;
 import javax.swing.event.ChangeListener;
-import org.netbeans.modules.bugtracking.TestIssue;
-import org.netbeans.modules.bugtracking.TestQuery;
 import org.netbeans.modules.bugtracking.TestRepository;
 import org.netbeans.modules.bugtracking.spi.RepositoryController;
 import org.netbeans.modules.bugtracking.spi.RepositoryInfo;
@@ -77,6 +75,8 @@
     private APITestRepositoryController controller;
     private List<APITestQuery> queries;
     private HashMap<String, APITestIssue> issues;
+    APITestIssue newIssue;
+    APITestQuery newQuery;
 
     public APITestRepository(RepositoryInfo info) {
         this.info = info;
@@ -136,13 +136,15 @@
     }
 
     @Override
-    public TestQuery createQuery() {
-        throw new UnsupportedOperationException("Not supported yet.");
+    public APITestQuery createQuery() {
+        newQuery = new APITestQuery(null, this);
+        return newQuery;
     }
 
     @Override
-    public TestIssue createIssue() {
-        throw new UnsupportedOperationException("Not supported yet.");
+    public APITestIssue createIssue() {
+        newIssue = new APITestIssue(null, this, true);
+        return newIssue;
     }
 
     @Override
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/UtilTest.java
copy from 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java
copy to 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/UtilTest.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/IssueTest.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/UtilTest.java
@@ -42,26 +42,29 @@
 
 package org.netbeans.modules.bugtracking.api;
 
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
+import java.util.Set;
 import java.util.logging.Level;
-import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.fail;
 import org.netbeans.junit.NbTestCase;
 import org.netbeans.modules.bugtracking.APIAccessor;
 import org.netbeans.modules.bugtracking.IssueImpl;
+import org.netbeans.modules.bugtracking.QueryImpl;
 import org.netbeans.modules.bugtracking.ui.issue.IssueTopComponent;
+import org.netbeans.modules.bugtracking.ui.query.QueryTopComponent;
 import org.openide.util.test.MockLookup;
+import org.openide.windows.TopComponent;
+import org.openide.windows.WindowManager;
 
 /**
  *
  * @author tomas
  */
-public class IssueTest extends NbTestCase {
+public class UtilTest extends NbTestCase {
 
-    public IssueTest(String arg0) {
+    public UtilTest(String arg0) {
         super(arg0);
     }
 
@@ -79,134 +82,84 @@
     @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();
+    public void testOpenIssue() throws InterruptedException {
+        APITestIssue apiIssue = getAPIIssue(APITestIssue.ID_1);
+        Issue issue = getIssue(APITestIssue.ID_1);
         
         assertFalse(apiIssue.wasOpened);
-        issue.open();
+        Util.openIssue(getRepo(), APITestIssue.ID_1);
         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();
+    public void testCreateNewIssue() {
+        Repository repo = getRepo();
+        APITestRepository apiRepo = getApiRepo();
         
+        assertNull(apiRepo.newIssue);
+        Util.createNewIssue(repo);
         
-        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);
+        long t = System.currentTimeMillis();
+        TopComponent openedTC = null;
+        while(openedTC == null) {
+            Set<TopComponent> openedTCs = 
WindowManager.getDefault().getRegistry().getOpened();
+            for (TopComponent tc : openedTCs) {
+                if(tc instanceof IssueTopComponent) {
+                    IssueTopComponent itc = (IssueTopComponent)tc;
+                    IssueImpl issueImpl = itc.getIssue();
+                    if(issueImpl != null && 
issueImpl.isData(apiRepo.newIssue)) {
+                        openedTC = tc;
+                        break;
+                    }
+                }
+            }
+            if(System.currentTimeMillis() - t > 5000) {
+                break;
+            }
     }
     
-    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);
+        assertNotNull(apiRepo.newIssue);
+        if(openedTC == null) {
+            fail("TopComponent with new issue wasn't opened");
+        }
+        openedTC.close();
     }
     
-    public void testPCL() {
-        APITestIssue apiIssue = getAPIIssue();
-        Issue issue = getIssue();
+    public void testCreateNewQuery() {
+        Repository repo = getRepo();
+        APITestRepository apiRepo = getApiRepo();
         
-        final boolean refreshed[] = new boolean[] {false};
-        PropertyChangeListener l = new PropertyChangeListener() {
-            @Override
-            public void propertyChange(PropertyChangeEvent evt) {
-                refreshed[0] = true;
+        assertNull(apiRepo.newQuery);
+        Util.createNewQuery(repo);
+        
+        long t = System.currentTimeMillis();
+        TopComponent openedTC = null;
+        while(openedTC == null) {
+            Set<TopComponent> openedTCs = 
WindowManager.getDefault().getRegistry().getOpened();
+            for (TopComponent tc : openedTCs) {
+                if(tc instanceof QueryTopComponent) {
+                    QueryTopComponent itc = (QueryTopComponent)tc;
+                    QueryImpl queryImpl = itc.getQuery();
+                    if(queryImpl != null && 
queryImpl.isData(apiRepo.newQuery)) {
+                        openedTC = tc;
+                        break;
             }
-        };
-        
-        issue.addPropertyChangeListener(l);
-        apiIssue.wasRefreshed = false;
-        issue.refresh();
-        assertTrue(apiIssue.wasRefreshed);
-        assertTrue(refreshed[0]);
-        
-        refreshed[0] = false;
-        issue.removePropertyChangeListener(l);
-        assertFalse(refreshed[0]);
+                }
+            }
+            if(System.currentTimeMillis() - t > 5000) {
+                break;
+            }
     }
     
-//    public void testGetSubtasks() {
-//        APITestIssue apiIssue = getAPIIssue();
-//        Issue issue = getIssue();
-//        
-//        assertEquals(apiIssue.getSubtasks().length, issue.getSubtasks());
-//    }
+        assertNotNull(apiRepo.newIssue);
+        if(openedTC == null) {
+            fail("TopComponent with new query wasn't opened");
+        }
+        openedTC.close();
+    }
     
     private APITestRepository getApiRepo() {
         return APITestKit.getAPIRepo(APITestRepository.ID);
@@ -216,12 +169,12 @@
         return APITestKit.getRepo(APITestRepository.ID);
     }
 
-    private APITestIssue getAPIIssue() {
-        return getApiRepo().getIssues(new String[] {APITestIssue.ID_1})[0];
+    private APITestIssue getAPIIssue(String id) {
+        return getApiRepo().getIssues(new String[] {id})[0];
     }
     
-    private Issue getIssue() {
-        return getRepo().getIssues(APITestIssue.ID_1)[0];
+    private Issue getIssue(String id) {
+        return getRepo().getIssues(id)[0];
     }
 
     private void assertOpened(APITestIssue apiIssue) throws 
InterruptedException {
@@ -234,5 +187,4 @@
             }
         }
     }
-    
 }

[hg] main-silver: added api util tests

Tomas Stupka 03/05/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