diff --git a/pom.xml b/pom.xml index 2037ed99..0a661f62 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,8 @@ parent - parent-web - testtools + parent-web + testtools interfaces env-version jsconfig diff --git a/testtools/pom.xml b/testtools/pom.xml index 3c07b308..21c7980b 100644 --- a/testtools/pom.xml +++ b/testtools/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 testtools @@ -15,4 +16,24 @@ 21.1.0-SNAPSHOT ../pom.xml + + + + net.datafaker + datafaker + ${datafaker.version} + + + org.junit.jupiter + junit-jupiter + + + org.mockito + mockito-core + + + org.hamcrest + hamcrest + + diff --git a/testtools/src/main/java/tv/hd3g/commons/authkit/AuditAfter.java b/testtools/src/main/java/tv/hd3g/commons/authkit/AuditAfter.java deleted file mode 100644 index 8413b71a..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/authkit/AuditAfter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of AuthKit. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2019 - * - */ -package tv.hd3g.commons.authkit; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target({ TYPE, METHOD }) -@Repeatable(AuditAllAfter.class) -public @interface AuditAfter { - - /** - * Audit as this name. - */ - String value(); - - /** - * This action use (read) security: make an audit report. - */ - boolean useSecurity() default false; - - /** - * This action change (write) security: make an audit report. - */ - boolean changeSecurity() default false; - - /** - * Make an audit report if an error occurs during this action. - */ - boolean cantDoErrors() default false; - -} diff --git a/testtools/src/main/java/tv/hd3g/commons/authkit/AuditAllAfter.java b/testtools/src/main/java/tv/hd3g/commons/authkit/AuditAllAfter.java deleted file mode 100644 index 3698fd1c..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/authkit/AuditAllAfter.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of AuthKit. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2019 - * - */ -package tv.hd3g.commons.authkit; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target({ TYPE, METHOD }) -public @interface AuditAllAfter { - AuditAfter[] value(); -} diff --git a/testtools/src/main/java/tv/hd3g/commons/authkit/CheckBefore.java b/testtools/src/main/java/tv/hd3g/commons/authkit/CheckBefore.java deleted file mode 100644 index 91040b0a..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/authkit/CheckBefore.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of AuthKit. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2019 - * - */ -package tv.hd3g.commons.authkit; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target({ TYPE, METHOD }) -@Repeatable(CheckOneBefore.class) -public @interface CheckBefore { - - /** - * Mandatory tag(s): all must match with request owner tags. - * If empty: just require logged user. - */ - String[] value() default {}; - -} diff --git a/testtools/src/main/java/tv/hd3g/commons/authkit/CheckOneBefore.java b/testtools/src/main/java/tv/hd3g/commons/authkit/CheckOneBefore.java deleted file mode 100644 index 6ad3b8c1..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/authkit/CheckOneBefore.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of AuthKit. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2019 - * - */ -package tv.hd3g.commons.authkit; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target({ TYPE, METHOD }) -public @interface CheckOneBefore { - CheckBefore[] value(); -} diff --git a/testtools/src/main/java/tv/hd3g/commons/mailkit/SendMailDto.java b/testtools/src/main/java/tv/hd3g/commons/mailkit/SendMailDto.java deleted file mode 100644 index c4c4b3ad..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/mailkit/SendMailDto.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * This file is part of MailKit. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2020 - * - */ -package tv.hd3g.commons.mailkit; - -import java.io.File; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.SortedSet; - -public class SendMailDto { - - private final String templateName; - private final Locale lang; - private final Map templateVars; - - private final String senderAddr; - private final List recipientsAddr; - private final List recipientsCCAddr; - private final List recipientsBCCAddr; - - private String replyToAddr; - private MessageGrade grade; - private String externalReference; - private String senderReference; - private SortedSet attachedFiles; - private Set resourceFiles; - - public enum MessageGrade { - EVENT_NOTICE(3), - MARKETING(3), - URGENT(2), - SECURITY(1), - TEST(4); - - private final int messagePriority; - - MessageGrade(final int messagePriority) { - this.messagePriority = messagePriority; - } - - public int getMessagePriority() { - return messagePriority; - } - } - - public SendMailDto(final String templateName, - final Locale lang, - final Map templateVars, - final String senderAddr, - final List recipientsAddr, - final List recipientsCCAddr, - final List recipientsBCCAddr) { - this.templateName = Objects.requireNonNull(templateName); - this.lang = Objects.requireNonNull(lang); - this.templateVars = Objects.requireNonNull(templateVars); - this.senderAddr = Objects.requireNonNull(senderAddr); - this.recipientsAddr = Objects.requireNonNull(recipientsAddr); - this.recipientsCCAddr = Objects.requireNonNull(recipientsCCAddr); - this.recipientsBCCAddr = Objects.requireNonNull(recipientsBCCAddr); - } - - public SendMailDto(final String templateName, - final Locale lang, - final Map templateVars, - final String senderAddr, - final String... recipientsAddr) { - this(templateName, lang, templateVars, senderAddr, - List.of(Objects.requireNonNull(recipientsAddr)), - List.of(), - List.of()); - } - - public void setReplyToAddr(final String replyToAddr) { - this.replyToAddr = replyToAddr; - } - - public void setExternalReference(final String externalReference) { - this.externalReference = externalReference; - } - - public void setSenderReference(final String senderReference) { - this.senderReference = senderReference; - } - - public void setGrade(final MessageGrade grade) { - this.grade = grade; - } - - public String getTemplateName() { - return templateName; - } - - public Locale getLang() { - return lang; - } - - public Map getTemplateVars() { - return templateVars; - } - - public String getSenderAddr() { - return senderAddr; - } - - public List getRecipientsAddr() { - return recipientsAddr; - } - - public List getRecipientsCCAddr() { - return recipientsCCAddr; - } - - public List getRecipientsBCCAddr() { - return recipientsBCCAddr; - } - - public MessageGrade getGrade() { - return grade; - } - - /** - * @return can be null - */ - public String getExternalReference() { - return externalReference; - } - - /** - * @return can be null - */ - public String getSenderReference() { - return senderReference; - } - - /** - * @return can be null - */ - public String getReplyToAddr() { - return replyToAddr; - } - - /** - * @return can be null - */ - public SortedSet getAttachedFiles() { - return attachedFiles; - } - - public void setAttachedFiles(final SortedSet attachedFiles) { - this.attachedFiles = attachedFiles; - } - - /** - * @return can be null - */ - public Set getResourceFiles() { - return resourceFiles; - } - - public void setResourceFiles(final Set resourceFiles) { - this.resourceFiles = resourceFiles; - } -} diff --git a/testtools/src/main/java/tv/hd3g/commons/mailkit/SendMailService.java b/testtools/src/main/java/tv/hd3g/commons/mailkit/SendMailService.java deleted file mode 100644 index 4751d211..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/mailkit/SendMailService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is part of MailKit. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2020 - * - */ -package tv.hd3g.commons.mailkit; - -public interface SendMailService { - - void sendEmail(final SendMailDto sendMailDto); - -} diff --git a/testtools/src/main/java/tv/hd3g/commons/authkit/RenforceCheckBefore.java b/testtools/src/main/java/tv/hd3g/commons/testtools/Fake.java similarity index 70% rename from testtools/src/main/java/tv/hd3g/commons/authkit/RenforceCheckBefore.java rename to testtools/src/main/java/tv/hd3g/commons/testtools/Fake.java index eb2f1562..5bdad8cb 100644 --- a/testtools/src/main/java/tv/hd3g/commons/authkit/RenforceCheckBefore.java +++ b/testtools/src/main/java/tv/hd3g/commons/testtools/Fake.java @@ -1,5 +1,5 @@ /* - * This file is part of AuthKit. + * This file is part of fflauncher. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -11,19 +11,23 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * - * Copyright (C) hdsdi3g for hd3g.tv 2019 + * Copyright (C) hdsdi3g for hd3g.tv 2024 * */ -package tv.hd3g.commons.authkit; +package tv.hd3g.commons.testtools; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; +@Target({ FIELD }) @Retention(RUNTIME) -@Target({ TYPE, METHOD }) -public @interface RenforceCheckBefore { +public @interface Fake { + + long min() default 0; + + long max() default Long.MAX_VALUE; + } diff --git a/testtools/src/main/java/tv/hd3g/commons/testtools/MockToolsExtendsJunit.java b/testtools/src/main/java/tv/hd3g/commons/testtools/MockToolsExtendsJunit.java new file mode 100644 index 00000000..aee829ed --- /dev/null +++ b/testtools/src/main/java/tv/hd3g/commons/testtools/MockToolsExtendsJunit.java @@ -0,0 +1,122 @@ +/* + * This file is part of fflauncher. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * Copyright (C) hdsdi3g for hd3g.tv 2024 + * + */ +package tv.hd3g.commons.testtools; + +import static org.mockito.MockitoAnnotations.openMocks; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.function.Consumer; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.mockito.Mock; +import org.mockito.Mockito; + +import net.datafaker.Faker; + +public class MockToolsExtendsJunit implements BeforeEachCallback, AfterEachCallback {// TODO test MockToolsExtendsJunit + static Faker faker = net.datafaker.Faker.instance(); + + Object getFake(final Field field, final Class fromClass) { + final Class type = field.getType(); + final var name = field.getName(); + + final var fakeA = field.getAnnotation(Fake.class); + + if (type.isAssignableFrom(String.class)) { + return faker.numerify(name + "#####"); + } else if (type.isAssignableFrom(File.class)) { + return new File(faker.numerify(name + "#####")); + } else if (type.isEnum()) { + return faker.options().option(type.getEnumConstants()); + } else if (type.isAssignableFrom(Integer.TYPE)) { + return faker.random().nextInt( + fakeA.min() < Integer.MIN_VALUE ? Integer.MIN_VALUE : (int) fakeA.min(), + fakeA.max() > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) fakeA.max()); + } else if (type.isAssignableFrom(Long.TYPE)) { + return faker.random().nextLong(fakeA.min(), fakeA.max()); + } else if (type.isAssignableFrom(Double.TYPE)) { + return faker.random().nextDouble(fakeA.min(), fakeA.max()); + } else if (type.isAssignableFrom(Float.TYPE)) { + return faker.random().getRandomInternal().nextFloat( + fakeA.min() < Float.MIN_VALUE ? Float.MIN_VALUE : (float) fakeA.min(), + fakeA.max() > Float.MAX_VALUE ? Float.MAX_VALUE : (float) fakeA.max()); + } else if (type.isAssignableFrom(Boolean.TYPE)) { + return faker.random().nextBoolean(); + } + + throw new IllegalArgumentException("Can't manage this type: " + + type.getName() + + " on field [" + fromClass.getName() + "." + name + "]"); + } + + void apply(final Object instance) { + try { + openMocks(instance).close(); + } catch (final Exception e) { + throw new IllegalStateException(e); + } + + final var testClass = instance.getClass(); + + final Consumer setValue = f -> { + try { + f.set(instance, getFake(f, instance.getClass())); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + }; + + Stream.of(testClass.getDeclaredFields()) + .filter(f -> f.getAnnotation(Fake.class) != null) + .peek(f -> f.setAccessible(true)) + .forEach(setValue); + } + + void check(final Object instance) { + Stream.of(instance.getClass().getDeclaredFields()) + .filter(f -> f.getAnnotation(Mock.class) != null) + .peek(f -> f.setAccessible(true)) + .map(f -> { + try { + return f.get(instance); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + }) + .forEach(Mockito::verifyNoMoreInteractions); + } + + @Override + public void beforeEach(final ExtensionContext context) throws Exception { + context.getRequiredTestInstances() + .getAllInstances() + .forEach(this::apply); + + } + + @Override + public void afterEach(final ExtensionContext context) throws Exception { + context.getRequiredTestInstances() + .getAllInstances() + .forEach(this::check); + } + +} diff --git a/testtools/src/main/java/tv/hd3g/commons/version/EnvironmentVersion.java b/testtools/src/main/java/tv/hd3g/commons/version/EnvironmentVersion.java deleted file mode 100644 index 78449be1..00000000 --- a/testtools/src/main/java/tv/hd3g/commons/version/EnvironmentVersion.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of env-version. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2023 - * - */ -package tv.hd3g.commons.version; - -import java.lang.management.ManagementFactory; -import java.util.Date; - -public record EnvironmentVersion( - String appVersion, - String prodlibVersion, - String frameworkVersion, - String jvmVersion, - String jvmNameVendor, - long pid, - Date startupTime) { - - public static EnvironmentVersion makeEnvironmentVersion(final String appVersion, - final String prodlibVersion, - final String frameworkVersion) { - final var jvmVersion = Runtime.version().toString(); - final var pid = ManagementFactory.getRuntimeMXBean().getPid(); - final var startupTime = new Date(ManagementFactory.getRuntimeMXBean().getStartTime()); - final var jvmNameVendor = ManagementFactory.getRuntimeMXBean().getVmName() + " " + - ManagementFactory.getRuntimeMXBean().getVmVendor(); - - return new EnvironmentVersion( - appVersion, - prodlibVersion, - frameworkVersion, - jvmVersion, - jvmNameVendor, - pid, - startupTime); - } - -} diff --git a/testtools/src/test/java/tv/hd3g/commons/mailkit/CodePolicyValidationTest.java b/testtools/src/test/java/tv/hd3g/commons/mailkit/CodePolicyValidationTest.java deleted file mode 100644 index c2d2fa57..00000000 --- a/testtools/src/test/java/tv/hd3g/commons/mailkit/CodePolicyValidationTest.java +++ /dev/null @@ -1,6 +0,0 @@ -package tv.hd3g.commons.mailkit; - -import tv.hd3g.commons.codepolicyvalidation.CheckPolicy; - -public class CodePolicyValidationTest extends CheckPolicy { -} diff --git a/testtools/src/test/java/tv/hd3g/commons/mailkit/MessageGradeTest.java b/testtools/src/test/java/tv/hd3g/commons/mailkit/MessageGradeTest.java deleted file mode 100644 index 755179c7..00000000 --- a/testtools/src/test/java/tv/hd3g/commons/mailkit/MessageGradeTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package tv.hd3g.commons.mailkit; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -import tv.hd3g.commons.mailkit.SendMailDto.MessageGrade; - -class MessageGradeTest { - - @Test - void testGetMessagePriority() { - assertEquals(3, MessageGrade.EVENT_NOTICE.getMessagePriority()); - assertEquals(3, MessageGrade.MARKETING.getMessagePriority()); - assertEquals(1, MessageGrade.SECURITY.getMessagePriority()); - assertEquals(4, MessageGrade.TEST.getMessagePriority()); - } - -} diff --git a/testtools/src/test/java/tv/hd3g/commons/mailkit/SendMailDtoTest.java b/testtools/src/test/java/tv/hd3g/commons/mailkit/SendMailDtoTest.java deleted file mode 100644 index 7962957c..00000000 --- a/testtools/src/test/java/tv/hd3g/commons/mailkit/SendMailDtoTest.java +++ /dev/null @@ -1,232 +0,0 @@ -package tv.hd3g.commons.mailkit; - -import static net.datafaker.Faker.instance; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.io.File; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import org.apache.commons.lang3.RandomStringUtils; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import net.datafaker.service.RandomService; -import tv.hd3g.commons.mailkit.SendMailDto.MessageGrade; - -class SendMailDtoTest { - - public final static RandomService random = instance().random(); - - private SendMailDto sendMailDto; - - private String templateName; - private String senderAddr; - private String replyToAddr; - private MessageGrade grade; - private String externalReference; - private String senderReference; - - @Mock - private Locale lang; - @Mock - private Map templateVars; - @Mock - private List recipientsAddr; - @Mock - private List recipientsCCAddr; - @Mock - private List recipientsBCCAddr; - @Mock - private SortedSet attachedFiles; - @Mock - private Set resourceFiles; - - @BeforeEach - public void init() throws Exception { - MockitoAnnotations.openMocks(this).close(); - templateName = makeRandomString(); - senderAddr = makeRandomString(); - replyToAddr = makeRandomString(); - grade = getRandomEnum(MessageGrade.class); - externalReference = makeRandomString(); - senderReference = makeRandomString(); - - sendMailDto = new SendMailDto(templateName, lang, templateVars, senderAddr, - recipientsAddr, recipientsCCAddr, recipientsBCCAddr); - } - - @Test - void testSendMailDtoStringLocaleMapOfStringObjectStringListOfStringListOfStringListOfString() { - final var list = makeRandomThings().collect(Collectors.toList()); - final var recipientsAddr = new String[list.size()]; - for (var pos = 0; pos < recipientsAddr.length; pos++) { - recipientsAddr[pos] = list.get(pos); - } - - sendMailDto = new SendMailDto(templateName, lang, templateVars, senderAddr, recipientsAddr); - assertEquals(templateName, sendMailDto.getTemplateName()); - assertEquals(lang, sendMailDto.getLang()); - assertEquals(templateVars, sendMailDto.getTemplateVars()); - assertEquals(senderAddr, sendMailDto.getSenderAddr()); - - final var rList = sendMailDto.getRecipientsAddr(); - final var rRecipientsAddr = new String[rList.size()]; - for (var pos = 0; pos < rRecipientsAddr.length; pos++) { - rRecipientsAddr[pos] = rList.get(pos); - } - assertArrayEquals(recipientsAddr, rRecipientsAddr); - } - - @Test - void testGetTemplateName() { - assertEquals(templateName, sendMailDto.getTemplateName()); - } - - @Test - void testGetLang() { - assertEquals(lang, sendMailDto.getLang()); - } - - @Test - void testGetTemplateVars() { - assertEquals(templateVars, sendMailDto.getTemplateVars()); - } - - @Test - void testGetSenderAddr() { - assertEquals(senderAddr, sendMailDto.getSenderAddr()); - } - - @Test - void testGetRecipientsAddr() { - assertEquals(recipientsAddr, sendMailDto.getRecipientsAddr()); - } - - @Test - void testGetRecipientsCCAddr() { - assertEquals(recipientsCCAddr, sendMailDto.getRecipientsCCAddr()); - } - - @Test - void testGetRecipientsBCCAddr() { - assertEquals(recipientsBCCAddr, sendMailDto.getRecipientsBCCAddr()); - } - - @Test - void testSetGrade() { - sendMailDto.setGrade(grade); - assertEquals(grade, sendMailDto.getGrade()); - } - - @Test - void testGetGrade() { - assertNull(sendMailDto.getGrade()); - } - - @Test - void testSetReplyToAddr() { - sendMailDto.setReplyToAddr(replyToAddr); - assertEquals(replyToAddr, sendMailDto.getReplyToAddr()); - } - - @Test - void testGetReplyToAddr() { - assertNull(sendMailDto.getReplyToAddr()); - } - - @Test - void testSetSenderReference() { - sendMailDto.setSenderReference(senderReference); - assertEquals(senderReference, sendMailDto.getSenderReference()); - } - - @Test - void testGetSenderReference() { - assertNull(sendMailDto.getSenderReference()); - } - - @Test - void testSetExternalReference() { - sendMailDto.setExternalReference(externalReference); - assertEquals(externalReference, sendMailDto.getExternalReference()); - } - - @Test - void testGetExternalReference() { - assertNull(sendMailDto.getExternalReference()); - } - - @Test - void testSetAttachedFiles() { - sendMailDto.setAttachedFiles(attachedFiles); - assertEquals(attachedFiles, sendMailDto.getAttachedFiles()); - } - - @Test - void testGetAttachedFiles() { - assertNull(sendMailDto.getAttachedFiles()); - } - - @Test - void testSetResourceFiles() { - sendMailDto.setResourceFiles(resourceFiles); - assertEquals(resourceFiles, sendMailDto.getResourceFiles()); - } - - @Test - void testGetResourceFiles() { - assertNull(sendMailDto.getResourceFiles()); - } - - public static > T getRandomEnum(final Class enum_class) { - final var x = random.nextInt(enum_class.getEnumConstants().length); - return enum_class.getEnumConstants()[x]; - } - - public static String makeRandomString() { - return RandomStringUtils.randomAscii(5000, 10000); - } - - public static String makeRandomThing() { - switch (random.nextInt(10)) { - case 0: - return instance().aviation().aircraft(); - case 1: - return instance().app().name(); - case 2: - return instance().commerce().material(); - case 3: - return instance().company().name(); - case 4: - return instance().food().dish(); - case 5: - return instance().food().ingredient(); - case 6: - return instance().food().fruit(); - case 7: - return instance().food().spice(); - case 8: - return instance().food().sushi(); - case 9: - return instance().food().vegetable(); - default: - return instance().food().vegetable(); - } - } - - public static Stream makeRandomThings() { - return IntStream.range(0, random.nextInt(1, 20)).distinct().mapToObj(i -> makeRandomThing()); - } - -} diff --git a/testtools/src/test/java/tv/hd3g/commons/version/EnvironmentVersionTest.java b/testtools/src/test/java/tv/hd3g/commons/version/EnvironmentVersionTest.java deleted file mode 100644 index fcdecf55..00000000 --- a/testtools/src/test/java/tv/hd3g/commons/version/EnvironmentVersionTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of interfaces. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Copyright (C) hdsdi3g for hd3g.tv 2023 - * - */ -package tv.hd3g.commons.version; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -import net.datafaker.Faker; - -class EnvironmentVersionTest { - static Faker faker = net.datafaker.Faker.instance(); - - @Test - void testMake() { - final var appVersion = faker.numerify("appVersion###"); - final var prodlibVersion = faker.numerify("prodlibVersion###"); - final var frameworkVersion = faker.numerify("frameworkVersion###"); - - final var v = EnvironmentVersion.makeEnvironmentVersion(appVersion, prodlibVersion, frameworkVersion); - - assertNotNull(v); - assertEquals(appVersion, v.appVersion()); - assertEquals(prodlibVersion, v.prodlibVersion()); - assertEquals(frameworkVersion, v.frameworkVersion()); - assertNotNull(v.jvmVersion()); - assertNotNull(v.jvmNameVendor()); - assertTrue(v.pid() > 0l); - assertTrue(v.startupTime().getTime() > 0); - } - -}