Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Changelog.md
Expand Up @@ -13,4 +13,6 @@

## autorisationimporter 4.4
* Opgrading til sdm4-core 4.3, der løser
NSPSUPPORT-126: ParserExecutor logger filers absolutte stier og md5-summer inden parser behandler dem
NSPSUPPORT-126: ParserExecutor logger filers absolutte stier og md5-summer inden parser behandler dem
* Opgraderet til sdm-core 4.9 for at kunne resette transaction time
* SDM-23: Reset transaction time før hver import
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>dk.nsi.stamdata4</groupId>
<artifactId>sdm-core</artifactId>
<version>4.3-SNAPSHOT</version>
<version>4.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
Expand Down Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>dk.nsi.stamdata4</groupId>
<artifactId>testutils</artifactId>
<version>4.1</version>
<version>4.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -78,6 +78,9 @@ public void process(File dataset) throws ParserException {
throw new ParserException("Data directory " + dataset.getAbsolutePath() + " contains " + files.length + " files, but expected exactly one");
}

// Make sure we update transaction time
persister.resetTransactionTime();

SLALogItem slaLogItem = slaLogger.createLogItem("AutorisationImporter", "All Files");

try {
Expand Down
101 changes: 101 additions & 0 deletions src/test/java/dk/nsi/sdm4/autorisation/AutorisationImportTest.java
@@ -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));
}

}
@@ -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();
}
}

0 comments on commit d374b38

Please sign in to comment.