Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problems when unit testing the content assist (which uses the Index)
problems when unit testing the content assist (which uses the Index) [message #732044] Mon, 03 October 2011 19:07 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

starting from this post

http://www.eclipse.org/forums/index.php/mv/msg/227257/716792/

I managed to start testing my content assist; however in a specific
case, my content assist uses the index to build the proposals. When
trying the editor in the new eclipse instance the content assist
correctly works, but not when doing the (plugin) unit test... in
particular, while debugging I see that the last instruction of my method

protected Collection<IEObjectDescription> getAllVisibleObjectsByType(
EObject context, EClass type) {
Resource eResource = context.eResource();
IResourceDescriptions index = resourceDescriptionsProvider
.getResourceDescriptions(eResource);
IResourceDescription resourceDescription = index
.getResourceDescription(eResource.getURI());

returns a null IResourceDescription

can this issue be dealt with, or isn't the index not available when
using AbstractContentAssistProcessorTest?

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems when unit testing the content assist (which uses the Index) [message #732047 is a reply to message #732044] Mon, 03 October 2011 19:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

no, once more this is not a usecase the test class is made for
once more you have to do manual work to get it running

(1) create a test project and add xtext nature with eclipse means (ResourcePlugin)
(2) hack the ContentAssistTest code that the uri of the created model
is within this project.

feel free to commit your results as a patch to a corresponding enhancement request.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: problems when unit testing the content assist (which uses the Index) [message #732070 is a reply to message #732047] Mon, 03 October 2011 21:05 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 10/03/2011 09:17 PM, Christian Dietrich wrote:
> Hi,
>
> no, once more this is not a usecase the test class is made for
> once more you have to do manual work to get it running
>
> (1) create a test project and add xtext nature with eclipse means
> (ResourcePlugin)
> (2) hack the ContentAssistTest code that the uri of the created model
> is within this project.
>
> feel free to commit your results as a patch to a corresponding
> enhancement request.

Actually I'm not related to the post I cited and in my test scenario
I've only one resource thus the index should be working shouldn't it?
For instance, the index works in the (non plugin) unit tests... after
all the ContentAssistProcessorTestBuilder loads the resource in the same
way AbstractXtextTests...

Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems when unit testing the content assist (which uses the Index) [message #732078 is a reply to message #732070] Mon, 03 October 2011 21:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No,

just local scoping will work. global (index based) wont

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: problems when unit testing the content assist (which uses the Index) [message #732080 is a reply to message #732078] Mon, 03 October 2011 21:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
btw why is the index asked in your case? importednamespaceaware scoping should do the trick/job

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: problems when unit testing the content assist (which uses the Index) [message #732085 is a reply to message #732080] Mon, 03 October 2011 21:29 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 10/03/2011 11:19 PM, Christian Dietrich wrote:
> btw why is the index asked in your case? importednamespaceaware scoping
> should do the trick/job

in my case for the things I query the index I don't have actual linking
resolution...

just to try to explain my context in my language I have rule like

ModifiesElement: 'modifies' elementName=ID ...

note that I do not refer to an actual 'Element' but to the name of an
'Element', because the actual 'Element' I will refer to will be known
only at generation time and could be provided by different composition
of modules... (the language I'm working in has a 'meta' flavor)

statically I only need to check that an 'Element' with the specified
name is defined somewhere in the whole source path (it could be defined
by several modules, but at least one module has to define it); that's
why I need to query the index just to check that at least somewhere
there will be an Element with that name (and in the content assist I'd
like to propose only the actual Elements defined).

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems when unit testing the content assist (which uses the Index) [message #732087 is a reply to message #732085] Mon, 03 October 2011 21:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

there is still the problem that the index standalone is still totaly different from the one in ui.
thus you have to handle this in the test. a resourceset based index wont work.
thus i'd still try to create the project manually and take care the uri of your test file
points to that project (by hacking org.eclipse.xtext.junit.AbstractXtextTests.doGetResource(InputStream, URI))

I know the AbstractTests Class is crappy regarding this Wink

~Christian

~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: problems when unit testing the content assist (which uses the Index) [message #732092 is a reply to message #732078] Mon, 03 October 2011 21:33 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 10/03/2011 11:14 PM, Christian Dietrich wrote:
> No,
>
> just local scoping will work. global (index based) wont
>
> ~Christian

thus global scoping works in a non-ui test environment because the
(default generated) runtime module has this binding

public Class<? extends
org.eclipse.xtext.resource.containers.IAllContainersState.Provider>
bindIAllContainersState$Provider() {
return
org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.class;
}

while the ui module has this one

public
com.google.inject.Provider<org.eclipse.xtext.resource.containers.IAllContainersState>
provideIAllContainersState() {
return org.eclipse.xtext.ui.shared.Access.getJavaProjectsState();
}

it could be enough to use the same binding of the non-ui runtime module
in my derived AbstractContentAssistProcessorTest, couldn't it?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems when unit testing the content assist (which uses the Index) [message #732093 is a reply to message #732092] Mon, 03 October 2011 21:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

no i guess one wont changed this since in ui you have usually this
project state. thus id still try to give xtext.ui what it wants:
a project.

~Christian

Am 03.10.2011 23:33, schrieb Lorenzo Bettini:
> On 10/03/2011 11:14 PM, Christian Dietrich wrote:
>> No,
>>
>> just local scoping will work. global (index based) wont
>>
>> ~Christian
>
> thus global scoping works in a non-ui test environment because the
> (default generated) runtime module has this binding
>
> public Class<? extends
> org.eclipse.xtext.resource.containers.IAllContainersState.Provider>
> bindIAllContainersState$Provider() {
> return
> org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.class;
>
> }
>
> while the ui module has this one
>
> public
> com.google.inject.Provider<org.eclipse.xtext.resource.containers.IAllContainersState>
> provideIAllContainersState() {
> return org.eclipse.xtext.ui.shared.Access.getJavaProjectsState();
> }
>
> it could be enough to use the same binding of the non-ui runtime module
> in my derived AbstractContentAssistProcessorTest, couldn't it?
>
> cheers
> Lorenzo
>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: problems when unit testing the content assist (which uses the Index) [message #732094 is a reply to message #732087] Mon, 03 October 2011 21:52 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 10/03/2011 11:39 PM, Christian Dietrich wrote:
> Hi,
>
> there is still the problem that the index standalone is still totaly
> different from the one in ui.
> thus you have to handle this in the test. a resourceset based index wont
> work.
> thus i'd still try to create the project manually and take care the uri
> of your test file
> points to that project (by hacking
> org.eclipse.xtext.junit.AbstractXtextTests.doGetResource(InputStream, URI))
>

it is quite clear how to create the project and the test file (using the
utility provided by xtext.junit.ui), but by hacking do you mean
something like the following?

1. override AbstractXtextTests.doGetResource(InputStream, URI)
2. in the overridden version ignore the passed URI and always use the
(platform) URI pointing to the created test file in the created project

but still I wouldn't be able to use the builder facilities, would I? I
mean build the program string by using append and then assertText?

cheers
Lorenzo

> I know the AbstractTests Class is crappy regarding this ;)


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems when unit testing the content assist (which uses the Index) [message #732095 is a reply to message #732094] Mon, 03 October 2011 21:55 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No,

the test file has not to physically exist.
just its resource uri must point to a file in
the test project.

~Christian

Am 03.10.2011 23:52, schrieb Lorenzo Bettini:
> On 10/03/2011 11:39 PM, Christian Dietrich wrote:
>> Hi,
>>
>> there is still the problem that the index standalone is still totaly
>> different from the one in ui.
>> thus you have to handle this in the test. a resourceset based index wont
>> work.
>> thus i'd still try to create the project manually and take care the uri
>> of your test file
>> points to that project (by hacking
>> org.eclipse.xtext.junit.AbstractXtextTests.doGetResource(InputStream,
>> URI))
>>
>
> it is quite clear how to create the project and the test file (using the
> utility provided by xtext.junit.ui), but by hacking do you mean
> something like the following?
>
> 1. override AbstractXtextTests.doGetResource(InputStream, URI)
> 2. in the overridden version ignore the passed URI and always use the
> (platform) URI pointing to the created test file in the created project
>
> but still I wouldn't be able to use the builder facilities, would I? I
> mean build the program string by using append and then assertText?
>
> cheers
> Lorenzo
>
>> I know the AbstractTests Class is crappy regarding this ;)
>
>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Embedding a second DSL
Next Topic:ValueConverters - Obtain File containing INode?
Goto Forum:
  


Current Time: Fri Apr 19 19:14:15 GMT 2024

Powered by FUDForum. Page generated in 0.04223 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top