[vlma-devel] commit: Some tests : IpBankTest and ProgramFactoryTest . (Adrien Grand )
git version control
git at videolan.org
Tue Jul 22 23:59:12 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Wed Jul 23 00:01:23 2008 +0200| [ea9e4a35d17cd3ebc9ec811527d569a61fca8ce2]
Some tests : IpBankTest and ProgramFactoryTest.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=ea9e4a35d17cd3ebc9ec811527d569a61fca8ce2
---
vlma-core/pom.xml | 17 ++++
.../src/main/java/org/videolan/vlma/IpBank.java | 4 +
.../test/java/org/videolan/vlma/IpBankTest.java | 87 ++++++++++++++++++++
.../java/org/videolan/vlma/ProgramFactoryTest.java | 46 ++++++++++
4 files changed, 154 insertions(+), 0 deletions(-)
diff --git a/vlma-core/pom.xml b/vlma-core/pom.xml
index 42365f9..601dc7f 100644
--- a/vlma-core/pom.xml
+++ b/vlma-core/pom.xml
@@ -114,5 +114,22 @@
<artifactId>xstream</artifactId>
<version>1.3</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>2.4.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-junit4</artifactId>
+ <version>2.4.0</version>
+ </dependency>
</dependencies>
</project>
diff --git a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
index 16007f1..2a9a1ff 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
@@ -79,6 +79,10 @@ public class IpBank {
}
}
+ public boolean isUsed(InetAddress ip) {
+ return usedIps.containsKey(ip) && usedIps.get(ip);
+ }
+
/**
* Gives a new IP address to the programmation, the first which is not used.
*
diff --git a/vlma-core/src/test/java/org/videolan/vlma/IpBankTest.java b/vlma-core/src/test/java/org/videolan/vlma/IpBankTest.java
new file mode 100644
index 0000000..ec2a9de
--- /dev/null
+++ b/vlma-core/src/test/java/org/videolan/vlma/IpBankTest.java
@@ -0,0 +1,87 @@
+package org.videolan.vlma;
+
+import static org.junit.Assert.*;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.videolan.vlma.model.media.Media;
+import org.videolan.vlma.model.media.Program;
+import org.videolan.vlma.model.media.StreamChannel;
+import org.videolan.vlma.model.media.TNTChannel;
+
+ at RunWith(JMock.class)
+public class IpBankTest {
+
+ private Mockery context = new JUnit4Mockery();
+ private Configuration configuration;
+ private IpBank ipBank;
+ private ProgramFactory factory;
+ private VLMaService vlmaService;
+ List<Media> medias;
+
+ @Before
+ public void setUp() throws Exception {
+ vlmaService = context.mock(VLMaService.class);
+ configuration = new BaseConfiguration();
+ configuration.setProperty("vlma.streaming.udp.ipbank.min", "239.127.42.253");
+ configuration.setProperty("vlma.streaming.udp.ipbank.max", "239.127.67.42");
+ configuration.setProperty("vlma.announcement", "PODCAST");
+ configuration.setProperty("vlma.streaming", "UDP_Multicast");
+ configuration.setProperty("vlma.encapsulation", "TS");
+ factory = new ProgramFactory();
+ factory.setConfiguration(configuration);
+ ipBank = new IpBank();
+ ipBank.setVlmaService(vlmaService);
+ ipBank.setConfiguration(configuration);
+ Media media1 = new StreamChannel();
+ media1.setName("Test1");
+ Media media2 = new TNTChannel();
+ media2.setName("Test2");
+ Program program = factory.getProgram();
+ program.setIp(InetAddress.getByName("239.127.62.15"));
+ media2.setProgram(program);
+ medias = new ArrayList<Media>();
+ medias.add(media1);
+ medias.add(media2);
+ context.checking(new Expectations() {
+ {
+ one(vlmaService).getMedias();
+ will(returnValue(medias));
+ }
+ });
+ ipBank.initIps();
+ }
+
+ @Test
+ public void testInit() throws Exception {
+ context.assertIsSatisfied();
+ assertTrue(ipBank.isUsed(InetAddress.getByName("239.127.62.15")));
+ assertFalse(ipBank.isUsed(InetAddress.getByName("239.127.12.42")));
+ }
+
+ @Test
+ public void testGetIp() {
+ InetAddress ip = ipBank.getIp();
+ assertTrue(ipBank.isUsed(ip));
+ }
+
+ @Test
+ public void testReleaseIp() {
+ InetAddress ip = ipBank.getIp();
+ assertTrue(ipBank.isUsed(ip));
+ ipBank.releaseIp(ip);
+ assertFalse(ipBank.isUsed(ip));
+ }
+
+}
diff --git a/vlma-core/src/test/java/org/videolan/vlma/ProgramFactoryTest.java b/vlma-core/src/test/java/org/videolan/vlma/ProgramFactoryTest.java
new file mode 100644
index 0000000..c4847ba
--- /dev/null
+++ b/vlma-core/src/test/java/org/videolan/vlma/ProgramFactoryTest.java
@@ -0,0 +1,46 @@
+package org.videolan.vlma;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.junit.Before;
+import org.junit.Test;
+import org.videolan.vlma.model.media.Program;
+import org.videolan.vlma.model.media.StreamingStrategy;
+
+public class ProgramFactoryTest {
+
+ private Configuration configuration;
+ private ProgramFactory factory;
+
+ @Before
+ public void setUp() {
+ configuration = new BaseConfiguration();
+ configuration.setProperty("vlma.announcement", "PODCAST");
+ configuration.setProperty("vlma.streaming", "HTTP");
+ configuration.setProperty("vlma.encapsulation", "TS");
+ factory = new ProgramFactory();
+ factory.setConfiguration(configuration);
+ }
+
+ @Test
+ public void testGetProgram() {
+ Program program = factory.getProgram();
+ assertNotNull(program);
+ assertEquals(program.getStreamingStrategy().getProtocol(), StreamingStrategy.Protocol.HTTP);
+ assertEquals(program.getStreamingStrategy().getEncapsulation(), StreamingStrategy.Encapsulation.TS);
+ assertEquals(program.getStreamingStrategy().getAnnouncements().size(), 1);
+ assertTrue(program.getStreamingStrategy().getAnnouncements().contains(StreamingStrategy.Announcement.PODCAST));
+ }
+
+ @Test
+ public void testSeveralAnnouncements() {
+ configuration.setProperty("vlma.announcement", "PODCAST, SAP");
+ Program program = factory.getProgram();
+ assertEquals(program.getStreamingStrategy().getAnnouncements().size(), 2);
+ assertTrue(program.getStreamingStrategy().getAnnouncements().contains(StreamingStrategy.Announcement.PODCAST));
+ assertTrue(program.getStreamingStrategy().getAnnouncements().contains(StreamingStrategy.Announcement.SAP));
+ }
+
+}
More information about the vlma-devel
mailing list