Initial Project Commit
This commit is contained in:
commit
a6dea9c888
2148 changed files with 173870 additions and 0 deletions
|
@ -0,0 +1,57 @@
|
|||
package com.oguerreiro.resilient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
public class GeneratePasswordBCript {
|
||||
|
||||
/**
|
||||
* Generates a BCrypt password encoded, to use in user direct insert in database
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
List<String> passwords = new ArrayList<String>();
|
||||
passwords.add("cpss");
|
||||
passwords.add("cbernardo");
|
||||
passwords.add("chicau");
|
||||
passwords.add("paulap");
|
||||
passwords.add("susana.santos");
|
||||
passwords.add("manuel.salvador");
|
||||
passwords.add("vitoria.ferreira");
|
||||
passwords.add("pfluz");
|
||||
passwords.add("sribeiro");
|
||||
passwords.add("patricia.ferreira");
|
||||
passwords.add("jose.malcato");
|
||||
passwords.add("maria.ravara");
|
||||
|
||||
String pwdAppend = "#";
|
||||
List<String> numbers = GeneratePasswordBCript.getRandom(passwords.size());
|
||||
|
||||
for (String user : passwords) {
|
||||
String pwdRandom = numbers.get(0);
|
||||
numbers.remove(0);
|
||||
String pwd = user + pwdAppend + pwdRandom;
|
||||
String pwdCrypt = new BCryptPasswordEncoder().encode(pwd);
|
||||
System.out.println(user + " :: " + pwd + " = " + pwdCrypt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static List<String> getRandom(int size) {
|
||||
Set<String> numbers = new HashSet<>();
|
||||
|
||||
while (numbers.size() < size) {
|
||||
int random = ThreadLocalRandom.current().nextInt(10000, 100000); // 10000 to 99999
|
||||
numbers.add(String.valueOf(random));
|
||||
}
|
||||
|
||||
// Convert to a list to allow indexed access
|
||||
return new ArrayList<>(numbers);
|
||||
}
|
||||
}
|
20
src/test/java/com/oguerreiro/resilient/IntegrationTest.java
Normal file
20
src/test/java/com/oguerreiro/resilient/IntegrationTest.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package com.oguerreiro.resilient;
|
||||
|
||||
import com.oguerreiro.resilient.config.AsyncSyncConfiguration;
|
||||
import com.oguerreiro.resilient.config.EmbeddedSQL;
|
||||
import com.oguerreiro.resilient.config.JacksonConfiguration;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* Base composite annotation for integration tests.
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@SpringBootTest(classes = { ResilientApp.class, JacksonConfiguration.class, AsyncSyncConfiguration.class })
|
||||
@EmbeddedSQL
|
||||
public @interface IntegrationTest {
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.oguerreiro.resilient;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.oguerreiro.resilient.domain.Organization;
|
||||
import com.oguerreiro.resilient.domain.PeriodVersion;
|
||||
import com.oguerreiro.resilient.repository.OrganizationRepository;
|
||||
import com.oguerreiro.resilient.repository.OutputDataRepository;
|
||||
import com.oguerreiro.resilient.repository.PeriodVersionRepository;
|
||||
|
||||
@ActiveProfiles("testdev") // Replace "dev" with your desired profile
|
||||
@SpringBootTest
|
||||
class OutputDataSumTest {
|
||||
@Autowired
|
||||
private OutputDataRepository outputDataRepository;
|
||||
|
||||
@Autowired
|
||||
private OrganizationRepository organizationRepository;
|
||||
|
||||
@Autowired
|
||||
private PeriodVersionRepository periodVersionRepository;
|
||||
|
||||
@Test
|
||||
void sumLikeQuery() {
|
||||
Organization org = organizationRepository.getReferenceById(4L);
|
||||
PeriodVersion periodVersion = periodVersionRepository.getReferenceById(1511L);
|
||||
BigDecimal sum = outputDataRepository.sumAllOutputsFor(org, periodVersion, "5301%");
|
||||
|
||||
System.out.println(sum.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.oguerreiro.resilient;
|
||||
|
||||
import static com.tngtech.archunit.base.DescribedPredicate.alwaysTrue;
|
||||
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.belongToAnyOf;
|
||||
import static com.tngtech.archunit.library.Architectures.layeredArchitecture;
|
||||
|
||||
import com.tngtech.archunit.core.importer.ImportOption.DoNotIncludeTests;
|
||||
import com.tngtech.archunit.junit.AnalyzeClasses;
|
||||
import com.tngtech.archunit.junit.ArchTest;
|
||||
import com.tngtech.archunit.lang.ArchRule;
|
||||
|
||||
@AnalyzeClasses(packagesOf = ResilientApp.class, importOptions = DoNotIncludeTests.class)
|
||||
class TechnicalStructureTest {
|
||||
|
||||
// prettier-ignore
|
||||
@ArchTest
|
||||
static final ArchRule respectsTechnicalArchitectureLayers = layeredArchitecture()
|
||||
.consideringAllDependencies()
|
||||
.layer("Config").definedBy("..config..")
|
||||
.layer("Web").definedBy("..web..")
|
||||
.optionalLayer("Service").definedBy("..service..")
|
||||
.layer("Security").definedBy("..security..")
|
||||
.optionalLayer("Persistence").definedBy("..repository..")
|
||||
.layer("Domain").definedBy("..domain..")
|
||||
|
||||
.whereLayer("Config").mayNotBeAccessedByAnyLayer()
|
||||
.whereLayer("Web").mayOnlyBeAccessedByLayers("Config")
|
||||
.whereLayer("Service").mayOnlyBeAccessedByLayers("Web", "Config")
|
||||
.whereLayer("Security").mayOnlyBeAccessedByLayers("Config", "Service", "Web")
|
||||
.whereLayer("Persistence").mayOnlyBeAccessedByLayers("Service", "Security", "Web", "Config")
|
||||
.whereLayer("Domain").mayOnlyBeAccessedByLayers("Persistence", "Service", "Security", "Web", "Config")
|
||||
|
||||
.ignoreDependency(belongToAnyOf(ResilientApp.class), alwaysTrue())
|
||||
.ignoreDependency(alwaysTrue(), belongToAnyOf(
|
||||
com.oguerreiro.resilient.config.Constants.class,
|
||||
com.oguerreiro.resilient.config.ApplicationProperties.class
|
||||
));
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
|
||||
@Configuration
|
||||
public class AsyncSyncConfiguration {
|
||||
|
||||
@Bean(name = "taskExecutor")
|
||||
public Executor taskExecutor() {
|
||||
return new SyncTaskExecutor();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.MarkerFactory;
|
||||
import org.springframework.boot.ansi.AnsiColor;
|
||||
import org.springframework.boot.ansi.AnsiElement;
|
||||
|
||||
class CRLFLogConverterTest {
|
||||
|
||||
@Test
|
||||
void transformShouldReturnInputStringWhenMarkerListIsEmpty() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
when(event.getMarkerList()).thenReturn(null);
|
||||
when(event.getLoggerName()).thenReturn("org.hibernate.example.Logger");
|
||||
String input = "Test input string";
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
String result = converter.transform(event, input);
|
||||
|
||||
assertEquals(input, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transformShouldReturnInputStringWhenMarkersContainCRLFSafeMarker() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
Marker marker = MarkerFactory.getMarker("CRLF_SAFE");
|
||||
List<Marker> markers = Collections.singletonList(marker);
|
||||
when(event.getMarkerList()).thenReturn(markers);
|
||||
String input = "Test input string";
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
String result = converter.transform(event, input);
|
||||
|
||||
assertEquals(input, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transformShouldReturnInputStringWhenMarkersNotContainCRLFSafeMarker() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
Marker marker = MarkerFactory.getMarker("CRLF_NOT_SAFE");
|
||||
List<Marker> markers = Collections.singletonList(marker);
|
||||
when(event.getMarkerList()).thenReturn(markers);
|
||||
when(event.getLoggerName()).thenReturn("org.hibernate.example.Logger");
|
||||
String input = "Test input string";
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
String result = converter.transform(event, input);
|
||||
|
||||
assertEquals(input, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transformShouldReturnInputStringWhenLoggerIsSafe() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
when(event.getLoggerName()).thenReturn("org.hibernate.example.Logger");
|
||||
String input = "Test input string";
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
String result = converter.transform(event, input);
|
||||
|
||||
assertEquals(input, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transformShouldReplaceNewlinesAndCarriageReturnsWithUnderscoreWhenMarkersDoNotContainCRLFSafeMarkerAndLoggerIsNotSafe() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
List<Marker> markers = Collections.emptyList();
|
||||
when(event.getMarkerList()).thenReturn(markers);
|
||||
when(event.getLoggerName()).thenReturn("com.mycompany.myapp.example.Logger");
|
||||
String input = "Test\ninput\rstring";
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
String result = converter.transform(event, input);
|
||||
|
||||
assertEquals("Test_input_string", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transformShouldReplaceNewlinesAndCarriageReturnsWithAnsiStringWhenMarkersDoNotContainCRLFSafeMarkerAndLoggerIsNotSafeAndAnsiElementIsNotNull() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
List<Marker> markers = Collections.emptyList();
|
||||
when(event.getMarkerList()).thenReturn(markers);
|
||||
when(event.getLoggerName()).thenReturn("com.mycompany.myapp.example.Logger");
|
||||
String input = "Test\ninput\rstring";
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
converter.setOptionList(List.of("red"));
|
||||
|
||||
String result = converter.transform(event, input);
|
||||
|
||||
assertEquals("Test_input_string", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isLoggerSafeShouldReturnTrueWhenLoggerNameStartsWithSafeLogger() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
when(event.getLoggerName()).thenReturn("org.springframework.boot.autoconfigure.example.Logger");
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
boolean result = converter.isLoggerSafe(event);
|
||||
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isLoggerSafeShouldReturnFalseWhenLoggerNameDoesNotStartWithSafeLogger() {
|
||||
ILoggingEvent event = mock(ILoggingEvent.class);
|
||||
when(event.getLoggerName()).thenReturn("com.mycompany.myapp.example.Logger");
|
||||
CRLFLogConverter converter = new CRLFLogConverter();
|
||||
|
||||
boolean result = converter.isLoggerSafe(event);
|
||||
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToAnsiString() {
|
||||
CRLFLogConverter cut = new CRLFLogConverter();
|
||||
AnsiElement ansiElement = AnsiColor.RED;
|
||||
|
||||
String result = cut.toAnsiString("input", ansiElement);
|
||||
|
||||
assertThat(result).isEqualTo("input");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EmbeddedSQL {
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testcontainers.containers.JdbcDatabaseContainer;
|
||||
import org.testcontainers.containers.MySQLContainer;
|
||||
import org.testcontainers.containers.output.Slf4jLogConsumer;
|
||||
|
||||
public class MysqlTestContainer implements SqlTestContainer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MysqlTestContainer.class);
|
||||
|
||||
private MySQLContainer<?> mysqlContainer;
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (null != mysqlContainer && mysqlContainer.isRunning()) {
|
||||
mysqlContainer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (null == mysqlContainer) {
|
||||
mysqlContainer = new MySQLContainer<>("mysql:8.4.0")
|
||||
.withDatabaseName("resilient")
|
||||
.withTmpFs(Collections.singletonMap("/testtmpfs", "rw"))
|
||||
.withLogConsumer(new Slf4jLogConsumer(log))
|
||||
.withReuse(true);
|
||||
}
|
||||
if (!mysqlContainer.isRunning()) {
|
||||
mysqlContainer.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcDatabaseContainer<?> getTestContainer() {
|
||||
return mysqlContainer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import com.oguerreiro.resilient.IntegrationTest;
|
||||
import java.util.Comparator;
|
||||
import org.junit.jupiter.api.ClassDescriptor;
|
||||
import org.junit.jupiter.api.ClassOrderer;
|
||||
import org.junit.jupiter.api.ClassOrdererContext;
|
||||
|
||||
public class SpringBootTestClassOrderer implements ClassOrderer {
|
||||
|
||||
@Override
|
||||
public void orderClasses(ClassOrdererContext context) {
|
||||
context.getClassDescriptors().sort(Comparator.comparingInt(SpringBootTestClassOrderer::getOrder));
|
||||
}
|
||||
|
||||
private static int getOrder(ClassDescriptor classDescriptor) {
|
||||
if (classDescriptor.findAnnotation(IntegrationTest.class).isPresent()) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.testcontainers.containers.JdbcDatabaseContainer;
|
||||
|
||||
public interface SqlTestContainer extends InitializingBean, DisposableBean {
|
||||
JdbcDatabaseContainer<?> getTestContainer();
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.test.context.ContextConfigurationAttributes;
|
||||
import org.springframework.test.context.ContextCustomizer;
|
||||
import org.springframework.test.context.ContextCustomizerFactory;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
|
||||
public class SqlTestContainersSpringContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(SqlTestContainersSpringContextCustomizerFactory.class);
|
||||
|
||||
private static SqlTestContainer prodTestContainer;
|
||||
|
||||
@Override
|
||||
public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {
|
||||
return new ContextCustomizer() {
|
||||
@Override
|
||||
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
|
||||
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
|
||||
TestPropertyValues testValues = TestPropertyValues.empty();
|
||||
EmbeddedSQL sqlAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, EmbeddedSQL.class);
|
||||
if (null != sqlAnnotation) {
|
||||
log.debug("detected the EmbeddedSQL annotation on class {}", testClass.getName());
|
||||
log.info("Warming up the sql database");
|
||||
if (null == prodTestContainer) {
|
||||
try {
|
||||
Class<? extends SqlTestContainer> containerClass = (Class<? extends SqlTestContainer>) Class.forName(
|
||||
this.getClass().getPackageName() + ".MysqlTestContainer"
|
||||
);
|
||||
prodTestContainer = beanFactory.createBean(containerClass);
|
||||
beanFactory.registerSingleton(containerClass.getName(), prodTestContainer);
|
||||
/**
|
||||
* ((DefaultListableBeanFactory)beanFactory).registerDisposableBean(containerClass.getName(), prodTestContainer);
|
||||
*/
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
testValues = testValues.and(
|
||||
"spring.datasource.url=" +
|
||||
prodTestContainer.getTestContainer().getJdbcUrl() +
|
||||
"?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&createDatabaseIfNotExist=true"
|
||||
);
|
||||
testValues = testValues.and("spring.datasource.username=" + prodTestContainer.getTestContainer().getUsername());
|
||||
testValues = testValues.and("spring.datasource.password=" + prodTestContainer.getTestContainer().getPassword());
|
||||
}
|
||||
testValues.applyTo(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return SqlTestContainer.class.getName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.hashCode() == obj.hashCode();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import static com.oguerreiro.resilient.config.StaticResourcesWebConfiguration.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import tech.jhipster.config.JHipsterDefaults;
|
||||
import tech.jhipster.config.JHipsterProperties;
|
||||
|
||||
class StaticResourcesWebConfigurerTest {
|
||||
|
||||
public static final int MAX_AGE_TEST = 5;
|
||||
public StaticResourcesWebConfiguration staticResourcesWebConfiguration;
|
||||
private ResourceHandlerRegistry resourceHandlerRegistry;
|
||||
private MockServletContext servletContext;
|
||||
private WebApplicationContext applicationContext;
|
||||
private JHipsterProperties props;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
servletContext = spy(new MockServletContext());
|
||||
applicationContext = mock(WebApplicationContext.class);
|
||||
resourceHandlerRegistry = spy(new ResourceHandlerRegistry(applicationContext, servletContext));
|
||||
props = new JHipsterProperties();
|
||||
staticResourcesWebConfiguration = spy(new StaticResourcesWebConfiguration(props));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendResourceHandlerAndInitializeIt() {
|
||||
staticResourcesWebConfiguration.addResourceHandlers(resourceHandlerRegistry);
|
||||
|
||||
verify(resourceHandlerRegistry, times(1)).addResourceHandler(RESOURCE_PATHS);
|
||||
verify(staticResourcesWebConfiguration, times(1)).initializeResourceHandler(any(ResourceHandlerRegistration.class));
|
||||
for (String testingPath : RESOURCE_PATHS) {
|
||||
assertThat(resourceHandlerRegistry.hasMappingForPattern(testingPath)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInitializeResourceHandlerWithCacheControlAndLocations() {
|
||||
CacheControl ccExpected = CacheControl.maxAge(5, TimeUnit.DAYS).cachePublic();
|
||||
when(staticResourcesWebConfiguration.getCacheControl()).thenReturn(ccExpected);
|
||||
ResourceHandlerRegistration resourceHandlerRegistration = spy(new ResourceHandlerRegistration(RESOURCE_PATHS));
|
||||
|
||||
staticResourcesWebConfiguration.initializeResourceHandler(resourceHandlerRegistration);
|
||||
|
||||
verify(staticResourcesWebConfiguration, times(1)).getCacheControl();
|
||||
verify(resourceHandlerRegistration, times(1)).setCacheControl(ccExpected);
|
||||
verify(resourceHandlerRegistration, times(1)).addResourceLocations(RESOURCE_LOCATIONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateCacheControlBasedOnJhipsterDefaultProperties() {
|
||||
CacheControl cacheExpected = CacheControl.maxAge(JHipsterDefaults.Http.Cache.timeToLiveInDays, TimeUnit.DAYS).cachePublic();
|
||||
assertThat(staticResourcesWebConfiguration.getCacheControl())
|
||||
.extracting(CacheControl::getHeaderValue)
|
||||
.isEqualTo(cacheExpected.getHeaderValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateCacheControlWithSpecificConfigurationInProperties() {
|
||||
props.getHttp().getCache().setTimeToLiveInDays(MAX_AGE_TEST);
|
||||
CacheControl cacheExpected = CacheControl.maxAge(MAX_AGE_TEST, TimeUnit.DAYS).cachePublic();
|
||||
assertThat(staticResourcesWebConfiguration.getCacheControl())
|
||||
.extracting(CacheControl::getHeaderValue)
|
||||
.isEqualTo(cacheExpected.getHeaderValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import tech.jhipster.config.JHipsterConstants;
|
||||
import tech.jhipster.config.JHipsterProperties;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link WebConfigurer} class.
|
||||
*/
|
||||
class WebConfigurerTest {
|
||||
|
||||
private WebConfigurer webConfigurer;
|
||||
|
||||
private MockServletContext servletContext;
|
||||
|
||||
private MockEnvironment env;
|
||||
|
||||
private JHipsterProperties props;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
servletContext = spy(new MockServletContext());
|
||||
doReturn(mock(FilterRegistration.Dynamic.class)).when(servletContext).addFilter(anyString(), any(Filter.class));
|
||||
doReturn(mock(ServletRegistration.Dynamic.class)).when(servletContext).addServlet(anyString(), any(Servlet.class));
|
||||
|
||||
env = new MockEnvironment();
|
||||
props = new JHipsterProperties();
|
||||
|
||||
webConfigurer = new WebConfigurer(env, props);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCustomizeServletContainer() {
|
||||
env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
|
||||
UndertowServletWebServerFactory container = new UndertowServletWebServerFactory();
|
||||
webConfigurer.customize(container);
|
||||
assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
|
||||
assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html");
|
||||
assertThat(container.getMimeMappings().get("json")).isEqualTo("application/json");
|
||||
if (container.getDocumentRoot() != null) {
|
||||
assertThat(container.getDocumentRoot()).isEqualTo(new File("target/classes/static/"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCorsFilterOnApiPath() throws Exception {
|
||||
props.getCors().setAllowedOrigins(Collections.singletonList("other.domain.com"));
|
||||
props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
|
||||
props.getCors().setAllowedHeaders(Collections.singletonList("*"));
|
||||
props.getCors().setMaxAge(1800L);
|
||||
props.getCors().setAllowCredentials(true);
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
|
||||
|
||||
mockMvc
|
||||
.perform(
|
||||
options("/api/test-cors")
|
||||
.header(HttpHeaders.ORIGIN, "other.domain.com")
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
||||
)
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com"))
|
||||
.andExpect(header().string(HttpHeaders.VARY, "Origin"))
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE"))
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"))
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800"));
|
||||
|
||||
mockMvc
|
||||
.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCorsFilterOnOtherPath() throws Exception {
|
||||
props.getCors().setAllowedOrigins(Collections.singletonList("*"));
|
||||
props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
|
||||
props.getCors().setAllowedHeaders(Collections.singletonList("*"));
|
||||
props.getCors().setMaxAge(1800L);
|
||||
props.getCors().setAllowCredentials(true);
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
|
||||
|
||||
mockMvc
|
||||
.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCorsFilterDeactivatedForNullAllowedOrigins() throws Exception {
|
||||
props.getCors().setAllowedOrigins(null);
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
|
||||
|
||||
mockMvc
|
||||
.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCorsFilterDeactivatedForEmptyAllowedOrigins() throws Exception {
|
||||
props.getCors().setAllowedOrigins(new ArrayList<>());
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
|
||||
|
||||
mockMvc
|
||||
.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.oguerreiro.resilient.config;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class WebConfigurerTestController {
|
||||
|
||||
@GetMapping("/api/test-cors")
|
||||
public void testCorsOnApiPath() {}
|
||||
|
||||
@GetMapping("/test/test-cors")
|
||||
public void testCorsOnOtherPath() {}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
package com.oguerreiro.resilient.config.timezone;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.IntegrationTest;
|
||||
import com.oguerreiro.resilient.repository.timezone.DateTimeWrapper;
|
||||
import com.oguerreiro.resilient.repository.timezone.DateTimeWrapperRepository;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Integration tests for verifying the behavior of Hibernate in the context of storing various date and time types across different databases.
|
||||
* The tests focus on ensuring that the stored values are correctly transformed and stored according to the configured timezone.
|
||||
* Timezone is environment specific, and can be adjusted according to your needs.
|
||||
*
|
||||
* For more context, refer to:
|
||||
* - GitHub Issue: https://github.com/jhipster/generator-jhipster/issues/22579
|
||||
* - Pull Request: https://github.com/jhipster/generator-jhipster/pull/22946
|
||||
*/
|
||||
@IntegrationTest
|
||||
class HibernateTimeZoneIT {
|
||||
|
||||
@Autowired
|
||||
private DateTimeWrapperRepository dateTimeWrapperRepository;
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Value("${spring.jpa.properties.hibernate.jdbc.time_zone:UTC}")
|
||||
private String zoneId;
|
||||
|
||||
private DateTimeWrapper dateTimeWrapper;
|
||||
private DateTimeFormatter dateTimeFormatter;
|
||||
private DateTimeFormatter timeFormatter;
|
||||
private DateTimeFormatter offsetTimeFormatter;
|
||||
private DateTimeFormatter dateFormatter;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
dateTimeWrapper = new DateTimeWrapper();
|
||||
dateTimeWrapper.setInstant(Instant.parse("2014-11-12T05:10:00.0Z"));
|
||||
dateTimeWrapper.setLocalDateTime(LocalDateTime.parse("2014-11-12T07:20:00.0"));
|
||||
dateTimeWrapper.setOffsetDateTime(OffsetDateTime.parse("2011-12-14T08:30:00.0Z"));
|
||||
dateTimeWrapper.setZonedDateTime(ZonedDateTime.parse("2011-12-14T08:40:00.0Z"));
|
||||
dateTimeWrapper.setLocalTime(LocalTime.parse("14:50:00"));
|
||||
dateTimeWrapper.setOffsetTime(OffsetTime.parse("14:00:00+02:00"));
|
||||
dateTimeWrapper.setLocalDate(LocalDate.parse("2016-09-10"));
|
||||
|
||||
dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").withZone(ZoneId.of(zoneId));
|
||||
timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss").withZone(ZoneId.of(zoneId));
|
||||
offsetTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeInstantWithZoneIdConfigShouldBeStoredOnConfiguredTimeZone() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("instant", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeFormatter.format(dateTimeWrapper.getInstant());
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeLocalDateTimeWithZoneIdConfigShouldBeStoredOnConfiguredTimeZone() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("local_date_time", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeWrapper.getLocalDateTime().atZone(ZoneId.systemDefault()).format(dateTimeFormatter);
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeOffsetDateTimeWithZoneIdConfigShouldBeStoredOnConfiguredTimeZone() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("offset_date_time", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeWrapper.getOffsetDateTime().format(dateTimeFormatter);
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeZoneDateTimeWithZoneIdConfigShouldBeStoredOnConfiguredTimeZone() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("zoned_date_time", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeWrapper.getZonedDateTime().format(dateTimeFormatter);
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeLocalTimeWithZoneIdConfigShouldBeStoredOnConfiguredTimeZoneAccordingToHis1stJan1970Value() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("local_time", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeWrapper
|
||||
.getLocalTime()
|
||||
.atDate(LocalDate.of(1970, Month.JANUARY, 1))
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.format(timeFormatter);
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeOffsetTimeWithZoneIdConfigShouldBeStoredOnConfiguredTimeZoneAccordingToHis1stJan1970Value() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("offset_time", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeWrapper
|
||||
.getOffsetTime()
|
||||
// Convert to configured timezone
|
||||
.withOffsetSameInstant(ZoneId.of(zoneId).getRules().getOffset(Instant.now()))
|
||||
// Normalize to System TimeZone.
|
||||
// TODO this behavior looks a bug, refer to https://github.com/jhipster/generator-jhipster/issues/22579.
|
||||
.withOffsetSameLocal(OffsetDateTime.ofInstant(Instant.EPOCH, ZoneId.systemDefault()).getOffset())
|
||||
// Convert the normalized value to configured timezone
|
||||
.withOffsetSameInstant(ZoneId.of(zoneId).getRules().getOffset(Instant.EPOCH))
|
||||
.format(offsetTimeFormatter);
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void storeLocalDateWithZoneIdConfigShouldBeStoredWithoutTransformation() {
|
||||
dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);
|
||||
|
||||
String request = generateSqlRequest("local_date", dateTimeWrapper.getId());
|
||||
SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
|
||||
String expectedValue = dateTimeWrapper.getLocalDate().format(dateFormatter);
|
||||
|
||||
assertThatValueFromSqlRowSetIsEqualToExpectedValue(resultSet, expectedValue);
|
||||
}
|
||||
|
||||
private String generateSqlRequest(String fieldName, long id) {
|
||||
return format("SELECT %s FROM jhi_date_time_wrapper where id=%d", fieldName, id);
|
||||
}
|
||||
|
||||
private void assertThatValueFromSqlRowSetIsEqualToExpectedValue(SqlRowSet sqlRowSet, String expectedValue) {
|
||||
while (sqlRowSet.next()) {
|
||||
String dbValue = sqlRowSet.getString(1);
|
||||
|
||||
assertThat(dbValue).isNotNull();
|
||||
assertThat(dbValue).isEqualTo(expectedValue);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class AssertUtils {
|
||||
|
||||
public static Comparator<ZonedDateTime> zonedDataTimeSameInstant = Comparator.nullsFirst(
|
||||
(e1, a2) -> e1.withZoneSameInstant(ZoneOffset.UTC).compareTo(a2.withZoneSameInstant(ZoneOffset.UTC))
|
||||
);
|
||||
|
||||
public static Comparator<BigDecimal> bigDecimalCompareTo = Comparator.nullsFirst((e1, a2) -> e1.compareTo(a2));
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class AuthorityAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertAuthorityAllPropertiesEquals(Authority expected, Authority actual) {
|
||||
assertAuthorityAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertAuthorityAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertAuthorityAllUpdatablePropertiesEquals(Authority expected, Authority actual) {
|
||||
assertAuthorityUpdatableFieldsEquals(expected, actual);
|
||||
assertAuthorityUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertAuthorityAutoGeneratedPropertiesEquals(Authority expected, Authority actual) {}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertAuthorityUpdatableFieldsEquals(Authority expected, Authority actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Authority relevant properties")
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertAuthorityUpdatableRelationshipsEquals(Authority expected, Authority actual) {}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.AuthorityTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AuthorityTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(Authority.class);
|
||||
Authority authority1 = getAuthoritySample1();
|
||||
Authority authority2 = new Authority();
|
||||
assertThat(authority1).isNotEqualTo(authority2);
|
||||
|
||||
authority2.setName(authority1.getName());
|
||||
assertThat(authority1).isEqualTo(authority2);
|
||||
|
||||
authority2 = getAuthoritySample2();
|
||||
assertThat(authority1).isNotEqualTo(authority2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hashCodeVerifier() {
|
||||
Authority authority = new Authority();
|
||||
assertThat(authority.hashCode()).isZero();
|
||||
|
||||
Authority authority1 = getAuthoritySample1();
|
||||
authority.setName(authority1.getName());
|
||||
assertThat(authority).hasSameHashCodeAs(authority1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuthorityTestSamples {
|
||||
|
||||
public static Authority getAuthoritySample1() {
|
||||
return new Authority().name("name1");
|
||||
}
|
||||
|
||||
public static Authority getAuthoritySample2() {
|
||||
return new Authority().name("name2");
|
||||
}
|
||||
|
||||
public static Authority getAuthorityRandomSampleGenerator() {
|
||||
return new Authority().name(UUID.randomUUID().toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.AssertUtils.bigDecimalCompareTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class InputDataAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataAllPropertiesEquals(InputData expected, InputData actual) {
|
||||
assertInputDataAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertInputDataAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships)
|
||||
* set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataAllUpdatablePropertiesEquals(InputData expected, InputData actual) {
|
||||
assertInputDataUpdatableFieldsEquals(expected, actual);
|
||||
assertInputDataUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties
|
||||
* (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataAutoGeneratedPropertiesEquals(InputData expected, InputData actual) {
|
||||
assertThat(expected).as("Verify InputData auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUpdatableFieldsEquals(InputData expected, InputData actual) {
|
||||
assertThat(expected).as("Verify InputData relevant properties")
|
||||
.satisfies(e -> assertThat(e.getSourceValue()).as("check sourceValue").usingComparator(bigDecimalCompareTo)
|
||||
.isEqualTo(actual.getSourceValue()))
|
||||
.satisfies(e -> assertThat(e.getVariableValue()).as("check variableValue").usingComparator(bigDecimalCompareTo)
|
||||
.isEqualTo(actual.getVariableValue()))
|
||||
.satisfies(e -> assertThat(e.getImputedValue()).as("check imputedValue").usingComparator(bigDecimalCompareTo)
|
||||
.isEqualTo(actual.getImputedValue()))
|
||||
.satisfies(e -> assertThat(e.getSourceType()).as("check sourceType").isEqualTo(actual.getSourceType()))
|
||||
.satisfies(e -> assertThat(e.getDataDate()).as("check dataDate").isEqualTo(actual.getDataDate()))
|
||||
.satisfies(e -> assertThat(e.getChangeDate()).as("check changeDate").isEqualTo(actual.getChangeDate()))
|
||||
.satisfies(
|
||||
e -> assertThat(e.getChangeUsername()).as("check changeUsername").isEqualTo(actual.getChangeUsername()))
|
||||
.satisfies(e -> assertThat(e.getDataSource()).as("check dataSource").isEqualTo(actual.getDataSource()))
|
||||
.satisfies(e -> assertThat(e.getDataUser()).as("check dataUser").isEqualTo(actual.getDataUser()))
|
||||
.satisfies(e -> assertThat(e.getDataComments()).as("check dataComments").isEqualTo(actual.getDataComments()))
|
||||
.satisfies(e -> assertThat(e.getCreationDate()).as("check creationDate").isEqualTo(actual.getCreationDate()))
|
||||
.satisfies(e -> assertThat(e.getCreationUsername()).as("check creationUsername")
|
||||
.isEqualTo(actual.getCreationUsername()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUpdatableRelationshipsEquals(InputData expected, InputData actual) {
|
||||
assertThat(expected).as("Verify InputData relationships")
|
||||
.satisfies(e -> assertThat(e.getVariable()).as("check variable").isEqualTo(actual.getVariable()))
|
||||
.satisfies(e -> assertThat(e.getPeriod()).as("check period").isEqualTo(actual.getPeriod()))
|
||||
.satisfies(e -> assertThat(e.getSourceUnit()).as("check sourceUnit").isEqualTo(actual.getSourceUnit()))
|
||||
.satisfies(e -> assertThat(e.getUnit()).as("check unit").isEqualTo(actual.getUnit()))
|
||||
.satisfies(e -> assertThat(e.getOwner()).as("check owner").isEqualTo(actual.getOwner()))
|
||||
.satisfies(
|
||||
e -> assertThat(e.getSourceInputData()).as("check sourceInputData").isEqualTo(actual.getSourceInputData()))
|
||||
.satisfies(e -> assertThat(e.getSourceInputDataUpload()).as("check sourceInputDataUpload")
|
||||
.isEqualTo(actual.getSourceInputDataUpload()));
|
||||
}
|
||||
}
|
141
src/test/java/com/oguerreiro/resilient/domain/InputDataTest.java
Normal file
141
src/test/java/com/oguerreiro/resilient/domain/InputDataTest.java
Normal file
|
@ -0,0 +1,141 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataSample1;
|
||||
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataSample2;
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableRandomSampleGenerator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class InputDataTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(InputData.class);
|
||||
InputData inputData1 = getInputDataSample1();
|
||||
InputData inputData2 = new InputData();
|
||||
assertThat(inputData1).isNotEqualTo(inputData2);
|
||||
|
||||
inputData2.setId(inputData1.getId());
|
||||
assertThat(inputData1).isEqualTo(inputData2);
|
||||
|
||||
inputData2 = getInputDataSample2();
|
||||
assertThat(inputData1).isNotEqualTo(inputData2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void inputDataTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
InputData inputDataBack = getInputDataRandomSampleGenerator();
|
||||
|
||||
inputData.addInputData(inputDataBack);
|
||||
assertThat(inputData.getInputData()).containsOnly(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputData()).isEqualTo(inputData);
|
||||
|
||||
inputData.removeInputData(inputDataBack);
|
||||
assertThat(inputData.getInputData()).doesNotContain(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputData()).isNull();
|
||||
|
||||
inputData.inputData(new HashSet<>(Set.of(inputDataBack)));
|
||||
assertThat(inputData.getInputData()).containsOnly(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputData()).isEqualTo(inputData);
|
||||
|
||||
inputData.setInputData(new HashSet<>());
|
||||
assertThat(inputData.getInputData()).doesNotContain(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
Variable variableBack = getVariableRandomSampleGenerator();
|
||||
|
||||
inputData.setVariable(variableBack);
|
||||
assertThat(inputData.getVariable()).isEqualTo(variableBack);
|
||||
|
||||
inputData.variable(null);
|
||||
assertThat(inputData.getVariable()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void periodTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
Period periodBack = getPeriodRandomSampleGenerator();
|
||||
|
||||
inputData.setPeriod(periodBack);
|
||||
assertThat(inputData.getPeriod()).isEqualTo(periodBack);
|
||||
|
||||
inputData.period(null);
|
||||
assertThat(inputData.getPeriod()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceUnitTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
inputData.setSourceUnit(unitBack);
|
||||
assertThat(inputData.getSourceUnit()).isEqualTo(unitBack);
|
||||
|
||||
inputData.sourceUnit(null);
|
||||
assertThat(inputData.getSourceUnit()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void unitTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
inputData.setUnit(unitBack);
|
||||
assertThat(inputData.getUnit()).isEqualTo(unitBack);
|
||||
|
||||
inputData.unit(null);
|
||||
assertThat(inputData.getUnit()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void ownerTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
Organization organizationBack = getOrganizationRandomSampleGenerator();
|
||||
|
||||
inputData.setOwner(organizationBack);
|
||||
assertThat(inputData.getOwner()).isEqualTo(organizationBack);
|
||||
|
||||
inputData.owner(null);
|
||||
assertThat(inputData.getOwner()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceInputDataTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
InputData inputDataBack = getInputDataRandomSampleGenerator();
|
||||
|
||||
inputData.setSourceInputData(inputDataBack);
|
||||
assertThat(inputData.getSourceInputData()).isEqualTo(inputDataBack);
|
||||
|
||||
inputData.sourceInputData(null);
|
||||
assertThat(inputData.getSourceInputData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceInputDataUploadTest() {
|
||||
InputData inputData = getInputDataRandomSampleGenerator();
|
||||
InputDataUpload inputDataUploadBack = getInputDataUploadRandomSampleGenerator();
|
||||
|
||||
inputData.setSourceInputDataUpload(inputDataUploadBack);
|
||||
assertThat(inputData.getSourceInputDataUpload()).isEqualTo(inputDataUploadBack);
|
||||
|
||||
inputData.sourceInputDataUpload(null);
|
||||
assertThat(inputData.getSourceInputDataUpload()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class InputDataTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static InputData getInputDataSample1() {
|
||||
return new InputData()
|
||||
.id(1L)
|
||||
.changeUsername("changeUsername1")
|
||||
.dataSource("dataSource1")
|
||||
.dataUser("dataUser1")
|
||||
.dataComments("dataComments1")
|
||||
.creationUsername("creationUsername1")
|
||||
.version(1);
|
||||
}
|
||||
|
||||
public static InputData getInputDataSample2() {
|
||||
return new InputData()
|
||||
.id(2L)
|
||||
.changeUsername("changeUsername2")
|
||||
.dataSource("dataSource2")
|
||||
.dataUser("dataUser2")
|
||||
.dataComments("dataComments2")
|
||||
.creationUsername("creationUsername2")
|
||||
.version(2);
|
||||
}
|
||||
|
||||
public static InputData getInputDataRandomSampleGenerator() {
|
||||
return new InputData()
|
||||
.id(longCount.incrementAndGet())
|
||||
.changeUsername(UUID.randomUUID().toString())
|
||||
.dataSource(UUID.randomUUID().toString())
|
||||
.dataUser(UUID.randomUUID().toString())
|
||||
.dataComments(UUID.randomUUID().toString())
|
||||
.creationUsername(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class InputDataUploadAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadAllPropertiesEquals(InputDataUpload expected, InputDataUpload actual) {
|
||||
assertInputDataUploadAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertInputDataUploadAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships)
|
||||
* set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadAllUpdatablePropertiesEquals(InputDataUpload expected,
|
||||
InputDataUpload actual) {
|
||||
assertInputDataUploadUpdatableFieldsEquals(expected, actual);
|
||||
assertInputDataUploadUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties
|
||||
* (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadAutoGeneratedPropertiesEquals(InputDataUpload expected,
|
||||
InputDataUpload actual) {
|
||||
assertThat(expected).as("Verify InputDataUpload auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadUpdatableFieldsEquals(InputDataUpload expected, InputDataUpload actual) {
|
||||
assertThat(expected).as("Verify InputDataUpload relevant properties")
|
||||
.satisfies(e -> assertThat(e.getTitle()).as("check title").isEqualTo(actual.getTitle()))
|
||||
.satisfies(e -> assertThat(e.getDataFile()).as("check dataFile").isEqualTo(actual.getDataFile()))
|
||||
.satisfies(e -> assertThat(e.getDataFileContentType()).as("check dataFile contenty type")
|
||||
.isEqualTo(actual.getDataFileContentType()))
|
||||
.satisfies(
|
||||
e -> assertThat(e.getUploadFileName()).as("check uploadFileName").isEqualTo(actual.getUploadFileName()))
|
||||
.satisfies(e -> assertThat(e.getDiskFileName()).as("check diskFileName").isEqualTo(actual.getDiskFileName()))
|
||||
.satisfies(e -> assertThat(e.getType()).as("check type").isEqualTo(actual.getType()))
|
||||
.satisfies(e -> assertThat(e.getState()).as("check state").isEqualTo(actual.getState()))
|
||||
.satisfies(e -> assertThat(e.getComments()).as("check comments").isEqualTo(actual.getComments()))
|
||||
.satisfies(e -> assertThat(e.getCreationDate()).as("check creationDate").isEqualTo(actual.getCreationDate()))
|
||||
.satisfies(e -> assertThat(e.getCreationUsername()).as("check creationUsername")
|
||||
.isEqualTo(actual.getCreationUsername()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadUpdatableRelationshipsEquals(InputDataUpload expected,
|
||||
InputDataUpload actual) {
|
||||
assertThat(expected).as("Verify InputDataUpload relationships")
|
||||
.satisfies(e -> assertThat(e.getPeriod()).as("check period").isEqualTo(actual.getPeriod()))
|
||||
.satisfies(e -> assertThat(e.getOwner()).as("check owner").isEqualTo(actual.getOwner()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class InputDataUploadLogAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadLogAllPropertiesEquals(InputDataUploadLog expected, InputDataUploadLog actual) {
|
||||
assertInputDataUploadLogAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertInputDataUploadLogAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadLogAllUpdatablePropertiesEquals(InputDataUploadLog expected, InputDataUploadLog actual) {
|
||||
assertInputDataUploadLogUpdatableFieldsEquals(expected, actual);
|
||||
assertInputDataUploadLogUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadLogAutoGeneratedPropertiesEquals(InputDataUploadLog expected, InputDataUploadLog actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify InputDataUploadLog auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadLogUpdatableFieldsEquals(InputDataUploadLog expected, InputDataUploadLog actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify InputDataUploadLog relevant properties")
|
||||
.satisfies(e -> assertThat(e.getLogMessage()).as("check logMessage").isEqualTo(actual.getLogMessage()))
|
||||
.satisfies(e -> assertThat(e.getCreationDate()).as("check creationDate").isEqualTo(actual.getCreationDate()))
|
||||
.satisfies(e -> assertThat(e.getCreationUsername()).as("check creationUsername").isEqualTo(actual.getCreationUsername()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertInputDataUploadLogUpdatableRelationshipsEquals(InputDataUploadLog expected, InputDataUploadLog actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify InputDataUploadLog relationships")
|
||||
.satisfies(e -> assertThat(e.getInputDataUpload()).as("check inputDataUpload").isEqualTo(actual.getInputDataUpload()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadLogTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class InputDataUploadLogTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(InputDataUploadLog.class);
|
||||
InputDataUploadLog inputDataUploadLog1 = getInputDataUploadLogSample1();
|
||||
InputDataUploadLog inputDataUploadLog2 = new InputDataUploadLog();
|
||||
assertThat(inputDataUploadLog1).isNotEqualTo(inputDataUploadLog2);
|
||||
|
||||
inputDataUploadLog2.setId(inputDataUploadLog1.getId());
|
||||
assertThat(inputDataUploadLog1).isEqualTo(inputDataUploadLog2);
|
||||
|
||||
inputDataUploadLog2 = getInputDataUploadLogSample2();
|
||||
assertThat(inputDataUploadLog1).isNotEqualTo(inputDataUploadLog2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void inputDataUploadTest() {
|
||||
InputDataUploadLog inputDataUploadLog = getInputDataUploadLogRandomSampleGenerator();
|
||||
InputDataUpload inputDataUploadBack = getInputDataUploadRandomSampleGenerator();
|
||||
|
||||
inputDataUploadLog.setInputDataUpload(inputDataUploadBack);
|
||||
assertThat(inputDataUploadLog.getInputDataUpload()).isEqualTo(inputDataUploadBack);
|
||||
|
||||
inputDataUploadLog.inputDataUpload(null);
|
||||
assertThat(inputDataUploadLog.getInputDataUpload()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class InputDataUploadLogTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static InputDataUploadLog getInputDataUploadLogSample1() {
|
||||
return new InputDataUploadLog().id(1L).logMessage("logMessage1").creationUsername("creationUsername1").version(1);
|
||||
}
|
||||
|
||||
public static InputDataUploadLog getInputDataUploadLogSample2() {
|
||||
return new InputDataUploadLog().id(2L).logMessage("logMessage2").creationUsername("creationUsername2").version(2);
|
||||
}
|
||||
|
||||
public static InputDataUploadLog getInputDataUploadLogRandomSampleGenerator() {
|
||||
return new InputDataUploadLog()
|
||||
.id(longCount.incrementAndGet())
|
||||
.logMessage(UUID.randomUUID().toString())
|
||||
.creationUsername(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadLogTestSamples.getInputDataUploadLogRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadSample1;
|
||||
import static com.oguerreiro.resilient.domain.InputDataUploadTestSamples.getInputDataUploadSample2;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class InputDataUploadTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(InputDataUpload.class);
|
||||
InputDataUpload inputDataUpload1 = getInputDataUploadSample1();
|
||||
InputDataUpload inputDataUpload2 = new InputDataUpload();
|
||||
assertThat(inputDataUpload1).isNotEqualTo(inputDataUpload2);
|
||||
|
||||
inputDataUpload2.setId(inputDataUpload1.getId());
|
||||
assertThat(inputDataUpload1).isEqualTo(inputDataUpload2);
|
||||
|
||||
inputDataUpload2 = getInputDataUploadSample2();
|
||||
assertThat(inputDataUpload1).isNotEqualTo(inputDataUpload2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void inputDataTest() {
|
||||
InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
|
||||
InputData inputDataBack = getInputDataRandomSampleGenerator();
|
||||
|
||||
inputDataUpload.addInputData(inputDataBack);
|
||||
assertThat(inputDataUpload.getInputData()).containsOnly(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputDataUpload()).isEqualTo(inputDataUpload);
|
||||
|
||||
inputDataUpload.removeInputData(inputDataBack);
|
||||
assertThat(inputDataUpload.getInputData()).doesNotContain(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputDataUpload()).isNull();
|
||||
|
||||
inputDataUpload.inputData(new HashSet<>(Set.of(inputDataBack)));
|
||||
assertThat(inputDataUpload.getInputData()).containsOnly(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputDataUpload()).isEqualTo(inputDataUpload);
|
||||
|
||||
inputDataUpload.setInputData(new HashSet<>());
|
||||
assertThat(inputDataUpload.getInputData()).doesNotContain(inputDataBack);
|
||||
assertThat(inputDataBack.getSourceInputDataUpload()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void inputDataUploadLogTest() {
|
||||
InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
|
||||
InputDataUploadLog inputDataUploadLogBack = getInputDataUploadLogRandomSampleGenerator();
|
||||
|
||||
inputDataUpload.addInputDataUploadLog(inputDataUploadLogBack);
|
||||
assertThat(inputDataUpload.getInputDataUploadLogs()).containsOnly(inputDataUploadLogBack);
|
||||
assertThat(inputDataUploadLogBack.getInputDataUpload()).isEqualTo(inputDataUpload);
|
||||
|
||||
inputDataUpload.removeInputDataUploadLog(inputDataUploadLogBack);
|
||||
assertThat(inputDataUpload.getInputDataUploadLogs()).doesNotContain(inputDataUploadLogBack);
|
||||
assertThat(inputDataUploadLogBack.getInputDataUpload()).isNull();
|
||||
|
||||
inputDataUpload.inputDataUploadLogs(new HashSet<>(Set.of(inputDataUploadLogBack)));
|
||||
assertThat(inputDataUpload.getInputDataUploadLogs()).containsOnly(inputDataUploadLogBack);
|
||||
assertThat(inputDataUploadLogBack.getInputDataUpload()).isEqualTo(inputDataUpload);
|
||||
|
||||
inputDataUpload.setInputDataUploadLogs(new HashSet<>());
|
||||
assertThat(inputDataUpload.getInputDataUploadLogs()).doesNotContain(inputDataUploadLogBack);
|
||||
assertThat(inputDataUploadLogBack.getInputDataUpload()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void periodTest() {
|
||||
InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
|
||||
Period periodBack = getPeriodRandomSampleGenerator();
|
||||
|
||||
inputDataUpload.setPeriod(periodBack);
|
||||
assertThat(inputDataUpload.getPeriod()).isEqualTo(periodBack);
|
||||
|
||||
inputDataUpload.period(null);
|
||||
assertThat(inputDataUpload.getPeriod()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void ownerTest() {
|
||||
InputDataUpload inputDataUpload = getInputDataUploadRandomSampleGenerator();
|
||||
Organization organizationBack = getOrganizationRandomSampleGenerator();
|
||||
|
||||
inputDataUpload.setOwner(organizationBack);
|
||||
assertThat(inputDataUpload.getOwner()).isEqualTo(organizationBack);
|
||||
|
||||
inputDataUpload.owner(null);
|
||||
assertThat(inputDataUpload.getOwner()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class InputDataUploadTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static InputDataUpload getInputDataUploadSample1() {
|
||||
return new InputDataUpload()
|
||||
.id(1L)
|
||||
.title("title1")
|
||||
.uploadFileName("uploadFileName1")
|
||||
.diskFileName("diskFileName1")
|
||||
.comments("comments1")
|
||||
.creationUsername("creationUsername1")
|
||||
.version(1);
|
||||
}
|
||||
|
||||
public static InputDataUpload getInputDataUploadSample2() {
|
||||
return new InputDataUpload()
|
||||
.id(2L)
|
||||
.title("title2")
|
||||
.uploadFileName("uploadFileName2")
|
||||
.diskFileName("diskFileName2")
|
||||
.comments("comments2")
|
||||
.creationUsername("creationUsername2")
|
||||
.version(2);
|
||||
}
|
||||
|
||||
public static InputDataUpload getInputDataUploadRandomSampleGenerator() {
|
||||
return new InputDataUpload()
|
||||
.id(longCount.incrementAndGet())
|
||||
.title(UUID.randomUUID().toString())
|
||||
.uploadFileName(UUID.randomUUID().toString())
|
||||
.diskFileName(UUID.randomUUID().toString())
|
||||
.comments(UUID.randomUUID().toString())
|
||||
.creationUsername(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MetadataPropertyAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataPropertyAllPropertiesEquals(MetadataProperty expected, MetadataProperty actual) {
|
||||
assertMetadataPropertyAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertMetadataPropertyAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataPropertyAllUpdatablePropertiesEquals(MetadataProperty expected, MetadataProperty actual) {
|
||||
assertMetadataPropertyUpdatableFieldsEquals(expected, actual);
|
||||
assertMetadataPropertyUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataPropertyAutoGeneratedPropertiesEquals(MetadataProperty expected, MetadataProperty actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify MetadataProperty auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataPropertyUpdatableFieldsEquals(MetadataProperty expected, MetadataProperty actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify MetadataProperty relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getMandatory()).as("check mandatory").isEqualTo(actual.getMandatory()))
|
||||
.satisfies(e -> assertThat(e.getMetadataType()).as("check metadataType").isEqualTo(actual.getMetadataType()))
|
||||
.satisfies(e -> assertThat(e.getPattern()).as("check pattern").isEqualTo(actual.getPattern()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataPropertyUpdatableRelationshipsEquals(MetadataProperty expected, MetadataProperty actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify MetadataProperty relationships")
|
||||
.satisfies(e -> assertThat(e.getOrganizationTypes()).as("check organizationTypes").isEqualTo(actual.getOrganizationTypes()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.MetadataPropertyTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTypeTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MetadataPropertyTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(MetadataProperty.class);
|
||||
MetadataProperty metadataProperty1 = getMetadataPropertySample1();
|
||||
MetadataProperty metadataProperty2 = new MetadataProperty();
|
||||
assertThat(metadataProperty1).isNotEqualTo(metadataProperty2);
|
||||
|
||||
metadataProperty2.setId(metadataProperty1.getId());
|
||||
assertThat(metadataProperty1).isEqualTo(metadataProperty2);
|
||||
|
||||
metadataProperty2 = getMetadataPropertySample2();
|
||||
assertThat(metadataProperty1).isNotEqualTo(metadataProperty2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void organizationTypeTest() {
|
||||
MetadataProperty metadataProperty = getMetadataPropertyRandomSampleGenerator();
|
||||
OrganizationType organizationTypeBack = getOrganizationTypeRandomSampleGenerator();
|
||||
|
||||
metadataProperty.addOrganizationType(organizationTypeBack);
|
||||
assertThat(metadataProperty.getOrganizationTypes()).containsOnly(organizationTypeBack);
|
||||
assertThat(organizationTypeBack.getMetadataProperties()).containsOnly(metadataProperty);
|
||||
|
||||
metadataProperty.removeOrganizationType(organizationTypeBack);
|
||||
assertThat(metadataProperty.getOrganizationTypes()).doesNotContain(organizationTypeBack);
|
||||
assertThat(organizationTypeBack.getMetadataProperties()).doesNotContain(metadataProperty);
|
||||
|
||||
metadataProperty.organizationTypes(new HashSet<>(Set.of(organizationTypeBack)));
|
||||
assertThat(metadataProperty.getOrganizationTypes()).containsOnly(organizationTypeBack);
|
||||
assertThat(organizationTypeBack.getMetadataProperties()).containsOnly(metadataProperty);
|
||||
|
||||
metadataProperty.setOrganizationTypes(new HashSet<>());
|
||||
assertThat(metadataProperty.getOrganizationTypes()).doesNotContain(organizationTypeBack);
|
||||
assertThat(organizationTypeBack.getMetadataProperties()).doesNotContain(metadataProperty);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class MetadataPropertyTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static MetadataProperty getMetadataPropertySample1() {
|
||||
return new MetadataProperty().id(1L).code("code1").name("name1").description("description1").pattern("pattern1").version(1);
|
||||
}
|
||||
|
||||
public static MetadataProperty getMetadataPropertySample2() {
|
||||
return new MetadataProperty().id(2L).code("code2").name("name2").description("description2").pattern("pattern2").version(2);
|
||||
}
|
||||
|
||||
public static MetadataProperty getMetadataPropertyRandomSampleGenerator() {
|
||||
return new MetadataProperty()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.pattern(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MetadataValueAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataValueAllPropertiesEquals(MetadataValue expected, MetadataValue actual) {
|
||||
assertMetadataValueAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertMetadataValueAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataValueAllUpdatablePropertiesEquals(MetadataValue expected, MetadataValue actual) {
|
||||
assertMetadataValueUpdatableFieldsEquals(expected, actual);
|
||||
assertMetadataValueUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataValueAutoGeneratedPropertiesEquals(MetadataValue expected, MetadataValue actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify MetadataValue auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataValueUpdatableFieldsEquals(MetadataValue expected, MetadataValue actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify MetadataValue relevant properties")
|
||||
.satisfies(
|
||||
e -> assertThat(e.getMetadataPropertyCode()).as("check metadataPropertyCode").isEqualTo(actual.getMetadataPropertyCode())
|
||||
)
|
||||
.satisfies(e -> assertThat(e.getTargetDomainKey()).as("check targetDomainKey").isEqualTo(actual.getTargetDomainKey()))
|
||||
.satisfies(e -> assertThat(e.getTargetDomainId()).as("check targetDomainId").isEqualTo(actual.getTargetDomainId()))
|
||||
.satisfies(e -> assertThat(e.getValue()).as("check value").isEqualTo(actual.getValue()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertMetadataValueUpdatableRelationshipsEquals(MetadataValue expected, MetadataValue actual) {}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.MetadataValueTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MetadataValueTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(MetadataValue.class);
|
||||
MetadataValue metadataValue1 = getMetadataValueSample1();
|
||||
MetadataValue metadataValue2 = new MetadataValue();
|
||||
assertThat(metadataValue1).isNotEqualTo(metadataValue2);
|
||||
|
||||
metadataValue2.setId(metadataValue1.getId());
|
||||
assertThat(metadataValue1).isEqualTo(metadataValue2);
|
||||
|
||||
metadataValue2 = getMetadataValueSample2();
|
||||
assertThat(metadataValue1).isNotEqualTo(metadataValue2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class MetadataValueTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static MetadataValue getMetadataValueSample1() {
|
||||
return new MetadataValue()
|
||||
.id(1L)
|
||||
.metadataPropertyCode("metadataPropertyCode1")
|
||||
.targetDomainKey("targetDomainKey1")
|
||||
.targetDomainId(1L)
|
||||
.value("value1")
|
||||
.version(1);
|
||||
}
|
||||
|
||||
public static MetadataValue getMetadataValueSample2() {
|
||||
return new MetadataValue()
|
||||
.id(2L)
|
||||
.metadataPropertyCode("metadataPropertyCode2")
|
||||
.targetDomainKey("targetDomainKey2")
|
||||
.targetDomainId(2L)
|
||||
.value("value2")
|
||||
.version(2);
|
||||
}
|
||||
|
||||
public static MetadataValue getMetadataValueRandomSampleGenerator() {
|
||||
return new MetadataValue()
|
||||
.id(longCount.incrementAndGet())
|
||||
.metadataPropertyCode(UUID.randomUUID().toString())
|
||||
.targetDomainKey(UUID.randomUUID().toString())
|
||||
.targetDomainId(longCount.incrementAndGet())
|
||||
.value(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
29
src/test/java/com/oguerreiro/resilient/domain/MvelTest.java
Normal file
29
src/test/java/com/oguerreiro/resilient/domain/MvelTest.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mvel2.MVEL;
|
||||
|
||||
public class MvelTest {
|
||||
@Test
|
||||
void mvelEvalTest() throws Exception {
|
||||
String expression = "int i = 10; " + "int ii = 20; " + "i*ii+10";
|
||||
expression = "10.10**2";
|
||||
//expression = "i = Math.pow(10.10, 2); Math.round(i * 100) / 100.0";
|
||||
//expression = "Math.round(Math.pow(10.10, 2) * 100) / 100.0";
|
||||
|
||||
Map<String, Object> variables = new HashMap<String, Object>();
|
||||
|
||||
System.out.println(evaluateExpression(expression, variables));
|
||||
}
|
||||
|
||||
public Object evaluateExpression(String expression, Map<String, Object> variables) {
|
||||
// Compiling the expression for performance (optional)
|
||||
Serializable compiledExpression = MVEL.compileExpression(expression);
|
||||
// Execute the compiled expression with variables
|
||||
return MVEL.executeExpression(compiledExpression, variables);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class OrganizationAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationAllPropertiesEquals(Organization expected, Organization actual) {
|
||||
assertOrganizationAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertOrganizationAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationAllUpdatablePropertiesEquals(Organization expected, Organization actual) {
|
||||
assertOrganizationUpdatableFieldsEquals(expected, actual);
|
||||
assertOrganizationUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationAutoGeneratedPropertiesEquals(Organization expected, Organization actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Organization auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationUpdatableFieldsEquals(Organization expected, Organization actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Organization relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getImage()).as("check image").isEqualTo(actual.getImage()))
|
||||
.satisfies(e -> assertThat(e.getImageContentType()).as("check image contenty type").isEqualTo(actual.getImageContentType()))
|
||||
.satisfies(e -> assertThat(e.getInputInventory()).as("check inputInventory").isEqualTo(actual.getInputInventory()))
|
||||
.satisfies(e -> assertThat(e.getOutputInventory()).as("check outputInventory").isEqualTo(actual.getOutputInventory()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationUpdatableRelationshipsEquals(Organization expected, Organization actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Organization relationships")
|
||||
.satisfies(e -> assertThat(e.getParent()).as("check parent").isEqualTo(actual.getParent()))
|
||||
.satisfies(e -> assertThat(e.getOrganizationType()).as("check organizationType").isEqualTo(actual.getOrganizationType()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationSample1;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.getOrganizationSample2;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTypeTestSamples.getOrganizationTypeRandomSampleGenerator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class OrganizationTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(Organization.class);
|
||||
Organization organization1 = getOrganizationSample1();
|
||||
Organization organization2 = new Organization();
|
||||
assertThat(organization1).isNotEqualTo(organization2);
|
||||
|
||||
organization2.setId(organization1.getId());
|
||||
assertThat(organization1).isEqualTo(organization2);
|
||||
|
||||
organization2 = getOrganizationSample2();
|
||||
assertThat(organization1).isNotEqualTo(organization2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void childTest() {
|
||||
Organization organization = getOrganizationRandomSampleGenerator();
|
||||
Organization organizationBack = getOrganizationRandomSampleGenerator();
|
||||
|
||||
organization.addChild(organizationBack);
|
||||
assertThat(organization.getChildren()).containsOnly(organizationBack);
|
||||
assertThat(organizationBack.getParent()).isEqualTo(organization);
|
||||
|
||||
organization.removeChild(organizationBack);
|
||||
assertThat(organization.getChildren()).doesNotContain(organizationBack);
|
||||
assertThat(organizationBack.getParent()).isNull();
|
||||
|
||||
organization.children(new ArrayList<>(Set.of(organizationBack)));
|
||||
assertThat(organization.getChildren()).containsOnly(organizationBack);
|
||||
assertThat(organizationBack.getParent()).isEqualTo(organization);
|
||||
|
||||
organization.setChildren(new ArrayList<>());
|
||||
assertThat(organization.getChildren()).doesNotContain(organizationBack);
|
||||
assertThat(organizationBack.getParent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void parentTest() {
|
||||
Organization organization = getOrganizationRandomSampleGenerator();
|
||||
Organization organizationBack = getOrganizationRandomSampleGenerator();
|
||||
|
||||
organization.setParent(organizationBack);
|
||||
assertThat(organization.getParent()).isEqualTo(organizationBack);
|
||||
|
||||
organization.parent(null);
|
||||
assertThat(organization.getParent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void organizationTypeTest() {
|
||||
Organization organization = getOrganizationRandomSampleGenerator();
|
||||
OrganizationType organizationTypeBack = getOrganizationTypeRandomSampleGenerator();
|
||||
|
||||
organization.setOrganizationType(organizationTypeBack);
|
||||
assertThat(organization.getOrganizationType()).isEqualTo(organizationTypeBack);
|
||||
|
||||
organization.organizationType(null);
|
||||
assertThat(organization.getOrganizationType()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class OrganizationTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static Organization getOrganizationSample1() {
|
||||
return new Organization().id(1L).code("code1").name("name1").version(1);
|
||||
}
|
||||
|
||||
public static Organization getOrganizationSample2() {
|
||||
return new Organization().id(2L).code("code2").name("name2").version(2);
|
||||
}
|
||||
|
||||
public static Organization getOrganizationRandomSampleGenerator() {
|
||||
return new Organization()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class OrganizationTypeAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationTypeAllPropertiesEquals(OrganizationType expected, OrganizationType actual) {
|
||||
assertOrganizationTypeAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertOrganizationTypeAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationTypeAllUpdatablePropertiesEquals(OrganizationType expected, OrganizationType actual) {
|
||||
assertOrganizationTypeUpdatableFieldsEquals(expected, actual);
|
||||
assertOrganizationTypeUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationTypeAutoGeneratedPropertiesEquals(OrganizationType expected, OrganizationType actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify OrganizationType auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationTypeUpdatableFieldsEquals(OrganizationType expected, OrganizationType actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify OrganizationType relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getNature()).as("check nature").isEqualTo(actual.getNature()))
|
||||
.satisfies(e -> assertThat(e.getIcon()).as("check icon").isEqualTo(actual.getIcon()))
|
||||
.satisfies(e -> assertThat(e.getIconContentType()).as("check icon contenty type").isEqualTo(actual.getIconContentType()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOrganizationTypeUpdatableRelationshipsEquals(OrganizationType expected, OrganizationType actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify OrganizationType relationships")
|
||||
.satisfies(e -> assertThat(e.getMetadataProperties()).as("check metadataProperties").isEqualTo(actual.getMetadataProperties()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.MetadataPropertyTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.OrganizationTypeTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class OrganizationTypeTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(OrganizationType.class);
|
||||
OrganizationType organizationType1 = getOrganizationTypeSample1();
|
||||
OrganizationType organizationType2 = new OrganizationType();
|
||||
assertThat(organizationType1).isNotEqualTo(organizationType2);
|
||||
|
||||
organizationType2.setId(organizationType1.getId());
|
||||
assertThat(organizationType1).isEqualTo(organizationType2);
|
||||
|
||||
organizationType2 = getOrganizationTypeSample2();
|
||||
assertThat(organizationType1).isNotEqualTo(organizationType2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void organizationTest() {
|
||||
OrganizationType organizationType = getOrganizationTypeRandomSampleGenerator();
|
||||
Organization organizationBack = getOrganizationRandomSampleGenerator();
|
||||
|
||||
organizationType.addOrganization(organizationBack);
|
||||
assertThat(organizationType.getOrganizations()).containsOnly(organizationBack);
|
||||
assertThat(organizationBack.getOrganizationType()).isEqualTo(organizationType);
|
||||
|
||||
organizationType.removeOrganization(organizationBack);
|
||||
assertThat(organizationType.getOrganizations()).doesNotContain(organizationBack);
|
||||
assertThat(organizationBack.getOrganizationType()).isNull();
|
||||
|
||||
organizationType.organizations(new HashSet<>(Set.of(organizationBack)));
|
||||
assertThat(organizationType.getOrganizations()).containsOnly(organizationBack);
|
||||
assertThat(organizationBack.getOrganizationType()).isEqualTo(organizationType);
|
||||
|
||||
organizationType.setOrganizations(new HashSet<>());
|
||||
assertThat(organizationType.getOrganizations()).doesNotContain(organizationBack);
|
||||
assertThat(organizationBack.getOrganizationType()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataPropertiesTest() {
|
||||
OrganizationType organizationType = getOrganizationTypeRandomSampleGenerator();
|
||||
MetadataProperty metadataPropertyBack = getMetadataPropertyRandomSampleGenerator();
|
||||
|
||||
organizationType.addMetadataProperties(metadataPropertyBack);
|
||||
assertThat(organizationType.getMetadataProperties()).containsOnly(metadataPropertyBack);
|
||||
|
||||
organizationType.removeMetadataProperties(metadataPropertyBack);
|
||||
assertThat(organizationType.getMetadataProperties()).doesNotContain(metadataPropertyBack);
|
||||
|
||||
organizationType.metadataProperties(new HashSet<>(Set.of(metadataPropertyBack)));
|
||||
assertThat(organizationType.getMetadataProperties()).containsOnly(metadataPropertyBack);
|
||||
|
||||
organizationType.setMetadataProperties(new HashSet<>());
|
||||
assertThat(organizationType.getMetadataProperties()).doesNotContain(metadataPropertyBack);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class OrganizationTypeTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static OrganizationType getOrganizationTypeSample1() {
|
||||
return new OrganizationType().id(1L).code("code1").name("name1").description("description1").version(1);
|
||||
}
|
||||
|
||||
public static OrganizationType getOrganizationTypeSample2() {
|
||||
return new OrganizationType().id(2L).code("code2").name("name2").description("description2").version(2);
|
||||
}
|
||||
|
||||
public static OrganizationType getOrganizationTypeRandomSampleGenerator() {
|
||||
return new OrganizationType()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.AssertUtils.bigDecimalCompareTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class OutputDataAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOutputDataAllPropertiesEquals(OutputData expected, OutputData actual) {
|
||||
assertOutputDataAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertOutputDataAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOutputDataAllUpdatablePropertiesEquals(OutputData expected, OutputData actual) {
|
||||
assertOutputDataUpdatableFieldsEquals(expected, actual);
|
||||
assertOutputDataUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOutputDataAutoGeneratedPropertiesEquals(OutputData expected, OutputData actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify OutputData auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOutputDataUpdatableFieldsEquals(OutputData expected, OutputData actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify OutputData relevant properties")
|
||||
.satisfies(e -> assertThat(e.getValue()).as("check value").usingComparator(bigDecimalCompareTo).isEqualTo(actual.getValue()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertOutputDataUpdatableRelationshipsEquals(OutputData expected, OutputData actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify OutputData relationships")
|
||||
.satisfies(e -> assertThat(e.getVariable()).as("check variable").isEqualTo(actual.getVariable()))
|
||||
.satisfies(e -> assertThat(e.getPeriod()).as("check period").isEqualTo(actual.getPeriod()))
|
||||
.satisfies(e -> assertThat(e.getPeriodVersion()).as("check periodVersion").isEqualTo(actual.getPeriodVersion()))
|
||||
.satisfies(e -> assertThat(e.getBaseUnit()).as("check baseUnit").isEqualTo(actual.getBaseUnit()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.OutputDataTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.PeriodVersionTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class OutputDataTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(OutputData.class);
|
||||
OutputData outputData1 = getOutputDataSample1();
|
||||
OutputData outputData2 = new OutputData();
|
||||
assertThat(outputData1).isNotEqualTo(outputData2);
|
||||
|
||||
outputData2.setId(outputData1.getId());
|
||||
assertThat(outputData1).isEqualTo(outputData2);
|
||||
|
||||
outputData2 = getOutputDataSample2();
|
||||
assertThat(outputData1).isNotEqualTo(outputData2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableTest() {
|
||||
OutputData outputData = getOutputDataRandomSampleGenerator();
|
||||
Variable variableBack = getVariableRandomSampleGenerator();
|
||||
|
||||
outputData.setVariable(variableBack);
|
||||
assertThat(outputData.getVariable()).isEqualTo(variableBack);
|
||||
|
||||
outputData.variable(null);
|
||||
assertThat(outputData.getVariable()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void periodTest() {
|
||||
OutputData outputData = getOutputDataRandomSampleGenerator();
|
||||
Period periodBack = getPeriodRandomSampleGenerator();
|
||||
|
||||
outputData.setPeriod(periodBack);
|
||||
assertThat(outputData.getPeriod()).isEqualTo(periodBack);
|
||||
|
||||
outputData.period(null);
|
||||
assertThat(outputData.getPeriod()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void periodVersionTest() {
|
||||
OutputData outputData = getOutputDataRandomSampleGenerator();
|
||||
PeriodVersion periodVersionBack = getPeriodVersionRandomSampleGenerator();
|
||||
|
||||
outputData.setPeriodVersion(periodVersionBack);
|
||||
assertThat(outputData.getPeriodVersion()).isEqualTo(periodVersionBack);
|
||||
|
||||
outputData.periodVersion(null);
|
||||
assertThat(outputData.getPeriodVersion()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void baseUnitTest() {
|
||||
OutputData outputData = getOutputDataRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
outputData.setBaseUnit(unitBack);
|
||||
assertThat(outputData.getBaseUnit()).isEqualTo(unitBack);
|
||||
|
||||
outputData.baseUnit(null);
|
||||
assertThat(outputData.getBaseUnit()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class OutputDataTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static OutputData getOutputDataSample1() {
|
||||
return new OutputData().id(1L).version(1);
|
||||
}
|
||||
|
||||
public static OutputData getOutputDataSample2() {
|
||||
return new OutputData().id(2L).version(2);
|
||||
}
|
||||
|
||||
public static OutputData getOutputDataRandomSampleGenerator() {
|
||||
return new OutputData().id(longCount.incrementAndGet()).version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class PeriodAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodAllPropertiesEquals(Period expected, Period actual) {
|
||||
assertPeriodAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertPeriodAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodAllUpdatablePropertiesEquals(Period expected, Period actual) {
|
||||
assertPeriodUpdatableFieldsEquals(expected, actual);
|
||||
assertPeriodUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodAutoGeneratedPropertiesEquals(Period expected, Period actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Period auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodUpdatableFieldsEquals(Period expected, Period actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Period relevant properties")
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getBeginDate()).as("check beginDate").isEqualTo(actual.getBeginDate()))
|
||||
.satisfies(e -> assertThat(e.getEndDate()).as("check endDate").isEqualTo(actual.getEndDate()))
|
||||
.satisfies(e -> assertThat(e.getState()).as("check state").isEqualTo(actual.getState()))
|
||||
.satisfies(e -> assertThat(e.getCreationDate()).as("check creationDate").isEqualTo(actual.getCreationDate()))
|
||||
.satisfies(e -> assertThat(e.getCreationUsername()).as("check creationUsername").isEqualTo(actual.getCreationUsername()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodUpdatableRelationshipsEquals(Period expected, Period actual) {}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodSample1;
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodSample2;
|
||||
import static com.oguerreiro.resilient.domain.PeriodVersionTestSamples.getPeriodVersionRandomSampleGenerator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class PeriodTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(Period.class);
|
||||
Period period1 = getPeriodSample1();
|
||||
Period period2 = new Period();
|
||||
assertThat(period1).isNotEqualTo(period2);
|
||||
|
||||
period2.setId(period1.getId());
|
||||
assertThat(period1).isEqualTo(period2);
|
||||
|
||||
period2 = getPeriodSample2();
|
||||
assertThat(period1).isNotEqualTo(period2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void periodVersionTest() {
|
||||
Period period = getPeriodRandomSampleGenerator();
|
||||
PeriodVersion periodVersionBack = getPeriodVersionRandomSampleGenerator();
|
||||
|
||||
period.addPeriodVersion(periodVersionBack);
|
||||
assertThat(period.getPeriodVersions()).containsOnly(periodVersionBack);
|
||||
assertThat(periodVersionBack.getPeriod()).isEqualTo(period);
|
||||
|
||||
period.removePeriodVersion(periodVersionBack);
|
||||
assertThat(period.getPeriodVersions()).doesNotContain(periodVersionBack);
|
||||
assertThat(periodVersionBack.getPeriod()).isNull();
|
||||
|
||||
period.periodVersions(new ArrayList<>(List.of(periodVersionBack)));
|
||||
assertThat(period.getPeriodVersions()).containsOnly(periodVersionBack);
|
||||
assertThat(periodVersionBack.getPeriod()).isEqualTo(period);
|
||||
|
||||
period.setPeriodVersions(new ArrayList<>());
|
||||
assertThat(period.getPeriodVersions()).doesNotContain(periodVersionBack);
|
||||
assertThat(periodVersionBack.getPeriod()).isNull();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class PeriodTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static Period getPeriodSample1() {
|
||||
return new Period().id(1L).name("name1").description("description1").creationUsername("creationUsername1").version(1);
|
||||
}
|
||||
|
||||
public static Period getPeriodSample2() {
|
||||
return new Period().id(2L).name("name2").description("description2").creationUsername("creationUsername2").version(2);
|
||||
}
|
||||
|
||||
public static Period getPeriodRandomSampleGenerator() {
|
||||
return new Period()
|
||||
.id(longCount.incrementAndGet())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.creationUsername(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class PeriodVersionAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodVersionAllPropertiesEquals(PeriodVersion expected, PeriodVersion actual) {
|
||||
assertPeriodVersionAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertPeriodVersionAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodVersionAllUpdatablePropertiesEquals(PeriodVersion expected, PeriodVersion actual) {
|
||||
assertPeriodVersionUpdatableFieldsEquals(expected, actual);
|
||||
assertPeriodVersionUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodVersionAutoGeneratedPropertiesEquals(PeriodVersion expected, PeriodVersion actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify PeriodVersion auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodVersionUpdatableFieldsEquals(PeriodVersion expected, PeriodVersion actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify PeriodVersion relevant properties")
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getPeriodVersion()).as("check periodVersion").isEqualTo(actual.getPeriodVersion()))
|
||||
.satisfies(e -> assertThat(e.getState()).as("check state").isEqualTo(actual.getState()))
|
||||
.satisfies(e -> assertThat(e.getCreationDate()).as("check creationDate").isEqualTo(actual.getCreationDate()))
|
||||
.satisfies(e -> assertThat(e.getCreationUsername()).as("check creationUsername").isEqualTo(actual.getCreationUsername()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertPeriodVersionUpdatableRelationshipsEquals(PeriodVersion expected, PeriodVersion actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify PeriodVersion relationships")
|
||||
.satisfies(e -> assertThat(e.getPeriod()).as("check period").isEqualTo(actual.getPeriod()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.PeriodTestSamples.getPeriodRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.PeriodVersionTestSamples.getPeriodVersionRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.PeriodVersionTestSamples.getPeriodVersionSample1;
|
||||
import static com.oguerreiro.resilient.domain.PeriodVersionTestSamples.getPeriodVersionSample2;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class PeriodVersionTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(PeriodVersion.class);
|
||||
PeriodVersion periodVersion1 = getPeriodVersionSample1();
|
||||
PeriodVersion periodVersion2 = new PeriodVersion();
|
||||
assertThat(periodVersion1).isNotEqualTo(periodVersion2);
|
||||
|
||||
periodVersion2.setId(periodVersion1.getId());
|
||||
assertThat(periodVersion1).isEqualTo(periodVersion2);
|
||||
|
||||
periodVersion2 = getPeriodVersionSample2();
|
||||
assertThat(periodVersion1).isNotEqualTo(periodVersion2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void periodTest() {
|
||||
PeriodVersion periodVersion = getPeriodVersionRandomSampleGenerator();
|
||||
Period periodBack = getPeriodRandomSampleGenerator();
|
||||
|
||||
periodVersion.setPeriod(periodBack);
|
||||
assertThat(periodVersion.getPeriod()).isEqualTo(periodBack);
|
||||
|
||||
periodVersion.period(null);
|
||||
assertThat(periodVersion.getPeriod()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class PeriodVersionTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static PeriodVersion getPeriodVersionSample1() {
|
||||
return new PeriodVersion()
|
||||
.id(1L)
|
||||
.name("name1")
|
||||
.description("description1")
|
||||
.periodVersion(1)
|
||||
.creationUsername("creationUsername1")
|
||||
.version(1);
|
||||
}
|
||||
|
||||
public static PeriodVersion getPeriodVersionSample2() {
|
||||
return new PeriodVersion()
|
||||
.id(2L)
|
||||
.name("name2")
|
||||
.description("description2")
|
||||
.periodVersion(2)
|
||||
.creationUsername("creationUsername2")
|
||||
.version(2);
|
||||
}
|
||||
|
||||
public static PeriodVersion getPeriodVersionRandomSampleGenerator() {
|
||||
return new PeriodVersion()
|
||||
.id(longCount.incrementAndGet())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.periodVersion(intCount.incrementAndGet())
|
||||
.creationUsername(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.AssertUtils.bigDecimalCompareTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class UnitAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitAllPropertiesEquals(Unit expected, Unit actual) {
|
||||
assertUnitAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertUnitAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitAllUpdatablePropertiesEquals(Unit expected, Unit actual) {
|
||||
assertUnitUpdatableFieldsEquals(expected, actual);
|
||||
assertUnitUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitAutoGeneratedPropertiesEquals(Unit expected, Unit actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Unit auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitUpdatableFieldsEquals(Unit expected, Unit actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Unit relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getSymbol()).as("check symbol").isEqualTo(actual.getSymbol()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(
|
||||
e ->
|
||||
assertThat(e.getConvertionRate())
|
||||
.as("check convertionRate")
|
||||
.usingComparator(bigDecimalCompareTo)
|
||||
.isEqualTo(actual.getConvertionRate())
|
||||
)
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitUpdatableRelationshipsEquals(Unit expected, Unit actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Unit relationships")
|
||||
.satisfies(e -> assertThat(e.getUnitType()).as("check unitType").isEqualTo(actual.getUnitType()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class UnitConverterAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitConverterAllPropertiesEquals(UnitConverter expected, UnitConverter actual) {
|
||||
assertUnitConverterAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertUnitConverterAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitConverterAllUpdatablePropertiesEquals(UnitConverter expected, UnitConverter actual) {
|
||||
assertUnitConverterUpdatableFieldsEquals(expected, actual);
|
||||
assertUnitConverterUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitConverterAutoGeneratedPropertiesEquals(UnitConverter expected, UnitConverter actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify UnitConverter auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitConverterUpdatableFieldsEquals(UnitConverter expected, UnitConverter actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify UnitConverter relevant properties")
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getConvertionFormula()).as("check convertionFormula").isEqualTo(actual.getConvertionFormula()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitConverterUpdatableRelationshipsEquals(UnitConverter expected, UnitConverter actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify UnitConverter relationships")
|
||||
.satisfies(e -> assertThat(e.getFromUnit()).as("check fromUnit").isEqualTo(actual.getFromUnit()))
|
||||
.satisfies(e -> assertThat(e.getToUnit()).as("check toUnit").isEqualTo(actual.getToUnit()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.UnitConverterTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UnitConverterTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(UnitConverter.class);
|
||||
UnitConverter unitConverter1 = getUnitConverterSample1();
|
||||
UnitConverter unitConverter2 = new UnitConverter();
|
||||
assertThat(unitConverter1).isNotEqualTo(unitConverter2);
|
||||
|
||||
unitConverter2.setId(unitConverter1.getId());
|
||||
assertThat(unitConverter1).isEqualTo(unitConverter2);
|
||||
|
||||
unitConverter2 = getUnitConverterSample2();
|
||||
assertThat(unitConverter1).isNotEqualTo(unitConverter2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromUnitTest() {
|
||||
UnitConverter unitConverter = getUnitConverterRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
unitConverter.setFromUnit(unitBack);
|
||||
assertThat(unitConverter.getFromUnit()).isEqualTo(unitBack);
|
||||
|
||||
unitConverter.fromUnit(null);
|
||||
assertThat(unitConverter.getFromUnit()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toUnitTest() {
|
||||
UnitConverter unitConverter = getUnitConverterRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
unitConverter.setToUnit(unitBack);
|
||||
assertThat(unitConverter.getToUnit()).isEqualTo(unitBack);
|
||||
|
||||
unitConverter.toUnit(null);
|
||||
assertThat(unitConverter.getToUnit()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class UnitConverterTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static UnitConverter getUnitConverterSample1() {
|
||||
return new UnitConverter().id(1L).name("name1").description("description1").convertionFormula("convertionFormula1").version(1);
|
||||
}
|
||||
|
||||
public static UnitConverter getUnitConverterSample2() {
|
||||
return new UnitConverter().id(2L).name("name2").description("description2").convertionFormula("convertionFormula2").version(2);
|
||||
}
|
||||
|
||||
public static UnitConverter getUnitConverterRandomSampleGenerator() {
|
||||
return new UnitConverter()
|
||||
.id(longCount.incrementAndGet())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.convertionFormula(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
40
src/test/java/com/oguerreiro/resilient/domain/UnitTest.java
Normal file
40
src/test/java/com/oguerreiro/resilient/domain/UnitTest.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitSample1;
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitSample2;
|
||||
import static com.oguerreiro.resilient.domain.UnitTypeTestSamples.getUnitTypeRandomSampleGenerator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class UnitTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(Unit.class);
|
||||
Unit unit1 = getUnitSample1();
|
||||
Unit unit2 = new Unit();
|
||||
assertThat(unit1).isNotEqualTo(unit2);
|
||||
|
||||
unit2.setId(unit1.getId());
|
||||
assertThat(unit1).isEqualTo(unit2);
|
||||
|
||||
unit2 = getUnitSample2();
|
||||
assertThat(unit1).isNotEqualTo(unit2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unitTypeTest() {
|
||||
Unit unit = getUnitRandomSampleGenerator();
|
||||
UnitType unitTypeBack = getUnitTypeRandomSampleGenerator();
|
||||
|
||||
unit.setUnitType(unitTypeBack);
|
||||
assertThat(unit.getUnitType()).isEqualTo(unitTypeBack);
|
||||
|
||||
unit.unitType(null);
|
||||
assertThat(unit.getUnitType()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class UnitTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static Unit getUnitSample1() {
|
||||
return new Unit().id(1L).code("code1").symbol("symbol1").name("name1").description("description1").version(1);
|
||||
}
|
||||
|
||||
public static Unit getUnitSample2() {
|
||||
return new Unit().id(2L).code("code2").symbol("symbol2").name("name2").description("description2").version(2);
|
||||
}
|
||||
|
||||
public static Unit getUnitRandomSampleGenerator() {
|
||||
return new Unit()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.symbol(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class UnitTypeAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitTypeAllPropertiesEquals(UnitType expected, UnitType actual) {
|
||||
assertUnitTypeAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertUnitTypeAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitTypeAllUpdatablePropertiesEquals(UnitType expected, UnitType actual) {
|
||||
assertUnitTypeUpdatableFieldsEquals(expected, actual);
|
||||
assertUnitTypeUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitTypeAutoGeneratedPropertiesEquals(UnitType expected, UnitType actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify UnitType auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitTypeUpdatableFieldsEquals(UnitType expected, UnitType actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify UnitType relevant properties")
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getValueType()).as("check valueType").isEqualTo(actual.getValueType()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertUnitTypeUpdatableRelationshipsEquals(UnitType expected, UnitType actual) {}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.UnitTypeTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UnitTypeTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(UnitType.class);
|
||||
UnitType unitType1 = getUnitTypeSample1();
|
||||
UnitType unitType2 = new UnitType();
|
||||
assertThat(unitType1).isNotEqualTo(unitType2);
|
||||
|
||||
unitType2.setId(unitType1.getId());
|
||||
assertThat(unitType1).isEqualTo(unitType2);
|
||||
|
||||
unitType2 = getUnitTypeSample2();
|
||||
assertThat(unitType1).isNotEqualTo(unitType2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unitTest() {
|
||||
UnitType unitType = getUnitTypeRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
unitType.addUnit(unitBack);
|
||||
assertThat(unitType.getUnits()).containsOnly(unitBack);
|
||||
assertThat(unitBack.getUnitType()).isEqualTo(unitType);
|
||||
|
||||
unitType.removeUnit(unitBack);
|
||||
assertThat(unitType.getUnits()).doesNotContain(unitBack);
|
||||
assertThat(unitBack.getUnitType()).isNull();
|
||||
|
||||
unitType.units(new HashSet<>(Set.of(unitBack)));
|
||||
assertThat(unitType.getUnits()).containsOnly(unitBack);
|
||||
assertThat(unitBack.getUnitType()).isEqualTo(unitType);
|
||||
|
||||
unitType.setUnits(new HashSet<>());
|
||||
assertThat(unitType.getUnits()).doesNotContain(unitBack);
|
||||
assertThat(unitBack.getUnitType()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class UnitTypeTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static UnitType getUnitTypeSample1() {
|
||||
return new UnitType().id(1L).name("name1").description("description1").version(1);
|
||||
}
|
||||
|
||||
public static UnitType getUnitTypeSample2() {
|
||||
return new UnitType().id(2L).name("name2").description("description2").version(2);
|
||||
}
|
||||
|
||||
public static UnitType getUnitTypeRandomSampleGenerator() {
|
||||
return new UnitType()
|
||||
.id(longCount.incrementAndGet())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class VariableAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableAllPropertiesEquals(Variable expected, Variable actual) {
|
||||
assertVariableAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertVariableAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableAllUpdatablePropertiesEquals(Variable expected, Variable actual) {
|
||||
assertVariableUpdatableFieldsEquals(expected, actual);
|
||||
assertVariableUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableAutoGeneratedPropertiesEquals(Variable expected, Variable actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Variable auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUpdatableFieldsEquals(Variable expected, Variable actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Variable relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getVariableIndex()).as("check variableIndex").isEqualTo(actual.getVariableIndex()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getInput()).as("check input").isEqualTo(actual.getInput()))
|
||||
.satisfies(e -> assertThat(e.getInputMode()).as("check inputMode").isEqualTo(actual.getInputMode()))
|
||||
.satisfies(e -> assertThat(e.getOutput()).as("check output").isEqualTo(actual.getOutput()))
|
||||
.satisfies(e -> assertThat(e.getOutputFormula()).as("check outputFormula").isEqualTo(actual.getOutputFormula()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUpdatableRelationshipsEquals(Variable expected, Variable actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify Variable relationships")
|
||||
.satisfies(e -> assertThat(e.getBaseUnit()).as("check baseUnit").isEqualTo(actual.getBaseUnit()))
|
||||
.satisfies(e -> assertThat(e.getVariableScope()).as("check variableScope").isEqualTo(actual.getVariableScope()))
|
||||
.satisfies(e -> assertThat(e.getVariableCategory()).as("check variableCategory").isEqualTo(actual.getVariableCategory()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class VariableCategoryAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableCategoryAllPropertiesEquals(VariableCategory expected, VariableCategory actual) {
|
||||
assertVariableCategoryAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertVariableCategoryAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableCategoryAllUpdatablePropertiesEquals(VariableCategory expected, VariableCategory actual) {
|
||||
assertVariableCategoryUpdatableFieldsEquals(expected, actual);
|
||||
assertVariableCategoryUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableCategoryAutoGeneratedPropertiesEquals(VariableCategory expected, VariableCategory actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableCategory auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableCategoryUpdatableFieldsEquals(VariableCategory expected, VariableCategory actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableCategory relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableCategoryUpdatableRelationshipsEquals(VariableCategory expected, VariableCategory actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableCategory relationships")
|
||||
.satisfies(e -> assertThat(e.getVariableScope()).as("check variableScope").isEqualTo(actual.getVariableScope()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.VariableCategoryTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableScopeTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableCategoryTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableCategory.class);
|
||||
VariableCategory variableCategory1 = getVariableCategorySample1();
|
||||
VariableCategory variableCategory2 = new VariableCategory();
|
||||
assertThat(variableCategory1).isNotEqualTo(variableCategory2);
|
||||
|
||||
variableCategory2.setId(variableCategory1.getId());
|
||||
assertThat(variableCategory1).isEqualTo(variableCategory2);
|
||||
|
||||
variableCategory2 = getVariableCategorySample2();
|
||||
assertThat(variableCategory1).isNotEqualTo(variableCategory2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableTest() {
|
||||
VariableCategory variableCategory = getVariableCategoryRandomSampleGenerator();
|
||||
Variable variableBack = getVariableRandomSampleGenerator();
|
||||
|
||||
variableCategory.addVariable(variableBack);
|
||||
assertThat(variableCategory.getVariables()).containsOnly(variableBack);
|
||||
assertThat(variableBack.getVariableCategory()).isEqualTo(variableCategory);
|
||||
|
||||
variableCategory.removeVariable(variableBack);
|
||||
assertThat(variableCategory.getVariables()).doesNotContain(variableBack);
|
||||
assertThat(variableBack.getVariableCategory()).isNull();
|
||||
|
||||
variableCategory.variables(new HashSet<>(Set.of(variableBack)));
|
||||
assertThat(variableCategory.getVariables()).containsOnly(variableBack);
|
||||
assertThat(variableBack.getVariableCategory()).isEqualTo(variableCategory);
|
||||
|
||||
variableCategory.setVariables(new HashSet<>());
|
||||
assertThat(variableCategory.getVariables()).doesNotContain(variableBack);
|
||||
assertThat(variableBack.getVariableCategory()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableScopeTest() {
|
||||
VariableCategory variableCategory = getVariableCategoryRandomSampleGenerator();
|
||||
VariableScope variableScopeBack = getVariableScopeRandomSampleGenerator();
|
||||
|
||||
variableCategory.setVariableScope(variableScopeBack);
|
||||
assertThat(variableCategory.getVariableScope()).isEqualTo(variableScopeBack);
|
||||
|
||||
variableCategory.variableScope(null);
|
||||
assertThat(variableCategory.getVariableScope()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class VariableCategoryTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static VariableCategory getVariableCategorySample1() {
|
||||
return new VariableCategory().id(1L).code("code1").name("name1").description("description1").version(1);
|
||||
}
|
||||
|
||||
public static VariableCategory getVariableCategorySample2() {
|
||||
return new VariableCategory().id(2L).code("code2").name("name2").description("description2").version(2);
|
||||
}
|
||||
|
||||
public static VariableCategory getVariableCategoryRandomSampleGenerator() {
|
||||
return new VariableCategory()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class VariableClassAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableClassAllPropertiesEquals(VariableClass expected, VariableClass actual) {
|
||||
assertVariableClassAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertVariableClassAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableClassAllUpdatablePropertiesEquals(VariableClass expected, VariableClass actual) {
|
||||
assertVariableClassUpdatableFieldsEquals(expected, actual);
|
||||
assertVariableClassUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableClassAutoGeneratedPropertiesEquals(VariableClass expected, VariableClass actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableClass auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableClassUpdatableFieldsEquals(VariableClass expected, VariableClass actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableClass relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableClassUpdatableRelationshipsEquals(VariableClass expected, VariableClass actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableClass relationships")
|
||||
.satisfies(e -> assertThat(e.getVariableClassType()).as("check variable class type").isEqualTo(actual.getVariableClassType()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.VariableClassTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableClassTypeTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableClassTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableClass.class);
|
||||
VariableClass variableClass1 = getVariableClassSample1();
|
||||
VariableClass variableClass2 = new VariableClass();
|
||||
assertThat(variableClass1).isNotEqualTo(variableClass2);
|
||||
|
||||
variableClass2.setId(variableClass1.getId());
|
||||
assertThat(variableClass1).isEqualTo(variableClass2);
|
||||
|
||||
variableClass2 = getVariableClassSample2();
|
||||
assertThat(variableClass1).isNotEqualTo(variableClass2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableTest() {
|
||||
VariableClass variableClass = getVariableClassRandomSampleGenerator();
|
||||
VariableClassType variableClassTypeBack = getVariableClassTypeRandomSampleGenerator();
|
||||
|
||||
variableClass.setVariableClassType(variableClassTypeBack);
|
||||
assertThat(variableClass.getVariableClassType()).isEqualTo(variableClassTypeBack);
|
||||
|
||||
variableClass.variableClassType(null);
|
||||
assertThat(variableClass.getVariableClassType()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class VariableClassTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static VariableClass getVariableClassSample1() {
|
||||
return new VariableClass().id(1L).code("code1").name("name1").version(1);
|
||||
}
|
||||
|
||||
public static VariableClass getVariableClassSample2() {
|
||||
return new VariableClass().id(2L).code("code2").name("name2").version(2);
|
||||
}
|
||||
|
||||
public static VariableClass getVariableClassRandomSampleGenerator() {
|
||||
return new VariableClass()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class VariableClassTypeTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static VariableClassType getVariableClassTypeSample1() {
|
||||
return new VariableClassType().id(1L).code("code1").name("name1").label("label1").version(1);
|
||||
}
|
||||
|
||||
public static VariableClassType getVariableClassTypeSample2() {
|
||||
return new VariableClassType().id(2L).code("code2").name("name2").label("label2").version(2);
|
||||
}
|
||||
|
||||
public static VariableClassType getVariableClassTypeRandomSampleGenerator() {
|
||||
return new VariableClassType()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.label(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class VariableScopeAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableScopeAllPropertiesEquals(VariableScope expected, VariableScope actual) {
|
||||
assertVariableScopeAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertVariableScopeAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableScopeAllUpdatablePropertiesEquals(VariableScope expected, VariableScope actual) {
|
||||
assertVariableScopeUpdatableFieldsEquals(expected, actual);
|
||||
assertVariableScopeUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableScopeAutoGeneratedPropertiesEquals(VariableScope expected, VariableScope actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableScope auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableScopeUpdatableFieldsEquals(VariableScope expected, VariableScope actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableScope relevant properties")
|
||||
.satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
|
||||
.satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
|
||||
.satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableScopeUpdatableRelationshipsEquals(VariableScope expected, VariableScope actual) {}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.VariableCategoryTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableScopeTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableScopeTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableScope.class);
|
||||
VariableScope variableScope1 = getVariableScopeSample1();
|
||||
VariableScope variableScope2 = new VariableScope();
|
||||
assertThat(variableScope1).isNotEqualTo(variableScope2);
|
||||
|
||||
variableScope2.setId(variableScope1.getId());
|
||||
assertThat(variableScope1).isEqualTo(variableScope2);
|
||||
|
||||
variableScope2 = getVariableScopeSample2();
|
||||
assertThat(variableScope1).isNotEqualTo(variableScope2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableCategoryTest() {
|
||||
VariableScope variableScope = getVariableScopeRandomSampleGenerator();
|
||||
VariableCategory variableCategoryBack = getVariableCategoryRandomSampleGenerator();
|
||||
|
||||
variableScope.addVariableCategory(variableCategoryBack);
|
||||
assertThat(variableScope.getVariableCategories()).containsOnly(variableCategoryBack);
|
||||
assertThat(variableCategoryBack.getVariableScope()).isEqualTo(variableScope);
|
||||
|
||||
variableScope.removeVariableCategory(variableCategoryBack);
|
||||
assertThat(variableScope.getVariableCategories()).doesNotContain(variableCategoryBack);
|
||||
assertThat(variableCategoryBack.getVariableScope()).isNull();
|
||||
|
||||
variableScope.variableCategories(new HashSet<>(Set.of(variableCategoryBack)));
|
||||
assertThat(variableScope.getVariableCategories()).containsOnly(variableCategoryBack);
|
||||
assertThat(variableCategoryBack.getVariableScope()).isEqualTo(variableScope);
|
||||
|
||||
variableScope.setVariableCategories(new HashSet<>());
|
||||
assertThat(variableScope.getVariableCategories()).doesNotContain(variableCategoryBack);
|
||||
assertThat(variableCategoryBack.getVariableScope()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableTest() {
|
||||
VariableScope variableScope = getVariableScopeRandomSampleGenerator();
|
||||
Variable variableBack = getVariableRandomSampleGenerator();
|
||||
|
||||
variableScope.addVariable(variableBack);
|
||||
assertThat(variableScope.getVariables()).containsOnly(variableBack);
|
||||
assertThat(variableBack.getVariableScope()).isEqualTo(variableScope);
|
||||
|
||||
variableScope.removeVariable(variableBack);
|
||||
assertThat(variableScope.getVariables()).doesNotContain(variableBack);
|
||||
assertThat(variableBack.getVariableScope()).isNull();
|
||||
|
||||
variableScope.variables(new HashSet<>(Set.of(variableBack)));
|
||||
assertThat(variableScope.getVariables()).containsOnly(variableBack);
|
||||
assertThat(variableBack.getVariableScope()).isEqualTo(variableScope);
|
||||
|
||||
variableScope.setVariables(new HashSet<>());
|
||||
assertThat(variableScope.getVariables()).doesNotContain(variableBack);
|
||||
assertThat(variableBack.getVariableScope()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class VariableScopeTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static VariableScope getVariableScopeSample1() {
|
||||
return new VariableScope().id(1L).code("code1").name("name1").description("description1").version(1);
|
||||
}
|
||||
|
||||
public static VariableScope getVariableScopeSample2() {
|
||||
return new VariableScope().id(2L).code("code2").name("name2").description("description2").version(2);
|
||||
}
|
||||
|
||||
public static VariableScope getVariableScopeRandomSampleGenerator() {
|
||||
return new VariableScope()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.InputDataTestSamples.getInputDataRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.OutputDataTestSamples.getOutputDataRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.getUnitRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.VariableCategoryTestSamples.getVariableCategoryRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.VariableClassTestSamples.getVariableClassRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.VariableScopeTestSamples.getVariableScopeRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableRandomSampleGenerator;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableSample1;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.getVariableSample2;
|
||||
import static com.oguerreiro.resilient.domain.VariableUnitsTestSamples.getVariableUnitsRandomSampleGenerator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
|
||||
class VariableTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(Variable.class);
|
||||
Variable variable1 = getVariableSample1();
|
||||
Variable variable2 = new Variable();
|
||||
assertThat(variable1).isNotEqualTo(variable2);
|
||||
|
||||
variable2.setId(variable1.getId());
|
||||
assertThat(variable1).isEqualTo(variable2);
|
||||
|
||||
variable2 = getVariableSample2();
|
||||
assertThat(variable1).isNotEqualTo(variable2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableUnitsTest() {
|
||||
Variable variable = getVariableRandomSampleGenerator();
|
||||
VariableUnits variableUnitsBack = getVariableUnitsRandomSampleGenerator();
|
||||
|
||||
variable.addVariableUnits(variableUnitsBack);
|
||||
assertThat(variable.getVariableUnits()).containsOnly(variableUnitsBack);
|
||||
assertThat(variableUnitsBack.getVariable()).isEqualTo(variable);
|
||||
|
||||
variable.removeVariableUnits(variableUnitsBack);
|
||||
assertThat(variable.getVariableUnits()).doesNotContain(variableUnitsBack);
|
||||
assertThat(variableUnitsBack.getVariable()).isNull();
|
||||
|
||||
variable.variableUnits(new HashSet<>(Set.of(variableUnitsBack)));
|
||||
assertThat(variable.getVariableUnits()).containsOnly(variableUnitsBack);
|
||||
assertThat(variableUnitsBack.getVariable()).isEqualTo(variable);
|
||||
|
||||
variable.setVariableUnits(new HashSet<>());
|
||||
assertThat(variable.getVariableUnits()).doesNotContain(variableUnitsBack);
|
||||
assertThat(variableUnitsBack.getVariable()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void baseUnitTest() {
|
||||
Variable variable = getVariableRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
variable.setBaseUnit(unitBack);
|
||||
assertThat(variable.getBaseUnit()).isEqualTo(unitBack);
|
||||
|
||||
variable.baseUnit(null);
|
||||
assertThat(variable.getBaseUnit()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableScopeTest() {
|
||||
Variable variable = getVariableRandomSampleGenerator();
|
||||
VariableScope variableScopeBack = getVariableScopeRandomSampleGenerator();
|
||||
|
||||
variable.setVariableScope(variableScopeBack);
|
||||
assertThat(variable.getVariableScope()).isEqualTo(variableScopeBack);
|
||||
|
||||
variable.variableScope(null);
|
||||
assertThat(variable.getVariableScope()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableCategoryTest() {
|
||||
Variable variable = getVariableRandomSampleGenerator();
|
||||
VariableCategory variableCategoryBack = getVariableCategoryRandomSampleGenerator();
|
||||
|
||||
variable.setVariableCategory(variableCategoryBack);
|
||||
assertThat(variable.getVariableCategory()).isEqualTo(variableCategoryBack);
|
||||
|
||||
variable.variableCategory(null);
|
||||
assertThat(variable.getVariableCategory()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class VariableTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static Variable getVariableSample1() {
|
||||
return new Variable()
|
||||
.id(1L)
|
||||
.code("code1")
|
||||
.variableIndex(1)
|
||||
.name("name1")
|
||||
.description("description1")
|
||||
.outputFormula("outputFormula1")
|
||||
.version(1);
|
||||
}
|
||||
|
||||
public static Variable getVariableSample2() {
|
||||
return new Variable()
|
||||
.id(2L)
|
||||
.code("code2")
|
||||
.variableIndex(2)
|
||||
.name("name2")
|
||||
.description("description2")
|
||||
.outputFormula("outputFormula2")
|
||||
.version(2);
|
||||
}
|
||||
|
||||
public static Variable getVariableRandomSampleGenerator() {
|
||||
return new Variable()
|
||||
.id(longCount.incrementAndGet())
|
||||
.code(UUID.randomUUID().toString())
|
||||
.variableIndex(intCount.incrementAndGet())
|
||||
.name(UUID.randomUUID().toString())
|
||||
.description(UUID.randomUUID().toString())
|
||||
.outputFormula(UUID.randomUUID().toString())
|
||||
.version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class VariableUnitsAsserts {
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUnitsAllPropertiesEquals(VariableUnits expected, VariableUnits actual) {
|
||||
assertVariableUnitsAutoGeneratedPropertiesEquals(expected, actual);
|
||||
assertVariableUnitsAllUpdatablePropertiesEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all updatable properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUnitsAllUpdatablePropertiesEquals(VariableUnits expected, VariableUnits actual) {
|
||||
assertVariableUnitsUpdatableFieldsEquals(expected, actual);
|
||||
assertVariableUnitsUpdatableRelationshipsEquals(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the auto generated properties (fields/relationships) set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUnitsAutoGeneratedPropertiesEquals(VariableUnits expected, VariableUnits actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableUnits auto generated properties")
|
||||
.satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable fields set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUnitsUpdatableFieldsEquals(VariableUnits expected, VariableUnits actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableUnits relevant properties")
|
||||
.satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the entity has all the updatable relationships set.
|
||||
*
|
||||
* @param expected the expected entity
|
||||
* @param actual the actual entity
|
||||
*/
|
||||
public static void assertVariableUnitsUpdatableRelationshipsEquals(VariableUnits expected, VariableUnits actual) {
|
||||
assertThat(expected)
|
||||
.as("Verify VariableUnits relationships")
|
||||
.satisfies(e -> assertThat(e.getVariable()).as("check variable").isEqualTo(actual.getVariable()))
|
||||
.satisfies(e -> assertThat(e.getUnit()).as("check unit").isEqualTo(actual.getUnit()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import static com.oguerreiro.resilient.domain.UnitTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableTestSamples.*;
|
||||
import static com.oguerreiro.resilient.domain.VariableUnitsTestSamples.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableUnitsTest {
|
||||
|
||||
@Test
|
||||
void equalsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableUnits.class);
|
||||
VariableUnits variableUnits1 = getVariableUnitsSample1();
|
||||
VariableUnits variableUnits2 = new VariableUnits();
|
||||
assertThat(variableUnits1).isNotEqualTo(variableUnits2);
|
||||
|
||||
variableUnits2.setId(variableUnits1.getId());
|
||||
assertThat(variableUnits1).isEqualTo(variableUnits2);
|
||||
|
||||
variableUnits2 = getVariableUnitsSample2();
|
||||
assertThat(variableUnits1).isNotEqualTo(variableUnits2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableTest() {
|
||||
VariableUnits variableUnits = getVariableUnitsRandomSampleGenerator();
|
||||
Variable variableBack = getVariableRandomSampleGenerator();
|
||||
|
||||
variableUnits.setVariable(variableBack);
|
||||
assertThat(variableUnits.getVariable()).isEqualTo(variableBack);
|
||||
|
||||
variableUnits.variable(null);
|
||||
assertThat(variableUnits.getVariable()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void unitTest() {
|
||||
VariableUnits variableUnits = getVariableUnitsRandomSampleGenerator();
|
||||
Unit unitBack = getUnitRandomSampleGenerator();
|
||||
|
||||
variableUnits.setUnit(unitBack);
|
||||
assertThat(variableUnits.getUnit()).isEqualTo(unitBack);
|
||||
|
||||
variableUnits.unit(null);
|
||||
assertThat(variableUnits.getUnit()).isNull();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.domain;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class VariableUnitsTestSamples {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));
|
||||
private static final AtomicInteger intCount = new AtomicInteger(random.nextInt() + (2 * Short.MAX_VALUE));
|
||||
|
||||
public static VariableUnits getVariableUnitsSample1() {
|
||||
return new VariableUnits().id(1L).version(1);
|
||||
}
|
||||
|
||||
public static VariableUnits getVariableUnitsSample2() {
|
||||
return new VariableUnits().id(2L).version(2);
|
||||
}
|
||||
|
||||
public static VariableUnits getVariableUnitsRandomSampleGenerator() {
|
||||
return new VariableUnits().id(longCount.incrementAndGet()).version(intCount.incrementAndGet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package com.oguerreiro.resilient.repository.timezone;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "jhi_date_time_wrapper")
|
||||
public class DateTimeWrapper implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "instant")
|
||||
private Instant instant;
|
||||
|
||||
@Column(name = "local_date_time")
|
||||
private LocalDateTime localDateTime;
|
||||
|
||||
@Column(name = "offset_date_time")
|
||||
private OffsetDateTime offsetDateTime;
|
||||
|
||||
@Column(name = "zoned_date_time")
|
||||
private ZonedDateTime zonedDateTime;
|
||||
|
||||
@Column(name = "local_time")
|
||||
private LocalTime localTime;
|
||||
|
||||
@Column(name = "offset_time")
|
||||
private OffsetTime offsetTime;
|
||||
|
||||
@Column(name = "local_date")
|
||||
private LocalDate localDate;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Instant getInstant() {
|
||||
return instant;
|
||||
}
|
||||
|
||||
public void setInstant(Instant instant) {
|
||||
this.instant = instant;
|
||||
}
|
||||
|
||||
public LocalDateTime getLocalDateTime() {
|
||||
return localDateTime;
|
||||
}
|
||||
|
||||
public void setLocalDateTime(LocalDateTime localDateTime) {
|
||||
this.localDateTime = localDateTime;
|
||||
}
|
||||
|
||||
public OffsetDateTime getOffsetDateTime() {
|
||||
return offsetDateTime;
|
||||
}
|
||||
|
||||
public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
|
||||
this.offsetDateTime = offsetDateTime;
|
||||
}
|
||||
|
||||
public ZonedDateTime getZonedDateTime() {
|
||||
return zonedDateTime;
|
||||
}
|
||||
|
||||
public void setZonedDateTime(ZonedDateTime zonedDateTime) {
|
||||
this.zonedDateTime = zonedDateTime;
|
||||
}
|
||||
|
||||
public LocalTime getLocalTime() {
|
||||
return localTime;
|
||||
}
|
||||
|
||||
public void setLocalTime(LocalTime localTime) {
|
||||
this.localTime = localTime;
|
||||
}
|
||||
|
||||
public OffsetTime getOffsetTime() {
|
||||
return offsetTime;
|
||||
}
|
||||
|
||||
public void setOffsetTime(OffsetTime offsetTime) {
|
||||
this.offsetTime = offsetTime;
|
||||
}
|
||||
|
||||
public LocalDate getLocalDate() {
|
||||
return localDate;
|
||||
}
|
||||
|
||||
public void setLocalDate(LocalDate localDate) {
|
||||
this.localDate = localDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DateTimeWrapper dateTimeWrapper = (DateTimeWrapper) o;
|
||||
return !(dateTimeWrapper.getId() == null || getId() == null) && Objects.equals(getId(), dateTimeWrapper.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId());
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TimeZoneTest{" +
|
||||
"id=" + id +
|
||||
", instant=" + instant +
|
||||
", localDateTime=" + localDateTime +
|
||||
", offsetDateTime=" + offsetDateTime +
|
||||
", zonedDateTime=" + zonedDateTime +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.oguerreiro.resilient.repository.timezone;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the {@link DateTimeWrapper} entity.
|
||||
*/
|
||||
@Repository
|
||||
public interface DateTimeWrapperRepository extends JpaRepository<DateTimeWrapper, Long> {}
|
|
@ -0,0 +1,136 @@
|
|||
package com.oguerreiro.resilient.security;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import com.oguerreiro.resilient.IntegrationTest;
|
||||
import com.oguerreiro.resilient.domain.User;
|
||||
import com.oguerreiro.resilient.repository.UserRepository;
|
||||
import com.oguerreiro.resilient.service.UserService;
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Integrations tests for {@link DomainUserDetailsService}.
|
||||
*/
|
||||
@Transactional
|
||||
@IntegrationTest
|
||||
class DomainUserDetailsServiceIT {
|
||||
|
||||
private static final String USER_ONE_LOGIN = "test-user-one";
|
||||
private static final String USER_ONE_EMAIL = "test-user-one@localhost";
|
||||
private static final String USER_TWO_LOGIN = "test-user-two";
|
||||
private static final String USER_TWO_EMAIL = "test-user-two@localhost";
|
||||
private static final String USER_THREE_LOGIN = "test-user-three";
|
||||
private static final String USER_THREE_EMAIL = "test-user-three@localhost";
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("userDetailsService")
|
||||
private UserDetailsService domainUserDetailsService;
|
||||
|
||||
public User getUserOne() {
|
||||
User userOne = new User();
|
||||
userOne.setLogin(USER_ONE_LOGIN);
|
||||
userOne.setPassword(RandomStringUtils.randomAlphanumeric(60));
|
||||
userOne.setActivated(true);
|
||||
userOne.setEmail(USER_ONE_EMAIL);
|
||||
userOne.setFirstName("userOne");
|
||||
userOne.setLastName("doe");
|
||||
userOne.setLangKey("en");
|
||||
return userOne;
|
||||
}
|
||||
|
||||
public User getUserTwo() {
|
||||
User userTwo = new User();
|
||||
userTwo.setLogin(USER_TWO_LOGIN);
|
||||
userTwo.setPassword(RandomStringUtils.randomAlphanumeric(60));
|
||||
userTwo.setActivated(true);
|
||||
userTwo.setEmail(USER_TWO_EMAIL);
|
||||
userTwo.setFirstName("userTwo");
|
||||
userTwo.setLastName("doe");
|
||||
userTwo.setLangKey("en");
|
||||
return userTwo;
|
||||
}
|
||||
|
||||
public User getUserThree() {
|
||||
User userThree = new User();
|
||||
userThree.setLogin(USER_THREE_LOGIN);
|
||||
userThree.setPassword(RandomStringUtils.randomAlphanumeric(60));
|
||||
userThree.setActivated(false);
|
||||
userThree.setEmail(USER_THREE_EMAIL);
|
||||
userThree.setFirstName("userThree");
|
||||
userThree.setLastName("doe");
|
||||
userThree.setLangKey("en");
|
||||
return userThree;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
userRepository.save(getUserOne());
|
||||
userRepository.save(getUserTwo());
|
||||
userRepository.save(getUserThree());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanup() {
|
||||
userService.deleteUser(USER_ONE_LOGIN);
|
||||
userService.deleteUser(USER_TWO_LOGIN);
|
||||
userService.deleteUser(USER_THREE_LOGIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertThatUserCanBeFoundByLogin() {
|
||||
UserDetails userDetails = domainUserDetailsService.loadUserByUsername(USER_ONE_LOGIN);
|
||||
assertThat(userDetails).isNotNull();
|
||||
assertThat(userDetails.getUsername()).isEqualTo(USER_ONE_LOGIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertThatUserCanBeFoundByLoginIgnoreCase() {
|
||||
UserDetails userDetails = domainUserDetailsService.loadUserByUsername(USER_ONE_LOGIN.toUpperCase(Locale.ENGLISH));
|
||||
assertThat(userDetails).isNotNull();
|
||||
assertThat(userDetails.getUsername()).isEqualTo(USER_ONE_LOGIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertThatUserCanBeFoundByEmail() {
|
||||
UserDetails userDetails = domainUserDetailsService.loadUserByUsername(USER_TWO_EMAIL);
|
||||
assertThat(userDetails).isNotNull();
|
||||
assertThat(userDetails.getUsername()).isEqualTo(USER_TWO_LOGIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertThatUserCanBeFoundByEmailIgnoreCase() {
|
||||
UserDetails userDetails = domainUserDetailsService.loadUserByUsername(USER_TWO_EMAIL.toUpperCase(Locale.ENGLISH));
|
||||
assertThat(userDetails).isNotNull();
|
||||
assertThat(userDetails.getUsername()).isEqualTo(USER_TWO_LOGIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertThatEmailIsPrioritizedOverLogin() {
|
||||
UserDetails userDetails = domainUserDetailsService.loadUserByUsername(USER_ONE_EMAIL);
|
||||
assertThat(userDetails).isNotNull();
|
||||
assertThat(userDetails.getUsername()).isEqualTo(USER_ONE_LOGIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertThatUserNotActivatedExceptionIsThrownForNotActivatedUsers() {
|
||||
assertThatExceptionOfType(UserNotActivatedException.class).isThrownBy(
|
||||
() -> domainUserDetailsService.loadUserByUsername(USER_THREE_LOGIN)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.oguerreiro.resilient.security;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
/**
|
||||
* Test class for the {@link SecurityUtils} utility class.
|
||||
*/
|
||||
class SecurityUtilsUnitTest {
|
||||
|
||||
@BeforeEach
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCurrentUserLogin() {
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("admin", "admin"));
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
Optional<String> login = SecurityUtils.getCurrentUserLogin();
|
||||
assertThat(login).contains("admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsAuthenticated() {
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("admin", "admin"));
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
boolean isAuthenticated = SecurityUtils.isAuthenticated();
|
||||
assertThat(isAuthenticated).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAnonymousIsNotAuthenticated() {
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
Collection<GrantedAuthority> authorities = new ArrayList<>();
|
||||
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ANONYMOUS));
|
||||
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("anonymous", "anonymous", authorities));
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
boolean isAuthenticated = SecurityUtils.isAuthenticated();
|
||||
assertThat(isAuthenticated).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHasCurrentUserThisAuthority() {
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
Collection<GrantedAuthority> authorities = new ArrayList<>();
|
||||
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.USER));
|
||||
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("user", "user", authorities));
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
|
||||
assertThat(SecurityUtils.hasCurrentUserThisAuthority(AuthoritiesConstants.USER)).isTrue();
|
||||
assertThat(SecurityUtils.hasCurrentUserThisAuthority(AuthoritiesConstants.ADMIN)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHasCurrentUserAnyOfAuthorities() {
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
Collection<GrantedAuthority> authorities = new ArrayList<>();
|
||||
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.USER));
|
||||
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("user", "user", authorities));
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
|
||||
assertThat(SecurityUtils.hasCurrentUserAnyOfAuthorities(AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN)).isTrue();
|
||||
assertThat(SecurityUtils.hasCurrentUserAnyOfAuthorities(AuthoritiesConstants.ANONYMOUS, AuthoritiesConstants.ADMIN)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHasCurrentUserNoneOfAuthorities() {
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
Collection<GrantedAuthority> authorities = new ArrayList<>();
|
||||
authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.USER));
|
||||
securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("user", "user", authorities));
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
|
||||
assertThat(SecurityUtils.hasCurrentUserNoneOfAuthorities(AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN)).isFalse();
|
||||
assertThat(SecurityUtils.hasCurrentUserNoneOfAuthorities(AuthoritiesConstants.ANONYMOUS, AuthoritiesConstants.ADMIN)).isTrue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
package com.oguerreiro.resilient.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.mail.MailSendException;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
|
||||
import com.oguerreiro.resilient.IntegrationTest;
|
||||
import com.oguerreiro.resilient.config.Constants;
|
||||
import com.oguerreiro.resilient.domain.User;
|
||||
|
||||
import jakarta.mail.Multipart;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.internet.MimeBodyPart;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
import tech.jhipster.config.JHipsterProperties;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link MailService}.
|
||||
*/
|
||||
@IntegrationTest
|
||||
class MailServiceIT {
|
||||
|
||||
private static final String[] languages = {
|
||||
"pt-pt",
|
||||
"en",
|
||||
// jhipster-needle-i18n-language-constant - JHipster will add/remove languages in this array
|
||||
};
|
||||
private static final Pattern PATTERN_LOCALE_3 = Pattern.compile("([a-z]{2})-([a-zA-Z]{4})-([a-z]{2})");
|
||||
private static final Pattern PATTERN_LOCALE_2 = Pattern.compile("([a-z]{2})-([a-z]{2})");
|
||||
|
||||
@Autowired
|
||||
private JHipsterProperties jHipsterProperties;
|
||||
|
||||
@MockBean
|
||||
private JavaMailSender javaMailSender;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<MimeMessage> messageCaptor;
|
||||
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
doNothing().when(javaMailSender).send(any(MimeMessage.class));
|
||||
when(javaMailSender.createMimeMessage()).thenReturn(new MimeMessage((Session) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendEmail() throws Exception {
|
||||
mailService.sendEmail("john.doe@example.com", "testSubject", "testContent", false, false);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
assertThat(message.getSubject()).isEqualTo("testSubject");
|
||||
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent()).isInstanceOf(String.class);
|
||||
assertThat(message.getContent()).hasToString("testContent");
|
||||
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendHtmlEmail() throws Exception {
|
||||
mailService.sendEmail("john.doe@example.com", "testSubject", "testContent", false, true);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
assertThat(message.getSubject()).isEqualTo("testSubject");
|
||||
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent()).isInstanceOf(String.class);
|
||||
assertThat(message.getContent()).hasToString("testContent");
|
||||
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendMultipartEmail() throws Exception {
|
||||
mailService.sendEmail("john.doe@example.com", "testSubject", "testContent", true, false);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
MimeMultipart mp = (MimeMultipart) message.getContent();
|
||||
MimeBodyPart part = (MimeBodyPart) ((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
|
||||
ByteArrayOutputStream aos = new ByteArrayOutputStream();
|
||||
part.writeTo(aos);
|
||||
assertThat(message.getSubject()).isEqualTo("testSubject");
|
||||
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent()).isInstanceOf(Multipart.class);
|
||||
assertThat(aos).hasToString("\r\ntestContent");
|
||||
assertThat(part.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendMultipartHtmlEmail() throws Exception {
|
||||
mailService.sendEmail("john.doe@example.com", "testSubject", "testContent", true, true);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
MimeMultipart mp = (MimeMultipart) message.getContent();
|
||||
MimeBodyPart part = (MimeBodyPart) ((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
|
||||
ByteArrayOutputStream aos = new ByteArrayOutputStream();
|
||||
part.writeTo(aos);
|
||||
assertThat(message.getSubject()).isEqualTo("testSubject");
|
||||
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent()).isInstanceOf(Multipart.class);
|
||||
assertThat(aos).hasToString("\r\ntestContent");
|
||||
assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendEmailFromTemplate() throws Exception {
|
||||
User user = new User();
|
||||
user.setLangKey(Constants.DEFAULT_LANGUAGE);
|
||||
user.setLogin("john");
|
||||
user.setEmail("john.doe@example.com");
|
||||
mailService.sendEmailFromTemplate(user, "mail/testEmail", "email.test.title");
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
assertThat(message.getSubject()).isEqualTo("test title");
|
||||
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent().toString()).isEqualToNormalizingNewlines("<html>test title, http://127.0.0.1:8080, john</html>\n");
|
||||
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendActivationEmail() throws Exception {
|
||||
User user = new User();
|
||||
user.setLangKey(Constants.DEFAULT_LANGUAGE);
|
||||
user.setLogin("john");
|
||||
user.setEmail("john.doe@example.com");
|
||||
mailService.sendActivationEmail(user);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent().toString()).isNotEmpty();
|
||||
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreationEmail() throws Exception {
|
||||
User user = new User();
|
||||
user.setLangKey(Constants.DEFAULT_LANGUAGE);
|
||||
user.setLogin("john");
|
||||
user.setEmail("john.doe@example.com");
|
||||
mailService.sendCreationEmail(user);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent().toString()).isNotEmpty();
|
||||
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendPasswordResetMail() throws Exception {
|
||||
User user = new User();
|
||||
user.setLangKey(Constants.DEFAULT_LANGUAGE);
|
||||
user.setLogin("john");
|
||||
user.setEmail("john.doe@example.com");
|
||||
mailService.sendPasswordResetMail(user);
|
||||
verify(javaMailSender).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
|
||||
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
|
||||
assertThat(message.getContent().toString()).isNotEmpty();
|
||||
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendEmailWithException() {
|
||||
doThrow(MailSendException.class).when(javaMailSender).send(any(MimeMessage.class));
|
||||
try {
|
||||
mailService.sendEmail("john.doe@example.com", "testSubject", "testContent", false, false);
|
||||
} catch (Exception e) {
|
||||
fail("Exception shouldn't have been thrown");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendLocalizedEmailForAllSupportedLanguages() throws Exception {
|
||||
User user = new User();
|
||||
user.setLogin("john");
|
||||
user.setEmail("john.doe@example.com");
|
||||
for (String langKey : languages) {
|
||||
user.setLangKey(langKey);
|
||||
mailService.sendEmailFromTemplate(user, "mail/testEmail", "email.test.title");
|
||||
verify(javaMailSender, atLeastOnce()).send(messageCaptor.capture());
|
||||
MimeMessage message = messageCaptor.getValue();
|
||||
|
||||
String propertyFilePath = "i18n/messages_" + getMessageSourceSuffixForLanguage(langKey) + ".properties";
|
||||
URL resource = this.getClass().getClassLoader().getResource(propertyFilePath);
|
||||
File file = new File(new URI(resource.getFile()).getPath());
|
||||
Properties properties = new Properties();
|
||||
properties.load(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")));
|
||||
|
||||
String emailTitle = (String) properties.get("email.test.title");
|
||||
assertThat(message.getSubject()).isEqualTo(emailTitle);
|
||||
assertThat(message.getContent().toString()).isEqualToNormalizingNewlines(
|
||||
"<html>" + emailTitle + ", http://127.0.0.1:8080, john</html>\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a lang key to the Java locale.
|
||||
*/
|
||||
private String getMessageSourceSuffixForLanguage(String langKey) {
|
||||
String javaLangKey = langKey;
|
||||
Matcher matcher2 = PATTERN_LOCALE_2.matcher(langKey);
|
||||
if (matcher2.matches()) {
|
||||
javaLangKey = matcher2.group(1) + "_" + matcher2.group(2).toUpperCase();
|
||||
}
|
||||
Matcher matcher3 = PATTERN_LOCALE_3.matcher(langKey);
|
||||
if (matcher3.matches()) {
|
||||
javaLangKey = matcher3.group(1) + "_" + matcher3.group(2) + "_" + matcher3.group(3).toUpperCase();
|
||||
}
|
||||
return javaLangKey;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,239 @@
|
|||
package com.oguerreiro.resilient.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.oguerreiro.resilient.IntegrationTest;
|
||||
import com.oguerreiro.resilient.domain.PersistentToken;
|
||||
import com.oguerreiro.resilient.domain.User;
|
||||
import com.oguerreiro.resilient.repository.PersistentTokenRepository;
|
||||
import com.oguerreiro.resilient.repository.UserRepository;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.data.auditing.AuditingHandler;
|
||||
import org.springframework.data.auditing.DateTimeProvider;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tech.jhipster.security.RandomUtil;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link UserService}.
|
||||
*/
|
||||
@IntegrationTest
|
||||
@Transactional
|
||||
class UserServiceIT {
|
||||
|
||||
private static final String DEFAULT_LOGIN = "johndoe_service";
|
||||
|
||||
private static final String DEFAULT_EMAIL = "johndoe_service@localhost";
|
||||
|
||||
private static final String DEFAULT_FIRSTNAME = "john";
|
||||
|
||||
private static final String DEFAULT_LASTNAME = "doe";
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
private static final String DEFAULT_IMAGEURL = "http://placehold.it/50x50";
|
||||
|
||||
private static final String DEFAULT_LANGKEY = "dummy";
|
||||
|
||||
@Autowired
|
||||
private PersistentTokenRepository persistentTokenRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private AuditingHandler auditingHandler;
|
||||
|
||||
@MockBean
|
||||
private DateTimeProvider dateTimeProvider;
|
||||
|
||||
private User user;
|
||||
|
||||
private Long numberOfUsers;
|
||||
|
||||
@BeforeEach
|
||||
public void countUsers() {
|
||||
numberOfUsers = userRepository.count();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
user = new User();
|
||||
user.setLogin(DEFAULT_LOGIN);
|
||||
user.setPassword(RandomStringUtils.randomAlphanumeric(60));
|
||||
user.setActivated(true);
|
||||
user.setEmail(DEFAULT_EMAIL);
|
||||
user.setFirstName(DEFAULT_FIRSTNAME);
|
||||
user.setLastName(DEFAULT_LASTNAME);
|
||||
user.setImageUrl(DEFAULT_IMAGEURL);
|
||||
user.setLangKey(DEFAULT_LANGKEY);
|
||||
|
||||
when(dateTimeProvider.getNow()).thenReturn(Optional.of(LocalDateTime.now()));
|
||||
auditingHandler.setDateTimeProvider(dateTimeProvider);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanupAndCheck() {
|
||||
cacheManager
|
||||
.getCacheNames()
|
||||
.stream()
|
||||
.map(cacheName -> this.cacheManager.getCache(cacheName))
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(Cache::clear);
|
||||
persistentTokenRepository.deleteAll();
|
||||
userService.deleteUser(DEFAULT_LOGIN);
|
||||
assertThat(userRepository.count()).isEqualTo(numberOfUsers);
|
||||
numberOfUsers = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void testRemoveOldPersistentTokens() {
|
||||
userRepository.saveAndFlush(user);
|
||||
int existingCount = persistentTokenRepository.findByUser(user).size();
|
||||
LocalDate today = LocalDate.now();
|
||||
generateUserToken(user, "1111-1111", today);
|
||||
generateUserToken(user, "2222-2222", today.minusDays(32));
|
||||
assertThat(persistentTokenRepository.findByUser(user)).hasSize(existingCount + 2);
|
||||
userService.removeOldPersistentTokens();
|
||||
assertThat(persistentTokenRepository.findByUser(user)).hasSize(existingCount + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatUserMustExistToResetPassword() {
|
||||
userRepository.saveAndFlush(user);
|
||||
Optional<User> maybeUser = userService.requestPasswordReset("invalid.login@localhost");
|
||||
assertThat(maybeUser).isNotPresent();
|
||||
|
||||
maybeUser = userService.requestPasswordReset(user.getEmail());
|
||||
assertThat(maybeUser).isPresent();
|
||||
assertThat(maybeUser.orElse(null).getEmail()).isEqualTo(user.getEmail());
|
||||
assertThat(maybeUser.orElse(null).getResetDate()).isNotNull();
|
||||
assertThat(maybeUser.orElse(null).getResetKey()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatOnlyActivatedUserCanRequestPasswordReset() {
|
||||
user.setActivated(false);
|
||||
userRepository.saveAndFlush(user);
|
||||
|
||||
Optional<User> maybeUser = userService.requestPasswordReset(user.getLogin());
|
||||
assertThat(maybeUser).isNotPresent();
|
||||
userRepository.delete(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatResetKeyMustNotBeOlderThan24Hours() {
|
||||
Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
|
||||
String resetKey = RandomUtil.generateResetKey();
|
||||
user.setActivated(true);
|
||||
user.setResetDate(daysAgo);
|
||||
user.setResetKey(resetKey);
|
||||
userRepository.saveAndFlush(user);
|
||||
|
||||
Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
|
||||
assertThat(maybeUser).isNotPresent();
|
||||
userRepository.delete(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatResetKeyMustBeValid() {
|
||||
Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
|
||||
user.setActivated(true);
|
||||
user.setResetDate(daysAgo);
|
||||
user.setResetKey("1234");
|
||||
userRepository.saveAndFlush(user);
|
||||
|
||||
Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
|
||||
assertThat(maybeUser).isNotPresent();
|
||||
userRepository.delete(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatUserCanResetPassword() {
|
||||
String oldPassword = user.getPassword();
|
||||
Instant daysAgo = Instant.now().minus(2, ChronoUnit.HOURS);
|
||||
String resetKey = RandomUtil.generateResetKey();
|
||||
user.setActivated(true);
|
||||
user.setResetDate(daysAgo);
|
||||
user.setResetKey(resetKey);
|
||||
userRepository.saveAndFlush(user);
|
||||
|
||||
Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
|
||||
assertThat(maybeUser).isPresent();
|
||||
assertThat(maybeUser.orElse(null).getResetDate()).isNull();
|
||||
assertThat(maybeUser.orElse(null).getResetKey()).isNull();
|
||||
assertThat(maybeUser.orElse(null).getPassword()).isNotEqualTo(oldPassword);
|
||||
|
||||
userRepository.delete(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatNotActivatedUsersWithNotNullActivationKeyCreatedBefore3DaysAreDeleted() {
|
||||
Instant now = Instant.now();
|
||||
when(dateTimeProvider.getNow()).thenReturn(Optional.of(now.minus(4, ChronoUnit.DAYS)));
|
||||
user.setActivated(false);
|
||||
user.setActivationKey(RandomStringUtils.random(20));
|
||||
User dbUser = userRepository.saveAndFlush(user);
|
||||
dbUser.setCreatedDate(now.minus(4, ChronoUnit.DAYS));
|
||||
userRepository.saveAndFlush(user);
|
||||
Instant threeDaysAgo = now.minus(3, ChronoUnit.DAYS);
|
||||
List<User> users = userRepository.findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(threeDaysAgo);
|
||||
assertThat(users).isNotEmpty();
|
||||
userService.removeNotActivatedUsers();
|
||||
users = userRepository.findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(threeDaysAgo);
|
||||
assertThat(users).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assertThatNotActivatedUsersWithNullActivationKeyCreatedBefore3DaysAreNotDeleted() {
|
||||
Instant now = Instant.now();
|
||||
when(dateTimeProvider.getNow()).thenReturn(Optional.of(now.minus(4, ChronoUnit.DAYS)));
|
||||
user.setActivated(false);
|
||||
User dbUser = userRepository.saveAndFlush(user);
|
||||
dbUser.setCreatedDate(now.minus(4, ChronoUnit.DAYS));
|
||||
userRepository.saveAndFlush(user);
|
||||
Instant threeDaysAgo = now.minus(3, ChronoUnit.DAYS);
|
||||
List<User> users = userRepository.findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(threeDaysAgo);
|
||||
assertThat(users).isEmpty();
|
||||
userService.removeNotActivatedUsers();
|
||||
Optional<User> maybeDbUser = userRepository.findById(dbUser.getId());
|
||||
assertThat(maybeDbUser).contains(dbUser);
|
||||
}
|
||||
|
||||
private void generateUserToken(User user, String tokenSeries, LocalDate localDate) {
|
||||
PersistentToken token = new PersistentToken();
|
||||
token.setSeries(tokenSeries);
|
||||
token.setUser(user);
|
||||
token.setTokenValue(tokenSeries + "-data");
|
||||
token.setTokenDate(localDate);
|
||||
token.setIpAddress("127.0.0.1");
|
||||
token.setUserAgent("Test agent");
|
||||
persistentTokenRepository.saveAndFlush(token);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
package com.oguerreiro.resilient.service.criteria;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableCriteriaTest {
|
||||
|
||||
@Test
|
||||
void newVariableCriteriaHasAllFiltersNullTest() {
|
||||
var variableCriteria = new VariableCriteria();
|
||||
assertThat(variableCriteria).is(criteriaFiltersAre(filter -> filter == null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableCriteriaFluentMethodsCreatesFiltersTest() {
|
||||
var variableCriteria = new VariableCriteria();
|
||||
|
||||
setAllFilters(variableCriteria);
|
||||
|
||||
assertThat(variableCriteria).is(criteriaFiltersAre(filter -> filter != null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableCriteriaCopyCreatesNullFilterTest() {
|
||||
var variableCriteria = new VariableCriteria();
|
||||
var copy = variableCriteria.copy();
|
||||
|
||||
assertThat(variableCriteria).satisfies(
|
||||
criteria ->
|
||||
assertThat(criteria).is(
|
||||
copyFiltersAre(copy, (a, b) -> (a == null || a instanceof Boolean) ? a == b : (a != b && a.equals(b)))
|
||||
),
|
||||
criteria -> assertThat(criteria).isEqualTo(copy),
|
||||
criteria -> assertThat(criteria).hasSameHashCodeAs(copy)
|
||||
);
|
||||
|
||||
assertThat(copy).satisfies(
|
||||
criteria -> assertThat(criteria).is(criteriaFiltersAre(filter -> filter == null)),
|
||||
criteria -> assertThat(criteria).isEqualTo(variableCriteria)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void variableCriteriaCopyDuplicatesEveryExistingFilterTest() {
|
||||
var variableCriteria = new VariableCriteria();
|
||||
setAllFilters(variableCriteria);
|
||||
|
||||
var copy = variableCriteria.copy();
|
||||
|
||||
assertThat(variableCriteria).satisfies(
|
||||
criteria ->
|
||||
assertThat(criteria).is(
|
||||
copyFiltersAre(copy, (a, b) -> (a == null || a instanceof Boolean) ? a == b : (a != b && a.equals(b)))
|
||||
),
|
||||
criteria -> assertThat(criteria).isEqualTo(copy),
|
||||
criteria -> assertThat(criteria).hasSameHashCodeAs(copy)
|
||||
);
|
||||
|
||||
assertThat(copy).satisfies(
|
||||
criteria -> assertThat(criteria).is(criteriaFiltersAre(filter -> filter != null)),
|
||||
criteria -> assertThat(criteria).isEqualTo(variableCriteria)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringVerifier() {
|
||||
var variableCriteria = new VariableCriteria();
|
||||
|
||||
assertThat(variableCriteria).hasToString("VariableCriteria{}");
|
||||
}
|
||||
|
||||
private static void setAllFilters(VariableCriteria variableCriteria) {
|
||||
variableCriteria.id();
|
||||
variableCriteria.code();
|
||||
variableCriteria.variableIndex();
|
||||
variableCriteria.name();
|
||||
variableCriteria.description();
|
||||
variableCriteria.input();
|
||||
variableCriteria.inputMode();
|
||||
variableCriteria.output();
|
||||
variableCriteria.outputFormula();
|
||||
variableCriteria.version();
|
||||
variableCriteria.variableUnitsId();
|
||||
variableCriteria.baseUnitId();
|
||||
variableCriteria.variableScopeId();
|
||||
variableCriteria.variableCategoryId();
|
||||
variableCriteria.distinct();
|
||||
}
|
||||
|
||||
private static Condition<VariableCriteria> criteriaFiltersAre(Function<Object, Boolean> condition) {
|
||||
return new Condition<>(
|
||||
criteria ->
|
||||
condition.apply(criteria.getId()) &&
|
||||
condition.apply(criteria.getCode()) &&
|
||||
condition.apply(criteria.getVariableIndex()) &&
|
||||
condition.apply(criteria.getName()) &&
|
||||
condition.apply(criteria.getDescription()) &&
|
||||
condition.apply(criteria.getInput()) &&
|
||||
condition.apply(criteria.getInputMode()) &&
|
||||
condition.apply(criteria.getOutput()) &&
|
||||
condition.apply(criteria.getOutputFormula()) &&
|
||||
condition.apply(criteria.getVersion()) &&
|
||||
condition.apply(criteria.getVariableUnitsId()) &&
|
||||
condition.apply(criteria.getBaseUnitId()) &&
|
||||
condition.apply(criteria.getVariableScopeId()) &&
|
||||
condition.apply(criteria.getVariableCategoryId()) &&
|
||||
condition.apply(criteria.getDistinct()),
|
||||
"every filter matches"
|
||||
);
|
||||
}
|
||||
|
||||
private static Condition<VariableCriteria> copyFiltersAre(VariableCriteria copy, BiFunction<Object, Object, Boolean> condition) {
|
||||
return new Condition<>(
|
||||
criteria ->
|
||||
condition.apply(criteria.getId(), copy.getId()) &&
|
||||
condition.apply(criteria.getCode(), copy.getCode()) &&
|
||||
condition.apply(criteria.getVariableIndex(), copy.getVariableIndex()) &&
|
||||
condition.apply(criteria.getName(), copy.getName()) &&
|
||||
condition.apply(criteria.getDescription(), copy.getDescription()) &&
|
||||
condition.apply(criteria.getInput(), copy.getInput()) &&
|
||||
condition.apply(criteria.getInputMode(), copy.getInputMode()) &&
|
||||
condition.apply(criteria.getOutput(), copy.getOutput()) &&
|
||||
condition.apply(criteria.getOutputFormula(), copy.getOutputFormula()) &&
|
||||
condition.apply(criteria.getVersion(), copy.getVersion()) &&
|
||||
condition.apply(criteria.getVariableUnitsId(), copy.getVariableUnitsId()) &&
|
||||
condition.apply(criteria.getBaseUnitId(), copy.getBaseUnitId()) &&
|
||||
condition.apply(criteria.getVariableScopeId(), copy.getVariableScopeId()) &&
|
||||
condition.apply(criteria.getVariableCategoryId(), copy.getVariableCategoryId()) &&
|
||||
condition.apply(criteria.getDistinct(), copy.getDistinct()),
|
||||
"every filter matches"
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class InputDataDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(InputDataDTO.class);
|
||||
InputDataDTO inputDataDTO1 = new InputDataDTO();
|
||||
inputDataDTO1.setId(1L);
|
||||
InputDataDTO inputDataDTO2 = new InputDataDTO();
|
||||
assertThat(inputDataDTO1).isNotEqualTo(inputDataDTO2);
|
||||
inputDataDTO2.setId(inputDataDTO1.getId());
|
||||
assertThat(inputDataDTO1).isEqualTo(inputDataDTO2);
|
||||
inputDataDTO2.setId(2L);
|
||||
assertThat(inputDataDTO1).isNotEqualTo(inputDataDTO2);
|
||||
inputDataDTO1.setId(null);
|
||||
assertThat(inputDataDTO1).isNotEqualTo(inputDataDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class InputDataUploadDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(InputDataUploadDTO.class);
|
||||
InputDataUploadDTO inputDataUploadDTO1 = new InputDataUploadDTO();
|
||||
inputDataUploadDTO1.setId(1L);
|
||||
InputDataUploadDTO inputDataUploadDTO2 = new InputDataUploadDTO();
|
||||
assertThat(inputDataUploadDTO1).isNotEqualTo(inputDataUploadDTO2);
|
||||
inputDataUploadDTO2.setId(inputDataUploadDTO1.getId());
|
||||
assertThat(inputDataUploadDTO1).isEqualTo(inputDataUploadDTO2);
|
||||
inputDataUploadDTO2.setId(2L);
|
||||
assertThat(inputDataUploadDTO1).isNotEqualTo(inputDataUploadDTO2);
|
||||
inputDataUploadDTO1.setId(null);
|
||||
assertThat(inputDataUploadDTO1).isNotEqualTo(inputDataUploadDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class InputDataUploadLogDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(InputDataUploadLogDTO.class);
|
||||
InputDataUploadLogDTO inputDataUploadLogDTO1 = new InputDataUploadLogDTO();
|
||||
inputDataUploadLogDTO1.setId(1L);
|
||||
InputDataUploadLogDTO inputDataUploadLogDTO2 = new InputDataUploadLogDTO();
|
||||
assertThat(inputDataUploadLogDTO1).isNotEqualTo(inputDataUploadLogDTO2);
|
||||
inputDataUploadLogDTO2.setId(inputDataUploadLogDTO1.getId());
|
||||
assertThat(inputDataUploadLogDTO1).isEqualTo(inputDataUploadLogDTO2);
|
||||
inputDataUploadLogDTO2.setId(2L);
|
||||
assertThat(inputDataUploadLogDTO1).isNotEqualTo(inputDataUploadLogDTO2);
|
||||
inputDataUploadLogDTO1.setId(null);
|
||||
assertThat(inputDataUploadLogDTO1).isNotEqualTo(inputDataUploadLogDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MetadataPropertyDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(MetadataPropertyDTO.class);
|
||||
MetadataPropertyDTO metadataPropertyDTO1 = new MetadataPropertyDTO();
|
||||
metadataPropertyDTO1.setId(1L);
|
||||
MetadataPropertyDTO metadataPropertyDTO2 = new MetadataPropertyDTO();
|
||||
assertThat(metadataPropertyDTO1).isNotEqualTo(metadataPropertyDTO2);
|
||||
metadataPropertyDTO2.setId(metadataPropertyDTO1.getId());
|
||||
assertThat(metadataPropertyDTO1).isEqualTo(metadataPropertyDTO2);
|
||||
metadataPropertyDTO2.setId(2L);
|
||||
assertThat(metadataPropertyDTO1).isNotEqualTo(metadataPropertyDTO2);
|
||||
metadataPropertyDTO1.setId(null);
|
||||
assertThat(metadataPropertyDTO1).isNotEqualTo(metadataPropertyDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MetadataValueDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(MetadataValueDTO.class);
|
||||
MetadataValueDTO metadataValueDTO1 = new MetadataValueDTO();
|
||||
metadataValueDTO1.setId(1L);
|
||||
MetadataValueDTO metadataValueDTO2 = new MetadataValueDTO();
|
||||
assertThat(metadataValueDTO1).isNotEqualTo(metadataValueDTO2);
|
||||
metadataValueDTO2.setId(metadataValueDTO1.getId());
|
||||
assertThat(metadataValueDTO1).isEqualTo(metadataValueDTO2);
|
||||
metadataValueDTO2.setId(2L);
|
||||
assertThat(metadataValueDTO1).isNotEqualTo(metadataValueDTO2);
|
||||
metadataValueDTO1.setId(null);
|
||||
assertThat(metadataValueDTO1).isNotEqualTo(metadataValueDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class OrganizationDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(OrganizationDTO.class);
|
||||
OrganizationDTO organizationDTO1 = new OrganizationDTO();
|
||||
organizationDTO1.setId(1L);
|
||||
OrganizationDTO organizationDTO2 = new OrganizationDTO();
|
||||
assertThat(organizationDTO1).isNotEqualTo(organizationDTO2);
|
||||
organizationDTO2.setId(organizationDTO1.getId());
|
||||
assertThat(organizationDTO1).isEqualTo(organizationDTO2);
|
||||
organizationDTO2.setId(2L);
|
||||
assertThat(organizationDTO1).isNotEqualTo(organizationDTO2);
|
||||
organizationDTO1.setId(null);
|
||||
assertThat(organizationDTO1).isNotEqualTo(organizationDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class OrganizationTypeDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(OrganizationTypeDTO.class);
|
||||
OrganizationTypeDTO organizationTypeDTO1 = new OrganizationTypeDTO();
|
||||
organizationTypeDTO1.setId(1L);
|
||||
OrganizationTypeDTO organizationTypeDTO2 = new OrganizationTypeDTO();
|
||||
assertThat(organizationTypeDTO1).isNotEqualTo(organizationTypeDTO2);
|
||||
organizationTypeDTO2.setId(organizationTypeDTO1.getId());
|
||||
assertThat(organizationTypeDTO1).isEqualTo(organizationTypeDTO2);
|
||||
organizationTypeDTO2.setId(2L);
|
||||
assertThat(organizationTypeDTO1).isNotEqualTo(organizationTypeDTO2);
|
||||
organizationTypeDTO1.setId(null);
|
||||
assertThat(organizationTypeDTO1).isNotEqualTo(organizationTypeDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class OutputDataDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(OutputDataDTO.class);
|
||||
OutputDataDTO outputDataDTO1 = new OutputDataDTO();
|
||||
outputDataDTO1.setId(1L);
|
||||
OutputDataDTO outputDataDTO2 = new OutputDataDTO();
|
||||
assertThat(outputDataDTO1).isNotEqualTo(outputDataDTO2);
|
||||
outputDataDTO2.setId(outputDataDTO1.getId());
|
||||
assertThat(outputDataDTO1).isEqualTo(outputDataDTO2);
|
||||
outputDataDTO2.setId(2L);
|
||||
assertThat(outputDataDTO1).isNotEqualTo(outputDataDTO2);
|
||||
outputDataDTO1.setId(null);
|
||||
assertThat(outputDataDTO1).isNotEqualTo(outputDataDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PeriodDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(PeriodDTO.class);
|
||||
PeriodDTO periodDTO1 = new PeriodDTO();
|
||||
periodDTO1.setId(1L);
|
||||
PeriodDTO periodDTO2 = new PeriodDTO();
|
||||
assertThat(periodDTO1).isNotEqualTo(periodDTO2);
|
||||
periodDTO2.setId(periodDTO1.getId());
|
||||
assertThat(periodDTO1).isEqualTo(periodDTO2);
|
||||
periodDTO2.setId(2L);
|
||||
assertThat(periodDTO1).isNotEqualTo(periodDTO2);
|
||||
periodDTO1.setId(null);
|
||||
assertThat(periodDTO1).isNotEqualTo(periodDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PeriodVersionDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(PeriodVersionDTO.class);
|
||||
PeriodVersionDTO periodVersionDTO1 = new PeriodVersionDTO();
|
||||
periodVersionDTO1.setId(1L);
|
||||
PeriodVersionDTO periodVersionDTO2 = new PeriodVersionDTO();
|
||||
assertThat(periodVersionDTO1).isNotEqualTo(periodVersionDTO2);
|
||||
periodVersionDTO2.setId(periodVersionDTO1.getId());
|
||||
assertThat(periodVersionDTO1).isEqualTo(periodVersionDTO2);
|
||||
periodVersionDTO2.setId(2L);
|
||||
assertThat(periodVersionDTO1).isNotEqualTo(periodVersionDTO2);
|
||||
periodVersionDTO1.setId(null);
|
||||
assertThat(periodVersionDTO1).isNotEqualTo(periodVersionDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UnitConverterDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(UnitConverterDTO.class);
|
||||
UnitConverterDTO unitConverterDTO1 = new UnitConverterDTO();
|
||||
unitConverterDTO1.setId(1L);
|
||||
UnitConverterDTO unitConverterDTO2 = new UnitConverterDTO();
|
||||
assertThat(unitConverterDTO1).isNotEqualTo(unitConverterDTO2);
|
||||
unitConverterDTO2.setId(unitConverterDTO1.getId());
|
||||
assertThat(unitConverterDTO1).isEqualTo(unitConverterDTO2);
|
||||
unitConverterDTO2.setId(2L);
|
||||
assertThat(unitConverterDTO1).isNotEqualTo(unitConverterDTO2);
|
||||
unitConverterDTO1.setId(null);
|
||||
assertThat(unitConverterDTO1).isNotEqualTo(unitConverterDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UnitDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(UnitDTO.class);
|
||||
UnitDTO unitDTO1 = new UnitDTO();
|
||||
unitDTO1.setId(1L);
|
||||
UnitDTO unitDTO2 = new UnitDTO();
|
||||
assertThat(unitDTO1).isNotEqualTo(unitDTO2);
|
||||
unitDTO2.setId(unitDTO1.getId());
|
||||
assertThat(unitDTO1).isEqualTo(unitDTO2);
|
||||
unitDTO2.setId(2L);
|
||||
assertThat(unitDTO1).isNotEqualTo(unitDTO2);
|
||||
unitDTO1.setId(null);
|
||||
assertThat(unitDTO1).isNotEqualTo(unitDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UnitTypeDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(UnitTypeDTO.class);
|
||||
UnitTypeDTO unitTypeDTO1 = new UnitTypeDTO();
|
||||
unitTypeDTO1.setId(1L);
|
||||
UnitTypeDTO unitTypeDTO2 = new UnitTypeDTO();
|
||||
assertThat(unitTypeDTO1).isNotEqualTo(unitTypeDTO2);
|
||||
unitTypeDTO2.setId(unitTypeDTO1.getId());
|
||||
assertThat(unitTypeDTO1).isEqualTo(unitTypeDTO2);
|
||||
unitTypeDTO2.setId(2L);
|
||||
assertThat(unitTypeDTO1).isNotEqualTo(unitTypeDTO2);
|
||||
unitTypeDTO1.setId(null);
|
||||
assertThat(unitTypeDTO1).isNotEqualTo(unitTypeDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableCategoryDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableCategoryDTO.class);
|
||||
VariableCategoryDTO variableCategoryDTO1 = new VariableCategoryDTO();
|
||||
variableCategoryDTO1.setId(1L);
|
||||
VariableCategoryDTO variableCategoryDTO2 = new VariableCategoryDTO();
|
||||
assertThat(variableCategoryDTO1).isNotEqualTo(variableCategoryDTO2);
|
||||
variableCategoryDTO2.setId(variableCategoryDTO1.getId());
|
||||
assertThat(variableCategoryDTO1).isEqualTo(variableCategoryDTO2);
|
||||
variableCategoryDTO2.setId(2L);
|
||||
assertThat(variableCategoryDTO1).isNotEqualTo(variableCategoryDTO2);
|
||||
variableCategoryDTO1.setId(null);
|
||||
assertThat(variableCategoryDTO1).isNotEqualTo(variableCategoryDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableClassDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableClassDTO.class);
|
||||
VariableClassDTO variableClassDTO1 = new VariableClassDTO();
|
||||
variableClassDTO1.setId(1L);
|
||||
VariableClassDTO variableClassDTO2 = new VariableClassDTO();
|
||||
assertThat(variableClassDTO1).isNotEqualTo(variableClassDTO2);
|
||||
variableClassDTO2.setId(variableClassDTO1.getId());
|
||||
assertThat(variableClassDTO1).isEqualTo(variableClassDTO2);
|
||||
variableClassDTO2.setId(2L);
|
||||
assertThat(variableClassDTO1).isNotEqualTo(variableClassDTO2);
|
||||
variableClassDTO1.setId(null);
|
||||
assertThat(variableClassDTO1).isNotEqualTo(variableClassDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableDTO.class);
|
||||
VariableDTO variableDTO1 = new VariableDTO();
|
||||
variableDTO1.setId(1L);
|
||||
VariableDTO variableDTO2 = new VariableDTO();
|
||||
assertThat(variableDTO1).isNotEqualTo(variableDTO2);
|
||||
variableDTO2.setId(variableDTO1.getId());
|
||||
assertThat(variableDTO1).isEqualTo(variableDTO2);
|
||||
variableDTO2.setId(2L);
|
||||
assertThat(variableDTO1).isNotEqualTo(variableDTO2);
|
||||
variableDTO1.setId(null);
|
||||
assertThat(variableDTO1).isNotEqualTo(variableDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableScopeDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableScopeDTO.class);
|
||||
VariableScopeDTO variableScopeDTO1 = new VariableScopeDTO();
|
||||
variableScopeDTO1.setId(1L);
|
||||
VariableScopeDTO variableScopeDTO2 = new VariableScopeDTO();
|
||||
assertThat(variableScopeDTO1).isNotEqualTo(variableScopeDTO2);
|
||||
variableScopeDTO2.setId(variableScopeDTO1.getId());
|
||||
assertThat(variableScopeDTO1).isEqualTo(variableScopeDTO2);
|
||||
variableScopeDTO2.setId(2L);
|
||||
assertThat(variableScopeDTO1).isNotEqualTo(variableScopeDTO2);
|
||||
variableScopeDTO1.setId(null);
|
||||
assertThat(variableScopeDTO1).isNotEqualTo(variableScopeDTO2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.oguerreiro.resilient.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.oguerreiro.resilient.web.rest.TestUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class VariableUnitsDTOTest {
|
||||
|
||||
@Test
|
||||
void dtoEqualsVerifier() throws Exception {
|
||||
TestUtil.equalsVerifier(VariableUnitsDTO.class);
|
||||
VariableUnitsDTO variableUnitsDTO1 = new VariableUnitsDTO();
|
||||
variableUnitsDTO1.setId(1L);
|
||||
VariableUnitsDTO variableUnitsDTO2 = new VariableUnitsDTO();
|
||||
assertThat(variableUnitsDTO1).isNotEqualTo(variableUnitsDTO2);
|
||||
variableUnitsDTO2.setId(variableUnitsDTO1.getId());
|
||||
assertThat(variableUnitsDTO1).isEqualTo(variableUnitsDTO2);
|
||||
variableUnitsDTO2.setId(2L);
|
||||
assertThat(variableUnitsDTO1).isNotEqualTo(variableUnitsDTO2);
|
||||
variableUnitsDTO1.setId(null);
|
||||
assertThat(variableUnitsDTO1).isNotEqualTo(variableUnitsDTO2);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue