incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1511772 - in /sling/branches/SLING-2987-healthcheck-redesign/hc-core/src: main/java/org/apache/sling/hc/impl/healthchecks/ test/java/org/apache/sling/hc/impl/
Date Thu, 08 Aug 2013 13:24:49 GMT
Author: bdelacretaz
Date: Thu Aug  8 13:24:49 2013
New Revision: 1511772

URL: http://svn.apache.org/r1511772
Log:
SLING-2987 - bindings tests

Added:
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/JmxScriptBindingTest.java
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/OsgiScriptBindingTest.java
Modified:
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/JmxScriptBinding.java
    sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/OsgiScriptBinding.java

Modified: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/JmxScriptBinding.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/JmxScriptBinding.java?rev=1511772&r1=1511771&r2=1511772&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/JmxScriptBinding.java
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/JmxScriptBinding.java
Thu Aug  8 13:24:49 2013
@@ -37,7 +37,7 @@ public class JmxScriptBinding {
     private MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
     private final Logger logger;
     
-    JmxScriptBinding(Logger logger) {
+    public JmxScriptBinding(Logger logger) {
         this.logger = logger;
     }
     

Modified: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/OsgiScriptBinding.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/OsgiScriptBinding.java?rev=1511772&r1=1511771&r2=1511772&view=diff
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/OsgiScriptBinding.java
(original)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/main/java/org/apache/sling/hc/impl/healthchecks/OsgiScriptBinding.java
Thu Aug  8 13:24:49 2013
@@ -30,7 +30,7 @@ public class OsgiScriptBinding {
     private final Logger logger;
     private final BundleContext bundleContext;
     
-    OsgiScriptBinding(BundleContext ctx, Logger logger) {
+    public OsgiScriptBinding(BundleContext ctx, Logger logger) {
         this.logger = logger;
         this.bundleContext = ctx;
     }

Added: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/JmxScriptBindingTest.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/JmxScriptBindingTest.java?rev=1511772&view=auto
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/JmxScriptBindingTest.java
(added)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/JmxScriptBindingTest.java
Thu Aug  8 13:24:49 2013
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.hc.impl;
+
+import org.apache.sling.hc.impl.healthchecks.JmxScriptBinding;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JmxScriptBindingTest {
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+    
+    @Test
+    public void testJmxAttribute() throws Exception {
+        final JmxScriptBinding b = new JmxScriptBinding(logger);
+        final Object result = b.attribute("java.lang:type=ClassLoading", "LoadedClassCount");
+        assertNotNull("Expecting non-null attribute value", result);
+        assertTrue("Expecting non-empty value", result.toString().length() > 0);
+    }
+}
\ No newline at end of file

Added: sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/OsgiScriptBindingTest.java
URL: http://svn.apache.org/viewvc/sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/OsgiScriptBindingTest.java?rev=1511772&view=auto
==============================================================================
--- sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/OsgiScriptBindingTest.java
(added)
+++ sling/branches/SLING-2987-healthcheck-redesign/hc-core/src/test/java/org/apache/sling/hc/impl/OsgiScriptBindingTest.java
Thu Aug  8 13:24:49 2013
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.hc.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.sling.hc.impl.healthchecks.OsgiScriptBinding;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OsgiScriptBindingTest {
+    
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+    
+    private Bundle mockBundle(boolean isFragment, boolean isActive) {
+        final Bundle b = Mockito.mock(Bundle.class);
+        Mockito.when(b.getState()).thenReturn(isActive ? Bundle.ACTIVE : Bundle.RESOLVED);
+        
+        final Dictionary<String, String> headers = new Hashtable<String, String>();
+        if(isFragment) {
+            headers.put(Constants.FRAGMENT_HOST, "FOO");
+        }
+        Mockito.when(b.getHeaders()).thenReturn(headers);
+        
+        return b;
+    }
+    
+    @Test
+    public void testInactiveBundles() throws Exception {
+        final BundleContext ctx = Mockito.mock(BundleContext.class);
+        final Bundle [] bundles = { 
+                mockBundle(false, true), 
+                mockBundle(false, false), 
+                mockBundle(false, true),
+                mockBundle(true, false)
+        };
+        Mockito.when(ctx.getBundles()).thenReturn(bundles);
+        
+        final OsgiScriptBinding b = new OsgiScriptBinding(ctx, logger);
+        assertEquals(1, b.inactiveBundlesCount());
+    }
+}
\ No newline at end of file



Mime
View raw message