sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1782927 - in /sling/trunk/launchpad/builder: pom.xml src/test/java/org/apache/sling/launchpad/SmokeIT.java
Date Tue, 14 Feb 2017 08:46:18 GMT
Author: cziegeler
Date: Tue Feb 14 08:46:18 2017
New Revision: 1782927

URL: http://svn.apache.org/viewvc?rev=1782927&view=rev
Log:
SLING-6518 : Remove dependency to org.json

Modified:
    sling/trunk/launchpad/builder/pom.xml
    sling/trunk/launchpad/builder/src/test/java/org/apache/sling/launchpad/SmokeIT.java

Modified: sling/trunk/launchpad/builder/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/pom.xml?rev=1782927&r1=1782926&r2=1782927&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/pom.xml (original)
+++ sling/trunk/launchpad/builder/pom.xml Tue Feb 14 08:46:18 2017
@@ -166,9 +166,9 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.json</groupId>
-            <artifactId>json</artifactId>
-            <version>20160212</version>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.utils</artifactId>
+            <version>1.9.0</version>
             <scope>test</scope>
         </dependency>
     </dependencies>

Modified: sling/trunk/launchpad/builder/src/test/java/org/apache/sling/launchpad/SmokeIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/test/java/org/apache/sling/launchpad/SmokeIT.java?rev=1782927&r1=1782926&r2=1782927&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/test/java/org/apache/sling/launchpad/SmokeIT.java (original)
+++ sling/trunk/launchpad/builder/src/test/java/org/apache/sling/launchpad/SmokeIT.java Tue
Feb 14 08:46:18 2017
@@ -21,9 +21,13 @@ import static org.hamcrest.CoreMatchers.
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
+import java.util.List;
+import java.util.Map;
+
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.apache.felix.utils.json.JSONParser;
 import org.apache.http.Header;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.UsernamePasswordCredentials;
@@ -34,9 +38,6 @@ import org.apache.http.impl.client.Basic
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.hamcrest.CoreMatchers;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.json.JSONTokener;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.w3c.dom.Document;
@@ -45,94 +46,97 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
 public class SmokeIT {
-    
+
     private static final int LAUNCHPAD_PORT = Integer.getInteger("launchpad.http.port", 8080);
     private static final int EXPECTED_BUNDLES_COUNT = Integer.getInteger("IT.expected.bundles.count",
Integer.MAX_VALUE);
-    
+
     @ClassRule
     public static LaunchpadReadyRule LAUNCHPAD = new LaunchpadReadyRule(LAUNCHPAD_PORT);
-    
+
     private CloseableHttpClient newClient() {
-        
+
         CredentialsProvider credsProvider = new BasicCredentialsProvider();
         UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "admin");
         credsProvider.setCredentials(new AuthScope("localhost", LAUNCHPAD_PORT), creds);
-        
+
         return HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
     }
