• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: EOEditingContext for JUnit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOEditingContext for JUnit


  • Subject: Re: EOEditingContext for JUnit
  • From: "Zak Burke" <email@hidden>
  • Date: Tue, 25 Mar 2008 14:46:37 -0400

On Mon, Mar 24, 2008 at 4:48 PM, Chris Meyer <email@hidden> wrote:
> Thanks. That seems to work. I created a new database config, set it to
> Memory and could easily reproduce the problem.
>
> Now... is there any way to choose the database config at runtime so that for
> my regular launch of the WOApplication, it uses one database config, and for
> my launch of the JUnit tests, it uses the other config?

If all you need to do is reset the model's connection privileges,
that's easy. Add the following to your Properties file, replacing
modelname with the actual name of your model:

modelname.username = username
modelname.password = password
modelname.driver = driver
modelname.URL = url

And add the following to your Application.java:

	public Application()
	{
		[...]
		dbInit();
	]


	/**
	 * register to receieve model-added notificaton so we can intercept it
	 * and update the cxn dictionary with params from the properties file.
	 *
	 */
	private void dbInit()
	{
		Class params[] = { com.webobjects.foundation.NSNotification.class };
		NSSelector selector = new NSSelector("receiveModelAddedNotification", params);
		NSNotificationCenter.defaultCenter().addObserver(this, selector,
EOModelGroup.ModelAddedNotification, null);
	}



	/**
	 * Intercept add-model notifications and reset the authentication
	 * fields in the model's connection dictionary if System.properties
	 * contains a username and password for this model. Setting the
	 * connection's driver and URL fields are optional.
	 *
	 * @param notification
	 */
	public void receiveModelAddedNotification(NSNotification notification)
	{
		EOModel model = (EOModel) notification.object();
		NSLog.out.appendln("Rewriting connection dictionary for " +
model.name() + "...");

		String username = System.getProperty(model.name() + ".username");
		String password = System.getProperty(model.name() + ".password");

		if (username != null && password != null)
		{
			NSLog.out.appendln("Rewriting connection dictionary for " +
model.name() + " with username " + username);

			NSMutableDictionary connD = model.connectionDictionary().mutableClone();

			connD.setObjectForKey(username, "username");
			connD.setObjectForKey(password, "password");

			String temp = System.getProperty(model.name() + ".driver");
			if (temp != null && temp.length() > 0)
				connD.setObjectForKey(username, "driver");

			temp = System.getProperty(model.name() + ".URL");
			if (temp != null && temp.length() > 0)
				connD.setObjectForKey(username, "URL");

			model.setConnectionDictionary(connD);
		}
	}


>
>
> On Mon, Mar 24, 2008 at 12:16 PM, Mike Schrag <email@hidden>
> wrote:
> > You can try using the JavaMemoryAdaptor from Wonder ... It's an
> > implementation of the adaptor layer in-memory, so to an EC it looks
> > completely "real" but it's actually just writing EO's into
> > NSDictionaries internally.  Really handy for test cases.  We use this
> > in the new examples in AjaxExample.app.  I think there's still a bug
> > that it doesn't properly impl support for inheritance at the moment,
> > though (just hadn't gotten around to looking into the reason).
> >
> > ms
> >
> >
> >
> >
> > On Mar 24, 2008, at 3:13 PM, Chris Meyer wrote:
> >
> > > I'm writing JUnit tests and I'm trying to add a test for a 'clone'
> > > problem. Unfortunately, the mockEditingContext() included with
> > > wounittest2 framework doesn't seem to have enough functionality to
> > > reproduce the bug.
> > >
> > > Is there a way to create a new editing context connected to an
> > > object store connected to a REAL database configured for testing?
> > >
> > > If so, how would I go about it in a JUnit test?
> > >
> > > Is there existing code to do something similar that I can look at?
> >
>
>
>  _______________________________________________
>  Do not post admin requests to the list. They will be ignored.
>  Webobjects-dev mailing list      (email@hidden)
>  Help/Unsubscribe/Update your Subscription:
>
>  This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: EOEditingContext for JUnit
      • From: "Chris Meyer" <email@hidden>
References: 
 >EOEditingContext for JUnit (From: "Chris Meyer" <email@hidden>)
 >Re: EOEditingContext for JUnit (From: Mike Schrag <email@hidden>)
 >Re: EOEditingContext for JUnit (From: "Chris Meyer" <email@hidden>)

  • Prev by Date: Re: EOEditingContext for JUnit
  • Next by Date: Click to Open :-)
  • Previous by thread: Re: EOEditingContext for JUnit
  • Next by thread: Re: EOEditingContext for JUnit
  • Index(es):
    • Date
    • Thread