You appear to want PostgreSQL to create a database if you connect to one that doesn't exist. It does not support doing that.
Yes, you can "feed it an sql query that would build the database" ... but you need to be connected to a database to issue the appropriate CREATE DATABASE
command.
Try using a pre- class or script in your unit testing framework to make a JDBC connection to PostgreSQL and create the test database. Or request that as a feature for your unit testing framework, or as a feature request for Hibernate. See this forum thread for prior discussion.
The general advice is to get the ORM to update the existing schema, not create a new one, or to use pre-test code to drop and re-create the DB.
As for the "in RAM" part ... if that's a speed concern, see Optimise PostgreSQL for fast testing .