Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
SDM-23: Reset transaction time før hver import
- Loading branch information
Kaspar Pedersen
committed
Apr 3, 2013
1 parent
16fd004
commit d374b38
Showing
5 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/test/java/dk/nsi/sdm4/autorisation/AutorisationImportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* The MIT License | ||
* | ||
* Original work sponsored and donated by National Board of e-Health (NSI), Denmark | ||
* (http://www.nsi.dk) | ||
* | ||
* Copyright (C) 2011 National Board of e-Health (NSI), Denmark (http://www.nsi.dk) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
* of the Software, and to permit persons to whom the Software is furnished to do | ||
* so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package dk.nsi.sdm4.autorisation; | ||
|
||
import dk.nsi.sdm4.core.parser.Parser; | ||
import dk.nsi.sdm4.testutils.TestDbConfiguration; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.Timestamp; | ||
import java.util.Date; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertFalse; | ||
import static org.apache.commons.io.FileUtils.toFile; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@Transactional | ||
@ContextConfiguration(classes = {AutorisationParserTestConfig.class, TestDbConfiguration.class}) | ||
public class AutorisationImportTest { | ||
|
||
@Rule | ||
public TemporaryFolder temp = new TemporaryFolder(); | ||
|
||
@Autowired | ||
private Parser parser; | ||
|
||
@Autowired | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Test | ||
public void testCanImport() throws IOException, InterruptedException { | ||
File dataset = createTestDataset("data/aut/valid/20090915AutDK.csv"); | ||
parser.process(dataset); | ||
long cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation"); | ||
assertEquals(4, cnt); | ||
Thread.sleep(1000); | ||
|
||
Date now = new Date(); | ||
Timestamp modifiedDate1 = | ||
jdbcTemplate.queryForObject("SELECT ModifiedDate FROM Autorisation LIMIT 1", Timestamp.class); | ||
|
||
// Import another file and check validTo is set correctly and modified date is updated | ||
dataset = createTestDataset("data/aut/valid/20090918AutDK.csv"); | ||
parser.process(dataset); | ||
cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation"); | ||
assertEquals(6, cnt); | ||
cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation WHERE ValidTo>=?", new Timestamp(now.getTime())); | ||
assertEquals(5, cnt); | ||
|
||
Timestamp modifiedDate2 = | ||
jdbcTemplate.queryForObject("SELECT ModifiedDate FROM Autorisation ORDER BY ModifiedDate DESC LIMIT 1", Timestamp.class); | ||
|
||
assertFalse(modifiedDate1.equals(modifiedDate2)); | ||
} | ||
|
||
private File createTestDataset(String filename) throws IOException { | ||
File dataset = temp.newFolder(); | ||
FileUtils.copyFileToDirectory(getFile(filename), dataset); | ||
return dataset; | ||
} | ||
|
||
private File getFile(String filename) { | ||
return toFile(getClass().getClassLoader().getResource(filename)); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/dk/nsi/sdm4/autorisation/AutorisationParserTestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dk.nsi.sdm4.autorisation; | ||
|
||
import dk.nsi.sdm4.autorisation.parser.AutorisationParser; | ||
import dk.nsi.sdm4.core.parser.Parser; | ||
import dk.nsi.sdm4.core.persistence.AuditingPersister; | ||
import dk.nsi.sdm4.core.persistence.Persister; | ||
import dk.sdsd.nsp.slalog.api.SLALogger; | ||
import dk.sdsd.nsp.slalog.impl.SLALoggerDummyImpl; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; | ||
|
||
@Configuration | ||
@PropertySource({"classpath:test.properties"}) | ||
public class AutorisationParserTestConfig { | ||
|
||
@Bean | ||
public Parser parser() { | ||
return new AutorisationParser(); | ||
} | ||
|
||
@Bean | ||
public Persister persister() { | ||
return new AuditingPersister(); | ||
} | ||
|
||
@Bean | ||
public SLALogger slaLogger() { | ||
return new SLALoggerDummyImpl(); | ||
} | ||
|
||
@Bean | ||
public static PropertySourcesPlaceholderConfigurer properties(){ | ||
return new PropertySourcesPlaceholderConfigurer(); | ||
} | ||
} |