[hg] main-silver: query api tests

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

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

diffstat:

 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestQueryProvider.java
     |    3 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestConnector.java
  |    2 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
      |   63 ++-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestRepository.java
 |    4 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/QueryTest.java 
        |  201 ++++++++++
 5 files changed, 257 insertions(+), 16 deletions(-)

diffs (384 lines):

diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestQueryProvider.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestQueryProvider.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestQueryProvider.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestQueryProvider.java
@@ -43,6 +43,7 @@
 
 import java.beans.PropertyChangeListener;
 import java.util.Collection;
+import org.netbeans.modules.bugtracking.api.APITestIssue;
 import org.netbeans.modules.bugtracking.spi.QueryController;
 import org.netbeans.modules.bugtracking.spi.QueryProvider;
 import org.openide.nodes.Node;
@@ -80,7 +81,7 @@
 
     @Override
     public Collection<TestIssue> getIssues(TestQuery q) {
-        return q.getIssues();
+        return (Collection<TestIssue>) q.getIssues();
     }
 
     @Override
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
@@ -162,7 +162,7 @@
 
         @Override
         public Collection<APITestIssue> getIssues(APITestQuery q) {
-            throw new UnsupportedOperationException("Not supported yet."); 
//To change body of generated methods, choose Tools | Templates.
+            return q.getIssues();
         }
 
         @Override
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
@@ -41,11 +41,18 @@
  */
 package org.netbeans.modules.bugtracking.api;
 
+import java.awt.Panel;
 import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.Arrays;
 import java.util.Collection;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
 import org.netbeans.modules.bugtracking.TestIssue;
 import org.netbeans.modules.bugtracking.TestQuery;
 import org.netbeans.modules.bugtracking.spi.QueryController;
