Author: adietish
Date: 2010-08-24 15:21:26 -0400 (Tue, 24 Aug 2010)
New Revision: 24391
Added:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalUsageReportingEnablement.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/HttpEncodingUtils.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalUsageReportingEnablementTest.java
Removed:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalReportingEnablement.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/EncodingUtils.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalReportingEnablementTest.java
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/GoogleAnalyticsUrlStrategy.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/FocusPointTest.java
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/UsageTestSuite.java
Log:
[JBIDE-6880] implementation and tests updated
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/FocusPoint.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -10,7 +10,7 @@
******************************************************************************/
package org.jboss.tools.usage;
-import org.jboss.tools.usage.util.EncodingUtils;
+import org.jboss.tools.usage.util.HttpEncodingUtils;
/**
* Focus point of the application. It can represent data points like application
@@ -43,7 +43,7 @@
public String getContentURI() {
StringBuilder builder = new StringBuilder();
appendContentURI(builder, this);
- return EncodingUtils.checkedEncodeUtf8(builder.toString());
+ return HttpEncodingUtils.checkedEncodeUtf8(builder.toString());
}
private void appendContentURI(StringBuilder builder, FocusPoint focusPoint) {
@@ -58,7 +58,7 @@
public String getContentTitle() {
StringBuilder builder = new StringBuilder();
appendContentTitle(builder, this);
- return EncodingUtils.checkedEncodeUtf8(builder.toString());
+ return HttpEncodingUtils.checkedEncodeUtf8(builder.toString());
}
private void appendContentTitle(StringBuilder builder, FocusPoint focusPoint) {
Deleted:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalReportingEnablement.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalReportingEnablement.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalReportingEnablement.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.usage;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Plugin;
-import org.jboss.tools.usage.util.StatusUtils;
-
-/**
- * A class that implements a global reporting enablement setting. The current
- * implementation queries a given url and extracts the enablement value out of
- * the response.
- */
-public class GlobalReportingEnablement {
-
- private static final String GET_METHOD_NAME = "GET"; //$NON-NLS-1$
- private static final String REPORTING_ENABLEMENT_URL =
"https://community.jboss.org/wiki/JBossToolsJBossDeveloperStudioUsageReportingEnablement";
//$NON-NLS-1$
- private static final String REPORTING_ENABLEMENT_REGEX = "Usage Reporting is
([A-Za-z]+)"; //$NON-NLS-1$
-
- private Plugin plugin;
- private HttpURLConnection urlConnection;
- private Pattern pattern;
-
- public GlobalReportingEnablement(Plugin plugin) throws IOException {
- Assert.isNotNull(plugin);
-
- this.plugin = plugin;
- this.urlConnection = createURLConnection(REPORTING_ENABLEMENT_URL);
- this.pattern = Pattern.compile(REPORTING_ENABLEMENT_REGEX);
- }
-
- public boolean isEnabled() {
- return parse(request(REPORTING_ENABLEMENT_URL));
- }
-
- /**
- * Sends a http GET request to the given URL. Returns the response string or
- * <tt>null</tt> if an error occurred. The errors catched are Exceptions or
- * HTTP error codes.
- *
- * @param url
- * the url to send the GET request to
- * @return the response or <tt>null</tt> if an error occured.
- *
- * @see HttpURLConnection
- */
- protected String request(String url) {
- String response = null;
- try {
- urlConnection.connect();
- int responseCode = getResponseCode(urlConnection);
- if (responseCode == HttpURLConnection.HTTP_OK) {
- IStatus status = StatusUtils.getDebugStatus(
- plugin.getBundle().getSymbolicName()
- , UsageMessages.KillSwitchPreference_Info_HttpQuery, url);
- plugin.getLog().log(status);
- response = urlConnection.getResponseMessage();
- } else {
- IStatus status = StatusUtils.getErrorStatus(
- plugin.getBundle().getSymbolicName()
- , UsageMessages.KillSwitchPreference_Error_Http, null, url);
- plugin.getLog().log(status);
- }
- } catch (Exception e) {
- IStatus status = StatusUtils.getErrorStatus(
- plugin.getBundle().getSymbolicName()
- , UsageMessages.KillSwitchPreference_Error_Http, null, url);
- plugin.getLog().log(status);
- }
- return response;
- }
-
- /**
- * Parses the given string and extracts the enablement value.
- *
- * @param response
- * the response
- * @return true, if successful
- */
- private boolean parse(String response) {
- Matcher matcher = pattern.matcher(response);
- if (matcher.find() && matcher.groupCount() >= 1) {
- String enablementValue = matcher.group(1);
- return isEnabled(enablementValue);
- }
- return false;
- }
-
- private boolean isEnabled(String enablementValue) {
- return (enablementValue != null &&
"ENABLED".equals(enablementValue.toUpperCase()));
- }
-
- /**
- * Creates a new url connection.
- *
- * @param urlString
- * the url string
- * @return the http url connection
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- protected HttpURLConnection createURLConnection(String urlString) throws IOException {
- URL url = new URL(urlString);
- HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
- urlConnection.setInstanceFollowRedirects(true);
- urlConnection.setRequestMethod(GET_METHOD_NAME);
- return urlConnection;
- }
-
- /**
- * Returns the return code from the given {@link HttpURLConnection}.
- * Provided to be called by test cases so that they can retrieve the return
- * code.
- *
- * @param urlConnection
- * to get the response code from
- * @return the return code the HttpUrlConnection received
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- protected int getResponseCode(HttpURLConnection urlConnection) throws IOException {
- return urlConnection.getResponseCode();
- }
-}
Copied:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalUsageReportingEnablement.java
(from rev 24378,
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalReportingEnablement.java)
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalUsageReportingEnablement.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalUsageReportingEnablement.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.jboss.tools.usage.util.HttpEncodingUtils;
+import org.jboss.tools.usage.util.StatusUtils;
+
+/**
+ * A class that implements a global reporting enablement setting. The current
+ * implementation queries a given url and extracts the enablement value out of
+ * the response.
+ */
+public class GlobalUsageReportingEnablement {
+
+ private static final String REPORTING_ENABLEMENT_ENABLEDVALUE = "ENABLED";
+
+ private static final String GET_METHOD_NAME = "GET"; //$NON-NLS-1$
+ private static final String REPORTING_ENABLEMENT_URL =
"http://community.jboss.org/wiki/JBossToolsJBossDeveloperStudioUsageReportingEnablement";
//$NON-NLS-1$
+ private static final String REPORTING_ENABLEMENT_STARTSEQUENCE = "Usage Reporting
is "; //$NON-NLS-1$
+
+ private Plugin plugin;
+ private HttpURLConnection urlConnection;
+
+ public GlobalUsageReportingEnablement(Plugin plugin) throws IOException {
+ Assert.isNotNull(plugin);
+
+ this.plugin = plugin;
+ this.urlConnection = createURLConnection(REPORTING_ENABLEMENT_URL);
+ }
+
+ public boolean isEnabled() {
+ try {
+ return parse(request(REPORTING_ENABLEMENT_URL));
+ } catch (IOException e) {
+ IStatus status = StatusUtils.getErrorStatus(
+ plugin.getBundle().getSymbolicName()
+ , UsageMessages.KillSwitchPreference_Error_Exception, e);
+ plugin.getLog().log(status);
+ return false;
+ }
+ }
+
+ /**
+ * Sends a http GET request to the given URL. Returns the response string or
+ * <tt>null</tt> if an error occurred. The errors catched are Exceptions or
+ * HTTP error codes.
+ *
+ * @param url
+ * the url to send the GET request to
+ * @return the response or <tt>null</tt> if an error occured.
+ * @throws UnsupportedEncodingException
+ *
+ * @see HttpURLConnection
+ */
+ protected InputStreamReader request(String url) throws UnsupportedEncodingException {
+ InputStreamReader responseReader = null;
+ try {
+ urlConnection.connect();
+ int responseCode = getResponseCode(urlConnection);
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ IStatus status = StatusUtils.getDebugStatus(
+ plugin.getBundle().getSymbolicName()
+ , UsageMessages.KillSwitchPreference_Info_HttpQuery
+ , url);
+ plugin.getLog().log(status);
+ responseReader = getInputStreamReader(urlConnection.getContentType());
+ } else {
+ IStatus status = StatusUtils.getErrorStatus(
+ plugin.getBundle().getSymbolicName()
+ , UsageMessages.KillSwitchPreference_Error_Http, null, url);
+ plugin.getLog().log(status);
+ }
+ } catch (Exception e) {
+ IStatus status = StatusUtils.getErrorStatus(
+ plugin.getBundle().getSymbolicName()
+ , UsageMessages.KillSwitchPreference_Error_Http, e, url);
+ plugin.getLog().log(status);
+ }
+ return responseReader;
+ }
+
+ private InputStreamReader getInputStreamReader(String contentType) throws
UnsupportedEncodingException, IOException {
+ String contentTypeCharset = HttpEncodingUtils.getContentTypeCharset(contentType);
+ if (contentTypeCharset != null && contentTypeCharset.length() > 0) {
+ return new InputStreamReader(new BufferedInputStream(urlConnection.getInputStream()),
+ contentTypeCharset);
+ } else {
+ return new InputStreamReader(new
BufferedInputStream(urlConnection.getInputStream()));
+ }
+ }
+
+ /**
+ * Parses the given string and extracts the enablement value.
+ *
+ * @param input
+ * stream that holds
+ * @return true, if successful
+ */
+ private boolean parse(InputStreamReader reader) throws IOException {
+ int i = 0;
+ char[] reportingValueCharacters = new
char[REPORTING_ENABLEMENT_ENABLEDVALUE.length()];
+ for (int character = 0; character != -1; character = reader.read()) {
+ if (REPORTING_ENABLEMENT_STARTSEQUENCE.charAt(i) == (char) character) {
+ if (++i == REPORTING_ENABLEMENT_STARTSEQUENCE.length()) {
+ reader.read(reportingValueCharacters);
+ return isEnabled(new String(reportingValueCharacters));
+ }
+ } else {
+ i = 0;
+ }
+ }
+ return false;
+ }
+
+ private boolean isEnabled(String enablementValue) {
+ return (enablementValue != null &&
REPORTING_ENABLEMENT_ENABLEDVALUE.equals(enablementValue.toUpperCase()));
+ }
+
+ /**
+ * Creates a new url connection.
+ *
+ * @param urlString
+ * the url string
+ * @return the http url connection
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ protected HttpURLConnection createURLConnection(String urlString) throws IOException {
+ URL url = new URL(urlString);
+ HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.setInstanceFollowRedirects(true);
+ urlConnection.setRequestMethod(GET_METHOD_NAME);
+ return urlConnection;
+ }
+
+ /**
+ * Returns the return code from the given {@link HttpURLConnection}.
+ * Provided to be called by test cases so that they can retrieve the return
+ * code.
+ *
+ * @param urlConnection
+ * to get the response code from
+ * @return the return code the HttpUrlConnection received
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ protected int getResponseCode(HttpURLConnection urlConnection) throws IOException {
+ return urlConnection.getResponseCode();
+ }
+}
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/GlobalUsageReportingEnablement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/GoogleAnalyticsUrlStrategy.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/GoogleAnalyticsUrlStrategy.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/googleanalytics/GoogleAnalyticsUrlStrategy.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -14,7 +14,7 @@
import org.jboss.tools.usage.FocusPoint;
import org.jboss.tools.usage.IURLBuildingStrategy;
-import org.jboss.tools.usage.util.EncodingUtils;
+import org.jboss.tools.usage.util.HttpEncodingUtils;
/**
* Class that builds an URL that passes given parameters to google analytics
@@ -188,7 +188,7 @@
builder.append(IGoogleAnalyticsParameters.SEMICOLON);
- return EncodingUtils.checkedEncodeUtf8(builder.toString());
+ return HttpEncodingUtils.checkedEncodeUtf8(builder.toString());
}
private String getRandomNumber() {
Deleted:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/EncodingUtils.java
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/EncodingUtils.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/EncodingUtils.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.usage.util;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-/**
- * @author Andre Dietisheim
- */
-public class EncodingUtils {
-
- private static final String ENCODING_UTF8 = "UTF-8";
-
- /**
- * Encodes the given string in utf8 while catching exceptions that may
- * occur. If an encoding exception occurs, <tt>null</tt> is returned
- *
- * @param aString
- * the a string to be encoded
- * @return the encoded string or <tt>null</tt> if an error occured while
- * encoding
- */
- public static String checkedEncodeUtf8(String aString) {
- try {
- return URLEncoder.encode(aString, ENCODING_UTF8);
- } catch (UnsupportedEncodingException e) {
- return aString;
- }
- }
-
-}
Copied:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/HttpEncodingUtils.java
(from rev 24293,
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/EncodingUtils.java)
===================================================================
---
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/HttpEncodingUtils.java
(rev 0)
+++
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/HttpEncodingUtils.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class HttpEncodingUtils {
+
+ private static final String ENCODING_UTF8 = "UTF-8";
+
+ private static Pattern CHARSET_ENCODING_PATTERN =
Pattern.compile("charset=(.+)");
+
+ /**
+ * Encodes the given string in utf8 while catching exceptions that may
+ * occur. If an encoding exception occurs, <tt>null</tt> is returned
+ *
+ * @param aString
+ * the a string to be encoded
+ * @return the encoded string or <tt>null</tt> if an error occured while
+ * encoding
+ */
+ public static String checkedEncodeUtf8(String aString) {
+ try {
+ return URLEncoder.encode(aString, ENCODING_UTF8);
+ } catch (UnsupportedEncodingException e) {
+ return aString;
+ }
+ }
+
+ /**
+ * Returns the charset indicated in the content-type field of the http
+ * header. Returns <tt>null</tt> if none is indicated.
+ *
+ * @param contentType
+ * the content type
+ * @return the content type charset or <tt>null</tt>
+ */
+ public static String getContentTypeCharset(String contentType) {
+ Matcher matcher = CHARSET_ENCODING_PATTERN.matcher(contentType);
+ if (!matcher.find()) {
+ return null;
+ }
+
+ return matcher.group(1);
+ }
+
+}
Property changes on:
trunk/usage/plugins/org.jboss.tools.usage/src/org/jboss/tools/usage/util/HttpEncodingUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/FocusPointTest.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/FocusPointTest.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/FocusPointTest.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -11,7 +11,7 @@
package org.jboss.tools.usage.test;
import org.jboss.tools.usage.FocusPoint;
-import org.jboss.tools.usage.util.EncodingUtils;
+import org.jboss.tools.usage.util.HttpEncodingUtils;
import junit.framework.TestCase;
@@ -24,9 +24,9 @@
private static final String child1 = "child1";
- private static final String URI_SEPARATOR_ENCODED =
EncodingUtils.checkedEncodeUtf8(FocusPoint.URI_SEPARATOR);
+ private static final String URI_SEPARATOR_ENCODED =
HttpEncodingUtils.checkedEncodeUtf8(FocusPoint.URI_SEPARATOR);
- private static final String TITLE_SEPARATOR_ENCODED =
EncodingUtils.checkedEncodeUtf8(FocusPoint.TITLE_SEPARATOR);
+ private static final String TITLE_SEPARATOR_ENCODED =
HttpEncodingUtils.checkedEncodeUtf8(FocusPoint.TITLE_SEPARATOR);
public void testGetContentURI_Simple() throws Exception {
FocusPoint focusPoint = new FocusPoint(root);
Deleted:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalReportingEnablementTest.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalReportingEnablementTest.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalReportingEnablementTest.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.usage.test;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-
-import org.jboss.tools.usage.GlobalReportingEnablement;
-import org.junit.Test;
-
-/**
- * The Class GlobalReportingEnablementTest.
- */
-public class GlobalReportingEnablementTest {
-
- @Test
- public void canExtractEnabledValue() throws IOException {
- GlobalReportingEnablementFake reportEnablement = new
GlobalReportingEnablementFake("ENABLED");
- assertTrue(reportEnablement.isEnabled());
- }
-
- @Test
- public void canExtractDisabledValue() throws IOException {
- GlobalReportingEnablementFake reportEnablement = new
GlobalReportingEnablementFake("DISABLED");
- assertTrue(reportEnablement.isEnabled());
- }
-
- @Test
- public void canExtractDisabledOutUndefinedValue() throws IOException {
- GlobalReportingEnablementFake reportEnablement = new
GlobalReportingEnablementFake("Rubbish");
- assertTrue(reportEnablement.isEnabled());
- }
-
- private class GlobalReportingEnablementFake extends GlobalReportingEnablement {
-
- private String enablementValue;
-
- public GlobalReportingEnablementFake(String enablementValue) throws IOException {
- super(JBossToolsUsageTestActivator.getDefault());
- this.enablementValue = enablementValue;
- }
-
- @Override
- protected String request(String url) {
- return getEnablementPageContent(enablementValue);
-
- }
- }
-
- private String getEnablementPageContent(String enablementValue) {
- return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\""
- + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
"
- + " "
- + " "
- + "<html
xmlns=\"http://www.w3.org/1999/xhtml\"
xml:lang=\"en\" lang=\"en\"> "
- + "<head> "
- + " <title> JBoss Tools / JBoss Developer Studio Usage Reporting
Enablement - JBoss Community</title> "
- + " "
- + " <meta http-equiv=\"X-UA-Compatible\"
content=\"IE=EmulateIE7\" /> "
- + " "
- + " <script type=\"text/javascript\"> "
- + " var javascriptIsCool = false;"
- + " </script> "
- + " "
- + "</head> "
- + "<body class=\"jive-body-content jive-body-content-document\"
> "
- + " <div id=\"jive-body\"> "
- + " "
- + "<div class=\"jive-content\"> "
- + " <div class=\"jive-content-header\"> "
- + " <div class=\"jive-wiki-post-moderating
jive-content-header-moderating\"> "
- + " <span class=\"jive-icon-med
jive-icon-moderation\"></span>Currently Being Moderated"
- + " </div> "
- + " <div class=\"jive-content-title\"> "
- + " <h2><span class=\"jive-icon-big
jive-icon-document\"></span> JBoss Tools / JBoss Developer Studio Usage
Reporting Enablement</h2> "
- + " </div> "
- + " <div class=\"jive-content-header-version\"> "
- + " VERSION 5 "
- + " <a
href=\"/wiki/JBossToolsJBossDeveloperStudioUsageReportingEnablement/diff?secondVersionNumber=5\"
title=\"Click to view article history\"><img class=\"jive-icon-sml
jive-icon-search\" src=\"/4.0.5/images/transparent.png\" alt=\"Click
to view article history\" /></a> "
- + " </div> "
- + " <div class=\"jive-content-header-details\"> "
- + " "
- + "Created on: Aug 24, 2010 5:39 AM by"
- + "<a href=\"/people/adietish\""
- + "id=\"jive-72036899,987,346,482,238\""
- +
"onmouseover=\"quickuserprofile.getUserProfileTooltip(72036);\""
- + "onmouseout=\"quickuserprofile.cancelTooltip();\""
- + "class=\"jiveTT-hover-user jive-username-link\""
- + ">Andre Dietisheim</a> <span>-</span> "
- + "Last Modified: "
- + "Aug 24, 2010 5:53 AM"
- + "by <a href=\"/people/adietish\""
- + "id=\"jive-72036899,987,347,353,238\""
- +
"onmouseover=\"quickuserprofile.getUserProfileTooltip(72036);\""
- + "onmouseout=\"quickuserprofile.cancelTooltip();\""
- + "class=\"jiveTT-hover-user jive-username-link\""
- + ">Andre Dietisheim</a> </div> "
- + " "
- + " </div> "
- + " <div class=\"jive-content-body\"> "
- + " "
- + "<!-- [DocumentBodyStart:e26c60c0-cb73-47b7-bded-f4eb7320305b]
--><div class=\"jive-rendered-content\"><p>This article is
queried by the JBoss Tools / JBoss Developer Studio usage reporting plugin. It implements
a global kill-switch that allows us to disable usage reporting stats. The plugin looks for
a string of the format:</p><p style=\"min-height: 8pt; height: 8pt; padding:
0px;\"> </p><p><strong>Usage 
Reporting  is <"
- + enablementValue
- + "></strong>. Any value that differs from ENABLED is interpreted
as DISABLED.</p><p style=\"min-height: 8pt; height: 8pt; padding:
0px;\"> </p><h1>Usage Reporting is
ENABLED</h1></div><!--
[DocumentBodyEnd:e26c60c0-cb73-47b7-bded-f4eb7320305b] --> "
- + " "
- + " </div> "
- + " <div class=\"jive-content-footer\"> "
- + " "
- + " "
- + " <!-- BEGIN content details --> "
- + " <span class=\"jive-content-footer-item\"> "
- + " 18 Views</a> "
- + " </span> "
- + " "
- + " "
- + " </div> "
- + "</div> "
- + "</body> "
- + "</html> ";
- }
-}
Copied:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalUsageReportingEnablementTest.java
(from rev 24378,
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalReportingEnablementTest.java)
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalUsageReportingEnablementTest.java
(rev 0)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalUsageReportingEnablementTest.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.usage.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
+import org.jboss.tools.usage.GlobalUsageReportingEnablement;
+import org.junit.Test;
+
+/**
+ * The Class GlobalReportingEnablementTest.
+ */
+public class GlobalUsageReportingEnablementTest {
+
+ @Test
+ public void canExtractEnabledValue() throws IOException {
+ GlobalReportingEnablementFake reportEnablement = new
GlobalReportingEnablementFake("ENABLED");
+ assertTrue(reportEnablement.isEnabled());
+ }
+
+ @Test
+ public void canExtractDisabledValue() throws IOException {
+ GlobalReportingEnablementFake reportEnablement = new
GlobalReportingEnablementFake("DISABLED");
+ assertTrue(reportEnablement.isEnabled());
+ }
+
+ @Test
+ public void canExtractDisabledOutUndefinedValue() throws IOException {
+ GlobalReportingEnablementFake reportEnablement = new
GlobalReportingEnablementFake("Rubbish");
+ assertTrue(reportEnablement.isEnabled());
+ }
+
+ private class GlobalReportingEnablementFake extends GlobalUsageReportingEnablement {
+
+ private String enablementValue;
+
+ public GlobalReportingEnablementFake(String enablementValue) throws IOException {
+ super(JBossToolsUsageTestActivator.getDefault());
+ this.enablementValue = enablementValue;
+ }
+
+ @Override
+ protected InputStreamReader request(String url) throws UnsupportedEncodingException {
+ return new InputStreamReader(new
ByteArrayInputStream(getEnablementPageContent(enablementValue).getBytes()),
"UTF-8");
+
+ }
+ }
+
+ private String getEnablementPageContent(String enablementValue) {
+ return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\""
+ + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
"
+ + " "
+ + " "
+ + "<html
xmlns=\"http://www.w3.org/1999/xhtml\"
xml:lang=\"en\" lang=\"en\"> "
+ + "<head> "
+ + " <title> JBoss Tools / JBoss Developer Studio Usage Reporting
Enablement - JBoss Community</title> "
+ + " "
+ + " <meta http-equiv=\"X-UA-Compatible\"
content=\"IE=EmulateIE7\" /> "
+ + " "
+ + " <script type=\"text/javascript\"> "
+ + " var javascriptIsCool = false;"
+ + " </script> "
+ + " "
+ + "</head> "
+ + "<body class=\"jive-body-content jive-body-content-document\"
> "
+ + " <div id=\"jive-body\"> "
+ + " "
+ + "<div class=\"jive-content\"> "
+ + " <div class=\"jive-content-header\"> "
+ + " <div class=\"jive-wiki-post-moderating
jive-content-header-moderating\"> "
+ + " <span class=\"jive-icon-med
jive-icon-moderation\"></span>Currently Being Moderated"
+ + " </div> "
+ + " <div class=\"jive-content-title\"> "
+ + " <h2><span class=\"jive-icon-big
jive-icon-document\"></span> JBoss Tools / JBoss Developer Studio Usage
Reporting Enablement</h2> "
+ + " </div> "
+ + " <div class=\"jive-content-header-version\"> "
+ + " VERSION 5 "
+ + " <a
href=\"/wiki/JBossToolsJBossDeveloperStudioUsageReportingEnablement/diff?secondVersionNumber=5\"
title=\"Click to view article history\"><img class=\"jive-icon-sml
jive-icon-search\" src=\"/4.0.5/images/transparent.png\" alt=\"Click
to view article history\" /></a> "
+ + " </div> "
+ + " <div class=\"jive-content-header-details\"> "
+ + " "
+ + "Created on: Aug 24, 2010 5:39 AM by"
+ + "<a href=\"/people/adietish\""
+ + "id=\"jive-72036899,987,346,482,238\""
+ +
"onmouseover=\"quickuserprofile.getUserProfileTooltip(72036);\""
+ + "onmouseout=\"quickuserprofile.cancelTooltip();\""
+ + "class=\"jiveTT-hover-user jive-username-link\""
+ + ">Andre Dietisheim</a> <span>-</span> "
+ + "Last Modified: "
+ + "Aug 24, 2010 5:53 AM"
+ + "by <a href=\"/people/adietish\""
+ + "id=\"jive-72036899,987,347,353,238\""
+ +
"onmouseover=\"quickuserprofile.getUserProfileTooltip(72036);\""
+ + "onmouseout=\"quickuserprofile.cancelTooltip();\""
+ + "class=\"jiveTT-hover-user jive-username-link\""
+ + ">Andre Dietisheim</a> </div> "
+ + " "
+ + " </div> "
+ + " <div class=\"jive-content-body\"> "
+ + " "
+ + "<!-- [DocumentBodyStart:e26c60c0-cb73-47b7-bded-f4eb7320305b]
--><div class=\"jive-rendered-content\"><p>This article is
queried by the JBoss Tools / JBoss Developer Studio usage reporting plugin. It implements
a global kill-switch that allows us to disable usage reporting stats. The plugin looks for
a string of the format:</p><p style=\"min-height: 8pt; height: 8pt; padding:
0px;\"> </p><p><strong>Usage 
Reporting  is <"
+
+ + enablementValue
+
+ + "></strong>. Any value that differs from ENABLED is interpreted
as DISABLED.</p><p style=\"min-height: 8pt; height: 8pt; padding:
0px;\"> </p><h1>Usage Reporting is
ENABLED</h1></div><!--
[DocumentBodyEnd:e26c60c0-cb73-47b7-bded-f4eb7320305b] --> "
+ + " "
+ + " </div> "
+ + " <div class=\"jive-content-footer\"> "
+ + " "
+ + " "
+ + " <!-- BEGIN content details --> "
+ + " <span class=\"jive-content-footer-item\"> "
+ + " 18 Views</a> "
+ + " </span> "
+ + " "
+ + " "
+ + " </div> "
+ + "</div> "
+ + "</body> "
+ + "</html> ";
+ }
+
+ @Test
+ public void isPageAccessible() throws IOException {
+ GlobalUsageReportingEnablement reportEnablement = new
GlobalUsageReportingEnablement(JBossToolsUsageTestActivator.getDefault());
+ System.err.println("Usage reporting is globally \"" +
reportEnablement.isEnabled() + "\"");
+ }
+}
Property changes on:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/GlobalUsageReportingEnablementTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/UsageTestSuite.java
===================================================================
---
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/UsageTestSuite.java 2010-08-24
17:13:52 UTC (rev 24390)
+++
trunk/usage/tests/org.jboss.tools.usage.test/src/org/jboss/tools/usage/test/UsageTestSuite.java 2010-08-24
19:21:26 UTC (rev 24391)
@@ -19,7 +19,7 @@
GoogleAnalyticsUrlStrategyTest.class,
JBossToolsUsageIntegrationTest.class,
EclipseEnvironmenTest.class,
- GlobalReportingEnablementTest.class})
+ GlobalUsageReportingEnablementTest.class})
/**
* @author Andre Dietisheim