added more unit tests to AddressRespositoryTest
parent
adee03eb2a
commit
4924d6c78c
|
@ -1,5 +1,6 @@
|
||||||
package org.mitre.openid.connect.repository;
|
package org.mitre.openid.connect.repository;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
|
@ -30,9 +31,41 @@ public class AddressRepositoryTest {
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager sharedManager;
|
private EntityManager sharedManager;
|
||||||
|
|
||||||
|
private Address address1;
|
||||||
|
private Address address2;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
//Use existing test-data.sql
|
||||||
|
address1 = new Address();
|
||||||
|
address1.setId(1L);
|
||||||
|
// too lazy to create formatted...
|
||||||
|
address1.setStreetAddress("7443 Et Road");
|
||||||
|
address1.setLocality("Pass Christian");
|
||||||
|
address1.setRegion("ID");
|
||||||
|
address1.setPostalCode("16183");
|
||||||
|
address1.setCountry("Jordan");
|
||||||
|
|
||||||
|
address2 = new Address();
|
||||||
|
address2.setId(2L);
|
||||||
|
address2.setStreetAddress("P.O. Box 893, 2523 Felis Rd.");
|
||||||
|
address2.setLocality("New Kensington");
|
||||||
|
address2.setRegion("NT");
|
||||||
|
address2.setPostalCode("I5V 3Z7");
|
||||||
|
address2.setCountry("Israel");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getById_valid() {
|
||||||
|
Address retrieved = repository.getById(1L);
|
||||||
|
assertThat(retrieved, is(not(nullValue())));
|
||||||
|
assertThat(retrieved.getId(), equalTo(address1.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getById_invalid() {
|
||||||
|
Address nullAddress = repository.getById(42L);
|
||||||
|
assertThat(nullAddress, is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -53,4 +86,52 @@ public class AddressRepositoryTest {
|
||||||
assertThat(saved.getId(), not(nullValue()));
|
assertThat(saved.getId(), not(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Rollback
|
||||||
|
public void save_validExisting() {
|
||||||
|
address1.setStreetAddress("A New address");
|
||||||
|
|
||||||
|
Address saved = repository.save(address1);
|
||||||
|
|
||||||
|
assertThat(saved, not(nullValue()));
|
||||||
|
assertThat(saved.getId(), equalTo(address1.getId()));
|
||||||
|
assertThat(saved.getStreetAddress(), equalTo(address1.getStreetAddress()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Rollback
|
||||||
|
public void remove_valid() {
|
||||||
|
|
||||||
|
Address managed = repository.getById((address1.getId()));
|
||||||
|
|
||||||
|
repository.remove(managed);
|
||||||
|
|
||||||
|
Address nullAddress = repository.getById(address1.getId());
|
||||||
|
|
||||||
|
assertThat(nullAddress, is(nullValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void remove_invalid() {
|
||||||
|
Address doesNotExist = new Address();
|
||||||
|
doesNotExist.setId(42L);
|
||||||
|
|
||||||
|
repository.remove(doesNotExist);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Rollback
|
||||||
|
public void removeById_valid() {
|
||||||
|
repository.removeById(address1.getId());
|
||||||
|
|
||||||
|
Address nullagg = repository.getById(address1.getId());
|
||||||
|
|
||||||
|
assertThat(nullagg, is(nullValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void removeById_invalid() {
|
||||||
|
|
||||||
|
repository.removeById(42L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,7 @@
|
||||||
<value>file:src/main/webapp/db/tables/userinfo.sql</value>
|
<value>file:src/main/webapp/db/tables/userinfo.sql</value>
|
||||||
<value>file:src/main/webapp/db/tables/whitelistedsite.sql</value>
|
<value>file:src/main/webapp/db/tables/whitelistedsite.sql</value>
|
||||||
<!-- Preloaded data -->
|
<!-- Preloaded data -->
|
||||||
<!--
|
|
||||||
<value>classpath:test-data.sql</value>
|
<value>classpath:test-data.sql</value>
|
||||||
// -->
|
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
<property name="dateConversionPatterns">
|
<property name="dateConversionPatterns">
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO ADDRESS (id, streetAddress, locality, region, postalCode, country) VALUES (1, '7443 Et Road', 'Pass Christian', 'ID', '16183', 'Jordan' );
|
||||||
|
INSERT INTO ADDRESS (id, streetAddress, locality, region, postalCode, country) VALUES (2, 'P.O. Box 893, 2523 Felis Rd.', 'New Kensington', 'NT', 'I5V 3Z7', 'Israel' );
|
||||||
|
INSERT INTO ADDRESS (id, streetAddress, locality, region, postalCode, country) VALUES (3, '1972 Non Rd.', 'Pulaski', 'NL', '83301', 'Western Sahara' );
|
||||||
|
|
Loading…
Reference in New Issue