JBoss Tools SVN: r31434 - in trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test: src/org/jboss/tools/cdi/seam/config/ui/test and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2011-05-23 16:27:12 -0400 (Mon, 23 May 2011)
New Revision: 31434
Removed:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java
Log:
JBIDE-8983
https://issues.jboss.org/browse/JBIDE-8983
Modified: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF 2011-05-23 20:25:53 UTC (rev 31433)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF 2011-05-23 20:27:12 UTC (rev 31434)
@@ -10,6 +10,7 @@
org.jboss.tools.common,
org.jboss.tools.common.el.core,
org.jboss.tools.common.model.ui,
+ org.jboss.tools.common.text.xml,
org.jboss.tools.cdi.core,
org.jboss.tools.cdi.core.test,
org.jboss.tools.cdi.seam.config.core,
Modified: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java 2011-05-23 20:25:53 UTC (rev 31433)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java 2011-05-23 20:27:12 UTC (rev 31434)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007-2010 Red Hat, Inc.
+ * Copyright (c) 2011 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,
@@ -11,238 +11,34 @@
package org.jboss.tools.cdi.seam.config.ui.test;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
import org.jboss.tools.common.editor.ObjectMultiPageEditor;
import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
-import org.jboss.tools.test.util.WorkbenchUtils;
+import org.jboss.tools.common.text.xml.contentassist.test.AbstractContentAssistantTestCase;
-//copied from ContentAssistantTestCase - they should have common super class
-public class ContentAssistantTestCase extends TestCase {
- protected IProject project = null;
- protected IEditorPart editor = null;
- protected StructuredTextEditor jspTextEditor = null;
- protected StructuredTextViewer viewer = null;
- protected IContentAssistant contentAssistant = null;
- protected IDocument document = null;
+public class ContentAssistantTestCase extends AbstractContentAssistantTestCase {
- public void openEditor(String fileName) {
- IEditorPart editorPart = WorkbenchUtils.openEditor(project.getName()+"/"+ fileName); //$NON-NLS-1$
- editor = editorPart;
-
-//getting editor start
+ protected void obtainTextEditor(IEditorPart editorPart) {
if(editorPart instanceof EditorPartWrapper) {
editorPart = ((EditorPartWrapper)editorPart).getEditor();
}
if (editorPart instanceof ObjectMultiPageEditor) {
- jspTextEditor = ((ObjectMultiPageEditor) editorPart).getSourceEditor();
+ textEditor = ((ObjectMultiPageEditor) editorPart).getSourceEditor();
} else if (editorPart instanceof StructuredTextEditor) {
- jspTextEditor = (StructuredTextEditor)editorPart;
+ textEditor = (StructuredTextEditor)editorPart;
}
// clean deffered events
while (Display.getCurrent().readAndDispatch());
-
-//getting editor end.
-
- viewer = jspTextEditor.getTextViewer();
- document = viewer.getDocument();
- SourceViewerConfiguration config = TestUtil
- .getSourceViewerConfiguration(jspTextEditor);
- contentAssistant = (config == null ? null : config
- .getContentAssistant(viewer));
-
- assertTrue(
- "Cannot get the Content Assistant instance for the editor for page \"" //$NON-NLS-1$
- + fileName + "\"", (contentAssistant != null)); //$NON-NLS-1$
-
- assertTrue("The IDocument is not instance of IStructuredDocument for page \"" //$NON-NLS-1$
- + fileName + "\"", //$NON-NLS-1$
- (document instanceof IStructuredDocument));
-
}
- public ICompletionProposal[] checkProposals(String fileName, int offset, String[] proposals, boolean exactly) {
- return checkProposals(fileName, null, offset, proposals, exactly, true);
- }
-
- public ICompletionProposal[] checkProposals(String fileName, String substring, int offset, String[] proposals, boolean exactly) {
- return checkProposals(fileName, substring, offset, proposals, exactly, false);
+ protected boolean isRelevantProposal(ICompletionProposal proposal) {
+ return (proposal instanceof CustomCompletionProposal)
+ && (proposal.getClass() != CustomCompletionProposal.class);
}
- public ICompletionProposal[] checkProposals(String fileName, String substring, int offset, String[] proposals, boolean exactly, boolean excludeELProposalsFromExactTest){
- openEditor(fileName);
- int position = 0;
- if (substring != null) {
- String documentContent = document.get();
- position = documentContent.indexOf(substring);
- }
-
- List<ICompletionProposal> res = TestUtil.collectProposals(contentAssistant, viewer, position+offset);
-
- assertTrue("Content Assistant returned no proposals", (res != null && res.size() > 0)); //$NON-NLS-1$
-
- // for (int i = 0; i < result.length; i++) {
- // System.out.println("proposal - "+result[i].getDisplayString());
- // }
-
- ICompletionProposal[] result = res.toArray(new ICompletionProposal[res.size()]);
- int foundCounter = 0;
- for (int i = 0; i < proposals.length; i++) {
- boolean found = compareProposal(proposals[i], result);
- if (found)
- foundCounter++;
- assertTrue("Proposal " + proposals[i] + " not found!", found ); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (exactly) {
- if (excludeELProposalsFromExactTest) {
- assertTrue("Some other proposals were found!", foundCounter == proposals.length); //$NON-NLS-1$
- } else {
- assertTrue("Some other proposals were found!", result.length == proposals.length); //$NON-NLS-1$
- }
- }
-
-// System.out.println("checkProposals <<< Exiting");
- return result;
- }
-
- //CustomCompletionProposal instead of AutoContentAssistantProposal
- public boolean compareProposal(String proposalName, ICompletionProposal[] proposals){
- for (int i = 0; i < proposals.length; i++) {
- if (proposals[i] instanceof CustomCompletionProposal) {
- CustomCompletionProposal ap = (CustomCompletionProposal)proposals[i];
-
- if(proposals[i].getClass() == CustomCompletionProposal.class) {
- //It is wtp's proposal - ignore it.
- continue;
- }
-
- String replacementString = ap.getReplacementString().toLowerCase();
- if (replacementString.equalsIgnoreCase(proposalName)) return true;
-
-
- // For a tag proposal there will be not only the the tag name but all others characters like default attributes, tag ending characters and so on
- if (replacementString.indexOf("/>") != -1) {
- replacementString = replacementString.substring(0, replacementString.indexOf("/>"));
- }
- if (replacementString.indexOf('>') != -1) {
- replacementString = replacementString.substring(0, replacementString.indexOf('>'));
- }
- if (replacementString.equalsIgnoreCase(proposalName)) return true;
-
- String[] replacementStringParts = replacementString.split(" "); //$NON-NLS-1$
- if (replacementStringParts != null && replacementStringParts.length > 0) {
- if (replacementStringParts[0].equalsIgnoreCase(proposalName)) return true;
- }
-
- // for an attribute proposal there will be a pare of attribute-value (i.e. attrName="attrValue")
- replacementStringParts = replacementString.split("="); //$NON-NLS-1$
- if (replacementStringParts != null && replacementStringParts.length > 0) {
- if (replacementStringParts[0].equalsIgnoreCase(proposalName)) return true;
- }
-
- // for an Unclosed EL the closing character is appended to the proposal string (i.e. person} )
- // perform case sensitive compare operation
- replacementStringParts = replacementString.split("}"); //$NON-NLS-1$
- if (replacementStringParts != null && replacementStringParts.length > 0) {
- if (replacementStringParts[0].equals(proposalName)) return true;
- }
-
- // For an attribute value proposal there will be the quote characters
- replacementString = Utils.trimQuotes(replacementString);
- if (replacementString.equalsIgnoreCase(proposalName)) return true;
-
- } else {
- if(proposals[i].getDisplayString().toLowerCase().equals(proposalName.toLowerCase())) return true;
- }
- }
- return false;
- }
-
- public void closeEditor() {
- if (editor != null) {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().closeEditor(editor, false);
- editor = null;
- }
- }
-
- /**
- * @return the project
- */
- public IProject getProject() {
- return project;
- }
-
- /**
- * @param project the project to set
- */
- public void setProject(IProject project) {
- this.project = project;
- }
-
- /**
- * @return the jspTextEditor
- */
- public StructuredTextEditor getTextEditor() {
- return jspTextEditor;
- }
-
- /**
- * @return the viewer
- */
- public StructuredTextViewer getViewer() {
- return viewer;
- }
-
- /**
- * @param viewer the viewer to set
- */
- public void setViewer(StructuredTextViewer viewer) {
- this.viewer = viewer;
- }
-
- /**
- * @return the contentAssistant
- */
- public IContentAssistant getContentAssistant() {
- return contentAssistant;
- }
-
- /**
- * @param contentAssistant the contentAssistant to set
- */
- public void setContentAssistant(IContentAssistant contentAssistant) {
- this.contentAssistant = contentAssistant;
- }
-
- /**
- * @return the document
- */
- public IDocument getDocument() {
- return document;
- }
-
- /**
- * @param document the document to set
- */
- public void setDocument(IDocument document) {
- this.document = document;
- }
}
\ No newline at end of file
Deleted: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java 2011-05-23 20:25:53 UTC (rev 31433)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java 2011-05-23 20:27:12 UTC (rev 31434)
@@ -1,144 +0,0 @@
-package org.jboss.tools.cdi.seam.config.ui.test;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistantExtension;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.AbstractTextEditor;
-import org.eclipse.wst.sse.ui.internal.contentassist.StructuredContentAssistant;
-import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
-
-//copied from org.jboss.tools.jst.jsp.test.TestUtil
-//TODO remove this class and move original to common
-public class TestUtil {
-
- /** The Constant MAX_IDLE. */
- public static final long MAX_IDLE = 5*60*1000L;
-
- /**
- * Returns the CA Processor from content assistant for the given offset in the document.
- *
- *
- * @param viewer
- * @param offset
- * @param ca
- */
-
- public static IContentAssistProcessor getProcessor(ITextViewer viewer, int offset, IContentAssistant ca) {
- try {
- IDocument document= viewer.getDocument();
- String type= TextUtilities.getContentType(document, ((IContentAssistantExtension)ca).getDocumentPartitioning(), offset, true);
- return ca.getContentAssistProcessor(type);
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /**
- * Process UI input but do not return for the specified time interval.
- *
- * @param waitTimeMillis
- * the number of milliseconds
- */
- public static void delay(long waitTimeMillis) {
- Display display = Display.getCurrent();
-
- // If this is the UI thread,
- // then process input.
- if (display != null) {
- long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
- while (System.currentTimeMillis() < endTimeMillis) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.update();
- }
- // Otherwise, perform a simple sleep.
- else {
- try {
- Thread.sleep(waitTimeMillis);
- } catch (InterruptedException e) {
- // Ignored.
- }
- }
- }
-
- /**
- * Wait for idle.
- */
- public static void waitForIdle(long maxIdle) {
- long start = System.currentTimeMillis();
- while (!Job.getJobManager().isIdle()) {
- delay(500);
- if ( (System.currentTimeMillis()-start) > maxIdle )
- throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
- }
- }
-
- public static SourceViewerConfiguration getSourceViewerConfiguration(AbstractTextEditor editor) {
- Class editorClass = editor.getClass();
- while (editorClass != null) {
- try {
- Method m = editorClass.getDeclaredMethod("getSourceViewerConfiguration", new Class[] {});
-
- if(m != null) {
- m.setAccessible(true);
- Object result = m.invoke(editor, new Object[]{});
- return (result instanceof SourceViewerConfiguration ? (SourceViewerConfiguration)result : null);
- }
- } catch (NoSuchMethodException ne) {
- } catch (Exception e) {
- }
- editorClass = editorClass.getSuperclass();
- }
- return null;
-
- }
-
- public static void prepareCAInvokation(IContentAssistant ca, ITextViewer viewer, int offset) {
- if (ca == null || viewer == null)
- return;
-
- // sets cursor position
- viewer.getTextWidget().setCaretOffset(offset);
-
- TestUtil.waitForIdle(TestUtil.MAX_IDLE);
- TestUtil.delay(1000);
-
- ca.showPossibleCompletions();
- }
-
- public static int MAX_CATEGORIES_COUNT = 10;
- public static List<ICompletionProposal> collectProposals(IContentAssistant ca, ITextViewer viewer, int offset) {
- prepareCAInvokation(ca, viewer, offset);
-
- final IContentAssistProcessor p= TestUtil.getProcessor(viewer, offset, ca);
- List<ICompletionProposal> res= new ArrayList<ICompletionProposal>();
- // Try to acquire all the proposal categories assuming that there are less than 10 or equal
- for (int i = 0; i < MAX_CATEGORIES_COUNT && p != null; i++) {
- ICompletionProposal[] result= p.computeCompletionProposals(viewer, offset);
- for (int j = 0; result != null && j < result.length; j++) {
- res.add(result[j]);
- }
- }
- return ProposalSorter.filterAndSortProposals(res, null, null);
- }
-
-}
13 years, 1 month
JBoss Tools SVN: r31433 - in trunk/common/plugins/org.jboss.tools.common.text.xml: src/org/jboss/tools/common/text/xml/contentassist and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2011-05-23 16:25:53 -0400 (Mon, 23 May 2011)
New Revision: 31433
Added:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/AbstractContentAssistantTestCase.java
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/CATestUtil.java
Modified:
trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF
Log:
JBIDE-8983
https://issues.jboss.org/browse/JBIDE-8983
Modified: trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF 2011-05-23 17:25:14 UTC (rev 31432)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/META-INF/MANIFEST.MF 2011-05-23 20:25:53 UTC (rev 31433)
@@ -8,6 +8,7 @@
Bundle-Localization: plugin
Export-Package: org.jboss.tools.common.text.xml,
org.jboss.tools.common.text.xml.contentassist,
+ org.jboss.tools.common.text.xml.contentassist.test,
org.jboss.tools.common.text.xml.internal.ui.preferencies,
org.jboss.tools.common.text.xml.ui,
org.jboss.tools.common.text.xml.ui.xpl,
@@ -27,6 +28,8 @@
org.eclipse.core.resources;bundle-version="3.7.100",
org.eclipse.wst.xsd.ui;bundle-version="1.2.404",
org.eclipse.wst.dtd.ui;bundle-version="1.0.600",
+ org.junit;bundle-version="3.8.2",
+ org.jboss.tools.tests,
org.eclipse.ui.ide;bundle-version="3.7.0"
Bundle-Version: 3.3.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/AbstractContentAssistantTestCase.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/AbstractContentAssistantTestCase.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/AbstractContentAssistantTestCase.java 2011-05-23 20:25:53 UTC (rev 31433)
@@ -0,0 +1,267 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.text.xml.contentassist.test;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+public abstract class AbstractContentAssistantTestCase extends TestCase {
+ protected String fileName;
+ protected IProject project = null;
+ protected IEditorPart editorPart = null;
+ protected StructuredTextEditor textEditor = null;
+ protected StructuredTextViewer viewer = null;
+ protected IContentAssistant contentAssistant = null;
+ protected IDocument document = null;
+
+ public void openEditor(String fileName) {
+ this.fileName = fileName;
+ editorPart = WorkbenchUtils.openEditor(project.getName()+"/"+ fileName); //$NON-NLS-1$
+
+ obtainTextEditor(editorPart);
+
+ viewer = textEditor.getTextViewer();
+ document = viewer.getDocument();
+ SourceViewerConfiguration config = CATestUtil
+ .getSourceViewerConfiguration(textEditor);
+ contentAssistant = (config == null ? null : config
+ .getContentAssistant(viewer));
+
+ assertTrue(
+ "Cannot get the Content Assistant instance for the editor for page \"" //$NON-NLS-1$
+ + fileName + "\"", (contentAssistant != null)); //$NON-NLS-1$
+
+ assertTrue("The IDocument is not instance of IStructuredDocument for page \"" //$NON-NLS-1$
+ + fileName + "\"", //$NON-NLS-1$
+ (document instanceof IStructuredDocument));
+
+ }
+
+ /**
+ * Looks into editorPart for the test editor to apply content assist to.
+ *
+ * @param editorPart
+ */
+ protected void obtainTextEditor(IEditorPart editorPart) {
+ }
+
+ public ICompletionProposal[] checkProposals(String fileName, int offset, String[] proposals, boolean exactly) {
+ return checkProposals(fileName, null, offset, proposals, exactly, true);
+ }
+
+ public ICompletionProposal[] checkProposals(String fileName, String substring, int offset, String[] proposals, boolean exactly) {
+ return checkProposals(fileName, substring, offset, proposals, exactly, false);
+ }
+ public ICompletionProposal[] checkProposals(String fileName, String substring, int offset, String[] proposals, boolean exactly, boolean excludeELProposalsFromExactTest){
+ openEditor(fileName);
+
+ int position = 0;
+ if (substring != null) {
+ String documentContent = document.get();
+ position = documentContent.indexOf(substring);
+ }
+
+ List<ICompletionProposal> res = CATestUtil.collectProposals(contentAssistant, viewer, position+offset);
+
+ assertTrue("Content Assistant returned no proposals", (res != null && res.size() > 0)); //$NON-NLS-1$
+
+ // for (int i = 0; i < result.length; i++) {
+ // System.out.println("proposal - "+result[i].getDisplayString());
+ // }
+
+ ICompletionProposal[] result = res.toArray(new ICompletionProposal[res.size()]);
+ int foundCounter = 0;
+ for (int i = 0; i < proposals.length; i++) {
+ boolean found = compareProposal(proposals[i], result);
+ if (found)
+ foundCounter++;
+ assertTrue("Proposal " + proposals[i] + " not found!", found ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (exactly) {
+ if (excludeELProposalsFromExactTest) {
+ assertTrue("Some other proposals were found!", foundCounter == proposals.length); //$NON-NLS-1$
+ } else {
+ assertTrue("Some other proposals were found!", result.length == proposals.length); //$NON-NLS-1$
+ }
+ }
+
+// System.out.println("checkProposals <<< Exiting");
+ return result;
+ }
+
+ /**
+ * Returns true if proposal is created by the content assistant being tested.
+ *
+ * @param proposal
+ * @return
+ */
+ protected boolean isRelevantProposal(ICompletionProposal proposal) {
+ return false;
+ }
+
+ public boolean compareProposal(String proposalName, ICompletionProposal[] proposals){
+ for (int i = 0; i < proposals.length; i++) {
+ if (isRelevantProposal(proposals[i])) {
+ CustomCompletionProposal ap = (CustomCompletionProposal)proposals[i];
+ String replacementString = ap.getReplacementString().toLowerCase();
+ if (replacementString.equalsIgnoreCase(proposalName)) return true;
+
+ // For a tag proposal there will be not only the the tag name but all others characters like default attributes, tag ending characters and so on
+ if (replacementString.indexOf("/>") != -1) {
+ replacementString = replacementString.substring(0, replacementString.indexOf("/>"));
+ }
+ if (replacementString.indexOf('>') != -1) {
+ replacementString = replacementString.substring(0, replacementString.indexOf('>'));
+ }
+ if (replacementString.equalsIgnoreCase(proposalName)) return true;
+
+ String[] replacementStringParts = replacementString.split(" "); //$NON-NLS-1$
+ if (replacementStringParts != null && replacementStringParts.length > 0) {
+ if (replacementStringParts[0].equalsIgnoreCase(proposalName)) return true;
+ }
+
+ // for an attribute proposal there will be a pare of attribute-value (i.e. attrName="attrValue")
+ replacementStringParts = replacementString.split("="); //$NON-NLS-1$
+ if (replacementStringParts != null && replacementStringParts.length > 0) {
+ if (replacementStringParts[0].equalsIgnoreCase(proposalName)) return true;
+ }
+
+ // for an Unclosed EL the closing character is appended to the proposal string (i.e. person} )
+ // perform case sensitive compare operation
+ replacementStringParts = replacementString.split("}"); //$NON-NLS-1$
+ if (replacementStringParts != null && replacementStringParts.length > 0) {
+ if (replacementStringParts[0].equals(proposalName)) return true;
+ }
+
+ // For an attribute value proposal there will be the quote characters
+ replacementString = /*Utils.*/trimQuotes(replacementString);
+ if (replacementString.equalsIgnoreCase(proposalName)) return true;
+
+ } else {
+ if(proposals[i].getDisplayString().toLowerCase().equals(proposalName.toLowerCase())) return true;
+ }
+ }
+ return false;
+ }
+
+ public void closeEditor() {
+ if (editorPart != null) {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().closeEditor(editorPart, false);
+ editorPart = null;
+ }
+ }
+
+ /**
+ * @return the project
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * @param project the project to set
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+ /**
+ * @return the jspTextEditor
+ */
+ public StructuredTextEditor getTextEditor() {
+ return textEditor;
+ }
+
+ /**
+ * @return the viewer
+ */
+ public StructuredTextViewer getViewer() {
+ return viewer;
+ }
+
+ /**
+ * @param viewer the viewer to set
+ */
+ public void setViewer(StructuredTextViewer viewer) {
+ this.viewer = viewer;
+ }
+
+ /**
+ * @return the contentAssistant
+ */
+ public IContentAssistant getContentAssistant() {
+ return contentAssistant;
+ }
+
+ /**
+ * @param contentAssistant the contentAssistant to set
+ */
+ public void setContentAssistant(IContentAssistant contentAssistant) {
+ this.contentAssistant = contentAssistant;
+ }
+
+ /**
+ * @return the document
+ */
+ public IDocument getDocument() {
+ return document;
+ }
+
+ /**
+ * @param document the document to set
+ */
+ public void setDocument(IDocument document) {
+ this.document = document;
+ }
+
+ //Copied from Utils. should be moved to common.
+ public static String trimQuotes(String word) {
+ if(word == null) return null;
+ String attrText = word;
+ int bStart = 0;
+ int bEnd = word.length() - 1;
+ StringBuffer sb = new StringBuffer(attrText);
+
+ //find start and end of path property
+ while (bStart < bEnd &&
+ (sb.charAt(bStart) == '\'' || sb.charAt(bStart) == '\"' ||
+ Character.isWhitespace(sb.charAt(bStart)))) {
+ bStart++;
+ }
+ while (bEnd >= 0 &&
+ (sb.charAt(bEnd) == '\'' || sb.charAt(bEnd) == '\"' ||
+ Character.isWhitespace(sb.charAt(bEnd)))) {
+ bEnd--;
+ }
+ bEnd++;
+ if (bEnd < bStart) bEnd = bStart;
+ return sb.substring(bStart, bEnd);
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/AbstractContentAssistantTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/CATestUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/CATestUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/CATestUtil.java 2011-05-23 20:25:53 UTC (rev 31433)
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.text.xml.contentassist.test;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistantExtension;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.wst.sse.ui.internal.contentassist.StructuredContentAssistant;
+import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
+
+public class CATestUtil {
+
+ /** The Constant MAX_IDLE. */
+ public static final long MAX_IDLE = 5*60*1000L;
+
+ /**
+ * Returns the CA Processor from content assistant for the given offset in the document.
+ *
+ *
+ * @param viewer
+ * @param offset
+ * @param ca
+ */
+
+ public static IContentAssistProcessor getProcessor(ITextViewer viewer, int offset, IContentAssistant ca) {
+ try {
+ IDocument document= viewer.getDocument();
+ String type= TextUtilities.getContentType(document, ((IContentAssistantExtension)ca).getDocumentPartitioning(), offset, true);
+ return ca.getContentAssistProcessor(type);
+ } catch (BadLocationException x) {
+ }
+
+ return null;
+ }
+
+ /**
+ * Process UI input but do not return for the specified time interval.
+ *
+ * @param waitTimeMillis
+ * the number of milliseconds
+ */
+ public static void delay(long waitTimeMillis) {
+ Display display = Display.getCurrent();
+
+ // If this is the UI thread,
+ // then process input.
+ if (display != null) {
+ long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
+ while (System.currentTimeMillis() < endTimeMillis) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.update();
+ }
+ // Otherwise, perform a simple sleep.
+ else {
+ try {
+ Thread.sleep(waitTimeMillis);
+ } catch (InterruptedException e) {
+ // Ignored.
+ }
+ }
+ }
+
+ /**
+ * Wait for idle.
+ */
+ public static void waitForIdle(long maxIdle) {
+ long start = System.currentTimeMillis();
+ while (!Job.getJobManager().isIdle()) {
+ delay(500);
+ if ( (System.currentTimeMillis()-start) > maxIdle )
+ throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
+ }
+ }
+
+ public static SourceViewerConfiguration getSourceViewerConfiguration(AbstractTextEditor editor) {
+ Class editorClass = editor.getClass();
+ while (editorClass != null) {
+ try {
+ Method m = editorClass.getDeclaredMethod("getSourceViewerConfiguration", new Class[] {});
+
+ if(m != null) {
+ m.setAccessible(true);
+ Object result = m.invoke(editor, new Object[]{});
+ return (result instanceof SourceViewerConfiguration ? (SourceViewerConfiguration)result : null);
+ }
+ } catch (NoSuchMethodException ne) {
+ } catch (Exception e) {
+ }
+ editorClass = editorClass.getSuperclass();
+ }
+ return null;
+
+ }
+
+ public static void prepareCAInvokation(IContentAssistant ca, ITextViewer viewer, int offset) {
+ if (ca == null || viewer == null)
+ return;
+
+ // sets cursor position
+ viewer.getTextWidget().setCaretOffset(offset);
+
+ CATestUtil.waitForIdle(CATestUtil.MAX_IDLE);
+ CATestUtil.delay(1000);
+
+ ca.showPossibleCompletions();
+ }
+
+ public static int MAX_CATEGORIES_COUNT = 10;
+ public static List<ICompletionProposal> collectProposals(IContentAssistant ca, ITextViewer viewer, int offset) {
+ prepareCAInvokation(ca, viewer, offset);
+
+ final IContentAssistProcessor p= CATestUtil.getProcessor(viewer, offset, ca);
+ List<ICompletionProposal> res= new ArrayList<ICompletionProposal>();
+ // Try to acquire all the proposal categories assuming that there are less than 10 or equal
+ for (int i = 0; i < MAX_CATEGORIES_COUNT && p != null; i++) {
+ ICompletionProposal[] result= p.computeCompletionProposals(viewer, offset);
+ for (int j = 0; result != null && j < result.length; j++) {
+ res.add(result[j]);
+ }
+ }
+ return ProposalSorter.filterAndSortProposals(res, null, null);
+ }
+ /**
+ * Close all opened editors
+ * @author mareshkau
+ */
+ public static final void closeAllEditors(){
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ IWorkbenchPart part = page.getViewReferences()[0].getPart(false);
+ page.activate(part);
+ // close
+ page.closeAllEditors(false);
+ }
+}
Property changes on: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/test/CATestUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
13 years, 1 month
JBoss Tools SVN: r31432 - trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2011-05-23 13:25:14 -0400 (Mon, 23 May 2011)
New Revision: 31432
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
Log:
JBIDE-8982
https://issues.jboss.org/browse/JBIDE-8982
Modified: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF 2011-05-23 13:00:46 UTC (rev 31431)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF 2011-05-23 17:25:14 UTC (rev 31432)
@@ -14,6 +14,7 @@
org.jboss.tools.cdi.core.test,
org.jboss.tools.cdi.seam.config.core,
org.jboss.tools.cdi.seam.config.core.test,
+ org.jboss.tools.cdi.seam.config.ui,
org.jboss.tools.tests,
org.eclipse.core.runtime,
org.eclipse.jdt.core
13 years, 1 month
JBoss Tools SVN: r31431 - in trunk/documentation/whatsnew/teiid: images and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: tejones
Date: 2011-05-23 09:00:46 -0400 (Mon, 23 May 2011)
New Revision: 31431
Added:
trunk/documentation/whatsnew/teiid/images/manage-extended-properties-dialog.png
trunk/documentation/whatsnew/teiid/images/manage-extended-properties-menu.png
Modified:
trunk/documentation/whatsnew/teiid/teiid-news-7.4.html
Log:
JBIDE-8902 Added Extended Properties section and images
Added: trunk/documentation/whatsnew/teiid/images/manage-extended-properties-dialog.png
===================================================================
(Binary files differ)
Property changes on: trunk/documentation/whatsnew/teiid/images/manage-extended-properties-dialog.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/documentation/whatsnew/teiid/images/manage-extended-properties-menu.png
===================================================================
(Binary files differ)
Property changes on: trunk/documentation/whatsnew/teiid/images/manage-extended-properties-menu.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/documentation/whatsnew/teiid/teiid-news-7.4.html
===================================================================
--- trunk/documentation/whatsnew/teiid/teiid-news-7.4.html 2011-05-23 12:36:23 UTC (rev 31430)
+++ trunk/documentation/whatsnew/teiid/teiid-news-7.4.html 2011-05-23 13:00:46 UTC (rev 31431)
@@ -166,8 +166,32 @@
alt="Export Model Project Set Wizard"/></p>
</td>
</tr>
-
<tr>
+ <td colspan="2">
+ <hr>
+ <h3>Extended Metadata</h3>
+ <hr> </td>
+ </tr>
+ <tr>
+ <td valign="top" align="left">
+ <p><b>Manage Extended Properties<b>
+ </b></p>
+ </td>
+ <td valign="top">
+ <p>In order to facilitate custom property usage for relational models and objects such as tables, columns, and
+ procedures, a dialog to create extended properties was added (TEIIDDES-945). These properties are exposed in Teiid
+ as indexed metadata and can be read by your custom translator.</p>
+ <p>In 7.4, you can add, edit and delete these extended properties by selecting a relational model or model object
+ using the "Modeling > Manage Extended Properties" action. The menu option and dialog is shown below. </p>
+ <p><img style="border: 1px solid ;"
+ src="images/manage-extended-properties-menu.png"
+ alt="Manage Extended Properties Menu Option"/></p>
+ <p><img style="border: 1px solid ;"
+ src="images/manage-extended-properties-dialog.png"
+ alt="Manage Extended Properties Dialog"/></p>
+ </td>
+ </tr>
+ <tr>
<td valign="top" align="left"><br>
</td>
<td valign="top"><br>
13 years, 1 month
JBoss Tools SVN: r31430 - trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 08:36:23 -0400 (Mon, 23 May 2011)
New Revision: 31430
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java
Log:
added missing integration tests to test suite
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java 2011-05-23 12:36:02 UTC (rev 31429)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java 2011-05-23 12:36:23 UTC (rev 31430)
@@ -68,7 +68,7 @@
// get a profile seen in the web UI
Realm realm = testSetup.getClient().listRealms("eu");
assertNotNull(realm);
- assertRealm("Europe", Realm.RealmState.AVAILABLE, 0, realm);
+ assertRealm("Europe", Realm.RealmState.AVAILABLE, Realm.LIMIT_DEFAULT, realm);
}
public void assertRealm(String name, Realm.RealmState state, int limit, Realm realm) {
13 years, 1 month
JBoss Tools SVN: r31429 - trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 08:36:02 -0400 (Mon, 23 May 2011)
New Revision: 31429
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java
Log:
[JBIDE-8980] changed test assert to reflect new limit values in mock server
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java 2011-05-23 10:13:59 UTC (rev 31428)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java 2011-05-23 12:36:02 UTC (rev 31429)
@@ -21,6 +21,8 @@
import org.jboss.tools.internal.deltacloud.client.test.client.ImageMockIntegrationTest;
import org.jboss.tools.internal.deltacloud.client.test.client.InstanceMockIntegrationTest;
import org.jboss.tools.internal.deltacloud.client.test.client.KeyMockIntegrationTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.ProfileMockIntegrationTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.RealmMockIntegrationTest;
import org.jboss.tools.internal.deltacloud.client.test.client.ServerTypeMockIntegrationTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -33,8 +35,10 @@
ImageMockIntegrationTest.class,
InstanceMockIntegrationTest.class,
KeyMockIntegrationTest.class,
- ServerTypeMockIntegrationTest.class
+ ServerTypeMockIntegrationTest.class,
+ RealmMockIntegrationTest.class,
+ ProfileMockIntegrationTest.class
})
+
public class DeltaCloudClientIntegrationTestSuite {
-
}
13 years, 1 month
JBoss Tools SVN: r31428 - in trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client: src/org/jboss/tools/deltacloud/client/unmarshal and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 06:13:59 -0400 (Mon, 23 May 2011)
New Revision: 31428
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/Assert.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java
Log:
[JBIDE-8975] removed dependency to org.eclipse.core.runtime
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/META-INF/MANIFEST.MF
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/META-INF/MANIFEST.MF 2011-05-23 08:00:09 UTC (rev 31427)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/META-INF/MANIFEST.MF 2011-05-23 10:13:59 UTC (rev 31428)
@@ -5,7 +5,6 @@
Bundle-SymbolicName: org.jboss.tools.deltacloud.client
Bundle-Version: 0.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0"
Export-Package: org.jboss.tools.deltacloud.client,
org.jboss.tools.deltacloud.client.request;x-friends:="org.jboss.tools.deltacloud.client.test",
org.jboss.tools.deltacloud.client.transport,
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java 2011-05-23 08:00:09 UTC (rev 31427)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java 2011-05-23 10:13:59 UTC (rev 31428)
@@ -22,10 +22,10 @@
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.runtime.Assert;
import org.jboss.tools.deltacloud.client.HardwareProfile;
import org.jboss.tools.deltacloud.client.Property;
import org.jboss.tools.deltacloud.client.Property.Kind;
+import org.jboss.tools.deltacloud.client.utils.Assert;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -33,16 +33,19 @@
/**
* @author André Dietisheim
*/
-public class HardwareProfileUnmarshaller extends AbstractDOMUnmarshaller<HardwareProfile> {
+public class HardwareProfileUnmarshaller extends
+ AbstractDOMUnmarshaller<HardwareProfile> {
public HardwareProfileUnmarshaller() {
super("hardware_profile", HardwareProfile.class);
}
@Override
- protected HardwareProfile doUnmarshall(Element element, HardwareProfile profile) throws Exception {
+ protected HardwareProfile doUnmarshall(Element element,
+ HardwareProfile profile) throws Exception {
profile.setId(getAttributeText("id", element));
- profile.setProperties(createProperties(element.getElementsByTagName("property")));
+ profile.setProperties(createProperties(element
+ .getElementsByTagName("property")));
return profile;
}
@@ -79,14 +82,15 @@
private void setRange(Element propertyElement, Property property) {
Node node = propertyElement.getElementsByTagName("range").item(0);
- Assert.isLegal(node instanceof Element);
+ Assert.isTrue(node instanceof Element);
Element rangeElement = (Element) node;
- property.setRange(rangeElement.getAttribute("first"), rangeElement.getAttribute("last"));
+ property.setRange(rangeElement.getAttribute("first"),
+ rangeElement.getAttribute("last"));
}
private void setEnum(Element propertyElement, Property property) {
Node node = propertyElement.getElementsByTagName("enum").item(0);
- Assert.isLegal(node instanceof Element);
+ Assert.isTrue(node instanceof Element);
Element enumElement = (Element) node;
NodeList nodeList = enumElement.getElementsByTagName("entry");
ArrayList<String> enumValues = new ArrayList<String>();
@@ -98,5 +102,5 @@
}
property.setEnums(enumValues);
}
-
+
}
Added: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/Assert.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/Assert.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/Assert.java 2011-05-23 10:13:59 UTC (rev 31428)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * 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
+ * ASF 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.jboss.tools.deltacloud.client.utils;
+
+/**
+ * Various assertion utility methods.
+ *
+ * @author André Dietisheim
+ */
+public class Assert {
+
+ public static void isValidArgument(boolean assertionResult) {
+ if (!assertionResult) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public static void isTrue(boolean assertionResult) {
+ if (!assertionResult) {
+ throw new AssertionError();
+ }
+ }
+
+}
Property changes on: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/Assert.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
13 years, 1 month
JBoss Tools SVN: r31427 - trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 04:00:09 -0400 (Mon, 23 May 2011)
New Revision: 31427
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java
Log:
[JBIDE-8978] fixed transport to throw specific errors when the server responds with 401 (was: reported IOException)
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java 2011-05-23 07:58:08 UTC (rev 31426)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java 2011-05-23 08:00:09 UTC (rev 31427)
@@ -51,7 +51,7 @@
@Test
public void testConnectionReportsFalseOnAuthFailure() throws MalformedURLException, DeltaCloudClientException,
DeltaCloudException {
- ServerFake serverFake = setupServerFake("HTTP/1.1 401 Forbidden\n\n\n");
+ ServerFake serverFake = setupServerFake("HTTP/1.1 401 Unauthorized\n\n\n");
try {
DeltaCloud deltaCloud = new DeltaCloudFake(
"http://localhost:" + ServerFake.DEFAULT_PORT,
13 years, 1 month
JBoss Tools SVN: r31426 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 03:58:08 -0400 (Mon, 23 May 2011)
New Revision: 31426
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java
Log:
[JBIDE-8978] fixed transport to throw specific errors when the server responds with 401 (was: reported IOException)
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java 2011-05-23 07:50:09 UTC (rev 31425)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java 2011-05-23 07:58:08 UTC (rev 31426)
@@ -28,6 +28,8 @@
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.jboss.tools.deltacloud.client.DeltaCloudNotFoundClientException;
import org.jboss.tools.deltacloud.client.HttpMethod;
@@ -40,8 +42,6 @@
private static final String PROPERTY_ACCEPT = "Accept";
private static final String PREFIX_BASIC_AUTHENTICATION = "Basic ";
private static final int TIMEOUT = 10 * 1024;
- private static final String RESPONSE_CODE_PREFIX = "HTTP response code: ";
- private static final int RESPONSE_CODE_LENGTH = 3;
public URLConnectionTransport(String username, String password) {
super(username, password);
@@ -49,9 +49,10 @@
@Override
protected InputStream doRequest(DeltaCloudRequest request) throws Exception {
+ HttpURLConnection connection = null;
try {
URL url = request.getUrl();
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection = (HttpURLConnection) url.openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setAllowUserInteraction(false);
@@ -61,8 +62,6 @@
addCredentials(connection);
setRequestMethod(request, connection);
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
- throwOnHttpErrors(
- connection.getResponseCode(), connection.getResponseMessage(), request.getUrl());
return in;
} catch (FileNotFoundException e) {
/*
@@ -70,7 +69,17 @@
*/
throw new DeltaCloudNotFoundClientException(
MessageFormat.format("Could not find resource {0}", request.getUrlString()));
+ } catch (IOException e) {
+ /*
+ * thrown by #connect when server resonds with 401.
+ */
+ HttpError httpError = HttpError.getInstance(e, connection);
+ if (httpError != null) {
+ throwOnHttpErrors(httpError.getStatusCode(), httpError.getStatusMessage(), request.getUrl());
+ }
+ throw e;
}
+
}
private void setRequestMethod(DeltaCloudRequest request, HttpURLConnection connection) throws IOException {
@@ -124,4 +133,54 @@
char[] encoded = Base64Coder.encode(out.toByteArray());
return new String(encoded);
}
+
+ private static final class HttpError {
+
+ private static final Pattern STATUS_REGEX = Pattern.compile(".+ HTTP response code: ([0-9]{3}) .+");
+ private int statusCode;
+ private String statusMessage;
+
+ private HttpError(int statusCode, String statusMessage) {
+ this.statusCode = statusCode;
+ this.statusMessage = statusMessage;
+ }
+
+ public static HttpError getInstance(IOException ioe, HttpURLConnection connection) throws IOException {
+ HttpError httpError = null;
+ try {
+ int statusCode = getStatusCode(ioe);
+ if (statusCode > -1) {
+ String statusMessage = connection.getResponseMessage();
+ httpError = new HttpError(statusCode, statusMessage);
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return httpError;
+ }
+
+ public String getStatusMessage() {
+ return statusMessage;
+ }
+
+ private static int getStatusCode(IOException e) {
+ Matcher matcher = STATUS_REGEX.matcher(e.getMessage());
+ if (matcher.matches()) {
+ return getStatusCode(matcher.group(1));
+ }
+ return -1;
+ }
+
+ private static int getStatusCode(String statusCode) {
+ try {
+ return Integer.parseInt(statusCode);
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+ }
}
13 years, 1 month
JBoss Tools SVN: r31425 - trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 03:50:09 -0400 (Mon, 23 May 2011)
New Revision: 31425
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java
Log:
[JBIDE-8975] renamed test method name to better match its purpose
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java 2011-05-23 07:37:52 UTC (rev 31424)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudMockIntegrationTest.java 2011-05-23 07:50:09 UTC (rev 31425)
@@ -64,7 +64,7 @@
}
@Test(expected = DeltaCloudException.class)
- public void testConnectionThrowsOnGeneralFailure() throws MalformedURLException, DeltaCloudClientException, DeltaCloudException {
+ public void testConnectionThrowsOnInternalServerError() throws MalformedURLException, DeltaCloudClientException, DeltaCloudException {
ServerFake serverFake = setupServerFake("HTTP/1.1 501 Some Error\ndummy dummy dummy\n\n");
try {
DeltaCloud deltaCloud =
13 years, 1 month