[jbosstools-commits] JBoss Tools SVN: r43338 - in trunk/cdi/tests/org.jboss.tools.cdi.core.test: resources/tck/tests/jbt/lookup/duplicateName and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Aug 30 19:26:09 EDT 2012


Author: scabanovich
Date: 2012-08-30 19:26:09 -0400 (Thu, 30 Aug 2012)
New Revision: 43338

Added:
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/lookup/duplicateName/TwoNamedProducers.java
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/project/CDIProjectAsYouTypeTest.java
Modified:
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/META-INF/MANIFEST.MF
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreAllTests.java
Log:
JBIDE-12520
https://issues.jboss.org/browse/JBIDE-12520
Test of CDIProjectAsYouType


Modified: trunk/cdi/tests/org.jboss.tools.cdi.core.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/META-INF/MANIFEST.MF	2012-08-30 22:29:56 UTC (rev 43337)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/META-INF/MANIFEST.MF	2012-08-30 23:26:09 UTC (rev 43338)
@@ -18,6 +18,7 @@
  org.eclipse.ltk.core.refactoring,
  org.jboss.tools.jst.web.kb,
  org.jboss.tools.cdi.xml,
+ org.eclipse.jface.text,
  org.eclipse.jst.standard.schemas,
  org.eclipse.wst.validation;bundle-version="1.2.0",
  org.eclipse.wst.common.frameworks;bundle-version="1.2.0",

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/lookup/duplicateName/TwoNamedProducers.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/lookup/duplicateName/TwoNamedProducers.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/lookup/duplicateName/TwoNamedProducers.java	2012-08-30 23:26:09 UTC (rev 43338)
@@ -0,0 +1,25 @@
+package org.jboss.jsr299.tck.tests.jbt.lookup.duplicateName;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+public class TwoNamedProducers {
+
+	@Inject @Named SomeType create;
+
+	@Produces
+	@Named
+	public SomeType create() {
+		return new SomeType();
+	}
+
+	@Produces
+	@Named("create")
+	public SomeType create2() {
+		return new SomeType();
+	}
+
+	public static class SomeType {
+	}
+}


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/lookup/duplicateName/TwoNamedProducers.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreAllTests.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreAllTests.java	2012-08-30 22:29:56 UTC (rev 43337)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreAllTests.java	2012-08-30 23:26:09 UTC (rev 43338)
@@ -19,6 +19,7 @@
 import org.jboss.tools.cdi.core.test.extension.ExtensionFactoryTest;
 import org.jboss.tools.cdi.core.test.extension.ExtensionManagerTest;
 import org.jboss.tools.cdi.core.test.extension.ExtensionsInSrsAndUsedProjectTest;
+import org.jboss.tools.cdi.core.test.project.CDIProjectAsYouTypeTest;
 import org.jboss.tools.cdi.core.test.project.EnableCDISupportForJarTest;
 import org.jboss.tools.cdi.core.test.project.EnableCDISupportForWarTest;
 import org.jboss.tools.cdi.core.test.tck.AssignabilityOfRawAndParameterizedTypesTest;
@@ -137,6 +138,7 @@
 		suite.addTestSuite(IncrementalValidationTest.class);
 
 		// As-you-type validation tests
+		suite.addTestSuite(CDIProjectAsYouTypeTest.class);
 		suite.addTestSuite(AYTDefenitionErrorsValidationTest.class);
 		suite.addTestSuite(AYTDeploymentProblemsValidationTests.class);
 		suite.addTestSuite(AYTBeansXmlValidationTest.class);

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/project/CDIProjectAsYouTypeTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/project/CDIProjectAsYouTypeTest.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/project/CDIProjectAsYouTypeTest.java	2012-08-30 23:26:09 UTC (rev 43338)
@@ -0,0 +1,101 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 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.cdi.core.test.project;
+
+import java.util.Collection;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.test.tck.TCKTest;
+import org.jboss.tools.cdi.internal.core.impl.CDIProjectAsYouType;
+import org.jboss.tools.common.util.IEditorWrapper;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+/**
+ * 
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class CDIProjectAsYouTypeTest extends TCKTest {
+
+	public void testModel() throws Exception {
+		IFile f = tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/lookup/duplicateName/TwoNamedProducers.java");
+		assertTrue(f.exists());
+		
+		IEditorPart editorPart = WorkbenchUtils.openEditor(f.getFullPath());
+		assertNotNull(editorPart);
+
+		try {
+			CDIProjectAsYouType ayt = new CDIProjectAsYouType(cdiProject, f);
+			Collection<IBean> bs = getInjectedBeans(ayt);
+			assertEquals(2, bs.size());
+
+			ISourceViewer s = getTextViewer(editorPart);
+		
+			modifyDocument(s.getDocument(), "create()", "_create()");
+
+			ayt = new CDIProjectAsYouType(cdiProject, f);
+			bs = getInjectedBeans(ayt);
+			assertEquals(1, bs.size());
+			
+			modifyDocument(s.getDocument(), "_create()", "create()");
+
+			ayt = new CDIProjectAsYouType(cdiProject, f);
+			bs = getInjectedBeans(ayt);
+			assertEquals(2, bs.size());
+		} finally {
+			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editorPart, false);
+		}
+	}
+
+	private Collection<IBean> getInjectedBeans(CDIProjectAsYouType ayt) {
+		Collection<IBean> bs = ayt.getBeans(true, "org.jboss.jsr299.tck.tests.jbt.lookup.duplicateName.TwoNamedProducers");
+		IBean b = bs.iterator().next();
+		Collection<IInjectionPoint> ps =  b.getInjectionPoints();
+		IInjectionPoint p = ps.iterator().next();
+		return ayt.getBeans(true, p);
+	}
+
+	private ISourceViewer getTextViewer(IEditorPart editorPart) {
+		ISourceViewer viewer = null;
+		ITextEditor textEditor = null;
+		if (editorPart instanceof IEditorWrapper) {
+			editorPart = ((IEditorWrapper) editorPart).getEditor();
+		}
+		if (editorPart instanceof ITextEditor) {
+			textEditor = (ITextEditor) editorPart;
+		} else {
+			textEditor = editorPart == null ? null : (ITextEditor)editorPart.getAdapter(ITextEditor.class);
+		}
+		if(textEditor instanceof JavaEditor) {
+			viewer = ((JavaEditor)textEditor).getViewer();
+		} else if(textEditor instanceof StructuredTextEditor) {
+			viewer = ((StructuredTextEditor)textEditor).getTextViewer();
+		}
+		return viewer;
+	}
+
+	private void modifyDocument(IDocument document, String oldText, String newText) throws BadLocationException {
+		int q = document.get().indexOf(oldText);
+		document.replace(q, oldText.length(), newText);
+	}
+
+}


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/project/CDIProjectAsYouTypeTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list