Basic functionallity
This commit is contained in:
47
src/test/java/se/slackers/locality/dao/MetaTagDaoTest.java
Executable file
47
src/test/java/se/slackers/locality/dao/MetaTagDaoTest.java
Executable file
@@ -0,0 +1,47 @@
|
||||
package se.slackers.locality.dao;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
import se.slackers.locality.model.MetaTag;
|
||||
|
||||
public class MetaTagDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected MetaTagDao tagDao;
|
||||
protected SessionFactory sessionFactory = null;
|
||||
|
||||
public void testSave() {
|
||||
MetaTag tag = new MetaTag();
|
||||
tag.setName("testMetaTag");
|
||||
tagDao.save(tag);
|
||||
|
||||
MetaTag fetchedMetaTag = tagDao.get("testMetaTag");
|
||||
assertEquals(tag.getId(), fetchedMetaTag.getId());
|
||||
}
|
||||
|
||||
public void testDelete() {
|
||||
MetaTag tag = new MetaTag();
|
||||
tag.setName("testMetaTag");
|
||||
tagDao.save(tag);
|
||||
|
||||
tagDao.delete(tag);
|
||||
try {
|
||||
tagDao.get("testMetaTag");
|
||||
fail();
|
||||
} catch (DataRetrievalFailureException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "application-context/main.xml", "application-context/data.xml" };
|
||||
}
|
||||
|
||||
public void setMetaTagDao(MetaTagDao tagDao) {
|
||||
this.tagDao = tagDao;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
}
|
||||
47
src/test/java/se/slackers/locality/dao/TagDaoTest.java
Executable file
47
src/test/java/se/slackers/locality/dao/TagDaoTest.java
Executable file
@@ -0,0 +1,47 @@
|
||||
package se.slackers.locality.dao;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
import se.slackers.locality.model.Tag;
|
||||
|
||||
public class TagDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected TagDao tagDao;
|
||||
protected SessionFactory sessionFactory = null;
|
||||
|
||||
public void testSave() {
|
||||
Tag tag = new Tag();
|
||||
tag.setName("testTag");
|
||||
tagDao.save(tag);
|
||||
|
||||
Tag fetchedTag = tagDao.get("testTag");
|
||||
assertEquals(tag.getId(), fetchedTag.getId());
|
||||
}
|
||||
|
||||
public void testDelete() {
|
||||
Tag tag = new Tag();
|
||||
tag.setName("testMetaTag");
|
||||
tagDao.save(tag);
|
||||
|
||||
tagDao.delete(tag);
|
||||
try {
|
||||
tagDao.get("testMetaTag");
|
||||
fail();
|
||||
} catch (DataRetrievalFailureException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "application-context/main.xml", "application-context/data.xml" };
|
||||
}
|
||||
|
||||
public void setTagDao(TagDao tagDao) {
|
||||
this.tagDao = tagDao;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
}
|
||||
45
src/test/java/se/slackers/locality/dao/TagTest.java
Executable file
45
src/test/java/se/slackers/locality/dao/TagTest.java
Executable file
@@ -0,0 +1,45 @@
|
||||
package se.slackers.locality.dao;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
import se.slackers.locality.model.MetaTag;
|
||||
import se.slackers.locality.model.Tag;
|
||||
|
||||
public class TagTest extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected TagDao tagDao;
|
||||
protected MetaTagDao metaTagDao;
|
||||
protected SessionFactory sessionFactory = null;
|
||||
|
||||
public void testManyToMany() {
|
||||
Tag tag = new Tag();
|
||||
MetaTag metatag = new MetaTag();
|
||||
|
||||
tag.setName("tag");
|
||||
metatag.setName("metatag");
|
||||
metatag.addTag(tag);
|
||||
|
||||
tagDao.save(tag);
|
||||
metaTagDao.save(metatag);
|
||||
|
||||
System.out.println(tagDao.get(tag.getId()));
|
||||
System.out.println(metaTagDao.get(metatag.getId()));
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "application-context/main.xml", "application-context/data.xml" };
|
||||
}
|
||||
|
||||
public void setTagDao(TagDao tagDao) {
|
||||
this.tagDao = tagDao;
|
||||
}
|
||||
|
||||
public void setMetaTagDao(MetaTagDao metaTagDao) {
|
||||
this.metaTagDao = metaTagDao;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
}
|
||||
100
src/test/java/se/slackers/locality/data/CircularBufferTest.java
Normal file
100
src/test/java/se/slackers/locality/data/CircularBufferTest.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package se.slackers.locality.data;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class CircularBufferTest extends TestCase {
|
||||
private CircularBuffer buffer = new CircularBuffer(1000);
|
||||
private byte [] temp = new byte[1000];
|
||||
|
||||
@Test
|
||||
public void testReadEmpty() {
|
||||
buffer.reset();
|
||||
assertEquals(0, buffer.read(temp, 0, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteRead() {
|
||||
buffer.reset();
|
||||
int length = 100;
|
||||
assertEquals(true, buffer.write(temp, 0, length));
|
||||
assertEquals(length, buffer.read(temp, 0, length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteReadOverflow() {
|
||||
buffer.reset();
|
||||
int length = 100;
|
||||
assertEquals(true, buffer.write(temp, 0, length));
|
||||
assertEquals(length, buffer.read(temp, 0, length*2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteOverEdge() {
|
||||
buffer.reset();
|
||||
assertEquals(true, buffer.write(temp, 0, 900));
|
||||
assertEquals(100, buffer.read(temp, 0, 100));
|
||||
// should be 200 bytes free in buffer
|
||||
assertEquals(true, buffer.write(temp, 0, 150));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteOverEdgeLimit() {
|
||||
buffer.reset();
|
||||
assertEquals(true, buffer.write(temp, 0, 900));
|
||||
assertEquals(100, buffer.read(temp, 0, 100));
|
||||
// should be 200 bytes free in buffer
|
||||
assertEquals(false, buffer.write(temp, 0, 250));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadOverEdge() {
|
||||
buffer.reset();
|
||||
assertEquals(true, buffer.write(temp, 0, 900));
|
||||
assertEquals(800, buffer.read(temp, 0, 800));
|
||||
// readIndex = 800, writeIndex = 900
|
||||
assertEquals(true, buffer.write(temp, 0, 500));
|
||||
assertEquals(500, buffer.read(temp, 0, 500));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadOverEdgeLimit() {
|
||||
buffer.reset();
|
||||
assertEquals(true, buffer.write(temp, 0, 900));
|
||||
assertEquals(800, buffer.read(temp, 0, 800));
|
||||
// readIndex = 800, writeIndex = 900
|
||||
assertEquals(true, buffer.write(temp, 0, 500));
|
||||
assertEquals(600, buffer.read(temp, 0, 700));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRandomness() {
|
||||
buffer.reset();
|
||||
int size = 0;
|
||||
|
||||
for (int i=0;i<100;i++) {
|
||||
size = 1000;
|
||||
while (true) {
|
||||
int len = (int)(Math.random()*400.0+100.0);
|
||||
if (!buffer.write(temp, 0, len))
|
||||
break;
|
||||
size -= len;
|
||||
}
|
||||
|
||||
assertTrue(size >= 0);
|
||||
|
||||
size = 1000-size;
|
||||
while (true) {
|
||||
int len = (int)(Math.random()*400.0+100.0);
|
||||
int bytes = buffer.read(temp, 0, len);
|
||||
size -= bytes;
|
||||
if (0 == bytes)
|
||||
break;
|
||||
}
|
||||
|
||||
assertTrue(size == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package se.slackers.locality.data;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ExpandOnWriteCircularBufferTest extends TestCase {
|
||||
private static final int SIZE = 1000;
|
||||
private ExpandOnWriteCircularBuffer buffer = new ExpandOnWriteCircularBuffer(SIZE);
|
||||
private byte [] temp = new byte[SIZE];
|
||||
|
||||
@Test
|
||||
public void testReadEmpty() {
|
||||
buffer.reset();
|
||||
assertEquals(0, buffer.read(0, temp, 0, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteRead() {
|
||||
buffer.reset();
|
||||
int length = 100;
|
||||
assertEquals(true, buffer.write(temp, 0, length));
|
||||
assertEquals(length, buffer.read(0, temp, 0, length));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRandomness() {
|
||||
buffer.reset();
|
||||
int size = 0;
|
||||
|
||||
for (int i=0;i<100;i++) {
|
||||
size = 0;
|
||||
for (int j=0;j<10;j++) {
|
||||
int len = (int)(Math.random()*400.0+100.0);
|
||||
buffer.write(temp, 0, len);
|
||||
size += len;
|
||||
}
|
||||
|
||||
assertTrue(size-SIZE+1 == buffer.getReadOffset());
|
||||
|
||||
buffer.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package se.slackers.locality.data;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import se.slackers.locality.media.Frame;
|
||||
|
||||
|
||||
public class FixedFrameSizeFrameStorageTest {
|
||||
|
||||
@Test
|
||||
public void testInsertUpdate() {
|
||||
FixedFrameSizeFrameStorage storage = new FixedFrameSizeFrameStorage();
|
||||
|
||||
// fill the storage with entries
|
||||
long time = 0;
|
||||
for (int i=0;i<100;i++) {
|
||||
storage.add(makeEntry(time));
|
||||
time += 26;
|
||||
}
|
||||
|
||||
FrameStorageEntry entry = storage.find(6*26+3);
|
||||
String value = new String(entry.getFrame().getData());
|
||||
assertEquals("10011100", value);
|
||||
|
||||
storage.purgeUntil(10*26);
|
||||
try {
|
||||
storage.find(10*26-1);
|
||||
fail();
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private FrameStorageEntry makeEntry(long time) {
|
||||
byte [] data = Long.toBinaryString(time).getBytes();
|
||||
|
||||
Frame frame = new Frame(data.length);
|
||||
frame.setLength(26);
|
||||
|
||||
System.arraycopy(data, 0, frame.getData(), 0, data.length);
|
||||
frame.setSize(data.length);
|
||||
|
||||
return new FrameStorageEntry(time, frame);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package se.slackers.locality.data;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import se.slackers.locality.model.Metadata;
|
||||
|
||||
|
||||
public class MetadataManagerTest {
|
||||
private MetadataManager mm = new MetadataManager();
|
||||
|
||||
|
||||
@Test
|
||||
public void testParse() {
|
||||
Metadata info = Metadata.create("ARTIST", "ALBUM", "TITLE");
|
||||
|
||||
String result = mm.parseFormat("${artist} $album$track ?(title,-) ${title}", info);
|
||||
assertEquals("ARTIST ALBUM - TITLE", result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package se.slackers.locality.media.reader.mp3;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import se.slackers.locality.media.Frame;
|
||||
import se.slackers.locality.model.Media;
|
||||
|
||||
public class Mp3MediaReaderTest extends TestCase {
|
||||
|
||||
private static final File base = new File("target/test-classes");
|
||||
private Media media = null;
|
||||
private Mp3MediaReader reader = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
media = new Media();
|
||||
media.setMediaFile(new File(base, "test.mp3"));
|
||||
|
||||
reader = new Mp3MediaReader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() {
|
||||
try {
|
||||
reader.open(media);
|
||||
Frame frame = new Frame(4096);
|
||||
|
||||
reader.readFrame(frame);
|
||||
reader.readFrame(frame);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/test/java/se/slackers/locality/net/HttpRequestTest.java
Normal file
19
src/test/java/se/slackers/locality/net/HttpRequestTest.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package se.slackers.locality.net;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import se.slackers.locality.net.HttpRequest;
|
||||
|
||||
|
||||
|
||||
public class HttpRequestTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testRequest() throws Exception {
|
||||
String httpRequest = "GET /media.mp3 HTTP/1.0\n\rHost: localhost\n\rUser-Agent: xmms/1.2.10\n\rIcy-MetaData:1\n\r\n\r";
|
||||
HttpRequest request = new HttpRequest(httpRequest);
|
||||
assertEquals("/media.mp3", request.getRequestPath());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package se.slackers.locality.shout;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import se.slackers.locality.data.FixedFrameSizeFrameStorage;
|
||||
import se.slackers.locality.media.queue.MediaQueue;
|
||||
import se.slackers.locality.media.queue.MediaQueueImpl;
|
||||
import se.slackers.locality.media.queue.MediaQueueProcessor;
|
||||
import se.slackers.locality.media.queue.PreloadDataMediaQueueProcessor;
|
||||
import se.slackers.locality.media.reader.MediaReaderFactory;
|
||||
import se.slackers.locality.media.reader.mp3.Mp3MediaReader;
|
||||
import se.slackers.locality.model.Media;
|
||||
import se.slackers.locality.shout.manager.ShoutRequestManager;
|
||||
import se.slackers.locality.shout.manager.ShoutRequestManagerImpl;
|
||||
|
||||
|
||||
public class ShoutServerTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testServerStart() {
|
||||
Media media = new Media();
|
||||
media.setMediaFile(new File("test.mp3"));
|
||||
|
||||
MediaReaderFactory mediaReaderFactory = new MediaReaderFactory();
|
||||
mediaReaderFactory.addMediaReader(new Mp3MediaReader());
|
||||
|
||||
MediaQueue queue = new MediaQueueImpl("mediaQueue");
|
||||
queue.setMountPoint("/media.mp3");
|
||||
queue.add(media);
|
||||
|
||||
MediaQueueProcessor processor = new PreloadDataMediaQueueProcessor();
|
||||
processor.setMediaQueue(queue);
|
||||
processor.setMediaReaderFactory(mediaReaderFactory);
|
||||
|
||||
queue.setMediaQueueProcessor(processor);
|
||||
queue.setFrameStorage( new FixedFrameSizeFrameStorage() );
|
||||
|
||||
ShoutRequestManager manager = new ShoutRequestManagerImpl();
|
||||
manager.registerQueue(queue);
|
||||
|
||||
ShoutServer server = new ShoutServer();
|
||||
server.setServerPort(8001);
|
||||
|
||||
server.setRequestManager(manager);
|
||||
server.run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user