Fix exception message during factory update with duplicate name (#11630)

6.19.x
Mykhailo Kuznietsov 2018-10-17 12:26:02 +03:00 committed by GitHub
parent 81b5a17136
commit c8071e04bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -56,7 +56,8 @@ public class JpaFactoryDao implements FactoryDao {
try {
doCreate(factory);
} catch (DuplicateKeyException ex) {
throw new ConflictException(ex.getLocalizedMessage());
throw new ConflictException(
format("Factory with name '%s' already exists for current user", factory.getName()));
} catch (IntegrityConstraintViolationException ex) {
throw new ConflictException(
"Could not create factory with creator that refers on non-existent user");
@ -73,7 +74,8 @@ public class JpaFactoryDao implements FactoryDao {
try {
return new FactoryImpl(doUpdate(update));
} catch (DuplicateKeyException ex) {
throw new ConflictException(ex.getLocalizedMessage());
throw new ConflictException(
format("Factory with name '%s' already exists for current user", update.getName()));
} catch (RuntimeException ex) {
throw new ServerException(ex.getLocalizedMessage(), ex);
}

View File

@ -125,7 +125,10 @@ public class FactoryDaoTest {
factoryDao.create(factory);
}
@Test(expectedExceptions = ConflictException.class)
@Test(
expectedExceptions = ConflictException.class,
expectedExceptionsMessageRegExp =
"Factory with name 'factoryName0' already exists for current user")
public void shouldThrowConflictExceptionWhenCreatingFactoryWithExistingNameAndUserId()
throws Exception {
final FactoryImpl factory = createFactory(10, users[0].getId());
@ -167,7 +170,10 @@ public class FactoryDaoTest {
assertEquals(factoryDao.getById(update.getId()), update);
}
@Test(expectedExceptions = ConflictException.class)
@Test(
expectedExceptions = ConflictException.class,
expectedExceptionsMessageRegExp =
"Factory with name 'factoryName1' already exists for current user")
public void shouldThrowConflictExceptionWhenUpdateFactoryWithExistingNameAndUserId()
throws Exception {
final FactoryImpl update = factories[0];