In my opinion, the simplest way would be to mock your service into throwing the constraint violation in your test. You can do it manually by extending the class for example, or you can use a mocking framework such as mockito. I prefer mocking frameworks because they simplify things a lot as you neither have to create and maintain additional classes nor have to deal with injecting them in your objects under test.
Taking mockito as a starting point you'd probably write something similar to:
import org.hibernate.exception.ConstraintViolationException;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
public class MyTest {
@Mock /* service mock */
private MyService myService;
@InjectMocks /* inject the mocks in the object under test */
private ServiceCaller serviceCaller;
@Test
public void shouldHandleConstraintViolation() {
// make the mock throw the exception when called
when(myService.someMethod(...)).thenThrow(new ConstraintViolationException(...))
// get the operation result
MyResult result = serviceCaller.doSomeStuffWhichInvokesTheServiceMethodThrowingConstraintViolation();
// verify all went according to plan
assertWhatever(result);
}
}