Re: [appengine-java] Re: junit and local_db.bin

2010-06-23 Thread Andrés Cerezo
Thank you very much!!! At last I've solved it. Where have you found
documentation about it? I was going crazy!!!


2010/6/23 Andrés Cerezo 

> Hi!! Have you got a .java complete? I'm starting to have a lot of errors
> (import, etc.)
>
> 2010/6/23 Nacho Coloma 
>
> I know that someone will arrive with a better implementation, but here
>> goes own little code snippet used to populate our test database. It
>> has survived five or six GAE upgrades, so glitches are expected :)
>>
>> You must have two things in consideration: the appid and version must
>> match, and you should enable datastore writes.
>>
>> File dbContents = new File("war/WEB-INF/appengine-generated/
>> local_db.bin");
>>LocalServiceTestHelper helper =
>>new LocalServiceTestHelper(new
>> LocalDatastoreServiceTestConfig()
>>
>>  .setBackingStoreLocation(dbContents.getAbsolutePath())
>>.setStoreDelayMs(4000)
>>.setNoStorage(false)
>>) {
>>@Override
>>protected Environment newEnvironment() {
>>return createEnvironment();
>>}
>>};
>>helper.setUp();
>> // ... now you can start writing your own data, and they will appear
>> in the console
>>
>>public static Environment createEnvironment() {
>>try {
>>// retrieve application id and version from
>> appengine-web.xml
>>String contents = FileUtils.readFileToString(new
>> File("war/WEB-INF/
>> appengine-web.xml"));
>>final String application =
>> StringUtils.substringBetween(contents,
>> "", "");
>>final String version =
>> StringUtils.substringBetween(contents,
>> "", "");
>>
>>// initialize GAE
>>return new TestEnvironment() {
>>
>>@Override
>>public String getAppId() {
>>return application;
>>}
>>
>>@Override
>>public String getVersionId() {
>>return version;
>>}
>>
>>@Override
>>public String getRequestNamespace() {
>>return "";
>>}
>>};
>>} catch (IOException e) {
>>throw new RuntimeException(e);
>> }
>>}
>>
>> On Jun 23, 11:05 am, Andrés Cerezo  wrote:
>> > Hi Rommel with the method listAllDomain I can see the data, there should
>> be
>> > a problem withhttp://127.0.0.1:/_ah/admin/datastoreperhaps a user
>> roll
>> > or something similar (in JUNIT or loggin withhttp://
>> 127.0.0.1:/_ah/admin/datastore?
>> >
>> > Thanks.
>> >
>> > 2010/6/22 Ronmell Fuentes 
>> >
>> > > Yup, for sure.
>> >
>> > > Let's suppose you have an entity called "domain" which has the
>> following
>> > > attributes:
>> >
>> > > 1. Key
>> > > 2. Name
>> >
>> > > public void listAllDomain(){
>> > > List  results;
>> > > Query query=factory.newQuery(Domain.class);
>> > > try{
>> > > results=(List) query.execute();
>> > > if(results.iterator().hasNext()){
>> > > for(int k=0;k> > > Domain dumb=results.get(k);
>> > > System.out.println("Key:
>> > > \t"+String.valueOf(dumb.getKey()).toString());
>> > > System.out.println("Domain
>> > > Name:\t"+dumb.getDomainName());
>> > > }
>> > > }
>> > > else System.out.println("no results exist");
>> > > }
>> > > finally{query.closeAll();}
>> > > }
>> >
>> > > Where Domain.clas is the class type for your entity called Domain.
>> > > besides, in the query object you can set filters for your query.
>> >
>> > > this method will show the data in your data Store.
>> >
>> > > As I can see, if the local_db.bin is getting bigger each time JUnit is
>> ran,
>> > > then the data must be there, so with this method you should be able to
>> see
>> > > all the data stored in your Data Store. you have just replace all
>> "Domain"
>> > > references for your Entity's.
>> >
>> > > Hope this is was helpful.
>> >
>> > > Rgds.
>> >
>> > > R
>> >
>> > > 2010/6/22 Andrés Cerezo 
>> >
>> > >> No, perhaps have yout got an example?
>> >
>> > >> 2010/6/22 Ronmell Fuentes 
>> >
>> > >>> have you tried to retrieve the data from your app, I mean, not using
>> the
>> > >>> http/_ah/admin console but using your own application, a class
>> written
>> > >>> in java to show the data, does it work??
>> >
>> > >>> 2010/6/22

Re: [appengine-java] Re: junit and local_db.bin

2010-06-23 Thread Andrés Cerezo
Hi!! Have you got a .java complete? I'm starting to have a lot of errors
(import, etc.)

2010/6/23 Nacho Coloma 

> I know that someone will arrive with a better implementation, but here
> goes own little code snippet used to populate our test database. It
> has survived five or six GAE upgrades, so glitches are expected :)
>
> You must have two things in consideration: the appid and version must
> match, and you should enable datastore writes.
>
> File dbContents = new File("war/WEB-INF/appengine-generated/
> local_db.bin");
>LocalServiceTestHelper helper =
>new LocalServiceTestHelper(new
> LocalDatastoreServiceTestConfig()
>
>  .setBackingStoreLocation(dbContents.getAbsolutePath())
>.setStoreDelayMs(4000)
>.setNoStorage(false)
>) {
>@Override
>protected Environment newEnvironment() {
>return createEnvironment();
>}
>};
>helper.setUp();
> // ... now you can start writing your own data, and they will appear
> in the console
>
>public static Environment createEnvironment() {
>try {
>// retrieve application id and version from
> appengine-web.xml
>String contents = FileUtils.readFileToString(new
> File("war/WEB-INF/
> appengine-web.xml"));
>final String application =
> StringUtils.substringBetween(contents,
> "", "");
>final String version =
> StringUtils.substringBetween(contents,
> "", "");
>
>// initialize GAE
>return new TestEnvironment() {
>
>@Override
>public String getAppId() {
>return application;
>}
>
>@Override
>public String getVersionId() {
>return version;
>}
>
>@Override
>public String getRequestNamespace() {
>return "";
>}
>};
>} catch (IOException e) {
>throw new RuntimeException(e);
> }
>}
>
> On Jun 23, 11:05 am, Andrés Cerezo  wrote:
> > Hi Rommel with the method listAllDomain I can see the data, there should
> be
> > a problem withhttp://127.0.0.1:/_ah/admin/datastoreperhaps a user
> roll
> > or something similar (in JUNIT or loggin withhttp://
> 127.0.0.1:/_ah/admin/datastore?
> >
> > Thanks.
> >
> > 2010/6/22 Ronmell Fuentes 
> >
> > > Yup, for sure.
> >
> > > Let's suppose you have an entity called "domain" which has the
> following
> > > attributes:
> >
> > > 1. Key
> > > 2. Name
> >
> > > public void listAllDomain(){
> > > List  results;
> > > Query query=factory.newQuery(Domain.class);
> > > try{
> > > results=(List) query.execute();
> > > if(results.iterator().hasNext()){
> > > for(int k=0;k > > Domain dumb=results.get(k);
> > > System.out.println("Key:
> > > \t"+String.valueOf(dumb.getKey()).toString());
> > > System.out.println("Domain
> > > Name:\t"+dumb.getDomainName());
> > > }
> > > }
> > > else System.out.println("no results exist");
> > > }
> > > finally{query.closeAll();}
> > > }
> >
> > > Where Domain.clas is the class type for your entity called Domain.
> > > besides, in the query object you can set filters for your query.
> >
> > > this method will show the data in your data Store.
> >
> > > As I can see, if the local_db.bin is getting bigger each time JUnit is
> ran,
> > > then the data must be there, so with this method you should be able to
> see
> > > all the data stored in your Data Store. you have just replace all
> "Domain"
> > > references for your Entity's.
> >
> > > Hope this is was helpful.
> >
> > > Rgds.
> >
> > > R
> >
> > > 2010/6/22 Andrés Cerezo 
> >
> > >> No, perhaps have yout got an example?
> >
> > >> 2010/6/22 Ronmell Fuentes 
> >
> > >>> have you tried to retrieve the data from your app, I mean, not using
> the
> > >>> http/_ah/admin console but using your own application, a class
> written
> > >>> in java to show the data, does it work??
> >
> > >>> 2010/6/22 Andrés Cerezo 
> >
> >  I think so, When I executed all is right, however I don't execute
> >  teardown method because If I executed this the data are deleted.
> Alsoeverytime I executed JUNIT the local_db.bin file is bigger than the last
> >  time so It has the data.
>

[appengine-java] Re: junit and local_db.bin

2010-06-23 Thread Nacho Coloma
I know that someone will arrive with a better implementation, but here
goes own little code snippet used to populate our test database. It
has survived five or six GAE upgrades, so glitches are expected :)

You must have two things in consideration: the appid and version must
match, and you should enable datastore writes.

File dbContents = new File("war/WEB-INF/appengine-generated/
local_db.bin");
LocalServiceTestHelper helper =
new LocalServiceTestHelper(new 
LocalDatastoreServiceTestConfig()

.setBackingStoreLocation(dbContents.getAbsolutePath())
.setStoreDelayMs(4000)
.setNoStorage(false)
) {
@Override
protected Environment newEnvironment() {
return createEnvironment();
}
};
helper.setUp();
// ... now you can start writing your own data, and they will appear
in the console

public static Environment createEnvironment() {
try {
// retrieve application id and version from 
appengine-web.xml
String contents = FileUtils.readFileToString(new 
File("war/WEB-INF/
appengine-web.xml"));
final String application = 
StringUtils.substringBetween(contents,
"", "");
final String version = 
StringUtils.substringBetween(contents,
"", "");

// initialize GAE
return new TestEnvironment() {

@Override
public String getAppId() {
return application;
}

@Override
public String getVersionId() {
return version;
}

@Override
public String getRequestNamespace() {
return "";
}
};
} catch (IOException e) {
throw new RuntimeException(e);
}
}

On Jun 23, 11:05 am, Andrés Cerezo  wrote:
> Hi Rommel with the method listAllDomain I can see the data, there should be
> a problem withhttp://127.0.0.1:/_ah/admin/datastoreperhaps a user roll
> or something similar (in JUNIT or loggin 
> withhttp://127.0.0.1:/_ah/admin/datastore?
>
> Thanks.
>
> 2010/6/22 Ronmell Fuentes 
>
> > Yup, for sure.
>
> > Let's suppose you have an entity called "domain" which has the following
> > attributes:
>
> > 1. Key
> > 2. Name
>
> > public void listAllDomain(){
> >         List  results;
> >         Query query=factory.newQuery(Domain.class);
> >         try{
> >             results=(List) query.execute();
> >             if(results.iterator().hasNext()){
> >                 for(int k=0;k >                     Domain dumb=results.get(k);
> >                     System.out.println("Key:
> > \t"+String.valueOf(dumb.getKey()).toString());
> >                     System.out.println("Domain
> > Name:\t"+dumb.getDomainName());
> >                 }
> >             }
> >             else System.out.println("no results exist");
> >         }
> >         finally{query.closeAll();}
> >     }
>
> > Where Domain.clas is the class type for your entity called Domain.
> > besides, in the query object you can set filters for your query.
>
> > this method will show the data in your data Store.
>
> > As I can see, if the local_db.bin is getting bigger each time JUnit is ran,
> > then the data must be there, so with this method you should be able to see
> > all the data stored in your Data Store. you have just replace all "Domain"
> > references for your Entity's.
>
> > Hope this is was helpful.
>
> > Rgds.
>
> > R
>
> > 2010/6/22 Andrés Cerezo 
>
> >> No, perhaps have yout got an example?
>
> >> 2010/6/22 Ronmell Fuentes 
>
> >>> have you tried to retrieve the data from your app, I mean, not using the
> >>> http/_ah/admin console but using your own application, a class written
> >>> in java to show the data, does it work??
>
> >>> 2010/6/22 Andrés Cerezo 
>
>  I think so, When I executed all is right, however I don't execute
>  teardown method because If I executed this the data are deleted. 
>  Alsoeverytime I executed JUNIT the local_db.bin file is bigger than the 
>  last
>  time so It has the data.
>
>  2010/6/22 Ronmell Fuentes 
>
> > is your JUnit well configured??
>
> > 2010/6/22 Andrés Cerezo 
>
> >>  But I can see the data created with the servlets with
> >>http://localhost:/_ah/admin, but not when I the data are created
> >> with junit.
>
> >> 2010/6/22