[hg] main-silver: added RepositoryQuery tests

  • From: Tomas Stupka < >
  • To:
  • Subject: [hg] main-silver: added RepositoryQuery tests
  • Date: Tue, 05 Mar 2013 11:40:12 -0800

changeset 1932c036b20c in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/1932c036b20c
description:
        added RepositoryQuery tests

diffstat:

 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryQueryTest.java
 |  127 ++++++++++
 bugtracking/var/bugtracking/storage                                          
           |    0 
 bugtracking/var/bugtracking/test/data                                        
           |    0 
 3 files changed, 127 insertions(+), 0 deletions(-)

diffs (146 lines):

diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryQueryTest.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryQueryTest.java
new file mode 100644
--- /dev/null
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/RepositoryQueryTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.bugtracking.spi.RepositoryQueryImplementation;
+import org.netbeans.modules.bugtracking.util.BugtrackingOwnerSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.test.MockLookup;
+
+/**
+ *
+ * @author tomas
+ */
+public class RepositoryQueryTest extends NbTestCase {
+
+    public RepositoryQueryTest(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 testDefaultImpl() throws IOException {
+        Repository repo = getRepo();
+        
+        File file = new File(getWorkDir(), "testfile");
+        file.createNewFile();
+        
+        BugtrackingOwnerSupport.getInstance().setFirmAssociation(file, 
repo.getImpl());
+        FileObject fo = FileUtil.toFileObject(file);
+        assertNotNull(fo);
+        Repository r = RepositoryQuery.getInstance().getRepository(fo, 
false);
+        assertNotNull(r);
+        assertEquals(repo, r);
+    }
+
+    public void testCustomImpl() throws IOException {
+        File noRepoFile = new File(getWorkDir(), "norepo");
+        noRepoFile.createNewFile();
+        File assocFile = new File(getWorkDir(), "someassocfile");
+        assocFile.createNewFile();
+        
+        FileObject noRepoFO = FileUtil.toFileObject(noRepoFile);
+        assertNotNull(noRepoFO);
+        Repository r = RepositoryQuery.getInstance().getRepository(noRepoFO, 
false);
+        assertNull(r);
+        
+        FileObject assocFO = FileUtil.toFileObject(assocFile);
+        assertNotNull(assocFO);
+        r = RepositoryQuery.getInstance().getRepository(assocFO, false);
+        assertNotNull(r);
+        assertEquals(getRepo(), r);
+    }
+    
+    private Repository getRepo() {
+        return APITestKit.getRepo(APITestRepository.ID);
+    }
+    
+    @org.openide.util.lookup.ServiceProvider(service = 
org.netbeans.modules.bugtracking.spi.RepositoryQueryImplementation.class)
+    public static class RepositoryQImpl implements 
RepositoryQueryImplementation {
+        @Override
+        public Repository getRepository(FileObject fileObject, boolean 
askIfUnknown) {
+            if(fileObject.getName().endsWith("norepo")) {
+                return null;
+            }
+            return APITestKit.getRepo(APITestRepository.ID);
+        }
+    }
+    
+}
diff --git a/bugtracking/var/bugtracking/storage 
b/bugtracking/var/bugtracking/storage
new file mode 100644
index 
0000000000000000000000000000000000000000..5401847ad8e50108faa98fb4f6612c371e5a99a6
GIT binary patch
literal 10
Rc${NkU|?o2WYA+U1ONfg0F(d#

diff --git a/bugtracking/var/bugtracking/test/data 
b/bugtracking/var/bugtracking/test/data
new file mode 100644
index 
0000000000000000000000000000000000000000..f22cd1cda79053ba9c88fd50315641a84b936c2a
GIT binary patch
literal 8
Pc${NkV6-(o&t(k&1kVA8


[hg] main-silver: added RepositoryQuery tests

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