]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/AbstractJVLCTest.java
jvlc: minor changes on unit tests
[vlc] / bindings / java / core / src / test / java / org / videolan / jvlc / AbstractJVLCTest.java
1 /*****************************************************************************
2  * AbstractJVLCTest.java: VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2008 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  *
9  * $Id $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 package org.videolan.jvlc;
27
28 import java.io.BufferedOutputStream;
29 import java.io.FileOutputStream;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.net.URL;
33 import java.net.URLConnection;
34
35 import org.apache.commons.io.IOUtils;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.videolan.jvlc.internal.AbstractVLCInternalTest;
41
42
43 public abstract class AbstractJVLCTest
44 {
45     
46     protected JVLC jvlc;
47
48     protected String mrl;
49
50     private String address = "http://streams.videolan.org/streams-videolan/reference/mp4/bl.mp4";
51
52     /**
53      * Logger.
54      */
55     private Logger log = LoggerFactory.getLogger(AbstractVLCInternalTest.class);
56
57     @Before
58     public void testSetup()
59     {
60         jvlc = new JVLC("-vvv --ignore-config --no-media-library -I dummy -A dummy -V dummy --rtsp-host 127.0.0.1:5554");
61         jvlc.setLogVerbosity(LoggerVerbosityLevel.DEBUG);
62         downloadSample();
63     }
64
65     @After
66     public void tearDown()
67     {
68         jvlc.release();
69     }
70
71     private void downloadSample()
72     {
73         OutputStream out = null;
74         URLConnection conn = null;
75         InputStream in = null;
76         URL sampleResource = this.getClass().getResource("/sample.avi");
77         if (sampleResource != null)
78         {
79             log.debug("Sample file already downloaded");
80             mrl = sampleResource.getPath();
81             return;
82         }
83         try
84         {
85             log.info("Downloading sample: {}", address);
86             String testResoucesPath = this.getClass().getResource("/sample").getPath();
87             URL url = new URL(address);
88             out = new BufferedOutputStream(new FileOutputStream(testResoucesPath + ".avi"));
89             conn = url.openConnection();
90             in = conn.getInputStream();
91             byte[] buffer = new byte[1024];
92             int numRead;
93             long numWritten = 0;
94             while ((numRead = in.read(buffer)) != -1)
95             {
96                 out.write(buffer, 0, numRead);
97                 numWritten += numRead;
98             }
99             log.info("Sample downloaded.");
100             mrl = testResoucesPath + ".avi";
101         }
102         catch (Exception e)
103         {
104             log.error("{}", e);
105         }
106         finally
107         {
108             IOUtils.closeQuietly(in);
109             IOUtils.closeQuietly(out);
110         }
111     }
112
113 }