Java SSL connection problem

If you are suffering from the dreaded message

PKIX path building failed: unable to find valid certification path to requested target

and you have installed the necessary certificates in your keystore.

Try passing

to your java runtime. You will now get *a lot* of details about the keystore which is used, the certificates which are available and the SSL negotiation.

This should help to figure out what exactly is going wrong (like a hostname match problem or problem caused by SNI or something else).

Database upgrate problem with Activiti moving from version 5.14 to 5.16

We are using PostgreSQL as our database and we wanted to upgrade Activiti from version 5.14 to 5.16 to be able to use the event system. Unfortunately this failed with the following problem.

org.postgresql.util.PSQLException: ERROR: constraint "act_ru_execution_proc_def_id__business_key__key" of relation "act_ru_execution" does not exist

I don’t really know what causes this. Maybe because we were still using PostgreSQL 8 until recently. Anyway, after some digging, it seems that executing the following SQL script before the update assures that the automatic database upgrade works for use.

ALTER TABLE act_ru_execution ADD CONSTRAINT act_ru_execution_proc_def_id__business_key__key UNIQUE(id_);
ALTER TABLE act_hi_procinst ADD CONSTRAINT act_hi_procinst_proc_def_id__business_key__key UNIQUE(id_);

Easier mocks with data

I have a love/hate relationship with mocks in unit tests. They are wonderful to mock out services, but building mocks or objects with just enough data for testing is often a pain. I end up writing code like:

Person person = new Person();
person.setName("John Doe");
Organization organization = new Organization();
organizaion.setName("Company Ltd");

I believe this is too verbose to be nice. As such test objects are often needed this code may be moved to a separate class to build test mother objects. This arguably makes things worse by hiding the values used and more or less forcing all tests to use the same field values.

When I need this object to be a Mockito mock it becomes something like this:

Person person = Mockito.mock(Person.class);
when(person.getName()).thenReturn("John Doe");
Organization organization = mock(Organization.class);
when(organizaion.getName()).thenReturn("Company Ltd");

This is not very readable.

Taking inspiration from faker gems in Ruby, I created a new library to make this more legible.

Person person = FakerMock.withFields(Person.class,
        "name", "John Doe",
        "location", "Brussels",
        "organization", FakerMock.withFields(Organization.class, 
                "name", "Company Ltd"));

This is now available as jFaker.

This is a reasonable simple start, but I would like to extend this to also support javabeans (same syntax but using FakerBean instead of FakerMock) and also te be able to have values read from a yaml file. In that case, I would probably use a syntax like

FakerBuilder faker = new FakerBuilder().
Person person = faker.withFields(Person.class,
        "name", "John Doe",
        "location", "Brussels",
        "organization", faker.withFields(Organization.class, 
                "name", "Company Ltd"));

Would this be useful for you?