Update junit Assert imports
[controller.git] / opendaylight / northbound / bundlescanner / implementation / src / test / java / org / opendaylight / controller / northbound / bundlescanner / internal / BundleScannerTest.java
index 0d7d7da1f0ccd48c8d5af658b21a4ae5ae1365fd..13431fbd86b7fdb11a6d2b9ac4027812f9ba7f8b 100644 (file)
@@ -1,38 +1,43 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.northbound.bundlescanner.internal;
 
-import static org.junit.Assert.*;
-
 import java.io.File;
 import java.io.FileFilter;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Set;
 import java.util.regex.Pattern;
 
-import javax.xml.bind.JAXBException;
-
-import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
-import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.Constants;
 import org.springframework.osgi.mock.MockBundle;
 import org.springframework.osgi.mock.MockBundleContext;
-import org.springframework.osgi.mock.MockFrameworkUtil;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 public class BundleScannerTest {
 
@@ -69,18 +74,18 @@ public class BundleScannerTest {
     public void testBundleEvents() throws Exception {
         MockBundle newBundle = new TestMockBundle("misc", "", "bundle_misc");
         assertTrue(bundleScanner.getAnnotatedClasses(
-                newBundle.getBundleContext(), null, false).size() == 0);
+                newBundle.getBundleContext(), null, null, false).size() == 0);
         BundleEvent event = new BundleEvent(BundleEvent.RESOLVED, newBundle);
         bundleScanner.bundleChanged(event);
         assertTrue(bundleScanner.getAnnotatedClasses(
-                newBundle.getBundleContext(), null, false).size() == 1);
+                newBundle.getBundleContext(), null, null, false).size() == 1);
     }
 
     @Test
     public void testAnnotatedClassesWithDependencies() throws Exception {
         for (Bundle bundle : bundles) {
             List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
-                    bundle.getBundleContext(), null, true);
+                    bundle.getBundleContext(), null, null, true);
             String name = bundle.getSymbolicName();
             System.out.println("name:" + name + " classes:" + classes.size());
             if ("misc".equals(name)) {
@@ -100,7 +105,7 @@ public class BundleScannerTest {
         Bundle bundle = findBundle("sub1");
         String[] annos = { "javax.xml.bind.annotation.XmlTransient" };
         List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
-                bundle.getBundleContext(), annos, true);
+                bundle.getBundleContext(), annos, null, true);
         assertTrue(classes.size() == 1);
     }
 
@@ -109,7 +114,7 @@ public class BundleScannerTest {
         Bundle bundle = findBundle("sub1");
         String[] annos = { "javax.xml.bind.annotation.*" };
         List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
-                bundle.getBundleContext(), annos, true);
+                bundle.getBundleContext(), annos, null, true);
         assertTrue(classes.size() == 6);
     }
 
@@ -118,7 +123,7 @@ public class BundleScannerTest {
         Bundle bundle = findBundle("sub1");
         String[] annos = { "non.existent.pkg" };
         List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
-                bundle.getBundleContext(), annos, true);
+                bundle.getBundleContext(), annos, null, true);
         assertTrue(classes.size() == 0);
     }
 
@@ -135,6 +140,17 @@ public class BundleScannerTest {
         assertFalse(pattern.matcher("Ljavax/servlet/FOO;").find());
     }
 
+    @Test
+    public void testExclude() {
+        Set<String> excludes = new HashSet<String>();
+        excludes.add("bundle_base.Animal");
+        Bundle bundle = findBundle("sub1");
+        String[] annos = { "javax.xml.bind.annotation.*" };
+        List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
+                bundle.getBundleContext(), annos, excludes, true);
+        assertTrue(classes.size() == 5);
+    }
+
     private static Bundle findBundle(String symName) {
         for (Bundle bundle : bundles) {
             if (bundle.getSymbolicName().equals(symName)) return bundle;