+import org.netbeans.modules.bugtracking.spi.QueryProvider;
+import org.openide.util.HelpCtx;
 
 /**
  *
@@ -56,10 +63,20 @@
     public static final String FIRST_QUERY_NAME = "First Query";
     public static final String SECOND_QUERY_NAME = "Second Query";
     
-    private String name;
+    static final String TOOLTIP_SUF = " - tooltip";
 
-    public APITestQuery(String name) {
+    private final String name;
+    boolean isSaved;
+    boolean wasRefreshed;
+    boolean wasOpened;
+    boolean wasRemoved;
+    QueryController.QueryMode openedMode;
+    private final APITestRepository repo;
+    private QueryController controller;
+
+    public APITestQuery(String name, APITestRepository repo) {
         this.name = name;
+        this.repo = repo;
     }
     
     @Override
@@ -69,47 +86,69 @@
 
     @Override
     public String getTooltip() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        return getDisplayName() + TOOLTIP_SUF;
     }
 
     @Override
     public QueryController getController() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        if(controller == null) {
+            controller = new QueryController() {
+                @Override
+                public void opened() {
+                    wasOpened = true;
+                }
+                JPanel panel;
+                @Override
+                public JComponent getComponent() {
+                    if(panel == null) {
+                        panel = new JPanel();
+                    }
+                    return panel;
+                }
+                @Override public void setMode(QueryController.QueryMode 
mode) { 
+                    openedMode = mode;
+                }
+                @Override public HelpCtx getHelpCtx() { return null; }
+            }; 
+        }
+        return controller;
     }
 
     @Override
     public boolean isSaved() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        return isSaved;
     }
 
     @Override
-    public Collection<TestIssue> getIssues() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+    public Collection<APITestIssue> getIssues() {
+        return Arrays.asList(repo.getIssues(new String[] 
{APITestIssue.ID_1}));
     }
 
     @Override
     public boolean contains(String id) {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        return getIssues().contains(id);
     }
 
+    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
     public void remove() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        wasRemoved = true;
     }
 
     @Override
     public void refresh() {
-        throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
+        wasRefreshed = true;
+        support.firePropertyChange(QueryProvider.EVENT_QUERY_ISSUES_CHANGED, 
null, null);
     }
     
 }
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
@@ -114,7 +114,7 @@
         for (String id : ids) {
             APITestIssue i = issues.get(id);
             if(i == null) {
-                i = new APITestIssue(id);
+                i = new APITestIssue(id, this);
                 issues.put(id, i);
             }
             ret.add(i);
@@ -148,7 +148,7 @@
     @Override
     public Collection<APITestQuery> getQueries() {
         if(queries == null) {
-            queries = Arrays.asList(new APITestQuery[] {new 
APITestQuery(APITestQuery.FIRST_QUERY_NAME), new 
APITestQuery(APITestQuery.SECOND_QUERY_NAME)});
+            queries = Arrays.asList(new APITestQuery[] {new 
APITestQuery(APITestQuery.FIRST_QUERY_NAME, this), new 
APITestQuery(APITestQuery.SECOND_QUERY_NAME, this)});
         }
         return queries;
     }
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/QueryTest.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/QueryTest.java
new file mode 100644
--- /dev/null
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/QueryTest.java
@@ -0,0 +1,201 @@
+/*
+ * 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.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.assertTrue;
+import static junit.framework.Assert.fail;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.bugtracking.APIAccessor;
+import org.netbeans.modules.bugtracking.ui.query.QueryTopComponent;
+import org.openide.util.test.MockLookup;
+
+/**
+ *
+ * @author tomas
+ */
+public class QueryTest extends NbTestCase {
+
+    public QueryTest(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() {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+        assertEquals(apiQuery.getDisplayName(), query.getDisplayName());
+        assertEquals(apiQuery.getTooltip(), query.getTooltip());
+    }
+    
+    public void testGetRepository() {
+        assertEquals(getRepo(), getQuery().getRepository());
+    }    
+    
+    public void testIsSaved() {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+        apiQuery.isSaved = false;
+        assertEquals(apiQuery.isSaved(), query.isSaved());
+        assertFalse(query.isSaved());
+        apiQuery.isSaved = true;
+        assertEquals(apiQuery.isSaved(), query.isSaved());
+        assertTrue(query.isSaved());
+    }
+    
+    public void testRefresh() {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+        apiQuery.wasRefreshed = false;
+        query.refresh();
+        assertTrue(apiQuery.wasRefreshed);
+    }
+    
+    public void testRemove() {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+        apiQuery.wasRemoved = false;
+        query.remove();
+        assertTrue(apiQuery.wasRemoved);
+    }
+    
+    public void testGetIssues() {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+        assertEquals(apiQuery.getIssues().size(), query.getIssues().size());
+    }
+    
+    public void testOpen() throws InterruptedException {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+//        assertOpen(query, apiQuery, Query.QueryMode.EDIT);
+        assertOpen(query, apiQuery, Query.QueryMode.SHOW_ALL);
+        assertOpen(query, apiQuery, Query.QueryMode.SHOW_NEW_OR_CHANGED);
+    }    
+    
+    public void testPCL() {
+        APITestQuery apiQuery = getAPIQuery();
+        Query query = getQuery();
+        
+        final boolean refreshed[] = new boolean[] {false};
+        PropertyChangeListener l = new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                refreshed[0] = true;
+            }
+        };
+        
+        query.addPropertyChangeListener(l);
+        apiQuery.wasRefreshed = false;
+        query.refresh();
+        assertTrue(apiQuery.wasRefreshed);
+        assertTrue(refreshed[0]);
+        
+        refreshed[0] = false;
+        query.removePropertyChangeListener(l);
+        assertFalse(refreshed[0]);
+    }
+
+    private APITestRepository getApiRepo() {
+        return APITestKit.getAPIRepo(APITestRepository.ID);
+    }
+
+    private Repository getRepo() {
+        return APITestKit.getRepo(APITestRepository.ID);
+    }
+
+    private APITestQuery getAPIQuery() {
+        return getApiRepo().getQueries().iterator().next();
+    }
+    
+    private Query getQuery() {
+        return getRepo().getQueries().iterator().next();
+    }
+
+    private void assertOpened(APITestQuery apiQuery) throws 
InterruptedException {
+        long t = System.currentTimeMillis();
+        while(!apiQuery.wasOpened) {
+            Thread.currentThread().sleep(200);
+            if(System.currentTimeMillis() - t > 5000) {
+                // timeout
+                fail("issue wasn't opened");
+            }
+        }
+    }
+
+    private void assertOpen(Query query, APITestQuery apiQuery, 
Query.QueryMode mode) throws InterruptedException {
+        apiQuery.wasOpened = false;
+        query.open(mode);
+        assertOpened(apiQuery);
+        assertEquals(mode.name(), apiQuery.openedMode.name());
+        
+        QueryTopComponent tc = 
QueryTopComponent.find(APIAccessor.IMPL.getImpl(query));
+        assertNotNull(tc);
+        tc.close();
+    }
+
+}

[hg] main-silver: query api tests

Tomas Stupka 03/02/2013

Project Features

About this Project

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