bump deps, refactor, remove archived libs, transfer common lib legacy flow (#15)

This commit is contained in:
Anatoly Karlov 2022-05-19 17:16:23 +07:00 committed by GitHub
parent 090bba7c1a
commit 0a439817f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 362 additions and 89 deletions

View File

@ -7,4 +7,4 @@ on:
jobs:
build:
uses: valitydev/base-workflow/.github/workflows/maven-library-build.yml@v1
uses: valitydev/base-workflow/.github/workflows/maven-library-build.yml@v1

View File

@ -13,4 +13,4 @@ jobs:
server-username: ${{ secrets.OSSRH_USERNAME }}
server-password: ${{ secrets.OSSRH_TOKEN }}
deploy-secret-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
deploy-secret-key-password: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
deploy-secret-key-password: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

72
pom.xml
View File

@ -11,7 +11,7 @@
</parent>
<artifactId>adapter-bank-payout-spring-boot-starter</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>Adapter-bank-payout-spring-boot-starter</name>
@ -39,22 +39,15 @@
</scm>
<properties>
<adapter-client-lib.version>1.0.1</adapter-client-lib.version>
<adapter-thrift-lib.version>1.0.0</adapter-thrift-lib.version>
<adapter-common-lib.version>1.0.0</adapter-common-lib.version>
<damsel.version>1.544-dcd92dd</damsel.version>
<damsel.version>1.563-d384c12</damsel.version>
<cds-proto.version>1.66-01353ce</cds-proto.version>
<spring-boot.version>2.3.8.RELEASE</spring-boot.version>
<spring-boot.version>2.6.7</spring-boot.version>
<woody.version>1.0.4</woody.version>
<geck.version>0.0.1</geck.version>
<lombok.version>1.18.22</lombok.version>
<slf4j-api.version>1.7.30</slf4j-api.version>
<lombok.version>1.18.24</lombok.version>
<slf4j-api.version>1.7.36</slf4j-api.version>
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
<error-mapping-java.version>1.0.0</error-mapping-java.version>
<junit.version>4.12</junit.version>
<adapter-common-lib.version>1.1.1</adapter-common-lib.version>
</properties>
<dependencies>
@ -77,11 +70,6 @@
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<!--spring-->
<dependency>
@ -105,7 +93,22 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!--vality-->
@ -115,17 +118,6 @@
<version>${woody.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>adapter-common-lib</artifactId>
<version>${adapter-common-lib.version}</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>error-mapping-java</artifactId>
<version>${error-mapping-java.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.vality.geck</groupId>
<artifactId>serializer</artifactId>
@ -138,14 +130,28 @@
<version>${damsel.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>adapter-common-lib</artifactId>
<version>${adapter-common-lib.version}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,7 +1,7 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.config.properties;
package dev.vality.adapter.bank.payout.spring.boot.starter.config;
import dev.vality.adapter.common.mapper.SimpleErrorMapping;
import dev.vality.error.mapping.ErrorMapping;
import dev.vality.adapter.common.component.SimpleErrorMapping;
import dev.vality.adapter.common.mapper.ErrorMapping;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -9,9 +9,8 @@ import org.springframework.core.io.Resource;
import java.io.IOException;
@Configuration
public class ErrorMappingProperties {
public class ErrorMappingConfiguration {
@Value("${error-mapping.file}")
private Resource errorMappingFilePath;

View File

@ -0,0 +1,20 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.exception;
public class DeserializationException extends RuntimeException {
public DeserializationException() {
super();
}
public DeserializationException(String message) {
super(message);
}
public DeserializationException(Throwable cause) {
super(cause);
}
public DeserializationException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,19 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.exception;
public class SerializationException extends RuntimeException {
public SerializationException() {
super();
}
public SerializationException(String message) {
super(message);
}
public SerializationException(Throwable cause) {
super(cause);
}
public SerializationException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,11 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.exception;
import org.apache.thrift.TException;
public class UnsupportedMethodException extends TException {
public UnsupportedMethodException() {
super("Unsupported method");
}
}

View File

@ -1,7 +1,6 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.model;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import dev.vality.adapter.common.model.PollingInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

View File

@ -0,0 +1,21 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.time.Instant;
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PollingInfo {
@JsonProperty(value = "start_date_time_polling")
private Instant startDateTimePolling;
@JsonProperty(value = "max_date_time_polling")
private Instant maxDateTimePolling;
}

View File

@ -0,0 +1,5 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.service;
public interface BackOff {
BackOffExecution start();
}

View File

@ -0,0 +1,6 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.service;
@FunctionalInterface
public interface BackOffExecution {
Long nextBackOff();
}

View File

@ -0,0 +1,72 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.service;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class ExponentialBackOff implements BackOff {
public static final Integer DEFAULT_MULTIPLIER = 2;
public static final Integer DEFAULT_INITIAL_INTERVAL = 2;
public static final Integer DEFAULT_MAX_INTERVAL = 300;
private Integer multiplier = DEFAULT_MULTIPLIER;
private Integer initialInterval = DEFAULT_INITIAL_INTERVAL;
private Integer maxInterval = DEFAULT_MAX_INTERVAL;
private Long startTime;
private Long currentTime;
public ExponentialBackOff(
Long startTime,
Long currentTime,
Integer multiplier,
Integer initialInterval,
Integer maxInterval) {
this.startTime = startTime;
this.currentTime = currentTime;
this.multiplier = multiplier;
this.initialInterval = initialInterval;
this.maxInterval = maxInterval;
}
@Override
public BackOffExecution start() {
return new ExponentialBackOffExecution();
}
private class ExponentialBackOffExecution implements BackOffExecution {
@Override
public Long nextBackOff() {
if (ExponentialBackOff.this.currentTime.equals(ExponentialBackOff.this.startTime)) {
return Long.valueOf(ExponentialBackOff.this.initialInterval);
}
long nextBackOff = computeNextInterval(
ExponentialBackOff.this.multiplier,
ExponentialBackOff.this.startTime,
ExponentialBackOff.this.currentTime);
if (nextBackOff > ExponentialBackOff.this.maxInterval) {
nextBackOff = (long) ExponentialBackOff.this.maxInterval;
}
return nextBackOff;
}
private long computeNextInterval(int multiplier, Long startTime, Long currentTime) {
long diff = (currentTime - startTime) / 1000;
if (diff < 1 || multiplier == 1) {
return initialInterval;
}
long result = initialInterval;
int step = 0;
while (diff >= result) {
long pow = (long) Math.pow(multiplier, step++);
result = initialInterval * pow;
}
return result;
}
}
}

View File

@ -0,0 +1,41 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.service;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.PollingInfo;
import java.time.Instant;
import java.util.Map;
public class ExponentialBackOffPollingService<T extends PollingInfo> {
public BackOffExecution prepareBackOffExecution(T pollingInfo, Map<String, String> options) {
return exponentialBackOff(pollingInfo, options)
.start();
}
public int prepareNextPollingInterval(T pollingInfo, Map<String, String> options) {
return exponentialBackOff(pollingInfo, options)
.start()
.nextBackOff()
.intValue();
}
private ExponentialBackOff exponentialBackOff(T pollingInfo, Map<String, String> options) {
final Long currentLocalTime = Instant.now().toEpochMilli();
Long startTime = pollingInfo.getStartDateTimePolling() != null
? pollingInfo.getStartDateTimePolling().toEpochMilli()
: currentLocalTime;
Integer exponential = TimeOptionsExtractors.extractExponent(options, ExponentialBackOff.DEFAULT_MULTIPLIER);
Integer defaultInitialExponential = TimeOptionsExtractors.extractDefaultInitialExponential(options,
ExponentialBackOff.DEFAULT_INITIAL_INTERVAL);
Integer maxTimeBackOff =
TimeOptionsExtractors.extractMaxTimeBackOff(options, ExponentialBackOff.DEFAULT_MAX_INTERVAL);
return new ExponentialBackOff(
startTime,
currentLocalTime,
exponential,
defaultInitialExponential,
maxTimeBackOff);
}
}

View File

@ -3,21 +3,20 @@ package dev.vality.adapter.bank.payout.spring.boot.starter.service;
import dev.vality.adapter.bank.payout.spring.boot.starter.config.properties.TimerProperties;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.EntryStateModel;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.ExitStateModel;
import dev.vality.adapter.common.model.PollingInfo;
import dev.vality.adapter.common.utils.times.ExponentialBackOffPollingService;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.PollingInfo;
import dev.vality.adapter.common.damsel.WithdrawalsProviderAdapterPackageCreators;
import dev.vality.adapter.common.mapper.ErrorMapping;
import dev.vality.damsel.domain.TransactionInfo;
import dev.vality.damsel.withdrawals.provider_adapter.FinishIntent;
import dev.vality.damsel.withdrawals.provider_adapter.FinishStatus;
import dev.vality.damsel.withdrawals.provider_adapter.Intent;
import dev.vality.damsel.withdrawals.provider_adapter.Success;
import dev.vality.error.mapping.ErrorMapping;
import dev.vality.java.damsel.utils.creators.WithdrawalsProviderAdapterPackageCreators;
import lombok.RequiredArgsConstructor;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import static dev.vality.java.damsel.utils.extractors.OptionsExtractors.extractMaxTimePolling;
import static dev.vality.adapter.common.damsel.OptionsExtractors.extractMaxTimePolling;
@RequiredArgsConstructor
public class IntentServiceImpl implements IntentService {

View File

@ -2,6 +2,7 @@ package dev.vality.adapter.bank.payout.spring.boot.starter.service;
import dev.vality.adapter.bank.payout.spring.boot.starter.converter.ExitStateToProcessResultConverter;
import dev.vality.adapter.bank.payout.spring.boot.starter.converter.WithdrawalToEntryStateConverter;
import dev.vality.adapter.bank.payout.spring.boot.starter.exception.UnsupportedMethodException;
import dev.vality.adapter.bank.payout.spring.boot.starter.flow.StepResolver;
import dev.vality.adapter.bank.payout.spring.boot.starter.handler.CommonHandler;
import dev.vality.adapter.bank.payout.spring.boot.starter.handler.GetQuoteHandler;
@ -9,16 +10,8 @@ import dev.vality.adapter.bank.payout.spring.boot.starter.handler.HandleCallback
import dev.vality.adapter.bank.payout.spring.boot.starter.model.EntryStateModel;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.ExitStateModel;
import dev.vality.adapter.bank.payout.spring.boot.starter.validator.WithdrawalValidator;
import dev.vality.adapter.common.exception.UnsupportedMethodException;
import dev.vality.damsel.msgpack.Value;
import dev.vality.damsel.withdrawals.provider_adapter.AdapterSrv;
import dev.vality.damsel.withdrawals.provider_adapter.Callback;
import dev.vality.damsel.withdrawals.provider_adapter.CallbackResult;
import dev.vality.damsel.withdrawals.provider_adapter.GetQuoteFailure;
import dev.vality.damsel.withdrawals.provider_adapter.GetQuoteParams;
import dev.vality.damsel.withdrawals.provider_adapter.ProcessResult;
import dev.vality.damsel.withdrawals.provider_adapter.Quote;
import dev.vality.damsel.withdrawals.provider_adapter.Withdrawal;
import dev.vality.damsel.withdrawals.provider_adapter.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;

View File

@ -1,21 +1,14 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.service;
import dev.vality.damsel.msgpack.Value;
import dev.vality.damsel.withdrawals.provider_adapter.AdapterSrv;
import dev.vality.damsel.withdrawals.provider_adapter.Callback;
import dev.vality.damsel.withdrawals.provider_adapter.CallbackResult;
import dev.vality.damsel.withdrawals.provider_adapter.GetQuoteFailure;
import dev.vality.damsel.withdrawals.provider_adapter.GetQuoteParams;
import dev.vality.damsel.withdrawals.provider_adapter.ProcessResult;
import dev.vality.damsel.withdrawals.provider_adapter.Quote;
import dev.vality.damsel.withdrawals.provider_adapter.Withdrawal;
import dev.vality.damsel.withdrawals.provider_adapter.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;
import java.util.Map;
import static dev.vality.java.damsel.utils.verification.ProxyProviderVerification.isUndefinedResultOrUnavailable;
import static dev.vality.adapter.common.damsel.ProxyProviderVerification.isUndefinedResultOrUnavailable;
@Slf4j
@RequiredArgsConstructor

View File

@ -0,0 +1,28 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.service;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TimeOptionsExtractors {
private static final String TIMER_EXPONENTIAL = "exponential";
private static final String MAX_TIME_BACKOFF = "max_time_backoff";
private static final String DEFAULT_INITIAL_EXPONENTIAL = "default_initial_exponential";
public static Integer extractExponent(Map<String, String> options, int maxTimePolling) {
return Integer.parseInt(options.getOrDefault(TIMER_EXPONENTIAL, String.valueOf(maxTimePolling)));
}
public static Integer extractMaxTimeBackOff(Map<String, String> options, int maxTimeBackOff) {
return Integer.parseInt(options.getOrDefault(MAX_TIME_BACKOFF, String.valueOf(maxTimeBackOff)));
}
public static Integer extractDefaultInitialExponential(Map<String, String> options, int defaultInitialExponential) {
return Integer.parseInt(
options.getOrDefault(DEFAULT_INITIAL_EXPONENTIAL, String.valueOf(defaultInitialExponential)));
}
}

View File

@ -1,9 +1,8 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.state.deserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.vality.adapter.bank.payout.spring.boot.starter.exception.DeserializationException;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.AdapterState;
import dev.vality.adapter.common.state.deserializer.DeserializationException;
import dev.vality.adapter.common.state.deserializer.Deserializer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

View File

@ -0,0 +1,9 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.state.deserializer;
public interface Deserializer<T> {
T read(byte[] data);
T read(String data);
}

View File

@ -2,9 +2,9 @@ package dev.vality.adapter.bank.payout.spring.boot.starter.state.serializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.AdapterState;
import dev.vality.adapter.common.state.serializer.StateSerializer;
public class AdapterStateSerializer extends StateSerializer<AdapterState> {
public AdapterStateSerializer(ObjectMapper mapper) {
super(mapper);
}

View File

@ -0,0 +1,9 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.state.serializer;
public interface Serializer<T> {
byte[] writeByte(T obj);
String writeString(T obj);
}

View File

@ -0,0 +1,37 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.state.serializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.vality.adapter.bank.payout.spring.boot.starter.exception.SerializationException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.io.IOException;
import java.util.Base64;
@Getter
@Setter
@AllArgsConstructor
public abstract class StateSerializer<T> implements Serializer<T> {
private final ObjectMapper mapper;
@Override
public byte[] writeByte(Object obj) {
try {
return mapper.writeValueAsBytes(obj);
} catch (IOException e) {
throw new SerializationException(e);
}
}
@Override
public String writeString(Object obj) {
try {
return Base64.getEncoder().encodeToString(getMapper().writeValueAsBytes(obj));
} catch (IOException e) {
throw new SerializationException(e);
}
}
}

View File

@ -1,5 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
dev.vality.adapter.bank.payout.spring.boot.starter.config.properties.ErrorMappingProperties,\
dev.vality.adapter.bank.payout.spring.boot.starter.config.ErrorMappingConfiguration,\
dev.vality.adapter.bank.payout.spring.boot.starter.config.properties.AdapterProperties,\
dev.vality.adapter.bank.payout.spring.boot.starter.config.properties.TimerProperties

View File

@ -5,4 +5,4 @@ time.config:
---
error-mapping:
file: classpath:fixture/errors.json
patternReason: "'%s' - '%s'" # 'code' - 'description'
patternReason: "'%s' - '%s'" # 'code' - 'description'

View File

@ -1,28 +1,30 @@
package dev.vality.adapter.bank.payout.spring.boot.starter.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.vality.adapter.common.mapper.SimpleObjectMapper;
import dev.vality.adapter.common.model.PollingInfo;
import org.junit.Test;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.time.Instant;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public class AdapterStateTest {
@Test
public void testUnwrappedPollingInfo() throws IOException {
ObjectMapper om = new SimpleObjectMapper().createSimpleObjectMapperFactory();
AdapterState as = new AdapterState();
as.setStep(Step.CHECK);
PollingInfo pollingInfo = new PollingInfo();
pollingInfo.setMaxDateTimePolling(Instant.now());
as.setPollingInfo(pollingInfo);
String str = om.writeValueAsString(as);
ObjectMapper objectMapper = getObjectMapper();
String str = objectMapper.writeValueAsString(as);
assertTrue(str.startsWith("{\"step\":\"CHECK\",\"max_date_time_polling\":"));
AdapterState acRestored = om.readValue(str, AdapterState.class);
AdapterState acRestored = objectMapper.readValue(str, AdapterState.class);
assertEquals(as.getStep(), acRestored.getStep());
assertNotNull(acRestored.getPollingInfo());
assertEquals(as.getPollingInfo().getMaxDateTimePolling(), acRestored.getPollingInfo().getMaxDateTimePolling());
@ -30,7 +32,7 @@ public class AdapterStateTest {
@Test
public void testUnwrappedPollingInfoIsNull() throws IOException {
ObjectMapper om = new SimpleObjectMapper().createSimpleObjectMapperFactory();
ObjectMapper om = getObjectMapper();
AdapterState as = new AdapterState();
as.setStep(Step.CHECK);
as.setPollingInfo(null);
@ -41,4 +43,11 @@ public class AdapterStateTest {
assertNotNull(acRestored.getPollingInfo());
}
private ObjectMapper getObjectMapper() {
return new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new JavaTimeModule())
.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
}

View File

@ -5,12 +5,11 @@ import dev.vality.adapter.bank.payout.spring.boot.starter.config.properties.Time
import dev.vality.adapter.bank.payout.spring.boot.starter.model.AdapterState;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.EntryStateModel;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.ExitStateModel;
import dev.vality.adapter.common.mapper.SimpleObjectMapper;
import dev.vality.adapter.common.model.PollingInfo;
import dev.vality.adapter.bank.payout.spring.boot.starter.model.PollingInfo;
import dev.vality.adapter.common.mapper.ErrorMapping;
import dev.vality.damsel.withdrawals.provider_adapter.Intent;
import dev.vality.error.mapping.ErrorMapping;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileInputStream;
@ -20,7 +19,8 @@ import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class IntentServiceImplTest {
@ -29,7 +29,7 @@ public class IntentServiceImplTest {
private IntentServiceImpl intentService;
@Before
@BeforeEach
public void setUp() throws IOException {
intentService = new IntentServiceImpl(prepareErrorMapping(), prepareTimerProperties());
}
@ -61,21 +61,20 @@ public class IntentServiceImplTest {
assertTrue(intent.getFinish().getStatus().isSetFailure());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void getSleepException() {
ExitStateModel exitStateModel = new ExitStateModel();
AdapterState adapterState = new AdapterState();
adapterState.setPollingInfo(new PollingInfo());
exitStateModel.setNextState(adapterState);
intentService.getSleep(exitStateModel);
assertThrows(IllegalArgumentException.class, () -> intentService.getSleep(exitStateModel));
}
private ErrorMapping prepareErrorMapping() throws IOException {
ObjectMapper mapper = new SimpleObjectMapper().createSimpleObjectMapperFactory();
ObjectMapper mapper = new ObjectMapper();
File file = new File(ERROR_MAPPING_FILE_PATH);
InputStream is = new FileInputStream(file);
ErrorMapping errorMapping = new ErrorMapping(is, ERROR_MAPPING_PATTERN, mapper);
errorMapping.validateMapping();
return errorMapping;
}
@ -85,5 +84,4 @@ public class IntentServiceImplTest {
timerProperties.setPollingDelay(10);
return timerProperties;
}
}