You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
4.3 KiB
110 lines
4.3 KiB
package de.superx.spring.jdbc.repositories; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
import static org.junit.Assert.assertNotNull; |
|
import static org.junit.Assert.assertTrue; |
|
|
|
import java.io.File; |
|
import java.sql.SQLException; |
|
|
|
import org.junit.Before; |
|
import org.junit.Test; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
import org.springframework.core.io.FileSystemResource; |
|
import org.springframework.jdbc.datasource.init.ScriptException; |
|
import org.springframework.jdbc.datasource.init.ScriptUtils; |
|
import org.springframework.test.context.ContextConfiguration; |
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
import com.fasterxml.jackson.databind.json.JsonMapper; |
|
|
|
import de.superx.BaseDbTest; |
|
import de.superx.TestApplicationConfigPg; |
|
import de.superx.jdbc.entity.kennx.Lieferfreigabe; |
|
import de.superx.jdbc.entity.kennx.LieferfreigabeStichtagsart; |
|
import de.superx.jdbc.repository.kennx.LieferfreigabeRepository; |
|
|
|
/** |
|
* Obsolet durch kennConfigApiTest. |
|
* Bei Wartungsaufwand können die Tests rausgenommen werden und es muss nur noch kennConfigApi gepflegt werden. |
|
* |
|
*/ |
|
@Transactional |
|
//@ContextConfiguration(classes = { TestApplicationConfigPg.class }) |
|
public class LieferfreigabeTest extends BaseDbTest { |
|
|
|
static String RW_TEST_PATH = String.join(File.separator, new String[] {"test", "resources", "db", "fixtures", "kennx" }); |
|
|
|
@Autowired |
|
private LieferfreigabeRepository repo; |
|
|
|
private static String kennx_tables = String.join(File.separator, new String[] {"test", "resources", "db", "fixtures", "kennx", "create_kennx_tables.sql" }); |
|
|
|
|
|
@Before |
|
public void createSchema() throws ScriptException, SQLException { |
|
ScriptUtils.executeSqlScript(dataSource.getConnection(), new FileSystemResource(new File(kennx_tables))); |
|
} |
|
|
|
|
|
@Test |
|
public void testCreateLieferfreigabe() { |
|
Lieferfreigabe l = new Lieferfreigabe(); |
|
l = repo.save(l); |
|
Integer id = l.tid; |
|
assertNotNull("id is generated", id); |
|
} |
|
|
|
@Test |
|
public void testCreateLieferfreigabeHochschulerfolgsbericht() { |
|
String file = "lieferfreigabeHochschulerfolgsbericht"; |
|
Lieferfreigabe lieferfreigabe = readStoredReportFromJson(file); |
|
int numberOfStichtagsarten = lieferfreigabe.lieferfreigabeStichtagsart.size(); |
|
lieferfreigabe = repo.save(lieferfreigabe); |
|
Integer id = lieferfreigabe.tid; |
|
int n = repo.countHsForLieferfreigabe(lieferfreigabe.tid.intValue()); |
|
assertNotNull("id is generated", id); |
|
assertEquals("Count hs", 1, n); |
|
n = repo.countForStichtagsarten(lieferfreigabe.tid.intValue()); |
|
assertEquals("Count Stichtagsarten", numberOfStichtagsarten, n); |
|
for(LieferfreigabeStichtagsart stichtagsart : lieferfreigabe.lieferfreigabeStichtagsart) { |
|
n = repo.countForBezugszeiten(stichtagsart.tid.intValue()); |
|
assertTrue("", n >= 1); |
|
assertTrue("", n <= 4); |
|
} |
|
} |
|
|
|
|
|
@Test |
|
public void testDeleteLieferfreigabe() { |
|
String file = "lieferfreigabeHochschulerfolgsbericht"; |
|
Lieferfreigabe lieferfreigabe = readStoredReportFromJson(file); |
|
lieferfreigabe = repo.save(lieferfreigabe); |
|
Integer id = lieferfreigabe.tid; |
|
repo.deleteById(id); |
|
int n = repo.countHsForLieferfreigabe(id.intValue()); |
|
assertEquals("Count hs", 0, n); |
|
n = repo.countForStichtagsarten(id.intValue()); |
|
assertEquals("Count Stichtagsarten", 0, n); |
|
for(LieferfreigabeStichtagsart stichtagsart : lieferfreigabe.lieferfreigabeStichtagsart) { |
|
n = repo.countForBezugszeiten(stichtagsart.tid.intValue()); |
|
assertEquals("Count Bezugszeiten", 0, n); |
|
} |
|
} |
|
|
|
|
|
public static Lieferfreigabe readStoredReportFromJson(String name) { |
|
String path = String.join(File.separator, new String[] {RW_TEST_PATH, "req", name + ".json"}); |
|
ObjectMapper mapper = JsonMapper.builder().findAndAddModules().build(); |
|
Lieferfreigabe lieferfreigabe = null; |
|
File test = new File (path); |
|
try { |
|
lieferfreigabe = mapper.readValue(test, Lieferfreigabe.class); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
} |
|
return lieferfreigabe; |
|
} |
|
|
|
}
|
|
|