import sources from develop/0.1.0
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.ibtp.kontor.comics;
|
||||
|
||||
import com.ibtp.kontor.comics.dal.PublisherImpl;
|
||||
import com.ibtp.kontor.comics.entity.PublisherEntity;
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 27.01.2015.
|
||||
*/
|
||||
public class CollectionTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
PublisherImpl publisherImpl = new PublisherImpl();
|
||||
Collection<PublisherEntity> publisherEntities = publisherImpl.findAll();
|
||||
for (Iterator<PublisherEntity> iterator = publisherEntities.iterator(); iterator.hasNext(); ) {
|
||||
PublisherEntity next = iterator.next();
|
||||
publisherImpl.delete(next);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddPublishers() {
|
||||
String publisherName = "Bongo Comics";
|
||||
PublisherImpl publisherImpl = new PublisherImpl();
|
||||
publisherImpl.addPublisher("Bongo Comics");
|
||||
publisherImpl.addPublisher("Marvel");
|
||||
Collection<PublisherEntity> publisherList = publisherImpl.findAll();
|
||||
Assert.assertEquals(2, publisherList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.ibtp.kontor.comics.dal;
|
||||
|
||||
import com.ibtp.kontor.comics.entity.ArtistEntity;
|
||||
import com.ibtp.kontor.dal.*;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ArtistImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArtistAddAndDelete() {
|
||||
String artistName = "testArtistAddAndDelete";
|
||||
ArtistImpl artistImpl = new ArtistImpl();
|
||||
artistImpl.addArtist(artistName);
|
||||
Collection<ArtistEntity> resultList = artistImpl.findByName(artistName);
|
||||
Assert.assertNotNull(resultList);
|
||||
Assert.assertTrue(resultList.size() > 0);
|
||||
ArtistEntity artist = (ArtistEntity)(resultList.toArray()[0]);
|
||||
artistImpl.delete(artist);
|
||||
resultList = artistImpl.findByName(artistName);
|
||||
Assert.assertNotNull(resultList);
|
||||
Assert.assertEquals(0, resultList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArtistFindAll() {
|
||||
ArtistImpl artistImpl = new ArtistImpl();
|
||||
Collection<ArtistEntity> artistList = artistImpl.findAll();
|
||||
Assert.assertNotNull(artistList);
|
||||
Assert.assertEquals(0, artistList.size());
|
||||
artistImpl.addArtist("testArtistFindAll1");
|
||||
artistImpl.addArtist("testArtistFindAll2");
|
||||
artistImpl.addArtist("testArtistFindAll3");
|
||||
artistList = artistImpl.findAll();
|
||||
Assert.assertNotNull(artistList);
|
||||
Assert.assertEquals(3, artistList.size());
|
||||
for (Iterator<ArtistEntity> iterator = artistList.iterator(); iterator.hasNext(); ) {
|
||||
ArtistEntity next = iterator.next();
|
||||
artistImpl.delete(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.ibtp.kontor.comics.dal;
|
||||
|
||||
import com.ibtp.kontor.comics.entity.ComicEntity;
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 28.01.2015.
|
||||
*/
|
||||
public class ComicImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComicAddAndDelete() {
|
||||
String comicTitle = "Comic1";
|
||||
ComicImpl comicImpl = new ComicImpl();
|
||||
comicImpl.addComic(comicTitle);
|
||||
Collection<ComicEntity> comicList = comicImpl.findByTitle(comicTitle);
|
||||
Assert.assertNotNull(comicList);
|
||||
Assert.assertEquals(1, comicList.size());
|
||||
comicImpl.delete((ComicEntity) comicList.toArray()[0]);
|
||||
comicList = comicImpl.findByTitle(comicTitle);
|
||||
Assert.assertNotNull(comicList);
|
||||
Assert.assertEquals(0, comicList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComicFindAll() {
|
||||
ComicImpl comicImpl = new ComicImpl();
|
||||
comicImpl.addComic("Comic1");
|
||||
comicImpl.addComic("Comic2");
|
||||
comicImpl.addComic("Comic3");
|
||||
Collection<ComicEntity> comicList = comicImpl.findAll();
|
||||
Assert.assertNotNull(comicList);
|
||||
Assert.assertEquals(3, comicList.size());
|
||||
for (Iterator<ComicEntity> iterator = comicList.iterator(); iterator.hasNext(); ) {
|
||||
ComicEntity next = iterator.next();
|
||||
comicImpl.delete(next);
|
||||
}
|
||||
comicList = comicImpl.findAll();
|
||||
Assert.assertNotNull(comicList);
|
||||
Assert.assertEquals(0, comicList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.ibtp.kontor.comics.dal;
|
||||
|
||||
import com.ibtp.kontor.comics.entity.IssueEntity;
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 28.01.2015.
|
||||
*/
|
||||
public class IssueImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssueAddAndDelete() {
|
||||
String issueNumber = "42";
|
||||
IssueImpl issueImpl = new IssueImpl();
|
||||
IssueEntity issue = new IssueEntity();
|
||||
issue.setNumber(issueNumber);
|
||||
issueImpl.store(issue);
|
||||
Collection<IssueEntity> issueList = issueImpl.findByNumber(issueNumber);
|
||||
Assert.assertNotNull(issueList);
|
||||
Assert.assertEquals(1, issueList.size());
|
||||
issueImpl.delete(issue);
|
||||
issueList = issueImpl.findByNumber(issueNumber);
|
||||
Assert.assertNotNull(issueList);
|
||||
Assert.assertEquals(0, issueList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssueFindAll() {
|
||||
IssueImpl issueImpl = new IssueImpl();
|
||||
IssueEntity issue1 = new IssueEntity();
|
||||
issue1.setNumber("issue1");
|
||||
IssueEntity issue2 = new IssueEntity();
|
||||
issue1.setNumber("issue2");
|
||||
IssueEntity issue3 = new IssueEntity();
|
||||
issue1.setNumber("issue3");
|
||||
issueImpl.store(issue1);
|
||||
issueImpl.store(issue2);
|
||||
issueImpl.store(issue3);
|
||||
Collection<IssueEntity> issueList = issueImpl.findAll();
|
||||
Assert.assertNotNull(issueList);
|
||||
Assert.assertEquals(3, issueList.size());
|
||||
for (Iterator<IssueEntity> iterator = issueList.iterator(); iterator.hasNext(); ) {
|
||||
IssueEntity next = iterator.next();
|
||||
issueImpl.delete(next);
|
||||
}
|
||||
issueList = issueImpl.findAll();
|
||||
Assert.assertNotNull(issueList);
|
||||
Assert.assertEquals(0, issueList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.ibtp.kontor.comics.dal;
|
||||
|
||||
import com.ibtp.kontor.comics.entity.PublisherEntity;
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 20.01.2015.
|
||||
*/
|
||||
public class PublisherImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublisherAddAndDelete() {
|
||||
String publisherName = "testPublisherAddAndDelete";
|
||||
PublisherImpl publisherImpl = new PublisherImpl();
|
||||
PublisherEntity publisher = publisherImpl.addPublisher(publisherName);
|
||||
Collection<PublisherEntity> publisherList = publisherImpl.findByName(publisherName);
|
||||
Assert.assertEquals(1, publisherList.size());
|
||||
publisherImpl.delete(publisher);
|
||||
publisherList = publisherImpl.findByName(publisherName);
|
||||
Assert.assertEquals(0, publisherList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublisherFindAll() {
|
||||
PublisherImpl publisherImpl = new PublisherImpl();
|
||||
publisherImpl.addPublisher("testDeletePublisher1");
|
||||
publisherImpl.addPublisher("testDeletePublisher2");
|
||||
publisherImpl.addPublisher("testDeletePublisher3");
|
||||
Collection<PublisherEntity> publisherList = publisherImpl.findAll();
|
||||
Assert.assertEquals(3, publisherList.size());
|
||||
for (Iterator<PublisherEntity> iterator = publisherList.iterator(); iterator.hasNext(); ) {
|
||||
PublisherEntity next = iterator.next();
|
||||
publisherImpl.delete(next);
|
||||
}
|
||||
publisherList = publisherImpl.findAll();
|
||||
Assert.assertEquals(0, publisherList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ibtp.kontor.comics.dal;
|
||||
|
||||
import com.ibtp.kontor.comics.entity.StoryArcEntity;
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 28.01.2015.
|
||||
*/
|
||||
public class StoryArcImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoryArcAddAndDelete() {
|
||||
String storyArcTtitle = "testStoryArcAddAndDelete";
|
||||
StoryArcImpl storyArcImpl = new StoryArcImpl();
|
||||
StoryArcEntity storyArc = new StoryArcEntity();
|
||||
storyArc.setTitle(storyArcTtitle);
|
||||
storyArcImpl.store(storyArc);
|
||||
Collection<StoryArcEntity> storyArcEntityCollection = storyArcImpl.findByTitle(storyArcTtitle);
|
||||
Assert.assertNotNull(storyArcEntityCollection);
|
||||
Assert.assertEquals(1, storyArcEntityCollection.size());
|
||||
storyArcImpl.delete(storyArc);
|
||||
storyArcEntityCollection = storyArcImpl.findByTitle(storyArcTtitle);
|
||||
Assert.assertNotNull(storyArcEntityCollection);
|
||||
Assert.assertEquals(0, storyArcEntityCollection.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoryArcFindAll() {
|
||||
StoryArcImpl storyArcImpl = new StoryArcImpl();
|
||||
StoryArcEntity storyArc;
|
||||
storyArc = new StoryArcEntity();
|
||||
storyArc.setTitle("testStoryArcFindAll1");
|
||||
storyArcImpl.store(storyArc);
|
||||
storyArc = new StoryArcEntity();
|
||||
storyArc.setTitle("testStoryArcFindAll2");
|
||||
storyArcImpl.store(storyArc);
|
||||
storyArc = new StoryArcEntity();
|
||||
storyArc.setTitle("testStoryArcFindAll3");
|
||||
storyArcImpl.store(storyArc);
|
||||
Collection<StoryArcEntity> storyArcEntityCollection = storyArcImpl.findAll();
|
||||
Assert.assertNotNull(storyArcEntityCollection);
|
||||
Assert.assertEquals(3, storyArcEntityCollection.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.ibtp.kontor.comics.dal;
|
||||
|
||||
import com.ibtp.kontor.comics.entity.VolumeEntity;
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 28.01.2015.
|
||||
*/
|
||||
public class VolumeImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVolumeAddAndDelete() {
|
||||
String volumeTitle = "testVolumeAddAndDelete";
|
||||
VolumeImpl volumeImpl = new VolumeImpl();
|
||||
VolumeEntity volume = new VolumeEntity();
|
||||
volume.setTitle(volumeTitle);
|
||||
VolumeEntity volumeEntity = volumeImpl.store(volume);
|
||||
Assert.assertNotNull(volumeEntity);
|
||||
Assert.assertEquals(volumeTitle, volumeEntity.getTitle());
|
||||
Collection<VolumeEntity> volumeList = volumeImpl.findByTitle(volumeTitle);
|
||||
Assert.assertNotNull(volumeList);
|
||||
Assert.assertEquals(1, volumeList.size());
|
||||
VolumeEntity result = (VolumeEntity)volumeList.toArray()[0];
|
||||
Assert.assertEquals(volume, result);
|
||||
volumeImpl.delete(result);
|
||||
volumeList = volumeImpl.findByTitle(volumeTitle);
|
||||
Assert.assertEquals(0, volumeList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVolumeFindAll() {
|
||||
VolumeImpl volumeImpl = new VolumeImpl();
|
||||
VolumeEntity volume;
|
||||
volume = new VolumeEntity();
|
||||
volume.setTitle("testVolumeFindAll1");
|
||||
volumeImpl.store(volume);
|
||||
volume = new VolumeEntity();
|
||||
volume.setTitle("testVolumeFindAll2");
|
||||
volumeImpl.store(volume);
|
||||
volume = new VolumeEntity();
|
||||
volume.setTitle("testVolumeFindAll3");
|
||||
volumeImpl.store(volume);
|
||||
Collection<VolumeEntity> volumeList = volumeImpl.findAll();
|
||||
Assert.assertNotNull(volumeList);
|
||||
Assert.assertEquals(3, volumeList.size());
|
||||
for (Iterator<VolumeEntity> iterator = volumeList.iterator(); iterator.hasNext(); ) {
|
||||
VolumeEntity next = iterator.next();
|
||||
volumeImpl.delete(next);
|
||||
}
|
||||
volumeList = volumeImpl.findAll();
|
||||
Assert.assertNotNull(volumeList);
|
||||
Assert.assertEquals(0, volumeList.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.ibtp.kontor.dal;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 10.02.2015.
|
||||
*/
|
||||
public class DataAccessLayerTest {
|
||||
|
||||
public void findTests(String packageName, String entityName) {
|
||||
String testClassName = packageName + entityName + "ImplTest";
|
||||
Class testClass;
|
||||
try {
|
||||
testClass = Class.forName(testClassName);
|
||||
Method addAndDelete = testClass.getMethod("test" + entityName + "AddAndDelete");
|
||||
Method findAll = testClass.getMethod("test" + entityName + "FindAll");
|
||||
} catch (ClassNotFoundException e) {
|
||||
Assert.fail("Class " + testClassName + " missing");
|
||||
} catch (NoSuchMethodException e) {
|
||||
Assert.fail("Test method for class " + testClassName + " missing");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindComicTests() {
|
||||
/*
|
||||
* Find all Tests
|
||||
*/
|
||||
String[] testClasses = new String[]{"Artist", "Comic", "Issue", "Publisher", "StoryArc", "Volume"};
|
||||
for (int i = 0; i < testClasses.length; i++) {
|
||||
String testEntity = testClasses[i];
|
||||
findTests("com.ibtp.kontor.comics.dal.", testEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindLibraryTests() {
|
||||
/*
|
||||
* Find all Tests
|
||||
*/
|
||||
String[] testClasses = new String[]{"Article", "Author", "Book", "File", "Title"};
|
||||
for (int i = 0; i < testClasses.length; i++) {
|
||||
String testEntity = testClasses[i];
|
||||
findTests("com.ibtp.kontor.library.dal.", testEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindTradingCardsTests() {
|
||||
/*
|
||||
* Find all Tests
|
||||
*/
|
||||
String[] testClasses = new String[]{"BaseSet", "Insert", "Manufacturer", "ParallelSet", "Player", "Position", "SportCard", "Sport", "Team"};
|
||||
for (int i = 0; i < testClasses.length; i++) {
|
||||
String testEntity = testClasses[i];
|
||||
findTests("com.ibtp.kontor.tradingcards.dal." , testEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.ibtp.kontor.library;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 27.01.2015.
|
||||
*/
|
||||
public class BookshelfTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAuthors() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ibtp.kontor.library.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.library.entity.ArticleEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 23.01.2015.
|
||||
*/
|
||||
public class ArticleImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddArticle() {
|
||||
String articleTitle = "testAddArticle";
|
||||
ArticleImpl articleImpl = new ArticleImpl();
|
||||
ArticleEntity article = articleImpl.addArticle(articleTitle);
|
||||
Assert.assertNotNull(article);
|
||||
List<ArticleEntity> articleList = articleImpl.findByTitle(articleTitle);
|
||||
Assert.assertEquals(1, articleList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArticleAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArticleFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.ibtp.kontor.library.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.library.entity.AuthorEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by thomas on 23.01.15.
|
||||
*/
|
||||
public class AuthorImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAuthor() {
|
||||
String authorName = "testAddAuthor";
|
||||
AuthorImpl authorImpl = new AuthorImpl();
|
||||
AuthorEntity author = authorImpl.addAuthor(authorName);
|
||||
Assert.assertNotNull(author);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAuthor() {
|
||||
String authorName = "testDeleteAuthor";
|
||||
AuthorImpl authorImpl = new AuthorImpl();
|
||||
AuthorEntity author = authorImpl.addAuthor(authorName);
|
||||
Assert.assertNotNull(author);
|
||||
List<AuthorEntity> authorList = authorImpl.findByName(authorName);
|
||||
Assert.assertEquals(1, authorList.size());
|
||||
authorImpl.delete(author);
|
||||
authorList = authorImpl.findByName(authorName);
|
||||
Assert.assertEquals(0, authorList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.library.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 27.01.2015.
|
||||
*/
|
||||
public class BookImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBookAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBookFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.library.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 27.01.2015.
|
||||
*/
|
||||
public class FileImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.library.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 27.01.2015.
|
||||
*/
|
||||
public class TitleImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitleAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitleFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package com.ibtp.kontor.tradingcards;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.tradingcards.dal.TeamImpl;
|
||||
import com.ibtp.kontor.tradingcards.entity.TeamEntity;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.tradingcards.dal.SportImpl;
|
||||
import com.ibtp.kontor.tradingcards.entity.SportEntity;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 27.01.2015.
|
||||
*/
|
||||
public class CollectionTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
setupSports();
|
||||
}
|
||||
|
||||
public void setupSports() {
|
||||
SportImpl sportImpl = new SportImpl();
|
||||
SportEntity football = sportImpl.addSport("Football");
|
||||
setupFootballTeams(football);
|
||||
SportEntity baseball = sportImpl.addSport("Baseball");
|
||||
setupFootballTeams(baseball);
|
||||
SportEntity basketball = sportImpl.addSport("Basketball");
|
||||
setupBasketballTeams(basketball);
|
||||
SportEntity hockey = sportImpl.addSport("Hockey");
|
||||
setupHockeyTeams(hockey);
|
||||
}
|
||||
|
||||
public void setupFootballTeams(SportEntity football) {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
teamImpl.addTeam("Dallas Cowboys", football);
|
||||
teamImpl.addTeam("New York Giants", football);
|
||||
teamImpl.addTeam("Philadelphia Eagles", football);
|
||||
teamImpl.addTeam("Arizona Cardinals", football);
|
||||
teamImpl.addTeam("Washington Redskins", football);
|
||||
teamImpl.addTeam("Detroit Lions", football);
|
||||
teamImpl.addTeam("Minnesota Vikings", football);
|
||||
teamImpl.addTeam("Green Bay Packers", football);
|
||||
teamImpl.addTeam("Chicago Bears", football);
|
||||
teamImpl.addTeam("Tampa Bay Buccaneers", football);
|
||||
teamImpl.addTeam("San Francisco 49ers", football);
|
||||
teamImpl.addTeam("New Orleans Saints", football);
|
||||
teamImpl.addTeam("Atlanta Falcons", football);
|
||||
teamImpl.addTeam("Los Angeles Rams", football);
|
||||
teamImpl.addTeam("Buffalo Bills", football);
|
||||
teamImpl.addTeam("Miami Dolphins", football);
|
||||
teamImpl.addTeam("New York Jets", football);
|
||||
teamImpl.addTeam("New England Patriots", football);
|
||||
teamImpl.addTeam("Indianapolis Colts", football);
|
||||
teamImpl.addTeam("Houston Oilers", football);
|
||||
teamImpl.addTeam("Pittsburgh Steelers", football);
|
||||
teamImpl.addTeam("Cleveland Browns", football);
|
||||
teamImpl.addTeam("Kansas City Chiefs", football);
|
||||
teamImpl.addTeam("Los Angeles Raiders", football);
|
||||
teamImpl.addTeam("Denver Broncos", football);
|
||||
teamImpl.addTeam("San Diego Chargers", football);
|
||||
teamImpl.addTeam("Seattle Seahawks", football);
|
||||
teamImpl.addTeam("Jacksonville Jaguars", football);
|
||||
teamImpl.addTeam("Houston Texans", football);
|
||||
}
|
||||
|
||||
public void setupBaseballTeams(SportEntity baseball) {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
}
|
||||
|
||||
public void setupBasketballTeams(SportEntity basketball) {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
teamImpl.addTeam("Houston Rockets", basketball);
|
||||
teamImpl.addTeam("San Antonio Spurs", basketball);
|
||||
teamImpl.addTeam("Utah Jazz", basketball);
|
||||
teamImpl.addTeam("Denver Nuggets", basketball);
|
||||
teamImpl.addTeam("Minnesota Timberwolves", basketball);
|
||||
teamImpl.addTeam("Dallas Mavericks", basketball);
|
||||
teamImpl.addTeam("Seattle SuperSonics", basketball);
|
||||
teamImpl.addTeam("Phoenix Suns", basketball);
|
||||
teamImpl.addTeam("Golden State Warriors", basketball);
|
||||
teamImpl.addTeam("Portland Trail Blazers", basketball);
|
||||
teamImpl.addTeam("Los Angeles Lakers", basketball);
|
||||
teamImpl.addTeam("Sacramento Kings", basketball);
|
||||
teamImpl.addTeam("Los Angeles Clippers", basketball);
|
||||
teamImpl.addTeam("New York Knicks", basketball);
|
||||
teamImpl.addTeam("Orlando Magic", basketball);
|
||||
teamImpl.addTeam("New Jersey Nets", basketball);
|
||||
teamImpl.addTeam("Miami Heat", basketball);
|
||||
teamImpl.addTeam("Boston Celtics", basketball);
|
||||
teamImpl.addTeam("Philadelphia 76ers", basketball);
|
||||
teamImpl.addTeam("Washington Bullets", basketball);
|
||||
teamImpl.addTeam("Atlanta Hawks", basketball);
|
||||
teamImpl.addTeam("Chicago Bulls", basketball);
|
||||
teamImpl.addTeam("Indiana Pacers", basketball);
|
||||
teamImpl.addTeam("Cleveland Cavaliers", basketball);
|
||||
teamImpl.addTeam("Charlotte Hornets", basketball);
|
||||
teamImpl.addTeam("Detroit Pistons", basketball);
|
||||
teamImpl.addTeam("Milwaukee Bucks", basketball);
|
||||
}
|
||||
|
||||
public void setupHockeyTeams(SportEntity hockey) {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
teamImpl.addTeam("New York Rangers", hockey);
|
||||
teamImpl.addTeam("Buffalo Sabers", hockey);
|
||||
teamImpl.addTeam("Detroit Red Wings", hockey);
|
||||
teamImpl.addTeam("Vancouver Canucks", hockey);
|
||||
teamImpl.addTeam("Mighty Ducks of Anaheim", hockey);
|
||||
teamImpl.addTeam("Calgary Flames", hockey);
|
||||
teamImpl.addTeam("Edmonton Oilers", hockey);
|
||||
teamImpl.addTeam("Los Angeles Kings", hockey);
|
||||
teamImpl.addTeam("San Jose Sharks", hockey);
|
||||
teamImpl.addTeam("Chicago Blackhawks", hockey);
|
||||
teamImpl.addTeam("Dallas Stars", hockey);
|
||||
teamImpl.addTeam("St. Louis Blues", hockey);
|
||||
teamImpl.addTeam("Toronto Maple Leafs", hockey);
|
||||
teamImpl.addTeam("Winnipeg Jets", hockey);
|
||||
teamImpl.addTeam("Boston Bruins", hockey);
|
||||
teamImpl.addTeam("Hartford Whalers", hockey);
|
||||
teamImpl.addTeam("Montreal Canadiers", hockey);
|
||||
teamImpl.addTeam("Ottawa Senators", hockey);
|
||||
teamImpl.addTeam("Pittsburgh Penguins", hockey);
|
||||
teamImpl.addTeam("Quebec Nordiques", hockey);
|
||||
teamImpl.addTeam("Florida Panthers", hockey);
|
||||
teamImpl.addTeam("New Jersey Devils", hockey);
|
||||
teamImpl.addTeam("New York Islanders", hockey);
|
||||
teamImpl.addTeam("Philadelphia Flyers", hockey);
|
||||
teamImpl.addTeam("Tamba Bay Lightning", hockey);
|
||||
teamImpl.addTeam("Washington Capitals", hockey);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
Collection<TeamEntity> teamEntities = teamImpl.findAll();
|
||||
for (Iterator<TeamEntity> iterator = teamEntities.iterator(); iterator.hasNext(); ) {
|
||||
TeamEntity next = iterator.next();
|
||||
teamImpl.delete(next);
|
||||
}
|
||||
SportImpl sportImpl = new SportImpl();
|
||||
Collection<SportEntity> sportEntities = sportImpl.findAll();
|
||||
for (Iterator<SportEntity> iterator = sportEntities.iterator(); iterator.hasNext(); ) {
|
||||
SportEntity next = iterator.next();
|
||||
sportImpl.delete(next);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gettAllSports() {
|
||||
SportImpl sportImpl = new SportImpl();
|
||||
Collection<SportEntity> resultList = sportImpl.findAll();
|
||||
Assert.assertEquals(4, resultList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllTeams() {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
Collection<TeamEntity> resultList = teamImpl.findAll();
|
||||
Assert.assertEquals(111, resultList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 27.01.2015.
|
||||
*/
|
||||
public class BaseSetImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseSetAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseSetFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 27.01.2015.
|
||||
*/
|
||||
public class InsertImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInsertAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.tradingcards.entity.ManufacturerEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 20.01.2015.
|
||||
*/
|
||||
public class ManufacturerImplTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addManufacturer() {
|
||||
String manufacturerName = "Manufacturer1";
|
||||
ManufacturerImpl manufacturerImpl = new ManufacturerImpl();
|
||||
ManufacturerEntity manufacturer = manufacturerImpl.addManufacturer(manufacturerName);
|
||||
Assert.assertNotNull(manufacturer);
|
||||
List<ManufacturerEntity> manufacturerList = manufacturerImpl.findByName(manufacturerName);
|
||||
Assert.assertTrue(manufacturerList.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteManufacturer() {
|
||||
String manufacturerName = "Manufacturer1";
|
||||
ManufacturerImpl manufacturerImpl = new ManufacturerImpl();
|
||||
List<ManufacturerEntity> manufacturerList = manufacturerImpl.findByName(manufacturerName);
|
||||
Assert.assertTrue(manufacturerList.size() > 0);
|
||||
manufacturerImpl.delete(manufacturerList.get(0));
|
||||
manufacturerList = manufacturerImpl.findByName(manufacturerName);
|
||||
Assert.assertEquals(0, manufacturerList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManufacturerAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManufacturerFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 27.01.2015.
|
||||
*/
|
||||
public class ParallelSetImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParallelSetAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParallelSetFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 27.01.2015.
|
||||
*/
|
||||
public class PlayerImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.tradingcards.entity.PositionEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 27.01.2015.
|
||||
*/
|
||||
public class PositionImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPositionAddAndDelete() {
|
||||
String positionName = "testPositionAddAndDelete";
|
||||
PositionImpl positionImpl = new PositionImpl();
|
||||
PositionEntity position = positionImpl.addPosition(positionName);
|
||||
Collection<PositionEntity> resultList = positionImpl.findByName(positionName);
|
||||
Assert.assertNotNull(resultList);
|
||||
Assert.assertEquals(1, resultList.size());
|
||||
positionImpl.delete(position);
|
||||
resultList = positionImpl.findByName(positionName);
|
||||
Assert.assertEquals(0, resultList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPositionFindAll() {
|
||||
PositionImpl positionImpl = new PositionImpl();
|
||||
Collection<PositionEntity> resultList = positionImpl.findAll();
|
||||
Assert.assertEquals(0, resultList.size());
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 27.01.2015.
|
||||
*/
|
||||
public class SportCardImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSportCardAddAndDelete() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSportCardFindAll() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.tradingcards.entity.SportEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 19.01.2015.
|
||||
*/
|
||||
public class SportImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSportAddAndDelete() {
|
||||
String sportName = "testSportAddAndDelete";
|
||||
SportImpl sportImpl = new SportImpl();
|
||||
SportEntity sport = sportImpl.addSport(sportName);
|
||||
List<SportEntity> sportList = sportImpl.findByName(sportName);
|
||||
Assert.assertEquals(1, sportList.size());
|
||||
sportImpl.delete(sport);
|
||||
List<SportEntity> result = sportImpl.findByName(sportName);
|
||||
Assert.assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSportFindAll() {
|
||||
SportImpl sportImpl = new SportImpl();
|
||||
Collection<SportEntity> resultList = sportImpl.findAll();
|
||||
Assert.assertEquals(0, resultList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ibtp.kontor.tradingcards.dal;
|
||||
|
||||
import com.ibtp.kontor.dal.DatabaseManager;
|
||||
import com.ibtp.kontor.util.LocalTestDatabase;
|
||||
import com.ibtp.kontor.tradingcards.entity.TeamEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by tpeetz on 20.01.2015.
|
||||
*/
|
||||
public class TeamImplTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DatabaseManager.setDatabase(new LocalTestDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTeamAddAndDelete() {
|
||||
String teamName = "testTeamAddAndDelete";
|
||||
TeamEntity team = new TeamEntity(teamName);
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
teamImpl.store(team);
|
||||
Collection<TeamEntity> resultList = teamImpl.findByName(teamName);
|
||||
Assert.assertEquals(1, resultList.size());
|
||||
teamImpl.delete(team);
|
||||
resultList = teamImpl.findByName(teamName);
|
||||
Assert.assertEquals(0, resultList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTeamFindAll() {
|
||||
TeamImpl teamImpl = new TeamImpl();
|
||||
Collection<TeamEntity> resultList = teamImpl.findAll();
|
||||
Assert.assertEquals(0, resultList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.ibtp.kontor.util;
|
||||
|
||||
import com.ibtp.kontor.dal.Database;
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.hsqldb.Server;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import javax.persistence.spi.PersistenceProvider;
|
||||
import javax.persistence.spi.PersistenceProviderResolver;
|
||||
import javax.persistence.spi.PersistenceProviderResolverHolder;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Created by TPEETZ on 21.01.2015.
|
||||
*/
|
||||
public class LocalTestDatabase implements Database {
|
||||
|
||||
private static Server server;
|
||||
private static EntityManagerFactory factory;
|
||||
private static EntityManager em;
|
||||
private static Logger logger = LoggerFactory.getLogger(LocalTestDatabase.class.getName());
|
||||
|
||||
static {
|
||||
logger.info("initialization and starting database");
|
||||
LocalTestDatabase.assureDatabaseRunning();
|
||||
}
|
||||
|
||||
public LocalTestDatabase() {
|
||||
logger.info("LocalDatabaseTest started");
|
||||
}
|
||||
|
||||
private static void assureDatabaseRunning() {
|
||||
if (LocalTestDatabase.server == null) {
|
||||
LocalTestDatabase.startDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
private static void startDatabase() {
|
||||
logger.info("startDatabase as kontor in hsqldb_databases/test");
|
||||
LocalTestDatabase.server = new Server();
|
||||
LocalTestDatabase.server.setAddress("localhost");
|
||||
LocalTestDatabase.server.setDatabaseName(0, "kontor");
|
||||
LocalTestDatabase.server.setDatabasePath(0, "file:build/hsqldb_databases/test");
|
||||
LocalTestDatabase.server.setPort(2345);
|
||||
LocalTestDatabase.server.setTrace(true);
|
||||
LocalTestDatabase.server.setLogWriter(new PrintWriter(System.out));
|
||||
LocalTestDatabase.server.start();
|
||||
}
|
||||
|
||||
private static void stopDatabase() {
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
private static EntityManagerFactory getFactory() {
|
||||
if (LocalTestDatabase.factory == null) {
|
||||
LocalTestDatabase.assureDatabaseRunning();
|
||||
PersistenceProviderResolverHolder.setPersistenceProviderResolver(new PersistenceProviderResolver() {
|
||||
private final List<PersistenceProvider> providers_ = Arrays.asList((PersistenceProvider) new HibernatePersistenceProvider());
|
||||
|
||||
@Override
|
||||
public void clearCachedProviders() {
|
||||
// Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PersistenceProvider> getPersistenceProviders() {
|
||||
return providers_;
|
||||
}
|
||||
});
|
||||
LocalTestDatabase.factory = Persistence.createEntityManagerFactory("com.ibtp.kontor");
|
||||
logger.info("EntityManagerFactory(com.ibtp.kontor) created");
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
private static EntityManager getSingleEntityManager() {
|
||||
return LocalTestDatabase.em;
|
||||
}
|
||||
|
||||
private static void setSingleEntityManager(EntityManager manager) {
|
||||
LocalTestDatabase.em = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityManager getEntityManager() {
|
||||
if (getSingleEntityManager() == null) {
|
||||
setSingleEntityManager(getFactory().createEntityManager());
|
||||
logger.info("EntityManager created");
|
||||
}
|
||||
return getSingleEntityManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String serverMessage;
|
||||
if (LocalTestDatabase.server == null) {
|
||||
serverMessage = "server:null";
|
||||
} else {
|
||||
serverMessage = LocalTestDatabase.server.toString();
|
||||
}
|
||||
return LocalTestDatabase.class.getName() + " " + serverMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
|
||||
version="2.0">
|
||||
<persistence-unit name="com.ibtp.kontor" >
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.ibtp.kontor.comics.entity.ArtistEntity</class>
|
||||
<class>com.ibtp.kontor.comics.entity.ComicEntity</class>
|
||||
<class>com.ibtp.kontor.comics.entity.IssueEntity</class>
|
||||
<class>com.ibtp.kontor.comics.entity.StoryArcEntity</class>
|
||||
<class>com.ibtp.kontor.comics.entity.VolumeEntity</class>
|
||||
<class>com.ibtp.kontor.comics.entity.PublisherEntity</class>
|
||||
<class>com.ibtp.kontor.library.entity.AuthorEntity</class>
|
||||
<class>com.ibtp.kontor.library.entity.ArticleEntity</class>
|
||||
<class>com.ibtp.kontor.library.entity.BookEntity</class>
|
||||
<class>com.ibtp.kontor.library.entity.FileEntity</class>
|
||||
<class>com.ibtp.kontor.library.entity.TitleEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.SportEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.TeamEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.PositionEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.PlayerEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.ManufacturerEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.BaseSetEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.InsertEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.ParallelSetEntity</class>
|
||||
<class>com.ibtp.kontor.tradingcards.entity.SportCardEntity</class>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
|
||||
<property name="javax.persistence.jdbc.user" value="sa"/>
|
||||
<property name="javax.persistence.jdbc.password" value=""/>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost:2345/kontor;shutdown=true;hsqldb.write_delay=false"/>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
<property name="hibernate.show_sql" value="true"/>
|
||||
<property name="hibernate.max_fetch_depth" value="3"/>
|
||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||
<property name="hsqldb.write_delay" value="false"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
|
||||
</Pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>build/kontortest.log</file>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</Pattern>
|
||||
</encoder>
|
||||
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||
<FileNamePattern>build/kontortest.%i.log.zip</FileNamePattern>
|
||||
<MinIndex>1</MinIndex>
|
||||
<MaxIndex>10</MaxIndex>
|
||||
</rollingPolicy>
|
||||
|
||||
<triggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
<MaxFileSize>2MB</MaxFileSize>
|
||||
</triggeringPolicy>
|
||||
|
||||
</appender>
|
||||
|
||||
<logger name="org.hibernate.type" level="ALL" />
|
||||
<logger name="org.hibernate" level="DEBUG" />
|
||||
<logger name="com.ibtp" level="DEBUG" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user