additional work on repositories, and services w/ unit tests
parent
5f2a64517c
commit
5ce3140bf2
Binary file not shown.
|
@ -0,0 +1,103 @@
|
|||
01-27 12:14:22 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Invalid value "null" for parameter "SQL" [90008-154]
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
|
||||
at org.h2.message.DbException.get(DbException.java:167)
|
||||
at org.h2.message.DbException.getInvalidValueException(DbException.java:213)
|
||||
at org.h2.jdbc.JdbcConnection.translateSQL(JdbcConnection.java:1189)
|
||||
at org.h2.jdbc.JdbcStatement.executeQuery(JdbcStatement.java:69)
|
||||
at org.mitre.jdbc.datasource.H2DataSourceFactory.executeQuery(H2DataSourceFactory.java:271)
|
||||
at org.mitre.jdbc.datasource.H2DataSourceFactory.testExecuteScriptQuery(H2DataSourceFactory.java:250)
|
||||
at org.mitre.jdbc.datasource.H2DataSourceFactory.populateDataSourceIfNecessary(H2DataSourceFactory.java:215)
|
||||
at org.mitre.jdbc.datasource.H2DataSourceFactory.initializeDataSource(H2DataSourceFactory.java:192)
|
||||
at org.mitre.jdbc.datasource.H2DataSourceFactory.getDataSource(H2DataSourceFactory.java:170)
|
||||
at org.mitre.jdbc.datasource.H2DataSourceFactory.getObject(H2DataSourceFactory.java:152)
|
||||
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
|
||||
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1441)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:248)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
|
||||
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
|
||||
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
|
||||
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
|
||||
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
|
||||
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
|
||||
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
|
||||
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
|
||||
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
|
||||
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
|
||||
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
|
||||
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
|
||||
at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
|
||||
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
|
||||
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
|
||||
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
|
||||
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
|
||||
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
|
||||
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
|
||||
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
|
||||
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
|
||||
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
|
||||
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
|
||||
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
|
||||
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
|
||||
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
|
||||
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
|
||||
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
|
||||
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
|
||||
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
|
||||
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
|
||||
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
|
||||
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
|
||||
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
|
||||
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
|
||||
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
|
||||
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
||||
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
||||
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
||||
at java.lang.reflect.Method.invoke(Method.java:597)
|
||||
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
|
||||
at $Proxy0.invoke(Unknown Source)
|
||||
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
|
||||
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
|
||||
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
|
||||
01-27 12:14:23 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:23 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:23 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
INSERT INTO ADDRESS (COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS) VALUES (?, ?, ?, ?, ?, ?) [42102-154]
|
||||
01-27 12:14:23 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:23 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:24 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:24 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:24 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "ADDRESS" not found; SQL statement:
|
||||
SELECT ID, COUNTRY, FORMATTED, LOCALITY, POSTALCODE, REGION, STREETADDRESS FROM ADDRESS WHERE (ID = ?) [42102-154]
|
||||
01-27 12:14:24 jdbc[2]: exception
|
||||
org.h2.jdbc.JdbcSQLException: Table "EVENT" not found; SQL statement:
|
||||
SELECT ID, TIMESTAMP, TYPE FROM event WHERE (ID = ?) [42102-154]
|
|
@ -253,6 +253,7 @@ public class H2DataSourceFactory implements FactoryBean {
|
|||
result = e.getMessage().toLowerCase().matches("table \".*\" not found.*\n*.*");
|
||||
}
|
||||
logger.debug("Executed query " + executeScriptQuery + " with result " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -269,6 +270,7 @@ public class H2DataSourceFactory implements FactoryBean {
|
|||
protected static ResultSet executeQuery(Connection conn, String executeScriptQuery) throws SQLException {
|
||||
Statement statement = conn.createStatement();
|
||||
return statement.executeQuery(executeScriptQuery);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,6 +76,10 @@ public class SqlFileParser {
|
|||
stateStack.push(State.INIT);
|
||||
processFile(resourceFile, sql);
|
||||
stateStack.pop();
|
||||
|
||||
//System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
|
||||
//System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>> SQL:: " + sql);
|
||||
//System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
|
||||
/**
|
||||
* Event repository interface
|
||||
*
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface EventRepository {
|
||||
|
||||
|
@ -19,6 +22,22 @@ public interface EventRepository {
|
|||
*/
|
||||
public Event getById(Long id);
|
||||
|
||||
/**
|
||||
* Returns the Events for a given Date range
|
||||
*
|
||||
* @param start
|
||||
* the Date to start from
|
||||
* @param end
|
||||
* the Date to end at
|
||||
* @param startChunk
|
||||
* the start chuck of a list you desire
|
||||
* @param chunkSize
|
||||
* the size of the chunk you desire
|
||||
*
|
||||
* @return a Collection of Events
|
||||
*/
|
||||
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize);
|
||||
|
||||
/**
|
||||
* Removes the given Event from the repository
|
||||
*
|
||||
|
@ -43,4 +62,5 @@ public interface EventRepository {
|
|||
* @return
|
||||
*/
|
||||
public Event save(Event event);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@ package org.mitre.openid.connect.repository.impl;
|
|||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
import org.mitre.openid.connect.repository.EventRepository;
|
||||
|
@ -28,6 +33,21 @@ public class JpaEventRepository implements EventRepository {
|
|||
return manager.find(Event.class, id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize) {
|
||||
|
||||
Query query = manager.createQuery("SELECT e FROM Event e WHERE e.timestamp BETWEEN :start AND :end");
|
||||
|
||||
query = query.setParameter("start", start, TemporalType.DATE);
|
||||
query = query.setParameter("end", end, TemporalType.DATE);
|
||||
query = query.setFirstResult(startChunk);
|
||||
query = query.setMaxResults(chunkSize);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(Event event) {
|
||||
|
@ -53,4 +73,5 @@ public class JpaEventRepository implements EventRepository {
|
|||
public Event save(Event event) {
|
||||
return saveOrUpdate(event.getId(), manager, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.mitre.openid.connect.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
|
||||
/**
|
||||
|
@ -9,14 +12,21 @@ import org.mitre.openid.connect.model.Event;
|
|||
*
|
||||
*/
|
||||
public interface EventService {
|
||||
|
||||
/**
|
||||
* Save Event
|
||||
* Returns the Events for a given Date range
|
||||
*
|
||||
* @param event
|
||||
* Event to be saved
|
||||
* @param start
|
||||
* the Date to start from
|
||||
* @param end
|
||||
* the Date to end at
|
||||
* @param startChunk
|
||||
* the start chuck of a list you desire
|
||||
* @param chunkSize
|
||||
* the size of the chunk you desire
|
||||
*
|
||||
* @return a Collection of Events
|
||||
*/
|
||||
public void save(Event event);
|
||||
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize);
|
||||
|
||||
/**
|
||||
* Get Event by id
|
||||
|
@ -42,4 +52,12 @@ public interface EventService {
|
|||
* id for Event to remove
|
||||
*/
|
||||
public void removeById(Long id);
|
||||
|
||||
/**
|
||||
* Save Event
|
||||
*
|
||||
* @param event
|
||||
* Event to be saved
|
||||
*/
|
||||
public void save(Event event);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.mitre.openid.connect.service.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mitre.openid.connect.model.Event;
|
||||
import org.mitre.openid.connect.repository.EventRepository;
|
||||
import org.mitre.openid.connect.service.EventService;
|
||||
|
@ -37,10 +40,12 @@ public class EventServiceImpl implements EventService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void save(Event event) {
|
||||
eventRepository.save(event);
|
||||
}
|
||||
public Collection<Event> getEventsDuringPeriod(Date start, Date end,
|
||||
int startChunk, int chunkSize) {
|
||||
|
||||
return eventRepository.getEventsDuringPeriod(start, end, startChunk, chunkSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event getById(Long id) {
|
||||
return eventRepository.getById(id);
|
||||
|
@ -56,4 +61,9 @@ public class EventServiceImpl implements EventService {
|
|||
eventRepository.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Event event) {
|
||||
eventRepository.save(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,12 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* AddressRepository unit test
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/application-context.xml", "classpath:test-context.xml"})
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
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 static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.Event;
|
||||
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;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* EventRepository unit test
|
||||
*
|
||||
* @author Michael Joseph Walsh
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/application-context.xml", "classpath:test-context.xml"})
|
||||
public class EventRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
private EventRepository repository;
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager sharedManager;
|
||||
|
||||
private Event event1;
|
||||
private Event event2;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
//Use existing test-data.sql
|
||||
event1 = new Event();
|
||||
event1.setId(1L);
|
||||
event1.setType(Event.EventType.LOGIN);
|
||||
event1.setTimestamp(new Date(86400000*5)); // 1 day = 86 400 000 milliseconds
|
||||
|
||||
event2 = new Event();
|
||||
event2.setId(2L);
|
||||
event2.setType(Event.EventType.AUTHORIZATION);
|
||||
event2.setTimestamp(new Date(86400000*10));
|
||||
|
||||
//repository.save(event1);
|
||||
//repository.save(event2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getById_valid() {
|
||||
Event retrieved = repository.getById(1L);
|
||||
assertThat(retrieved, is(not(nullValue())));
|
||||
assertThat(retrieved.getId(), equalTo(event1.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getById_invalid() {
|
||||
Event nullAddress = repository.getById(42L);
|
||||
assertThat(nullAddress, is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEventsDuringPeriod() {
|
||||
List<Event> allEvents = Lists.newArrayList(event1, event2);
|
||||
|
||||
List<Event> retrieved = (List<Event>) repository.getEventsDuringPeriod(new Date(0L), new Date(86400000*11), 0, 10);
|
||||
|
||||
if (allEvents.size() != retrieved.size()) {
|
||||
fail("Retrieved and expected are not of equal size!");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
public void save_validNew() {
|
||||
|
||||
Event newEvent = new Event();
|
||||
newEvent.setType(Event.EventType.LOGIN);
|
||||
newEvent.setTimestamp(new Date());
|
||||
|
||||
Event saved = repository.save(newEvent);
|
||||
sharedManager.flush();
|
||||
|
||||
assertThat(saved, is(sameInstance(newEvent)));
|
||||
assertThat(saved.getId(), not(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
public void save_validExisting() {
|
||||
event1.setType(Event.EventType.ACCESS);
|
||||
|
||||
Event saved = repository.save(event1);
|
||||
|
||||
assertThat(saved, not(nullValue()));
|
||||
assertThat(saved.getId(), equalTo(event1.getId()));
|
||||
assertThat(saved.getType(), equalTo(event1.getType()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
public void remove_valid() {
|
||||
|
||||
Event managed = repository.getById((event1.getId()));
|
||||
|
||||
repository.remove(managed);
|
||||
|
||||
Event nullAddress = repository.getById(event1.getId());
|
||||
|
||||
assertThat(nullAddress, is(nullValue()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void remove_invalid() {
|
||||
Event doesNotExist = new Event();
|
||||
doesNotExist.setId(42L);
|
||||
|
||||
repository.remove(doesNotExist);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback
|
||||
public void removeById_valid() {
|
||||
repository.removeById(event1.getId());
|
||||
|
||||
Event nullagg = repository.getById(event1.getId());
|
||||
|
||||
assertThat(nullagg, is(nullValue()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void removeById_invalid() {
|
||||
|
||||
repository.removeById(42L);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
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' );
|
||||
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 event (ID, TIMESTAMP, TYPE) VALUES (1, '1970-01-05 19:00:00.0', 0);
|
||||
INSERT INTO event (ID, TIMESTAMP, TYPE) VALUES (2, '1970-01-10 19:00:00.0', 1);
|
Loading…
Reference in New Issue