Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing #24

Open
wants to merge 9 commits into
base: unit-tests
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build on Push & Pull Request
on: [push, pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: maven-settings-xml-action
uses: whelk-io/maven-settings-xml-action@v20
with:
servers: >
[
{
"id": "github-message-rosa",
"username": "${env.GITHUB_USERNAME}",
"password": "${env.GITHUB_TOKEN}"
},
{
"id": "github-adapter",
"username": "${env.GITHUB_USERNAME}",
"password": "${env.GITHUB_TOKEN}"
},
{
"id": "github-utils",
"username": "${env.GITHUB_USERNAME}",
"password": "${env.GITHUB_TOKEN}"
},
{
"id": "github-dao",
"username": "${env.GITHUB_USERNAME}",
"password": "${env.GITHUB_TOKEN}"
}
]
output_file: $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_USERNAME: ${{ secrets.USERNAME }}
GITHUB_TOKEN: ${{ secrets.TOKEN }}

- name: Build and analyze
env:
GITHUB_USERNAME: ${{ secrets.USERNAME }}
GITHUB_TOKEN: ${{ secrets.TOKEN }}
run: mvn -s $GITHUB_WORKSPACE/settings.xml clean install -DskipTests

29 changes: 29 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Docker Build & Push on Tag

on:
push:
tags:
- 'v*.*.*'

jobs:
docker-build-push:
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- uses: actions/checkout@v1
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Build the tagged Docker image
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}
docker build . --file Dockerfile --build-arg username=${{ secrets.USERNAME }} --build-arg token=${{ secrets.TOKEN }} --tag samagragovernance/orchestrator:$RELEASE_VERSION
- name: Push the tagged Docker image
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: docker push samagragovernance/orchestrator:$RELEASE_VERSION
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Build stage
FROM maven:3.6.0-jdk-11-slim AS build
ENV HOME=/home/app
RUN mkdir -p $HOME
WORKDIR $HOME
ADD pom.xml $HOME

# Arguments
ARG username
ARG token

# Print arguments value
RUN echo $username
RUN echo $token

# copy settings file to home settings file
COPY /settings.xml $HOME/settings.xml

# replace username & token in settings file
RUN sed -i "s/USERNAME/$username/g" $HOME/settings.xml
RUN sed -i "s/TOKEN/$token/g" $HOME/settings.xml
RUN cat $HOME/settings.xml

# Maven package build
RUN mvn -s $HOME/settings.xml dependency:go-offline

ADD /src $HOME/src
RUN mvn package -s $HOME/settings.xml -DskipTests=true

