hprange / wounit

The WOUnit framework contains a set of utilities for testing WebObjects applications using JUnit 4.7 or later capabilities.
http://hprange.github.io/wounit/
Apache License 2.0
19 stars 18 forks source link

Add support for fetch specs defined in the EOModel #20

Open mariussoutier opened 12 years ago

mariussoutier commented 12 years ago

In the EOModel I have a fetch spec defined with the qualifier $patient of type Patient. This auto-generates a method which does:

public static NSArray<net.starhealthcare.sffoundation.model.SFIncident> fetchIncidentsWithDiagnosesForPatient(EOEditingContext editingContext, NSDictionary<String, Object> bindings) {
  EOFetchSpecification fetchSpec = EOFetchSpecification.fetchSpecificationNamed("fetchSpecName", "Incident");
  fetchSpec = fetchSpec.fetchSpecificationWithQualifierBindings(bindings);
  return editingContext.objectsWithFetchSpecification(fetchSpec);
}

I then call it like this:

fetchIncidentsWithDiagnosesForPatient(this.editingContext(), patient);

This does not work with WOUnit, the following exception gets thrown:

com.webobjects.eocontrol.EOQualifier$QualifierVariableSubstitutionException: Error in variable substitution: value for variable $patient not found
at com.webobjects.eocontrol.EOKeyValueQualifier.qualifierWithBindings(EOKeyValueQualifier.java:270)
at com.webobjects.eocontrol.EOQualifier._andOrQualifierWithBindingsAndOptions(EOQualifier.java:719)
at com.webobjects.eocontrol.EOAndQualifier.qualifierWithBindings(EOAndQualifier.java:146)
at com.webobjects.eocontrol.EOFetchSpecification.fetchSpecificationWithQualifierBindings(EOFetchSpecification.java:182)
hprange commented 12 years ago

I'm looking into this problem now.

hprange commented 12 years ago

What editing context? MockEditingContext or TemporaryEditingContext?

I've written some tests and it worked with MockEditingContext. The TemporaryEditingContext didn't find any object, but it also didn't throw any exception.

mariussoutier commented 12 years ago

I tried both, didn't work. Have you tried a Fetch Spec with a parameter?

hprange commented 12 years ago

Yes, I tried 3 scenarios:

  1. Fetch Spec with a String parameter.
  2. Fetch Spec with a Foo entity parameter.
  3. Fetch Spec with both String and Foo entity parameters.

Maybe I'm missing something? Does Incident or Patient inherit from other entity? What is the kind of relationship between them? To one? To many? Many-to-many?

mariussoutier commented 12 years ago

To-many, a patient has many incidents, an incident has one patient. The spec looks like this: patient = $patient and incidentID = diagnoses.incidentID and (disabled = null or disabled = 'false')

hprange commented 12 years ago

Marius,

I've tried to reproduce the same entities and the same relationships in a test model. I'm still unable to reproduce the error on fetchIncidentsWithDiagnosesForPatient on both: MockEditingContext and TemporaryEditingContext.

The same fetchSpecification works in runtime with real editing contexts, right? Looking into the stack trace, it doesn't seem to be a WOUnit problem. :(

MathieuClusiau commented 12 years ago

Hi, I have similor problem with a fetch specs defined in the EOModel.

My fetch does not return any results when I use MockEditingContext with relationship To many. But if I use ERXEC.newEditingContext() all is ok.

//@Rule
public MockEditingContext editingContext = new MockEditingContext("Core");
//public EOEditingContext editingContext2 = ERXEC.newEditingContext();

//@Dummy   for one book many page
private Book _book;

//@Dummy
private Page _page;

@Test
public void testListeMembreValides() {
    _book = Book.createBook(editingContext); //create 
    _book.setTitle("TestBook");

    _page = Page.createPage(editingContext); //create 
    _page.setEmpty(true);
    _book.addToRelationPage(_page); // this fonction call addObjectToBothSideOfRelationshipWithKey(objet, _book.ClefPages) 

    // This fetch is ok with the MockEditingContext and EOEditingContext
    NSArray<? extends Book> listBook =  Book.fetchBooks(editingContext, Book.QualTitle.contains("TestBook"), null, false);
    assertFalse(listBook.count() == 0);

    // This fetch fails with the MockEditingContext, but works with EOEditingContext
    NSArray<? extends Book> listBook2 =  Book.fetchBooks(editingContext, Book.QualTitle.contains("TestBook").and(Book.QualPages.dot(Page.QualEmpty).isTrue()), null, false);
    assertFalse(listBook2.count() == 0);        
}
hprange commented 12 years ago

I'm looking into this problem again.

hprange commented 12 years ago

It seems to be a problem in the qualifier evaluation algorithm provided by the core WebObjects classes. I'm writing to the list to ask for advice.

MathieuClusiau commented 12 years ago

Thanks for your investigation. Let me know when you have solution.

syrinx2012 commented 11 years ago

Hello Henrique,

I was just wondering if there was a fix for this issue? It's definitely a blocker for our development team. Unless there is a workaround?

Thank you.

Martin

hprange commented 11 years ago

@syrinx2012 this issue is caused by a bug in the core WebObjects classes. Kieran Kelleher pushed a change to Wonder that I think is supposed to fix this problem or, at least, is related to the problem. You can see the change here:

https://github.com/wocommunity/wonder/commit/ea23f97a2d18455fba38d496e0ee348aee41b0c0

I still don't have a work around for this issue. However, I'll try to address this problem after WOWODC.

syrinx2012 commented 11 years ago

Thanks for the information. However, I'm already running version 6.0.4 of Wonder, which include this fix, and the problem still exist. I guess it's caused by something else. Thanks a lot for looking into this!

MathieuClusiau commented 11 years ago

For your information, I will try to solve this issue this year.

Mathieu

MathieuClusiau commented 11 years ago

Hello Henrique,

I found a solution. I need to put more effort on it to be sure it's a good solution. I will give you the fix when it's be ready.

note: The problem is in WebObjects and the fix is in Wonder.

Mathieu

hprange commented 11 years ago

Mathieu, nice to hear. Just let me know if you need any help.