Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 76C65200C1B for ; Tue, 14 Feb 2017 09:46:21 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 755D0160B5F; Tue, 14 Feb 2017 08:46:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9798A160B52 for ; Tue, 14 Feb 2017 09:46:20 +0100 (CET) Received: (qmail 64064 invoked by uid 500); 14 Feb 2017 08:46:19 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 64054 invoked by uid 99); 14 Feb 2017 08:46:19 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2017 08:46:19 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 373793A0096 for ; Tue, 14 Feb 2017 08:46:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170214084619.373793A0096@svn01-us-west.apache.org> archived-at: Tue, 14 Feb 2017 08:46:21 -0000 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 @@ test - org.json - json - 20160212 + org.apache.felix + org.apache.felix.utils + 1.9.0 test 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 obj = new JSONParser(response.getEntity().getContent()).getParsed(); + + @SuppressWarnings("unchecked") + List status = (List) obj.get("s"); + + @SuppressWarnings("unchecked") + List bundles = (List) 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 bundle = (Map) 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 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); + } } }