Entity framework unit testing with sqlite - unit-testing

Is it possible to unit test Entity Framework v2 repositories with SqLite? Is this only possible if my entities are plain Poco and not automatically generated by Entity Framework?
I've generated a entity model from SqlServer and in the generated .edmx file i found this in section SSDL content: Provider="System.Data.SqlClient". Correct me if I am wrong, but shouldnt that be System.Data.SQLite in order to work with sqlite?

Its only possible if two entity models are created (one for each provider) and then make both object contexts implement the same interface.
Its not worth the effort to manage two entity models.
I hope this get fixed in Entity Framework Ver 3.

Related

X Unit Testing Filtered Include EF Core

We have a scenario in .Net Core API to Soft Delete Principal entity and all its dependent entities So We just loaded the dependent entities to include only Active dependent entities with Include(), set the Active = false and update with '''SavesChanges()'''. This part of logic is working fine. The problem is on Unit Test Part.
We have configured DbContext to use In Memory Seed data, so it is not filtering dependent entities as per logic due to shared context. It works fine if We add AsNoTracking(), however in that case we are not able to update the relationships.

Unit test for insertedFact in optaplanner

How do we unit test rules in optaplanner that depend on insertedFact?
As per the examples for drools, its inserting fact using session object and then unit testing the actual rule. How can we access session object in optaplanner? I am creating SolverFactory using xml resource.
Take a look at ScoreVerifier, explained in the docs. It's part of optaplanner-test.jar.

How to make #ManyToOne work with Spring Lemon?

I have an existing Spring MVC + Spring Security + Thymeleaf project. My intention is to add Spring Lemon functionalities to it.
I followed Spring Lemon Getting Started guide, and built a Lemon-powered project. It runs successfully.
Now I'm trying to copy my entities into the Lemon project.
Things go well until I modify my entities to extend VersionedEntity, as said in the documentation.
Then I get this error :
![Error]http://i.stack.imgur.com/snz86.png
Looks like VersionedEntity is incompatible with my ManyToOne relationships. And when I delete those relationships, the problem disappears.
How do i get the tables generated with those JPA annotations ?
VersionedEntity is a lightweight class to support versioning, which extends LemonEntity, which in turn extends Spring Data JPA's AbstractAuditable. So, to pin point where could be the problem, I think you could try extending your classes straight from from LemonEntity or AbstractAuditable, and then see if the issue still remains.
Let's see what you find. If the issue comes even if your entities extend AbstractAuditable, maybe AbstractAuditable isn't compatible with #ManyToOne (assuming your code is fine). In that case, I think raising it with Spring Data JPA guys (either add spring-data-jpa tag to this question or create a separate question with that tag) will help.
Even extending AbstractAuditable didn't solve it. With the help of Sanjay, I understood that when you extend VersionedEntity or LemonEntity, you don't need the Id field in your entity class anymore. Then I deleted it, and it worked.

RealmSwift Unit Test For Realm.io Migration

I need to write unit case for realm.io migration. How do i simulate a before and after Object Class?
One solution is to have a realm file previously saved (such as in your unit test bundle) with the schema version from which you want to test the migration. Your realm object in code is kept in its most recent version, while the realm schema in disk contains an older version.
Have a look at the migration sample app.
In the sample there are versions V0, V1 and V2 of the same Person object, as well as three different realm database files with different schema versions default-v0.realm, default-v1.realm and default-v2.realm.
The same migrationBlock is then used in all versions of the database to ensure it can correctly bring any possible old schema to the newest V2.

#ManyToOne in multiple jars with Glassfish/EclipseLink

I've got two jars, dog.jar and person.jar, both packaged as ejb modules within a single ear. Dog.java is an Entity that references another Entity Person.java via a OneToMany mapping on an "owner" field. Each jar has its own persistence.xml, which reference a common persistence unit, but each persistence.xml only contains the classes contained in that jar.
Upon startup, Glassfish complains:
Exception Description: [class com.example.dog.entities.Dog] uses a non-entity [class com.example.person.entities.Person] as target entity in the relationship attribute [field owner].
It seems to work if I add the Person class to the dog jar's persistence.xml, but I don't like that at all. The Person class is already defined in the persistence.xml of the person.jar, which is in same named persistence unit, in the same ear, so it should find it at runtime! I don't want to repeat myself.
Plus, I use the handy Eclipse JPA tooling to auto-sycnhronize the class names in the persistence.xml, and when I do that it only finds the Dog.java when I run it on dog's persistence.xml. So I don't want to have to hunt down all references and manually add them to persistence.xml and worry about them getting blown away when I resynchronize.
Also I made sure I put the person ejb module before the dog ejb module in the application.xml.
This is my first foray into JPA and Java EE, so I could be doing something wrong... I drank the koolaid by reading books and articles but nobody seems to ever show a good mutli-module enterprise example...