add sources (for web crawler), implement unit tests for json config
This commit is contained in:
parent
f452a9059d
commit
ca609e3848
3 changed files with 106 additions and 0 deletions
|
|
@ -4,10 +4,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public FrameConfig frame;
|
||||
public DBConfig db;
|
||||
public List<SourceItem> sources;
|
||||
|
||||
public static Config loadConfig(String path) throws IOException {
|
||||
return new ObjectMapper().readerFor(Config.class).readValue(new File(path));
|
||||
|
|
|
|||
22
src/main/java/com/mykola2312/mptv/config/SourceItem.java
Normal file
22
src/main/java/com/mykola2312/mptv/config/SourceItem.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package com.mykola2312.mptv.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.*;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class SourceItem {
|
||||
public enum SourceType {
|
||||
@JsonProperty("m3u")
|
||||
M3U
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public SourceType type;
|
||||
public String url;
|
||||
|
||||
@Nullable
|
||||
public String cookies;
|
||||
|
||||
@Nullable
|
||||
public String singleCategory;
|
||||
}
|
||||
82
src/test/java/com/mykola2312/mptv/TestConfig.java
Normal file
82
src/test/java/com/mykola2312/mptv/TestConfig.java
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package com.mykola2312.mptv;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mykola2312.mptv.config.Config;
|
||||
import com.mykola2312.mptv.config.SourceItem;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestConfig {
|
||||
public static final String JSON_CONFIG =
|
||||
"""
|
||||
{
|
||||
"frame": {
|
||||
"width": 1366,
|
||||
"height": 1024,
|
||||
"fullscreen": false,
|
||||
"fontName": "Arial",
|
||||
"fontSize": 64
|
||||
},
|
||||
|
||||
"db": {
|
||||
"url": "jdbc:sqlite:mptv.db",
|
||||
"user": "",
|
||||
"password": ""
|
||||
},
|
||||
|
||||
"sources": [
|
||||
{
|
||||
"type": "m3u",
|
||||
"url": "https://example.com/list.m3u",
|
||||
"cookies": null,
|
||||
"singleCategory": null
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
private static Config loadConfig() throws IOException {
|
||||
return new ObjectMapper().readerFor(Config.class).readValue(JSON_CONFIG);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testConfigGeneral() {
|
||||
Config config = null;
|
||||
try {
|
||||
config = loadConfig();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
assertNotNull(config);
|
||||
|
||||
assertNotNull(config.frame);
|
||||
assertNotNull(config.db);
|
||||
assertNotNull(config.sources);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testSources() {
|
||||
Config config = null;
|
||||
try {
|
||||
config = loadConfig();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
assertNotNull(config);
|
||||
assertNotNull(config.sources);
|
||||
|
||||
assertNotEquals(0, config.sources.size());
|
||||
|
||||
SourceItem m3u = config.sources.get(0);
|
||||
assertEquals(SourceItem.SourceType.M3U, m3u.type);
|
||||
assertEquals("https://example.com/list.m3u", m3u.url);
|
||||
assertNull(m3u.cookies);
|
||||
assertNull(m3u.singleCategory);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue