Java DBunit not null assertion for given column - dbunit

I'm using DBUnit for testing my DAO layer. One of the columns that I have to validate, contains XML document. Is it possible that for that particular column I do something like not null assertion using DBUnit? I don't want to make strict assertion as this XML contains some dynamic values like timestamps etc.

Related

Unit testing for Golang squirrel query having VALUES clause

I am using golang,squirrel query builder tool and postgres DB.
I am having a query conatining a VALUES clause for "constant table" building.
The indiviual column values inside the VALUES clause are generated from an external map.
That part of the query would be similar to the one given below.
VALUES('us','us'),('ca','ca'),('se','eu').........
i am using the sqlmock library of go. ref:-https://pkg.go.dev/github.com/DATA-DOG/go-sqlmock#v1.5.0
In the testing phase, I am checking whether the raw query is as expected.
But the problem i am facing is like, the order of the individual rows inside the VALUES
clause keeps on changing. So i cannot frame an exact expected query to match the actual sql query.

How to include the boundary values while using spring data jpa

I am writing an application which contains an entity with property named addedDate of type Date.
I have written an interface which extends MongoRepository and defined a method named
findByAddedDateBetween(Date startDate,Date endDate);
But when I query with 2 dates the output only contain list entities between the dates,Not including the entities whose addedDates is the queried dates. I want to include the boundary values also.
According to Spring JPA documentation for MongoDB, the between keyword is not inclusive in Mongo DB if you use 2 parameters.
As an alternative, you can use the spring Range class. You must use this method in order to include boundaries.
findByAddedDateBetween(Range<Date> range)
Where Range is declared like this :
Range<Date> range = Range.of(Range.Bound.inclusive(dateStart), Range.Bound.inclusive(dateEnd));

Spring Data JPA and NULL filter, if Double field value is null nothing is returned

I have a data JPA entity where it contains a "price" type Double. Now, the users need to able to filter the records based on that field (Between min and max). Now the problem is, the value in the DB can be null for some records. My data JPA repository uses a native query like "price BETWEEN :priceFrom AND :priceTo". Now, if the user does not specify anything in the filter conditions, all record including the ones where prices is null should be returned. However, this query does not return those record. I know, I can create a new method with query "price IS NULL" and check the filter values in my service layer and call the null version if nothing is specified. But, I have multiple fields with the same requirement then it results in a lot of duplicate methods to maintain. Is there a better approach to handle that situation?
It seems to me, that you can specify
(:priceFrom is null and :priceTo is null and price is null)
OR price between :priceFrom and :priceTo
if priceFrom and priceTo are entered, second part of OR will be used, otherwise it selects records where price is null
Since you are using Spring Data JPA - Specifications should solve this for you. This is a JPA Criteria based solution.
For any complex-enough API – searching/filtering your resources by very simple fields is simply not enough. A query language is more flexible and allows you to filter down to exactly the resources you need. Hence you should easily be able to program for NULL (in the scenario that you currently need) and anything else that you might need.
This is scalable for multiple fields and easy to code/configure. There are a few links which will give you more insight into it
Spring Blog
Tutorial 1
Tutorial 2
Hopefully, this is helpful.

Spring Data MongoDB sorting with nullsLast as a URL query parameter

I'm using spring data MongoDB and trying to sort my results in a specific field in a specific direction and I want the null values to be the last.
The way I do that is sending the fields i want to sort in the URL as a query parameter something like the following:
/Resource?sort=date,asc
When the controller receives this request i can see the order cases in the Pageable attribute are filled correctly and the sorting is made automatically by the findAll(Pageable) method provided by spring data, the sorting is working fine, but if the date is null it will bring the Resources with a null date first, and I want the opposite.
Is there anyway to add a request parameter in the URL so the results will be ordered by date ASC and the null values at the last?
If not how can i achieve this ? maybe modifying the Pageable object but i there's no method such nullsLast()

Partial match for number columns in a Spring Data JPA query

I am working with a legacy system which requires doing a query for a partial match on a number field. So I want to do something like
where ID like concat(:num, '%') where num parameter is of the type Long. Is there a way to do that using Spring Data JPA derived queries. If the id was a string then I can simply do
findByIdContaining(String id)
I would appreciate any help.
No, this is not possible with derived queries (those where the query is derived from the method name). But it's easy with an annotated #Query annotation.

Resources