Skip to content

Commit

Permalink
Add test for complete resource-config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Dec 30, 2024
1 parent 9eebb10 commit 44eaa19
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
63 changes: 63 additions & 0 deletions core/src/main/resources/META-INF/native-image/resource-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2440,9 +2440,15 @@
{
"pattern": "\\Qorg/thymeleaf/thymeleaf.properties\\E"
},
{
"pattern": "\\Qstatic/css/additional.css\\E"
},
{
"pattern": "\\Qstatic/css/alllibs.css\\E"
},
{
"pattern": "\\Qstatic/css/alllibs.css.map\\E"
},
{
"pattern": "\\Qstatic/css/bright.css\\E"
},
Expand Down Expand Up @@ -2631,6 +2637,63 @@
},
{
"pattern": "java.base:\\Qsun/text/resources/SentenceBreakIteratorData\\E"
},
{
"pattern": "\\Qstatic/css/auto.css.map\\E"
},
{
"pattern": "\\Qstatic/css/bright.css.map\\E"
},
{
"pattern": "\\Qstatic/css/dark.css.map\\E"
},
{
"pattern": "\\Qstatic/css/grey.css.map\\E"
},
{
"pattern": "\\Qstatic/DO-NOT-EDIT-THESE-FILES\\E"
},
{
"pattern": "\\Qstatic/favicon.ico\\E"
},
{
"pattern": "\\Qstatic/img/checkmark.png\\E"
},
{
"pattern": "\\Qstatic/img/redcross.png\\E"
},
{
"pattern": "\\Qstatic/img/torbox.svg\\E"
},
{
"pattern": "\\Qstatic/index.html\\E"
},
{
"pattern": "\\Qstatic/js/additional.js\\E"
},
{
"pattern": "\\Qstatic/js/alllibs.js.map\\E"
},
{
"pattern": "\\Qstatic/js/nzbhydra.js.map\\E"
},
{
"pattern": "\\Qstatic/main.js\\E"
},
{
"pattern": "\\Qstatic/polyfills.js\\E"
},
{
"pattern": "\\Qstatic/runtime.js\\E"
},
{
"pattern": "\\Qstatic/styles.css\\E"
},
{
"pattern": "\\Qstatic/styles.css.map\\E"
},
{
"pattern": "\\Qstatic/vendor.js\\E"
}
]},
"bundles": [
Expand Down
64 changes: 64 additions & 0 deletions core/src/test/java/org/nzbhydra/ResourceConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* (C) Copyright 2024 TheOtherP ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.nzbhydra;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;

class ResourceConfigTest {

@Test
void shouldContainAllStaticResources() throws IOException {
// Get all files from static directory
Path staticDir = Paths.get("src/main/resources/static");
List<String> staticFiles;
try (Stream<Path> walked = Files.walk(staticDir)) {
staticFiles = walked
.filter(Files::isRegularFile)
.map(path -> "static/" + staticDir.relativize(path)
.toString()
.replace(File.separator, "/"))
.toList();
}

// Read and parse resource-config.json
Path configPath = Paths.get("src/main/resources/META-INF/native-image/resource-config.json");
ObjectMapper mapper = new ObjectMapper();
JsonNode config = mapper.readTree(configPath.toFile());

// Extract all patterns from config
List<String> patterns = new ArrayList<>();
config.get("resources").get("includes")
.forEach(include -> patterns.add(include.get("pattern").asText()));

assertThat(patterns)
.containsAll(staticFiles.stream().map(staticFile -> "\\Q" + staticFile + "\\E").toList());

}
}

0 comments on commit 44eaa19

Please sign in to comment.