-    
+
     @Test
     public void verifyAllBundlesStarted() throws Exception {
 
         try ( CloseableHttpClient client = newClient() ) {
-            
+
             HttpGet get = new HttpGet("http://localhost:" + LAUNCHPAD_PORT + "/system/console/bundles.json");
-            
+
             try ( CloseableHttpResponse response = client.execute(get) ) {
-                
+
                 if ( response.getStatusLine().getStatusCode() != 200 ) {
                     fail("Unexpected status line " + response.getStatusLine());
                 }
-                
+
                 Header contentType = response.getFirstHeader("Content-Type");
                 assertThat("Content-Type header", contentType.getValue(), CoreMatchers.startsWith("application/json"));
 
-                JSONObject obj = new JSONObject(new JSONTokener(response.getEntity().getContent()));
-                
-                JSONArray status = obj.getJSONArray("s");
-                
-                JSONArray bundles = obj.getJSONArray("data");
-                if(bundles.length() < EXPECTED_BUNDLES_COUNT) {
-                    fail("Expected at least " + EXPECTED_BUNDLES_COUNT + " bundles, got "
+ bundles.length());
+                Map<String, Object> obj = new JSONParser(response.getEntity().getContent()).getParsed();
+
+                @SuppressWarnings("unchecked")
+                List<Object> status = (List<Object>) obj.get("s");
+
+                @SuppressWarnings("unchecked")
+                List<Object> bundles = (List<Object>) obj.get("data");
+                if(bundles.size() < EXPECTED_BUNDLES_COUNT) {
+                    fail("Expected at least " + EXPECTED_BUNDLES_COUNT + " bundles, got "
+ bundles.size());
                 }
-                
+
                 BundleStatus bs = new BundleStatus(status);
-                
+
                 if ( bs.resolvedBundles != 0 || bs.installedBundles != 0 ) {
-                    
+
                     StringBuilder out = new StringBuilder();
                     out.append("Expected all bundles to be active, but instead got ")
                         .append(bs.resolvedBundles).append(" resolved bundles, ")
                         .append(bs.installedBundles).append(" installed bundlles: ");
-                    
-                    for ( int i = 0 ; i < bundles.length(); i++ ) {
-                        JSONObject bundle = bundles.getJSONObject(i);
-                        
-                        String bundleState = bundle.getString("state");
-                        String bundleSymbolicName = bundle.getString("symbolicName");
-                        String bundleVersion = bundle.getString("version");
-                        
+
+                    for ( int i = 0 ; i < bundles.size(); i++ ) {
+                        @SuppressWarnings("unchecked")
+                        Map<String, Object> bundle = (Map<String, Object>) bundles.get(i);
+
+                        String bundleState = (String) bundle.get("state");
+                        String bundleSymbolicName = (String) bundle.get("symbolicName");
+                        String bundleVersion = (String) bundle.get("version");
+
                         switch ( bundleState ) {
                             case "Active":
                             case "Fragment":
                                 continue;
-                            
+
                             default:
                                 out.append("\n- ").append(bundleSymbolicName).append(" ").append(bundleVersion).append("
is in state " ).append(bundleState);
                         }
                     }
-                    
+
                     fail(out.toString());
                 }
             }
         }
     }
-    
+
     @Test
     public void ensureRepositoryIsStarted() throws Exception {
         try ( CloseableHttpClient client = newClient() ) {
-            
+
             HttpGet get = new HttpGet("http://localhost:" + LAUNCHPAD_PORT + "/server/default/jcr:root");
-            
+
             try ( CloseableHttpResponse response = client.execute(get) ) {
-                
+
                 if ( response.getStatusLine().getStatusCode() != 200 ) {
                     fail("Unexpected status line " + response.getStatusLine());
                 }
-                
+
                 Header contentType = response.getFirstHeader("Content-Type");
                 assertThat("Content-Type header", contentType.getValue(), equalTo("text/xml"));
-                
+
                 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                 dbf.setNamespaceAware(true);
                 DocumentBuilder db = dbf.newDocumentBuilder();
@@ -140,30 +144,30 @@ public class SmokeIT {
 
                 Element docElement = document.getDocumentElement();
                 NamedNodeMap attrs = docElement.getAttributes();
-                
+
                 Node nameAttr = attrs.getNamedItemNS("http://www.jcp.org/jcr/sv/1.0", "name");
                 assertThat("no 'name' attribute found", nameAttr, notNullValue());
                 assertThat("Invalid name attribute value", nameAttr.getNodeValue(), equalTo("jcr:root"));
             }
         }
     }
-    
+
     static class BundleStatus {
-        
-        int totalBundles;
-        int activeBundles;
-        int activeFragments;
-        int resolvedBundles;
-        int installedBundles;
-        
-        public BundleStatus(JSONArray array) {
-            
-            totalBundles = array.getInt(0);
-            activeBundles = array.getInt(1);
-            activeFragments = array.getInt(2);
-            resolvedBundles = array.getInt(3);
-            installedBundles = array.getInt(4);
-            
+
+        long totalBundles;
+        long activeBundles;
+        long activeFragments;
+        long resolvedBundles;
+        long installedBundles;
+
+        public BundleStatus(List<Object> array) {
+
+            totalBundles = (Long)array.get(0);
+            activeBundles = (Long)array.get(1);
+            activeFragments = (Long)array.get(2);
+            resolvedBundles = (Long)array.get(3);
+            installedBundles = (Long)array.get(4);
+
         }
     }
 }



Mime
View raw message