RE: [coldbox:7981] Re: What is the best way to do this now with unit tests?

Further to this it still doesn't work, when it gets into the event and the
event then calls a service the rc.spaceURL throws an error on an ORM call.

Regards,

Andrew Scott

<http://www.andyscott.id.au/> http://www.andyscott.id.au/

Andrew,

I’m having a hard time following your response. Perhaps, if you posted your full code we could make fewer assumptions and provide you better support?

Thanks,

Aaron

Andrew,

Below, please find a working unit test. This code registers a new user using a UserService which talks to a UserDAO where ORM calls are made. I hope this helps–and, for what it is worth, I use MXUnit’s Eclipse program for most of my tests.

function validate_submision_is_accepted()
{
var event = “”;

url.email = ‘fake@faker.com’;
url.emailConfirm = url.email;
url.password = ‘password332211’;
url.username = ‘unittestUser22’;

var Event = execute(“Landing.validate”);
var rc = Event.getCollection();
var prc = Event.getCollection(private=true);

// Verify model population
assertEquals(url.email, rc.User.getEmail());
assertEquals(url.password, rc.User.getPassword());
assertEquals(url.username, rc.User.getUsername());

// Verify the validation worked

assert(prc.validSubmission,‘Invalid User Data’);

// Veirfy the service registered the user

assert(prc.registrationComplete,‘UserService.register() returned false.’);

// Confirm the package for REST/Proxy calls.
assertEquals(200, prc.package.statuscode);
assertEquals(‘confirm’,prc.package.body.uri);

return;
}

Aaron have you tried doing it the way I had with the new script structure creation?

Like I stated if I do this.

form = {

name = ‘Andrew Scott’,

email = ‘andy@stiff.com.ua’,

website = ‘’,

comment = ‘weeeeeee’,

rememberInfo = false,

commentSubscribe = false,

blogEntryId = 1,

spaceUrl = ‘AndyScott’

};

structAppend(rc, form);

It works, if I do it the way you did it it works. But it doesn’t work if you do this.

url = {

name = ‘Andrew Scott’,

email = ‘andy@stiff.com.ua’,

website = ‘’,

comment = ‘weeeeeee’,

rememberInfo = false,

commentSubscribe = false,

blogEntryId = 1,

spaceUrl = ‘AndyScott’

};

I am assumming that this might be a ColdFusion issue, and that the URL is actually getting stored in the variables scope. Which is why it works the other way, but I clearly stated that this was the method as above that I want to do this, which I think some people also missed.

However as I added I got this to work by adding.

structAppend(rc, form);

However this now seems to fail when I am doing this.

private any function getBlogSettings(required space) {

var local = {};

local.criteria = {

spaceurl = arguments.space

};

savecontent variable=“local.hqlQuery” {

writeOutput(“from blog b where b.Space.uniqueUrl=:spaceurl”);

}

// We should only ever get one so return the top row

return ORMService.executeQuery(query=local.hqlQuery, params = local.criteria, asQuery = false)[1];

} private any function getBlogSettings(required space) {

var local = {};

local.criteria = {

spaceurl = arguments.space

};

savecontent variable=“local.hqlQuery” {

writeOutput(“from blog b where b.Space.uniqueUrl=:spaceurl”);

}

// We should only ever get one so return the top row

return ORMService.executeQuery(query=local.hqlQuery, params = local.criteria, asQuery = false)[1];

}

If I comment the code out that is calling this function it works fine and the test will run, I have jugged some logging in here to see what is being passed and it is the correct information. Now all this code actually works, but because I have been slack on the unit tests. I have found that this is causing more issues than it is worth at the moment.

I just found this wont work as well.

public void function setup() {

setAppMapping("/");

setConfigMapping(ExpandPath(instance.AppMapping & “/config/coldbox.cfc”));

super.setup();

instance.event = getRequestContext();

instance.trans = ormGetSession().beginTransaction();

}

//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------

public void function teardown() {

if(StructKeyExists(instance, “trans”)) {

instance.trans.rollback();

}

}

And I am again forced to modify working code to get this unit test working, the reason this doesn’t work is because once again the save function is killing the ORMSession. But as this works outside of a unit test I should not be modifying code working code to satisfy a unit test either.

And no the above code is not causing the problem with the function getBlogSettings() either have eliminated that.

I wish people can see that the tranasactional in the save is backwards, in its workings and I feel like I run into its shortfalls each and everytime L

Regards,

Andrew Scott

http://www.andyscott.id.au/

Btw the error being thrown with the getBlogSettings() is org.hibernate.hql.ast.QuerySyntaxException: blog is not mapped [from blog b where b.Space.uniqueUrl=:spaceurl]

Regards,

Andrew Scott

http://www.andyscott.id.au/

Ok, I don’t know how but it appears the problem with the table not mapped was due to a corrupt database. Once the ORM rebuilt the tables again, and I migrated the data back into the database it all seems to work fine now.

Now I only have to work out how the database schema got corrupted.

By the way just so you all know

form = {

name = ‘Andrew Scott’,

email = ‘andy@stiff.com.ua’,

website = ‘’,

comment = ‘weeeeeee’,

rememberInfo = false,

commentSubscribe = false,

blogEntryId = 1,

spaceUrl = ‘AndyScott’

};

Does indeed put the form variable into the variables scope, which was not expected but makes sense.

Regards,

Andrew Scott

http://www.andyscott.id.au/