More content tests
This commit is contained in:
@@ -132,6 +132,10 @@ public class DynamicProductType implements ProductType<DynamicProduct> {
|
|||||||
return products.get(random.nextInt(products.size()));
|
return products.get(random.nextInt(products.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, DynamicProduct> getVariations() {
|
||||||
|
return variations;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ProductPrototype {
|
private static class ProductPrototype {
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
package de.siphalor.was;
|
package de.siphalor.was;
|
||||||
|
|
||||||
import de.siphalor.was.content.ContentManager;
|
import de.siphalor.was.content.ContentManager;
|
||||||
|
import de.siphalor.was.content.lang.I18n;
|
||||||
import de.siphalor.was.content.pack.ContentPack;
|
import de.siphalor.was.content.pack.ContentPack;
|
||||||
import de.siphalor.was.content.pack.JarContentPack;
|
import de.siphalor.was.content.pack.JarContentPack;
|
||||||
|
import de.siphalor.was.content.product.Product;
|
||||||
|
import de.siphalor.was.content.product.ProductManager;
|
||||||
|
import de.siphalor.was.content.product.dynamic.DynamicProduct;
|
||||||
|
import de.siphalor.was.content.product.dynamic.DynamicProductType;
|
||||||
|
import de.siphalor.was.content.resource.Resource;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.function.Executable;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ContentTests {
|
public class ContentTests {
|
||||||
static ContentManager contentManager;
|
static ContentManager contentManager;
|
||||||
@@ -18,7 +28,7 @@ public class ContentTests {
|
|||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void prepareAll() {
|
public static void prepareAll() {
|
||||||
contentManager = new ContentManager();
|
contentManager = new ContentManager();
|
||||||
contentPack = new JarContentPack("jar", "content");
|
contentPack = new JarContentPack("", "content");
|
||||||
contentManager.addPack(contentPack);
|
contentManager.addPack(contentPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,4 +46,52 @@ public class ContentTests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void productsI18n() {
|
||||||
|
ProductManager productManager = new ProductManager();
|
||||||
|
productManager.reload(contentManager);
|
||||||
|
I18n i18n = I18n.getInstance();
|
||||||
|
i18n.reload(contentManager);
|
||||||
|
|
||||||
|
Assertions.assertAll(
|
||||||
|
"Missing translations for products",
|
||||||
|
productManager.getTypes().stream().flatMap(productType -> {
|
||||||
|
String productKey = "products." + productType.getId();
|
||||||
|
Stream<Executable> stream = Arrays.stream(productType.getProperties()).map(property -> () ->
|
||||||
|
Assertions.assertTrue(
|
||||||
|
i18n.containsKey(productKey + "." + property),
|
||||||
|
() -> "Missing translation for property " + property + "@" + productType.getId() + ": " + productKey + "." + property
|
||||||
|
)
|
||||||
|
);
|
||||||
|
stream = Stream.concat(stream, Stream.of(() -> Assertions.assertTrue(i18n.containsKey(productKey), "Missing translation for product name: " + productKey)));
|
||||||
|
return stream;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void productImages() {
|
||||||
|
ProductManager productManager = new ProductManager();
|
||||||
|
productManager.reload(contentManager);
|
||||||
|
|
||||||
|
Assertions.assertAll(productManager.getTypes().stream().flatMap(productType -> {
|
||||||
|
if (productType instanceof DynamicProductType) {
|
||||||
|
return ((DynamicProductType) productType).getVariations().values().stream().map(dynamicProduct -> () -> {
|
||||||
|
Resource resource = contentManager.getResource(dynamicProduct.getTextureLocation()).orElse(null);
|
||||||
|
Assertions.assertNotNull(resource,
|
||||||
|
() -> "Couldn't find image resource for " + dynamicProduct.getTranslationKey()
|
||||||
|
+ " with properties " + dynamicProduct.getPropertySpecifier()
|
||||||
|
+ ": " + dynamicProduct.getTextureLocation()
|
||||||
|
);
|
||||||
|
Assertions.assertDoesNotThrow(() -> ImageIO.read(resource.getInputStream()),
|
||||||
|
() -> "Failed to load image resource for " + dynamicProduct.getTranslationKey()
|
||||||
|
+ "with properties " + dynamicProduct.getPropertySpecifier()
|
||||||
|
+ ": " + dynamicProduct.getTextureLocation()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Stream.empty();
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user