@@ -0,0 +1,3484 @@
+package sg.ncl.service.user.data.jpa.repositories;%0A%0Aimport org.apache.commons.lang3.RandomStringUtils;%0Aimport org.h2.jdbc.JdbcSQLException;%0Aimport org.hibernate.exception.ConstraintViolationException;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException;%0Aimport org.springframework.dao.DataIntegrityViolationException;%0Aimport sg.ncl.service.user.AbstractTest;%0Aimport sg.ncl.service.user.data.jpa.entities.AddressEntity;%0A%0Aimport javax.inject.Inject;%0A%0Aimport static org.hamcrest.Matchers.*;%0Aimport static org.junit.Assert.assertThat;%0A%0A/**%0A * @author Christopher Zhong%0A */%0Apublic class AddressRepositoryTest extends AbstractTest %7B%0A%0A    @Inject%0A    private AddressRepository repository;%0A%0A    @Rule%0A    public final ExpectedException exception = ExpectedException.none();%0A%0A    @Test%0A    public void testRepositoryExists() throws Exception %7B%0A        assertThat(repository, is(not(nullValue(AddressRepository.class))));%0A    %7D%0A%0A    @Test%0A    public void testGood() throws Exception %7B%0A        final AddressEntity entity = getAddressEntity();%0A%0A        final long count = repository.count();%0A        final AddressEntity persistedEntity = repository.save(entity);%0A        assertThat(persistedEntity.getId(), is(not(nullValue(Long.class))));%0A        assertThat(repository.count(), is(equalTo(count + 1)));%0A    %7D%0A%0A    @Test%0A    public void testNullAddress1() throws Exception %7B%0A        final AddressEntity entity = getAddressEntity();%0A        entity.setAddress1(null);%0A        try %7B%0A            repository.save(entity);%0A        %7D catch (Exception e) %7B%0A            checkException(e, %22NULL not allowed for column %5C%22ADDRESS_1%5C%22%22);%0A            return;%0A        %7D%0A        exception.expect(DataIntegrityViolationException.class);%0A    %7D%0A%0A    @Test%0A    public void testNullCountry() throws Exception %7B%0A        final AddressEntity entity = getAddressEntity();%0A        entity.setCountry(null);%0A        try %7B%0A            repository.save(entity);%0A        %7D catch (Exception e) %7B%0A            checkException(e, %22NULL not allowed for column %5C%22COUNTRY%5C%22%22);%0A            return;%0A        %7D%0A        exception.expect(DataIntegrityViolationException.class);%0A    %7D%0A%0A    @Test%0A    public void testNullZipCode() throws Exception %7B%0A        final AddressEntity entity = getAddressEntity();%0A        entity.setZipCode(null);%0A        try %7B%0A            repository.save(entity);%0A        %7D catch (Exception e) %7B%0A            checkException(e, %22NULL not allowed for column %5C%22ZIP_CODE%5C%22%22);%0A            return;%0A        %7D%0A        exception.expect(DataIntegrityViolationException.class);%0A    %7D%0A%0A    private void checkException(final Exception e, final String message) %7B%0A        assertThat(e, is(instanceOf(DataIntegrityViolationException.class)));%0A        assertThat(e.getCause(), is(instanceOf(ConstraintViolationException.class)));%0A        assertThat(e.getCause().getCause(), is(instanceOf(JdbcSQLException.class)));%0A        assertThat(e.getCause().getCause().getMessage(), containsString(message));%0A    %7D%0A%0A    public static AddressEntity getAddressEntity() %7B%0A        final AddressEntity address = new AddressEntity();%0A        address.setAddress1(RandomStringUtils.randomAlphanumeric(20));%0A        address.setAddress2(RandomStringUtils.randomAlphanumeric(20));%0A        address.setCountry(RandomStringUtils.randomAlphanumeric(20));%0A        address.setRegion(RandomStringUtils.randomAlphanumeric(20));%0A        address.setZipCode(RandomStringUtils.randomAlphanumeric(20));%0A        return address;%0A    %7D%0A%0A%7D

Add integration test for AddressRepository (DEV-100)