# Package stage
FROM openjdk:12-alpine
ENV HOME=/home/app
ENV export $(cat .env | xargs)
WORKDIR $HOME
COPY --from=build $HOME/target/*.jar app.jar

EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
37 changes: 33 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -19,6 +19,25 @@
<java.version>11</java.version>
</properties>

<!-- For Downloading repositories from github packages -->
<repositories>
<repository>
<id>github-utils</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/samagra-comms/utils</url>
</repository>
<repository>
<id>github-dao</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/samagra-comms/dao</url>
</repository>
<repository>
<id>github-message-rosa</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/samagra-comms/message-rosa</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -90,7 +109,7 @@
<dependency>
<groupId>com.uci</groupId>
<artifactId>dao</artifactId>
<version>1.0</version>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -103,12 +122,17 @@
<dependency>
<groupId>com.uci</groupId>
<artifactId>message-rosa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.uci</groupId>
<artifactId>utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.3</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.7.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -129,7 +153,12 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
32 changes: 32 additions & 0 deletions settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
<server>
<id>github-utils</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
<server>
<id>github-message-rosa</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
<server>
<id>github-dao</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
<server>
<id>github-adapter</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
</servers>
</settings>
Original file line number Diff line number Diff line change
@@ -70,12 +70,12 @@ public CampaignService getCampaignService() {
return new CampaignService(webClient, fusionAuthClient, cache);
}

@Bean
public KieSession DroolSession() {
Resource resource = ResourceFactory.newClassPathResource("OrchestratorRules.xlsx", getClass());
KieSession kSession = new DroolsBeanFactory().getKieSession(resource);
return kSession;
}
// @Bean
// public KieSession DroolSession() {
// Resource resource = ResourceFactory.newClassPathResource("OrchestratorRules.xlsx", getClass());
// KieSession kSession = new DroolsBeanFactory().getKieSession(resource);
// return kSession;
// }

@Bean
Map<String, Object> kafkaConsumerConfiguration() {
Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@

import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
287 changes: 248 additions & 39 deletions src/test/java/com/uci/orchestrator/ApplicationConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,269 @@
package com.uci.orchestrator;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.benmanes.caffeine.cache.Cache;
import com.google.common.util.concurrent.ListenableFuture;
import com.uci.dao.repository.XMessageRepository;
import com.uci.orchestrator.Consumer.ReactiveConsumer;
import com.uci.utils.BotService;
import com.uci.utils.CampaignService;
import com.uci.utils.cache.service.RedisCacheService;
import com.uci.utils.kafka.ReactiveProducer;
import com.uci.utils.kafka.SimpleProducer;
import com.uci.utils.service.UserService;
import io.fusionauth.client.FusionAuthClient;
import org.apache.kafka.clients.consumer.*;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.TopicPartition;
import org.json.JSONArray;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.test.context.TestPropertySource;
import org.springframework.kafka.support.SendResult;
import org.springframework.kafka.support.serializer.JsonDeserializer;
import org.springframework.web.reactive.function.client.WebClient;

import com.uci.utils.CampaignService;
import com.uci.utils.kafka.ReactiveProducer;
import com.uci.utils.kafka.SimpleProducer;

import io.fusionauth.client.FusionAuthClient;
import reactor.core.CoreSubscriber;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.kafka.receiver.KafkaReceiver;
import reactor.kafka.receiver.ReceiverOffset;
import reactor.kafka.receiver.ReceiverOptions;
import reactor.kafka.receiver.ReceiverRecord;
import reactor.kafka.sender.KafkaSender;
import reactor.kafka.sender.SenderOptions;

@Configuration
@ConfigurationProperties
@TestPropertySource("classpath:test-application.properties")
import java.time.LocalTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

//@Configuration
//@ConfigurationProperties
//@TestPropertySource("classpath:test-application.properties")
public class ApplicationConfiguration{
@Value("${campaign.url}")
public String CAMPAIGN_URL;

@Value("${campaign.admin.token}")
private String CAMPAIGN_ADMIN_TOKEN;

@Value("${fusionauth.url}")
private String fusionAuthUrl;
// @Value("${campaign.url}")
// public String CAMPAIGN_URL;
//
// @Value("${campaign.admin.token}")
// private String CAMPAIGN_ADMIN_TOKEN;
//
// @Value("${fusionauth.url}")
// private String fusionAuthUrl;
//
// @Value("${fusionauth.key}")
// private String fusionAuthKey;
//
// @Value("${spring.kafka.bootstrap-servers}")
// private String BOOTSTRAP_SERVERS;

@Autowired
Flux<ReceiverRecord<String, String>> reactiveKafkaReceiver;

@MockBean
XMessageRepository xMessageRepository;

@Autowired
public SimpleProducer kafkaProducer;

@Autowired
public ReactiveProducer reactiveProducer;

@MockBean
public BotService botService;

@MockBean
public CampaignService campaignService;

@MockBean
public UserService userService;

@MockBean
public RedisCacheService redisCacheService;

@Bean
public UserService getUserService(){
return new UserService();
}

@Bean
public RedisCacheService getRedisCacheService(){
return new RedisCacheService(new RedisTemplate<>());
}

@Bean
public Cache getCache(){
return Mockito.mock(Cache.class);
}

@Bean
public SimpleProducer getSimpleProducer(){
return new SimpleProducer(kafkaTemplate());
}

@Bean
public BotService getBotService(){
WebClient webClient = WebClient.builder()
.baseUrl("CAMPAIGN_URL")
.defaultHeader("admin-token", "CAMPAIGN_ADMIN_TOKEN")
.build();
return new BotService(webClient, getFAClient(), getCache());
}

@Bean
public FusionAuthClient getFAClient() {
return new FusionAuthClient("FUSIONAUTH_KEY", "FUSIONAUTH_URL");
}

@Bean
public CampaignService getCampaignService() {
WebClient webClient = WebClient.builder()
.baseUrl("CAMPAIGN_URL")
.defaultHeader("admin-token", "CAMPAIGN_ADMIN_TOKEN")
.build();
return new CampaignService(webClient, getFAClient(), getCache());
}

@Bean
public ReactiveConsumer getReactiveConsumer() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
Mockito.when(botService.getCurrentAdapter("UCI Demo")).thenReturn(Mono.just("44a9df72-3d7a-4ece-94c5-98cf26307324"));
JsonNode campaignNode = objectMapper.readTree("{\"id\":\"d655cf03-1f6f-4510-acf6-d3f51b488a5e\",\"name\":\"UCI Demo\",\"startingMessage\":\"Hi UCI\",\"users\":[],\"logicIDs\":[\"e96b0865-5a76-4566-8694-c09361b8ae32\"],\"owners\":null,\"created_at\":\"2021-07-08T18:48:37.740Z\",\"updated_at\":\"2022-02-11T14:09:53.570Z\",\"status\":\"enabled\",\"description\":\"For Internal Demo\",\"startDate\":\"2022-02-01T00:00:00.000Z\",\"endDate\":null,\"purpose\":\"For Internal Demo\",\"ownerOrgID\":\"ORG_001\",\"ownerID\":\"95e4942d-cbe8-477d-aebd-ad8e6de4bfc8\",\"userSegments\":[],\"logic\":[{\"id\":\"e96b0865-5a76-4566-8694-c09361b8ae32\",\"transformers\":[{\"id\":\"bbf56981-b8c9-40e9-8067-468c2c753659\",\"meta\":{\"form\":\"https://hosted.my.form.here.com\",\"formID\":\"UCI-demo-1\"}}],\"adapter\":{\"id\":\"44a9df72-3d7a-4ece-94c5-98cf26307324\",\"channel\":\"WhatsApp\",\"provider\":\"gupshup\",\"config\":{\"2WAY\":\"2000193033\",\"phone\":\"9876543210\",\"HSM_ID\":\"2000193031\",\"credentials\":{\"vault\":\"samagra\",\"variable\":\"gupshupSamagraProd\"}},\"name\":\"SamagraProd\",\"updated_at\":\"2021-06-16T06:02:39.125Z\",\"created_at\":\"2021-06-16T06:02:41.823Z\"},\"name\":\"UCI Demo\",\"created_at\":\"2021-07-08T18:47:44.925Z\",\"updated_at\":\"2022-02-03T12:29:32.959Z\",\"description\":null}]}");
Mockito.when(campaignService.getCampaignFromNameTransformer("UCI Demo")).thenReturn(Mono.just(campaignNode));
userService.CAMPAIGN_URL = "http://localhost";
Mockito.when(userService.getUsersFromFederatedServers(Mockito.anyString())).thenReturn(new JSONArray());
Mockito.when(redisCacheService.getFAUserIDForAppCache("yOJcM+Gm7yVkKeQqPhdDKNb0wsmh8St/ty+pM5Q+4W4=" + "-" + "d655cf03-1f6f-4510-acf6-d3f51b488a5e")).thenReturn("91311fd1-5c1c-4f81-b9eb-2d259159554a");
Mockito.when(xMessageRepository.findAllByUserIdAndTimestampAfter(Mockito.any(), Mockito.any())).thenReturn(Flux.just());
return new ReactiveConsumer(reactiveKafkaReceiver);
}

@Bean
Map<String, Object> kafkaConsumerConfiguration() {
Map<String, Object> configuration = new HashMap<>();
configuration.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "165.232.182.146:9094");
configuration.put(ConsumerConfig.GROUP_ID_CONFIG, "sample-producer");
configuration.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, org.springframework.kafka.support.serializer.JsonSerializer.class);
configuration.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, org.springframework.kafka.support.serializer.JsonSerializer.class);
configuration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
configuration.put(ProducerConfig.ACKS_CONFIG, "all");
return configuration;
}

@Bean
Map<String, Object> kafkaProducerConfiguration() {
Map<String, Object> configuration = new HashMap<>();
configuration.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "165.232.182.146:9094");
configuration.put(ProducerConfig.CLIENT_ID_CONFIG, "sample-producer");
configuration.put(ProducerConfig.ACKS_CONFIG, "all");
configuration.put(org.springframework.kafka.support.serializer.JsonSerializer.ADD_TYPE_INFO_HEADERS, false);
configuration.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, org.springframework.kafka.support.serializer.JsonSerializer.class);
configuration.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, org.springframework.kafka.support.serializer.JsonSerializer.class);
return configuration;
}

@Bean
ReceiverOptions<String, String> kafkaReceiverOptions(@Value("inbound-processed") String[] inTopicName) {
ReceiverOptions<String, String> options = ReceiverOptions.create(kafkaConsumerConfiguration());
return options.subscription(Arrays.asList(inTopicName))
.withKeyDeserializer(new JsonDeserializer<>())
.withValueDeserializer(new JsonDeserializer(String.class));
}

@Value("${fusionauth.key}")
private String fusionAuthKey;
@Bean
SenderOptions<Integer, String> kafkaSenderOptions() {
return SenderOptions.create(kafkaProducerConfiguration());
}

@Value("${spring.kafka.bootstrap-servers}")
private String BOOTSTRAP_SERVERS;

@Bean
public WebClient getWebClient() {
return WebClient.builder().baseUrl(CAMPAIGN_URL).defaultHeader("admin-token", CAMPAIGN_ADMIN_TOKEN).build();
Flux<ReceiverRecord<String, String>> reactiveKafkaReceiver(@Autowired ReceiverOptions<String, String> kafkaReceiverOptions) {
KafkaReceiver<String, String> kafkaReceiver = KafkaReceiver.create(kafkaReceiverOptions);
Consumer consumer = new MockConsumer<String, String>(OffsetResetStrategy.EARLIEST);
ConsumerRecord<String, String> consumerRecord = new ConsumerRecord<String, String >("inbound-processed", 0, 33, null,
"<?xml version=\"1.0\"?>\n" +
"<xMessage>\n" +
" <app>UCI Demo</app>\n" +
" <channel>WhatsApp</channel>\n" +
" <channelURI>WhatsApp</channelURI>\n" +
" <from>\n" +
" <bot>false</bot>\n" +
" <broadcast>false</broadcast>\n" +
" <deviceType>PHONE</deviceType>\n" +
" <userID>7823807161</userID>\n" +
" </from>\n" +
" <messageId>\n" +
" <channelMessageId>ABEGkZlgQyWAAgo-sDVSUOa9jH0z</channelMessageId>\n" +
" </messageId>\n" +
" <messageState>REPLIED</messageState>\n" +
" <messageType>TEXT</messageType>\n" +
" <payload>\n" +
" <text>Hi UCI</text>\n" +
" </payload>\n" +
" <provider>Netcore</provider>\n" +
" <providerURI>Netcore</providerURI>\n" +
" <timestamp>1636621428000</timestamp>\n" +
" <to>\n" +
" <bot>false</bot>\n" +
" <broadcast>false</broadcast>\n" +
" <userID>admin</userID>\n" +
" </to>\n" +
"</xMessage>"
);

ReceiverOffset receiverOffset = new ReceiverOffset() {
@Override
public TopicPartition topicPartition() {
return new TopicPartition("inbound-processed", 0);
}

@Override
public long offset() {
return 0;
}

@Override
public void acknowledge() {

}

@Override
public Mono<Void> commit() {
return null;
}
};
ReceiverRecord<String, String> receiverRecord = new ReceiverRecord<String, String >(consumerRecord, receiverOffset);
// return KafkaReceiver.create(kafkaReceiverOptions).receive();
return Flux.just(receiverRecord);
}





@Bean
public FusionAuthClient getFusionAuthClient() {
return new FusionAuthClient(fusionAuthKey, fusionAuthUrl);
KafkaSender<Integer, String> reactiveKafkaSender(SenderOptions<Integer, String> kafkaSenderOptions) {
return KafkaSender.create(kafkaSenderOptions);
}


@Bean
ReactiveProducer kafkaReactiveProducer() {
return new ReactiveProducer();
}

@Bean
public CampaignService campaignService() {
return new CampaignService(getWebClient(), getFusionAuthClient());
}
ProducerFactory<String, String> producerFactory(){
ProducerFactory<String, String> producerFactory = new DefaultKafkaProducerFactory<>(kafkaProducerConfiguration());
return producerFactory;
}

@Bean
KafkaTemplate<String, String> kafkaTemplate() {
KafkaTemplate<String, String> kafkaTemplate = new KafkaTemplate<>(producerFactory());
return (KafkaTemplate<String, String>) kafkaTemplate;
}
}
125 changes: 50 additions & 75 deletions src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest.java
Original file line number Diff line number Diff line change
@@ -1,94 +1,69 @@
package com.uci.orchestrator.Consumer;

import static org.mockito.Mockito.when;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.reactive.function.client.WebClient;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.uci.orchestrator.ApplicationConfiguration;
import com.uci.utils.CampaignService;

import io.fusionauth.client.FusionAuthClient;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import com.uci.utils.kafka.SimpleProducer;
import messagerosa.core.model.XMessage;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;

@ExtendWith(MockitoExtension.class)
@RunWith(SpringRunner.class)
@Slf4j
//@SpringBootTest()
//@ExtendWith(MockitoExtension.class)
//@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApplicationConfiguration.class)
public class CampaignConsumerTest {
private static Logger LOGGER = null;

@Mock
public WebClient webClient;

@Mock
public FusionAuthClient fusionAuthClient;



@Autowired
SimpleProducer kafkaProducer;

@Autowired
public CampaignService campaignService;


@Autowired
public CampaignConsumer campaignConsumer;

// public CampaignConsumer campaignConsumer;



// @Before
@SneakyThrows
@BeforeEach
public void init() throws JsonMappingException, JsonProcessingException {
// System.out.println("setupp");

System.setProperty("log4j.configurationFile","log4j2-testconfig.xml");
LOGGER = LogManager.getLogger();

//
WebClient client = Mockito.mock(WebClient.class);

System.out.println(client);

System.out.println(client.get());

campaignService = new CampaignService(client, fusionAuthClient);

CampaignConsumer campaignConsumer = new CampaignConsumer();

ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("{\"id\":\"api.bot.getByParam\",\"ver\":\"1.0\",\"ts\":\"2021-09-07T09:13:15.692Z\",\"params\":{\"resmsgid\":\"d5809ec0-0fbb-11ec-8e04-21de24b1fc83\",\"msgid\":\"d57f6640-0fbb-11ec-8e04-21de24b1fc83\",\"status\":\"successful\",\"err\":null,\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"data\":{\"id\":\"d655cf03-1f6f-4510-acf6-d3f51b488a5e\",\"name\":\"UCI Demo\",\"startingMessage\":\"Hi UCI\",\"users\":[],\"logicIDs\":[\"e96b0865-5a76-4566-8694-c09361b8ae32\"],\"owners\":null,\"created_at\":\"2021-07-08T18:48:37.740Z\",\"updated_at\":\"2021-07-14T16:59:09.088Z\",\"status\":\"Draft\",\"description\":\"For Internal Demo\",\"startDate\":\"2021-07-07T18:30:00.000Z\",\"endDate\":\"2021-07-22T18:30:00.000Z\",\"purpose\":\"For Internal Demo\",\"ownerOrgID\":null,\"ownerID\":null,\"logic\":[{\"id\":\"e96b0865-5a76-4566-8694-c09361b8ae32\",\"transformers\":[{\"id\":\"bbf56981-b8c9-40e9-8067-468c2c753659\",\"meta\":{\"form\":\"https://hosted.my.form.here.com\",\"formID\":\"UCI-demo-4\"}}],\"adapter\":\"44a9df72-3d7a-4ece-94c5-98cf26307324\",\"name\":\"UCI Demo\",\"created_at\":\"2021-07-08T18:47:44.925Z\",\"updated_at\":\"2021-07-08T18:47:44.925Z\",\"description\":null,\"ownerOrgID\":null,\"ownerID\":null}]}}}");

// Mockito.when(campaignService.getCampaignFromID("d655cf03-1f6f-4510-acf6-d3f51b488a5e")).thenReturn(Mono.just(json));


//// @Before
// @SneakyThrows
// @BeforeAll
// public static void init() throws JsonMappingException, JsonProcessingException {
//// System.out.println("setupp");
//
// System.setProperty("log4j.configurationFile","log4j2-testconfig.xml");
// LOGGER = LogManager.getLogger();
//
////
//// WebClient client = Mockito.mock(WebClient.class);
////
//// System.out.println(client);
////
//// System.out.println(client.get());
////
//// campaignService = new CampaignService(client, fusionAuthClient,null);
////
//// CampaignConsumer campaignConsumer = new CampaignConsumer();
//
//
//// Mockito.when(campaignService.getCampaignFromID("d655cf03-1f6f-4510-acf6-d3f51b488a5e")).thenReturn(Mono.just(json));
//
// }

@Test
void consumeMessage() {
}

@Test
public void processMessageTest() throws Exception {
// System.out.println("test");
LOGGER.info("test");
void processMessage() throws Exception {
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("{\"id\":\"api.bot.getByParam\",\"ver\":\"1.0\",\"ts\":\"2021-09-07T09:13:15.692Z\",\"params\":{\"resmsgid\":\"d5809ec0-0fbb-11ec-8e04-21de24b1fc83\",\"msgid\":\"d57f6640-0fbb-11ec-8e04-21de24b1fc83\",\"status\":\"successful\",\"err\":null,\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"data\":{\"id\":\"d655cf03-1f6f-4510-acf6-d3f51b488a5e\",\"name\":\"UCI Demo\",\"startingMessage\":\"Hi UCI\",\"users\":[],\"logicIDs\":[\"e96b0865-5a76-4566-8694-c09361b8ae32\"],\"owners\":null,\"created_at\":\"2021-07-08T18:48:37.740Z\",\"updated_at\":\"2021-07-14T16:59:09.088Z\",\"status\":\"Draft\",\"description\":\"For Internal Demo\",\"startDate\":\"2021-07-07T18:30:00.000Z\",\"endDate\":\"2021-07-22T18:30:00.000Z\",\"purpose\":\"For Internal Demo\",\"ownerOrgID\":null,\"ownerID\":null,\"logic\":[{\"id\":\"e96b0865-5a76-4566-8694-c09361b8ae32\",\"transformers\":[{\"id\":\"bbf56981-b8c9-40e9-8067-468c2c753659\",\"meta\":{\"form\":\"https://hosted.my.form.here.com\",\"formID\":\"UCI-demo-4\"}}],\"adapter\":\"44a9df72-3d7a-4ece-94c5-98cf26307324\",\"name\":\"UCI Demo\",\"created_at\":\"2021-07-08T18:47:44.925Z\",\"updated_at\":\"2021-07-08T18:47:44.925Z\",\"description\":null,\"ownerOrgID\":null,\"ownerID\":null}]}}}");

Mono<XMessage> response = campaignConsumer.processMessage("d655cf03-1f6f-4510-acf6-d3f51b488a5e");

StepVerifier.create(response).verifyComplete();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.uci.orchestrator.Consumer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.uci.orchestrator.ApplicationConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


@Slf4j
@SpringBootTest(classes = ApplicationConfiguration.class)
@ExtendWith(MockitoExtension.class)
class ReactiveConsumerTest {

@Autowired
ReactiveConsumer reactiveConsumer;

@Test
void onMessage() throws JsonProcessingException {
reactiveConsumer.onMessage();
}
}
34 changes: 17 additions & 17 deletions src/test/java/com/uci/orchestrator/IntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.uci.orchestrator;

import com.uci.orchestrator.Drools.DroolsBeanFactory;
//import com.uci.orchestrator.Drools.DroolsBeanFactory;
import messagerosa.core.model.XMessage;
import org.junit.Before;
//import org.junit.Before;
import org.junit.Test;
import org.kie.api.io.Resource;
import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory;
//import org.kie.api.io.Resource;
//import org.kie.api.runtime.KieSession;
//import org.kie.internal.io.ResourceFactory;

public class IntegrationTest {
private KieSession kSession;

@Before
public void setup() {
Resource resource = ResourceFactory.newClassPathResource("OrchestratorRules.xlsx", getClass());
kSession = new DroolsBeanFactory().getKieSession(resource);
System.out.println(new DroolsBeanFactory().getDrlFromExcel("OrchestratorRules.xlsx"));
}
// private KieSession kSession;
//
// @Before
// public void setup() {
// Resource resource = ResourceFactory.newClassPathResource("OrchestratorRules.xlsx", getClass());
// kSession = new DroolsBeanFactory().getKieSession(resource);
// System.out.println(new DroolsBeanFactory().getDrlFromExcel("OrchestratorRules.xlsx"));
// }

@Test
public void testChangeInChannel() throws Exception {
@@ -26,8 +26,8 @@ public void testChangeInChannel() throws Exception {
xMessage.setApp("ResumeBuilder");
xMessage.setTimestamp((long) 1592900000);
System.out.println(xMessage.secondsSinceLastMessage());
kSession.insert(xMessage);
kSession.fireAllRules();
// kSession.insert(xMessage);
// kSession.fireAllRules();
System.out.println(xMessage.getTransformers());
System.out.println(xMessage.toXML());
}
@@ -38,8 +38,8 @@ public void testForTransformer() throws Exception {
xMessage.setMessageState(XMessage.MessageState.REPLIED);
xMessage.setApp("Test");
System.out.println(xMessage.secondsSinceLastMessage());
kSession.insert(xMessage);
kSession.fireAllRules();
// kSession.insert(xMessage);
// kSession.fireAllRules();
System.out.println(xMessage.getTransformers());
System.out.println(xMessage.toXML());
}
25 changes: 0 additions & 25 deletions src/test/java/com/uci/orchestrator/User/CampaignServiceTest.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/java/com/uci/orchestrator/User/TestConfig.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/test/java/com/uci/orchestrator/User/UserServiceTest.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/test/resources/log4j2-testconfig.xml

This file was deleted.