ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1506423 - in /ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication: AuthenticationTestBase.java LogAuthenticationTest.java ObrAuthenticationTest.java
Date Wed, 24 Jul 2013 07:32:08 GMT
Author: bramk
Date: Wed Jul 24 07:32:07 2013
New Revision: 1506423

URL: http://svn.apache.org/r1506423
Log:
Added logging on itest failing in ci

Modified:
    ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/AuthenticationTestBase.java
    ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java
    ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java

Modified: ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/AuthenticationTestBase.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/AuthenticationTestBase.java?rev=1506423&r1=1506422&r2=1506423&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/AuthenticationTestBase.java
(original)
+++ ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/AuthenticationTestBase.java
Wed Jul 24 07:32:07 2013
@@ -24,12 +24,16 @@ import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Date;
+import java.util.Enumeration;
 
 import junit.framework.Assert;
 
 import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.apache.ace.it.IntegrationTestBase;
 import org.apache.ace.repository.Repository;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
 import org.osgi.service.useradmin.UserAdmin;
 
 /**
@@ -37,12 +41,27 @@ import org.osgi.service.useradmin.UserAd
  */
 public class AuthenticationTestBase extends IntegrationTestBase {
 
+    protected static void printLog(LogReaderService logReader) {
+        Enumeration<?> e = logReader.getLog();
+        System.out.println("Log:");
+        while (e.hasMoreElements()) {
+            LogEntry entry = (LogEntry) e.nextElement();
+            System.out.println(" * " + (new Date(entry.getTime())) + " - " + entry.getMessage()
+ " - " + entry.getBundle().getBundleId() + " - " + entry.getException());
+            if (entry.getException() != null) {
+                entry.getException().printStackTrace();
+            }
+        }
+    }
+
     /**
      * Imports a single user into the user repository.
      * 
-     * @param userName the name of the user to import;
-     * @param password the password of the user to import.
-     * @throws Exception in case of exceptions during the import.
+     * @param userName
+     *            the name of the user to import;
+     * @param password
+     *            the password of the user to import.
+     * @throws Exception
+     *             in case of exceptions during the import.
      */
     protected final void importSingleUser(Repository userRepository, String userName, String
password) throws Exception {
         ByteArrayInputStream bis = new ByteArrayInputStream((
@@ -59,12 +78,17 @@ public class AuthenticationTestBase exte
     /**
      * Waits for a HTTP URL to become 'available', will retry every 100 milliseconds until
it is available or timeout
      * has been exceeded. Available in this context means the specified status code is returned
when accessing the URL.
-     *
-     * @param url HTTP URL that should be tested for availability.
-     * @param responseCode The response code to be expected on the specified URL when it
is available.
-     * @param timeout Amount of milliseconds to keep trying to access the URL.
-     * @return True if the response of the URL has the specified status code within the specified
timeout delay, false otherwise.
-     * @throws IllegalArgumentException If the specified URL does not use the HTTP protocol.
+     * 
+     * @param url
+     *            HTTP URL that should be tested for availability.
+     * @param responseCode
+     *            The response code to be expected on the specified URL when it is available.
+     * @param timeout
+     *            Amount of milliseconds to keep trying to access the URL.
+     * @return True if the response of the URL has the specified status code within the specified
timeout delay, false
+     *         otherwise.
+     * @throws IllegalArgumentException
+     *             If the specified URL does not use the HTTP protocol.
      */
     protected final boolean waitForURL(ConnectionFactory connectionFactory, URL url, int
responseCode, int timeout) {
         long deadline = System.currentTimeMillis() + timeout;
@@ -83,7 +107,8 @@ public class AuthenticationTestBase exte
                         System.err.println("Got response code " + respCode + " for " + url);
                     }
                 }
-            } catch (ClassCastException cce) {
+            }
+            catch (ClassCastException cce) {
                 throw new IllegalArgumentException("Expected url to be an HTTP url, not:
" + url.toString(), cce);
             }
             catch (IOException ioe) {
@@ -102,9 +127,12 @@ public class AuthenticationTestBase exte
     /**
      * Waits until a user with a given name appears in the user admin.
      * 
-     * @param userAdmin the user admin to use;
-     * @param userName the name of the user to wait for.
-     * @throws Exception in case of exceptions during the wait.
+     * @param userAdmin
+     *            the user admin to use;
+     * @param userName
+     *            the name of the user to wait for.
+     * @throws Exception
+     *             in case of exceptions during the wait.
      */
     protected final void waitForUser(UserAdmin userAdmin, String userName) throws Exception
{
         int count = 0;

Modified: ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java?rev=1506423&r1=1506422&r2=1506423&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java
(original)
+++ ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java
Wed Jul 24 07:32:07 2013
@@ -35,13 +35,14 @@ import org.apache.ace.identification.pro
 import org.apache.ace.log.Log;
 import org.apache.ace.log.LogDescriptor;
 import org.apache.ace.log.LogEvent;
+import org.apache.ace.log.server.store.LogStore;
 import org.apache.ace.repository.Repository;
 import org.apache.ace.repository.impl.constants.RepositoryConstants;
-import org.apache.ace.log.server.store.LogStore;
 import org.apache.ace.test.constants.TestConstants;
 import org.apache.felix.dm.Component;
 import org.osgi.framework.Constants;
 import org.osgi.service.http.HttpService;
+import org.osgi.service.log.LogReaderService;
 import org.osgi.service.useradmin.UserAdmin;
 
 /**
@@ -64,71 +65,24 @@ public class LogAuthenticationTest exten
     private volatile Repository m_userRepository;
     private volatile UserAdmin m_userAdmin;
     private volatile ConnectionFactory m_connectionFactory;
+    private volatile LogReaderService m_logReader;
 
-    /**
-     * Tests that accessing the log servlet with authentication works when given the right
credentials.
-     */
-    public void testAccessLogServletWithCorrectCredentialsOk() throws Exception {
-        String tid1 = "42";
-        String tid2 = "47";
-
-        // prepare the store
-        List<LogEvent> events = new ArrayList<LogEvent>();
-        events.add(new LogEvent(tid1, 1, 1, 1, 1, new Properties()));
-        events.add(new LogEvent(tid2, 1, 1, 1, 1, new Properties()));
-        m_serverStore.put(events);
-
-        List<String> result = getResponse("http://localhost:" + TestConstants.PORT
+ "/auditlog/query");
-        assertTrue("We expect at least two logs on the server.", result.size() > 1);
-    }
-    
-    /**
-     * Tests that the log synchronization works when the log servlet has authentication enabled.
-     */
-    public void testLogSynchronizationOk() throws Exception {
-        final int type = 12345;
-        
-        // now log another event
-        Properties props = new Properties();
-        props.put("one", "value1");
-        props.put("two", "value2");
-        m_auditLog.log(type, props);
-
-        boolean found = false;
-        
-        long startTime = System.currentTimeMillis();
-        long waitTime = 15000; // milliseconds
-        
-        while (!found && ((System.currentTimeMillis() - startTime) < waitTime))
{
-            // synchronize again
-            m_auditLogSyncTask.run();
-
-            // get and evaluate results (note that there is some concurrency that might interfere
with this test)
-            List<LogDescriptor> ranges2 = m_serverStore.getDescriptors();
-            if (ranges2.isEmpty()) {
-                continue;
-            }
-
-            for (LogDescriptor descriptor : ranges2) {
-	            List<LogEvent> events = m_serverStore.get(descriptor);
-	            for (LogEvent event : events) {
-	                if (event.getType() == type) {
-	                    Dictionary properties = event.getProperties();
-	                    assertEquals("value1", properties.get("one"));
-	                    assertEquals("value2", properties.get("two"));
-	                    found = true;
-	                    break;
-	                }
-	            }
-            }
-
-            // wait if we have not found anything yet
-            if (!found) {
-                TimeUnit.MILLISECONDS.sleep(100);
-            }
-        }
-
-        assertTrue("We could not retrieve our audit log event (after 5 seconds).", found);
+    @Override
+    protected Component[] getDependencies() {
+        return new Component[] {
+                createComponent()
+                    .setImplementation(this)
+                    .add(createServiceDependency().setService(UserAdmin.class).setRequired(true))
+                    .add(createServiceDependency().setService(LogReaderService.class).setRequired(true))
+                    .add(createServiceDependency()
+                        .setService(Repository.class, "(&(" + RepositoryConstants.REPOSITORY_NAME
+ "=users)(" + RepositoryConstants.REPOSITORY_CUSTOMER + "=apache))")
+                        .setRequired(true))
+                    .add(createServiceDependency().setService(ConnectionFactory.class).setRequired(true))
+                    .add(createServiceDependency().setService(HttpService.class).setRequired(true))
+                    .add(createServiceDependency().setService(Log.class, "(&(" + Constants.OBJECTCLASS
+ "=" + Log.class.getName() + ")(name=auditlog))").setRequired(true))
+                    .add(createServiceDependency().setService(LogStore.class, "(&(" +
Constants.OBJECTCLASS + "=" + LogStore.class.getName() + ")(name=auditlog))").setRequired(true))
+                    .add(createServiceDependency().setService(Runnable.class, "(&(" +
Constants.OBJECTCLASS + "=" + Runnable.class.getName() + ")(taskName=auditlog))").setRequired(true))
+            };
     }
 
     @Override
@@ -153,9 +107,7 @@ public class LogAuthenticationTest exten
         assertTrue("Failed to access auditlog in time!", waitForURL(m_connectionFactory,
testURL, 200, 15000));
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     protected void configureProvisionedServices() throws Exception {
         String baseURL = "http://" + HOST + ":" + TestConstants.PORT;
 
@@ -192,28 +144,6 @@ public class LogAuthenticationTest exten
             "name", "auditlog");
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    protected Component[] getDependencies() {
-        return new Component[] {
-                createComponent()
-                    .setImplementation(this)
-                    .add(createServiceDependency().setService(UserAdmin.class).setRequired(true))
-                    .add(createServiceDependency()
-                        .setService(Repository.class, "(&(" + RepositoryConstants.REPOSITORY_NAME
+ "=users)(" + RepositoryConstants.REPOSITORY_CUSTOMER + "=apache))")
-                        .setRequired(true))
-                    .add(createServiceDependency().setService(ConnectionFactory.class).setRequired(true))
-                    .add(createServiceDependency().setService(HttpService.class).setRequired(true))
-                    .add(createServiceDependency().setService(Log.class, "(&(" + Constants.OBJECTCLASS
+ "=" + Log.class.getName() + ")(name=auditlog))").setRequired(true))
-                    .add(createServiceDependency().setService(LogStore.class, "(&(" +
Constants.OBJECTCLASS + "=" + LogStore.class.getName() + ")(name=auditlog))").setRequired(true))
-                    .add(createServiceDependency().setService(Runnable.class, "(&(" +
Constants.OBJECTCLASS + "=" + Runnable.class.getName() + ")(taskName=auditlog))").setRequired(true))
-            };
-    }
-
-    /**
-     * Overridden in order to use the connection factory for accessing URLs.
-     */
     @Override
     protected List<String> getResponse(String request) throws IOException {
         List<String> result = new ArrayList<String>();
@@ -248,9 +178,87 @@ public class LogAuthenticationTest exten
     
     @Override
     protected void tearDown() throws Exception {
-    	super.tearDown();
-    	
-    	// Remove the configuration to start without any configured authentication...
-    	getConfiguration(m_configurationPID).delete();
+        super.tearDown();
+        
+        // Remove the configuration to start without any configured authentication...
+        getConfiguration(m_configurationPID).delete();
+    }
+
+    /**
+     * Tests that accessing the log servlet with authentication works when given the right
credentials.
+     */
+    public void testAccessLogServletWithCorrectCredentialsOk() throws Exception {
+        try {
+        String tid1 = "42";
+        String tid2 = "47";
+
+        // prepare the store
+        List<LogEvent> events = new ArrayList<LogEvent>();
+        events.add(new LogEvent(tid1, 1, 1, 1, 1, new Properties()));
+        events.add(new LogEvent(tid2, 1, 1, 1, 1, new Properties()));
+        m_serverStore.put(events);
+
+        List<String> result = getResponse("http://localhost:" + TestConstants.PORT
+ "/auditlog/query");
+        assertTrue("We expect at least two logs on the server.", result.size() > 1);
+        }
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
+        }
+    }
+    
+    /**
+     * Tests that the log synchronization works when the log servlet has authentication enabled.
+     */
+    public void testLogSynchronizationOk() throws Exception {
+        try{
+        final int type = 12345;
+        
+        // now log another event
+        Properties props = new Properties();
+        props.put("one", "value1");
+        props.put("two", "value2");
+        m_auditLog.log(type, props);
+
+        boolean found = false;
+        
+        long startTime = System.currentTimeMillis();
+        long waitTime = 15000; // milliseconds
+        
+        while (!found && ((System.currentTimeMillis() - startTime) < waitTime))
{
+            // synchronize again
+            m_auditLogSyncTask.run();
+
+            // get and evaluate results (note that there is some concurrency that might interfere
with this test)
+            List<LogDescriptor> ranges2 = m_serverStore.getDescriptors();
+            if (ranges2.isEmpty()) {
+                continue;
+            }
+
+            for (LogDescriptor descriptor : ranges2) {
+	            List<LogEvent> events = m_serverStore.get(descriptor);
+	            for (LogEvent event : events) {
+	                if (event.getType() == type) {
+	                    Dictionary properties = event.getProperties();
+	                    assertEquals("value1", properties.get("one"));
+	                    assertEquals("value2", properties.get("two"));
+	                    found = true;
+	                    break;
+	                }
+	            }
+            }
+
+            // wait if we have not found anything yet
+            if (!found) {
+                TimeUnit.MILLISECONDS.sleep(100);
+            }
+        }
+
+        assertTrue("We could not retrieve our audit log event (after 5 seconds).", found);
+        }
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
+        }
     }
 }

Modified: ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java?rev=1506423&r1=1506422&r2=1506423&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java
(original)
+++ ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java
Wed Jul 24 07:32:07 2013
@@ -42,6 +42,7 @@ import org.apache.felix.dm.Component;
 import org.osgi.framework.Constants;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogReaderService;
 import org.osgi.service.useradmin.UserAdmin;
 
 /**
@@ -60,12 +61,14 @@ public class ObrAuthenticationTest exten
     private volatile UserAdmin m_userAdmin;
     private volatile ConfigurationAdmin m_configAdmin;
     private volatile ConnectionFactory m_connectionFactory;
+    private volatile LogReaderService m_logReader;
 
     @Override
     protected Component[] getDependencies() {
         return new Component[] {
             createComponent()
                 .setImplementation(this)
+                .add(createServiceDependency().setService(LogReaderService.class).setRequired(true))
                 .add(createServiceDependency().setService(ArtifactRepository.class).setRequired(true))
                 .add(createServiceDependency().setService(ConnectionFactory.class).setRequired(true))
                 .add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
@@ -131,6 +134,7 @@ public class ObrAuthenticationTest exten
         assertTrue("Failed to access auditlog in time!", waitForURL(m_connectionFactory,
testURL, 200, 15000));
     }
 
+    @Override
     public void tearDown() throws Exception {
         FileUtils.removeDirectoryWithContent(m_storeLocation);
         Configuration configuration = getConfiguration(m_authConfigPID);
@@ -142,67 +146,83 @@ public class ObrAuthenticationTest exten
     /**
      * Test that we can retrieve the 'repository.xml' from the OBR.
      */
-    public void testAccessObrRepositoryWithCredentialsOk() throws IOException {
-        URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml");
-
-        URLConnection conn = m_connectionFactory.createConnection(url);
-        assertNotNull(conn);
-
-        Object content = conn.getContent();
-        assertNotNull(content);
+    public void testAccessObrRepositoryWithCredentialsOk() throws Exception {
+        try {
+            URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml");
+            URLConnection conn = m_connectionFactory.createConnection(url);
+            assertNotNull(conn);
+            Object content = conn.getContent();
+            assertNotNull(content);
+        }
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
+        }
     }
 
     /**
      * Test that we cannot retrieve the 'repository.xml' from the OBR without any credentials.
      */
-    public void testAccessObrRepositoryWithoutCredentialsFail() throws IOException {
-        URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml");
-
-        // do NOT use connection factory as it will supply the credentials for us...
-        URLConnection conn = url.openConnection();
-        assertNotNull(conn);
-
-        // we expect a 401 for this URL...
-        NetUtils.waitForURL(url, 401, 15000);
-
+    public void testAccessObrRepositoryWithoutCredentialsFail() throws Exception {
         try {
-            // ...causing all other methods on URLConnection to fail...
-            conn.getContent(); // should fail!
-            fail("IOException expected!");
+            URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml");
+
+            // do NOT use connection factory as it will supply the credentials for us...
+            URLConnection conn = url.openConnection();
+            assertNotNull(conn);
+
+            // we expect a 401 for this URL...
+            NetUtils.waitForURL(url, 401, 15000);
+
+            try {
+                // ...causing all other methods on URLConnection to fail...
+                conn.getContent(); // should fail!
+                fail("IOException expected!");
+            }
+            catch (IOException exception) {
+                // Ok; ignored...
+            }
         }
-        catch (IOException exception) {
-            // Ok; ignored...
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
         }
     }
 
     /**
      * Test that we cannot retrieve the 'repository.xml' from the OBR with incorrect credentials.
      */
-    public void testAccessObrRepositoryWithWrongCredentialsFail() throws IOException {
-        org.osgi.service.cm.Configuration configuration = m_configAdmin.getConfiguration(m_authConfigPID);
-        assertNotNull(configuration);
-
-        // Simulate incorrect credentials by updating the config of the connection factory...
-        configuration.getProperties().put("authentication.user.name", "foo");
-
-        configuration.update();
-
-        URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml");
+    public void testAccessObrRepositoryWithWrongCredentialsFail() throws Exception {
+        try {
+            org.osgi.service.cm.Configuration configuration = m_configAdmin.getConfiguration(m_authConfigPID);
+            assertNotNull(configuration);
 
-        // do NOT use connection factory as it will supply the credentials for us...
-        URLConnection conn = url.openConnection();
-        assertNotNull(conn);
+            // Simulate incorrect credentials by updating the config of the connection factory...
+            configuration.getProperties().put("authentication.user.name", "foo");
 
-        // we expect a 401 for this URL...
-        NetUtils.waitForURL(url, 401, 15000);
+            configuration.update();
 
-        try {
-            // ...causing all other methods on URLConnection to fail...
-            conn.getContent(); // should fail!
-            fail("IOException expected!");
+            URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml");
+
+            // do NOT use connection factory as it will supply the credentials for us...
+            URLConnection conn = url.openConnection();
+            assertNotNull(conn);
+
+            // we expect a 401 for this URL...
+            NetUtils.waitForURL(url, 401, 15000);
+
+            try {
+                // ...causing all other methods on URLConnection to fail...
+                conn.getContent(); // should fail!
+                fail("IOException expected!");
+            }
+            catch (IOException exception) {
+                // Ok; ignored...
+            }
         }
-        catch (IOException exception) {
-            // Ok; ignored...
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
         }
     }
 
@@ -211,36 +231,42 @@ public class ObrAuthenticationTest exten
      * as well.
      */
     public void testImportArtifactWithCredentialsOk() throws Exception {
-        // Use a valid JAR file, without a Bundle-SymbolicName header.
-        Manifest manifest = new Manifest();
-        Attributes attributes = manifest.getMainAttributes();
-        attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1");
-        attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
-        attributes.putValue(BundleHelper.KEY_SYMBOLICNAME, "org.apache.ace.test1");
-
-        File temp = File.createTempFile("org.apache.ace.test1", ".jar");
-        temp.deleteOnExit();
-        JarOutputStream jos = new JarOutputStream(new FileOutputStream(temp), manifest);
-        jos.close();
-
-        m_artifactRepository.importArtifact(temp.toURI().toURL(), true /* upload */);
-
-        assertEquals(1, m_artifactRepository.get().size());
-        assertTrue(m_artifactRepository.getResourceProcessors().isEmpty());
-
-        // Create a JAR file which looks like a resource processor supplying bundle.
-        attributes.putValue(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "someProcessor");
-        attributes.putValue(BundleHelper.KEY_VERSION, "1.0.0.processor");
-
-        temp = File.createTempFile("org.apache.ace.test2", ".jar");
-        temp.deleteOnExit();
-        jos = new JarOutputStream(new FileOutputStream(temp), manifest);
-        jos.close();
+        try {
+            // Use a valid JAR file, without a Bundle-SymbolicName header.
+            Manifest manifest = new Manifest();
+            Attributes attributes = manifest.getMainAttributes();
+            attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1");
+            attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
+            attributes.putValue(BundleHelper.KEY_SYMBOLICNAME, "org.apache.ace.test1");
+
+            File temp = File.createTempFile("org.apache.ace.test1", ".jar");
+            temp.deleteOnExit();
+            JarOutputStream jos = new JarOutputStream(new FileOutputStream(temp), manifest);
+            jos.close();
+
+            m_artifactRepository.importArtifact(temp.toURI().toURL(), true /* upload */);
+
+            assertEquals(1, m_artifactRepository.get().size());
+            assertTrue(m_artifactRepository.getResourceProcessors().isEmpty());
+
+            // Create a JAR file which looks like a resource processor supplying bundle.
+            attributes.putValue(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "someProcessor");
+            attributes.putValue(BundleHelper.KEY_VERSION, "1.0.0.processor");
+
+            temp = File.createTempFile("org.apache.ace.test2", ".jar");
+            temp.deleteOnExit();
+            jos = new JarOutputStream(new FileOutputStream(temp), manifest);
+            jos.close();
 
-        m_artifactRepository.importArtifact(temp.toURI().toURL(), true);
+            m_artifactRepository.importArtifact(temp.toURI().toURL(), true);
 
-        assertEquals(1, m_artifactRepository.get().size());
-        assertEquals(1, m_artifactRepository.getResourceProcessors().size());
+            assertEquals(1, m_artifactRepository.get().size());
+            assertEquals(1, m_artifactRepository.getResourceProcessors().size());
+        }
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
+        }
     }
 
     /**
@@ -248,30 +274,36 @@ public class ObrAuthenticationTest exten
      * as well.
      */
     public void testImportArtifactWithoutCredentialsFail() throws Exception {
-        org.osgi.service.cm.Configuration configuration = m_configAdmin.getConfiguration(m_authConfigPID);
-        assertNotNull(configuration);
-
-        // Delete the credentials for the OBR-URL, thereby simulating wrong credentials for
the OBR...
-        configuration.delete();
+        try {
+            org.osgi.service.cm.Configuration configuration = m_configAdmin.getConfiguration(m_authConfigPID);
+            assertNotNull(configuration);
 
-        // Use a valid JAR file, without a Bundle-SymbolicName header.
-        Manifest manifest = new Manifest();
-        Attributes attributes = manifest.getMainAttributes();
-        attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1");
-        attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
-        attributes.putValue(BundleHelper.KEY_SYMBOLICNAME, "org.apache.ace.test3");
-
-        File temp = File.createTempFile("org.apache.ace.test3", ".jar");
-        temp.deleteOnExit();
-        JarOutputStream jos = new JarOutputStream(new FileOutputStream(temp), manifest);
-        jos.close();
+            // Delete the credentials for the OBR-URL, thereby simulating wrong credentials
for the OBR...
+            configuration.delete();
 
-        try {
-            m_artifactRepository.importArtifact(temp.toURI().toURL(), true /* upload */);
// should fail!
-            fail("IOException expected!");
+            // Use a valid JAR file, without a Bundle-SymbolicName header.
+            Manifest manifest = new Manifest();
+            Attributes attributes = manifest.getMainAttributes();
+            attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1");
+            attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
+            attributes.putValue(BundleHelper.KEY_SYMBOLICNAME, "org.apache.ace.test3");
+
+            File temp = File.createTempFile("org.apache.ace.test3", ".jar");
+            temp.deleteOnExit();
+            JarOutputStream jos = new JarOutputStream(new FileOutputStream(temp), manifest);
+            jos.close();
+
+            try {
+                m_artifactRepository.importArtifact(temp.toURI().toURL(), true /* upload
*/); // should fail!
+                fail("IOException expected!");
+            }
+            catch (IOException exception) {
+                // Ok; expected...
+            }
         }
-        catch (IOException exception) {
-            // Ok; expected...
+        catch (Exception e) {
+            printLog(m_logReader);
+            throw e;
         }
     }
 }



Mime
View raw message