corrections to JPA Query Language syntax in ApprovedSite named queries, added test-context.xml, and added first unit test

pull/59/head
Michael Joseph Walsh 2012-01-26 15:36:27 -05:00
parent b9dc024086
commit adee03eb2a
3 changed files with 96 additions and 2 deletions

View File

@ -23,8 +23,8 @@ import org.mitre.oauth2.model.ClientDetailsEntity;
@Table(name="approvedsite")
@NamedQueries({
@NamedQuery(name = "ApprovedSite.getAll", query = "select a from ApprovedSite a"),
@NamedQuery(name = "ApprovedSite.getByUserInfo", query = "select a from ApprovedSite a if a.userInfo = :approvedSiteUserInfo"),
@NamedQuery(name = "ApprovedSite.getByClientDetails", query = "select a from approvedSite if a.clientDetails = :approvedSiteClientDetails")
@NamedQuery(name = "ApprovedSite.getByUserInfo", query = "select a from ApprovedSite a where a.userInfo = :approvedSiteUserInfo"),
@NamedQuery(name = "ApprovedSite.getByClientDetails", query = "select a from ApprovedSite a where a.clientDetails = :approvedSiteClientDetails")
})
public class ApprovedSite {

View File

@ -0,0 +1,56 @@
package org.mitre.openid.connect.repository;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mitre.openid.connect.model.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/application-context.xml", "classpath:test-context.xml"})
public class AddressRepositoryTest {
@Autowired
private AddressRepository repository;
@PersistenceContext
private EntityManager sharedManager;
@Before
public void setup() {
}
@Test
@Rollback
public void save_validNew() {
// See: http://openid.net/specs/openid-connect-basic-1_0.html#address_claim
Address newAddress = new Address();
newAddress.setStreetAddress("P.O. Box 517, 8158 Elementum Rd.");
newAddress.setLocality("Whittier");
newAddress.setRegion("YT");
newAddress.setPostalCode("U6Q 3F2");
newAddress.setCountry("Cyprus");
Address saved = repository.save(newAddress);
sharedManager.flush();
assertThat(saved, is(sameInstance(newAddress)));
assertThat(saved.getId(), not(nullValue()));
}
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" >
<!-- Creates an in-memory database populated with test jdbc -->
<bean id="dataSource" class="org.mitre.jdbc.datasource.H2DataSourceFactory">
<property name="databaseName" value="connect"/>
<property name="scriptLocations" >
<list>
<!-- OpenID Connect Data model -->
<value>file:src/main/webapp/db/tables/accesstoken.sql</value>
<value>file:src/main/webapp/db/tables/address.sql</value>
<value>file:src/main/webapp/db/tables/approvedsite.sql</value>
<value>file:src/main/webapp/db/tables/authorities.sql</value>
<value>file:src/main/webapp/db/tables/clientdetails.sql</value>
<value>file:src/main/webapp/db/tables/event.sql</value>
<value>file:src/main/webapp/db/tables/granttypes.sql</value>
<value>file:src/main/webapp/db/tables/idtoken.sql</value>
<value>file:src/main/webapp/db/tables/idtokenclaims.sql</value>
<value>file:src/main/webapp/db/tables/refreshtoken.sql</value>
<value>file:src/main/webapp/db/tables/scope.sql</value>
<value>file:src/main/webapp/db/tables/userinfo.sql</value>
<value>file:src/main/webapp/db/tables/whitelistedsite.sql</value>
<!-- Preloaded data -->
<!--
<value>classpath:test-data.sql</value>
// -->
</list>
</property>
<property name="dateConversionPatterns">
<map>
<entry key="yyyy/mm/dd hh24:mi:ss" value="yyy/MM/dd HH:mm:ss" />
<entry key="yyyy-mm-dd" value="yyyy-MM-dd" />
</map>
</property>
</bean>
</beans>