Have 2 hibernate.properties files - database

I have a Spring Boot project with Hibernate. I would like to use 2 separate hibernate.properties files: one for normal use of application, another only for test.
So, how can I do that? Or maybe it is not possible? I don't want to comment/uncomment lines in this file for tests.
Thanks for every answers and help.
#hibernate.connection.driver_class = org.postgresql.Driver
#hibernate.connection.url = jdbc:postgresql://localhost:5432/dummydb
#hibernate.connection.username = postgres
#hibernate.connection.password = postgres
#hibernate.dialect = org.hibernate.dialect.PostgreSQL91Dialect
hibernate.connection.driver_class = org.hsqldb.jdbcDriver
hibernate.connection.url = jdbc:hsqldb:mem:dummydb
hibernate.connection.username = user
hibernate.connection.password = password
hibernate.hbm2ddl.auto=create
hibernate.dialect = org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true

You can use Spring profiles to separet production and test envirionments.
In your case you need to create 2 property files: application.property and application-test.property. First must contains you production env, Second envirionments for tests.
Then you need to chouse test profile when unit tests are executed. Just add #ActiveProfiles(profiles = "test") to your test classes.

Related

Adding count to terraform module

I have already deployed my VPC via this module listed below before I added a count.
This worked just fine, however do to changes in our infrastructure, I need to add a count to the module
module "core_vpc" {
source = "./modules/vpc"
count = var.environment == "qa" || var.environment == "production" ? 1 : 0
aws_region = var.aws_region
environment = var.environment
system = var.system
role = var.system
vpc_name = var.system
vpc_cidr = var.vpc_cidr
ssh_key_name = var.ssh_key_name
ssh_key_public = var.ssh_key_public
nat_subnets = var.nat_subnets
nat_azs = var.vpc_subnet_azs
}
Now Terraform wants to update my state file and destroy much of my configuration and replace it with what is shown in the example below. This is of course not just limited to route association, but all resources created within the module.I can't let this happen as I have production running and not want to mess with that.
module.K8_subnets.aws_route_table_association.subnet[0] will be destroyed
and replace it with:
module.K8_subnets[0].aws_route_table_association.subnet[0] will be created
Is there a way of preventing Terraform of making these changes? Short of changing it manually in the tf-state.
All I want is the for the VPC not to be deployed in DEV.
Thanks.
You can "move" the terraform state using tf state mv src target. Specifically you can move the old non-counter version into the new counted version at index 0:
terraform state mv 'module.K8_subnets' 'module.K8_subnets[0]'
This works for individual resources as well as for entire modules. And it works for for_each resource as well, there you would not have an index but a key to move to. And this even works the other way around, if you remove the count / for_each but want to still keep the resource(s).

What is the proper way to test SpringBoot Database with H2?

I am trying to run Springboot test with H2 in-memory db with Mybatis.
So far I have done
configuring h2 DB in application-test.properties
adding annotation
#SpringBootTest, #TestPropertySource (locations = "TEST_APPLICATION_PROPERTIES_LOCATION")
autowiring dao and serviceImpl beans
adding seed.sql and purge.sql to the test class with
#SqlGroup({
#Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:/database/seed.sql"),
#Sql(executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:/database/purge.sql") })
Despite the above measures, I still have two problems
I can't retrieve user that I input with the seed.sql. I made a user with id="admin", pw="admin", and was trying to retrieve with findById("admin"). But it always returns null.
I can't open h2 DB while debugging with the #test. I simply can't access h2 with localhost:8080/h2-console (the path was written explicitly in application-test.properties)
Is there any extra measure that I should take to test SpringBoot with h2?
Add spring.h2.console.enabled=true in your properties file.

Registration with profile picture using services in Drupal

I've been trying to upload a user profile picture during the user registration using Service 3 and so far I haven't had any luck. I tested passing a hard coded fid in the field "picture" and also tried to pass the fields "filemime", "filename", etc. and it didn't work neither.
Any idea about what fields I need to populate?
I guess it must be related to this post Using Drupal Services and DIOS SDK for setting user picture in iOS app
but it doesn't have and answer neither.
I use following code -
//Picture is first uploaded from ios using file service and fid is passed in $data object
$file_contents_object = file_load($data->picture_fid);
$file_contents_array['fid'] = $file_contents_object->fid;
$file_contents_array['uid'] = $file_contents_object->uid;
$file_contents_array['filename'] = $file_contents_object->filename;
$file_contents_array['uri'] = $file_contents_object->uri;
$file_contents_array['filemime'] = $file_contents_object->filemime;
$file_contents_array['filesize'] = $file_contents_object->filesize;
$file_contents_array['status'] = $file_contents_object->status;
$file_contents_array['timestamp'] = $file_contents_object->timestamp;
$file_contents_array['rdf_mapping'] = $file_contents_object->rdf_mapping;
//use your cck field here
$user_obj->field_user_profile_picture['und'][0] = $file_contents_array;
Hope this will help.

nodejs connecting to db only once

I have a db.js file that has this line in the top to connect to the database.. i call this file to run queries from inside other js files:
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./mydatabase');
db.serialize(function() {
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
db.close();
If i require() this above file 4 times in different files, does this mean sqlite database will be initialized that many times?
I want to initalize it only the first time..
Is this inefficient? Is there a more efficient way?
Official documentation: https://github.com/mapbox/node-sqlite3/wiki/Caching
Sqlite3 module can do caching internally if you use require('sqlite3').cached, i.e. it won't create new connections on new sqlite3.cached.Database(file) as long as string held by file is identical, but reuse existing ones. See in the source for yourself here:
https://github.com/mapbox/node-sqlite3/blob/master/lib/sqlite3.js
However, you should not depend on that. Do some kind of dependency injection, it will save many headaches along the way. In simplest form it will be writing your modules that they export functions accepting database object as their argument:
//module1.js
module.exports = function(db){
db.serialize(...)
//dostuff
}
//start.js
var sqlite3 = require('sqlite3').verbose();
var module1 = require('./module1.js');
var db = new sqlite3.Database('./mydatabase');
module1(db);

Why isn't Modernizr loading in Drupal 7 info file?

name = Lucas description = Drupal-thema gemaakt voor de kinderafdeling
AZ St-Lucas Gent. package = Core version = VERSION core = 7.x
stylesheets[all][] = style.css
scripts[] = scripts/lib/modernizr.js
settings[garland_width] = fluid
; Information added by drupal.org packaging script on 2013-02-20
version = "7.x" project = "drupal" datestamp = "1361393684"
It's possible that your JS file isn't at that location, meaning that Drupal will automatically avoid generating a 404 by omitting the call to the non-existent file.
You could also rely on the Modernizr Drupal module and it takes care of placement for you. It can also keep Modernizr up to date more easily by supplying you with a drush command to refresh the file, along with a nice API that allows for custom builds to be generated more conveniently. Check it out!
see the installation instructions to use modernizr http://drupal.org/project/modernizr

Resources