diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..67cfe66
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -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
+
\ No newline at end of file
diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml
new file mode 100644
index 0000000..5becbb7
--- /dev/null
+++ b/.github/workflows/docker-build-push.yml
@@ -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
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..a9e105c
--- /dev/null
+++ b/Dockerfile
@@ -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"]
diff --git a/pom.xml b/pom.xml
index 5f091cc..1373149 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,25 @@
11
+
+
+
+ github-utils
+ GitHub Packages
+ https://maven.pkg.github.com/samagra-comms/utils
+
+
+ github-dao
+ GitHub Packages
+ https://maven.pkg.github.com/samagra-comms/dao
+
+
+ github-message-rosa
+ GitHub Packages
+ https://maven.pkg.github.com/samagra-comms/message-rosa
+
+
+
org.springframework.boot
@@ -90,7 +109,7 @@
com.uci
dao
- 1.0
+ 0.0.1
org.springframework.boot
@@ -103,12 +122,17 @@
com.uci
message-rosa
- 0.0.1-SNAPSHOT
+ 0.0.1
com.uci
utils
- 0.0.1-SNAPSHOT
+ 0.0.3
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 3.7.7
org.springframework.boot
@@ -129,7 +153,12 @@
org.springframework.data
spring-data-cassandra
-
+
+ io.projectreactor
+ reactor-test
+ test
+
+
diff --git a/settings.xml b/settings.xml
new file mode 100644
index 0000000..f1b88bf
--- /dev/null
+++ b/settings.xml
@@ -0,0 +1,32 @@
+
+
+
+ github
+ USERNAME
+ TOKEN
+
+
+ github-utils
+ USERNAME
+ TOKEN
+
+
+ github-message-rosa
+ USERNAME
+ TOKEN
+
+
+ github-dao
+ USERNAME
+ TOKEN
+
+
+ github-adapter
+ USERNAME
+ TOKEN
+
+
+
diff --git a/src/main/java/com/uci/orchestrator/Application/AppConfigOrchestrator.java b/src/main/java/com/uci/orchestrator/Application/AppConfigOrchestrator.java
index c461cdf..8c74d28 100644
--- a/src/main/java/com/uci/orchestrator/Application/AppConfigOrchestrator.java
+++ b/src/main/java/com/uci/orchestrator/Application/AppConfigOrchestrator.java
@@ -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 kafkaConsumerConfiguration() {
diff --git a/src/main/java/com/uci/orchestrator/Controllers/Health/ServiceStatusController.java b/src/main/java/com/uci/orchestrator/Controllers/Health/ServiceStatusController.java
index 5a54ebd..e140505 100644
--- a/src/main/java/com/uci/orchestrator/Controllers/Health/ServiceStatusController.java
+++ b/src/main/java/com/uci/orchestrator/Controllers/Health/ServiceStatusController.java
@@ -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;
diff --git a/src/test/java/com/uci/orchestrator/ApplicationConfiguration.java b/src/test/java/com/uci/orchestrator/ApplicationConfiguration.java
index d16990d..f82c7d7 100644
--- a/src/test/java/com/uci/orchestrator/ApplicationConfiguration.java
+++ b/src/test/java/com/uci/orchestrator/ApplicationConfiguration.java
@@ -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> 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 kafkaConsumerConfiguration() {
+ Map 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 kafkaProducerConfiguration() {
+ Map 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 kafkaReceiverOptions(@Value("inbound-processed") String[] inTopicName) {
+ ReceiverOptions 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 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> reactiveKafkaReceiver(@Autowired ReceiverOptions kafkaReceiverOptions) {
+ KafkaReceiver kafkaReceiver = KafkaReceiver.create(kafkaReceiverOptions);
+ Consumer consumer = new MockConsumer(OffsetResetStrategy.EARLIEST);
+ ConsumerRecord consumerRecord = new ConsumerRecord("inbound-processed", 0, 33, null,
+ "\n" +
+ "\n" +
+ " UCI Demo\n" +
+ " WhatsApp\n" +
+ " WhatsApp\n" +
+ " \n" +
+ " false\n" +
+ " false\n" +
+ " PHONE\n" +
+ " 7823807161\n" +
+ " \n" +
+ " \n" +
+ " ABEGkZlgQyWAAgo-sDVSUOa9jH0z\n" +
+ " \n" +
+ " REPLIED\n" +
+ " TEXT\n" +
+ " \n" +
+ " Hi UCI\n" +
+ " \n" +
+ " Netcore\n" +
+ " Netcore\n" +
+ " 1636621428000\n" +
+ " \n" +
+ " false\n" +
+ " false\n" +
+ " admin\n" +
+ " \n" +
+ ""
+ );
+
+ 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 commit() {
+ return null;
+ }
+ };
+ ReceiverRecord receiverRecord = new ReceiverRecord(consumerRecord, receiverOffset);
+// return KafkaReceiver.create(kafkaReceiverOptions).receive();
+ return Flux.just(receiverRecord);
}
-
+
+
+
+
@Bean
- public FusionAuthClient getFusionAuthClient() {
- return new FusionAuthClient(fusionAuthKey, fusionAuthUrl);
+ KafkaSender reactiveKafkaSender(SenderOptions kafkaSenderOptions) {
+ return KafkaSender.create(kafkaSenderOptions);
}
-
+
+ @Bean
+ ReactiveProducer kafkaReactiveProducer() {
+ return new ReactiveProducer();
+ }
+
@Bean
- public CampaignService campaignService() {
- return new CampaignService(getWebClient(), getFusionAuthClient());
- }
+ ProducerFactory producerFactory(){
+ ProducerFactory producerFactory = new DefaultKafkaProducerFactory<>(kafkaProducerConfiguration());
+ return producerFactory;
+ }
+
+ @Bean
+ KafkaTemplate kafkaTemplate() {
+ KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory());
+ return (KafkaTemplate) kafkaTemplate;
+ }
}
diff --git a/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest.java b/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest.java
index 809f41a..bd3636e 100644
--- a/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest.java
+++ b/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest.java
@@ -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 response = campaignConsumer.processMessage("d655cf03-1f6f-4510-acf6-d3f51b488a5e");
-
StepVerifier.create(response).verifyComplete();
}
}
diff --git a/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest2.java b/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest2.java
deleted file mode 100644
index 5db8231..0000000
--- a/src/test/java/com/uci/orchestrator/Consumer/CampaignConsumerTest2.java
+++ /dev/null
@@ -1,88 +0,0 @@
-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.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.TestPropertySource;
-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 messagerosa.core.model.XMessage;
-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(classes=ApplicationConfiguration.class)
-@TestPropertySource("classpath:test-application.properties")
-//@SpringBootTest()
-public class CampaignConsumerTest2 {
- private static Logger LOGGER = null;
-
- @Autowired
- public WebClient webClient;
-
- @Autowired
- public FusionAuthClient fusionAuthClient;
-
- @Autowired
- public CampaignService campaignService;
-
- @Mock
- public CampaignConsumer campaignConsumer;
-
-// public CampaignConsumer campaignConsumer;
-
-
-
-// @Before
- @SneakyThrows
- @BeforeEach
- public void init() throws JsonMappingException, JsonProcessingException {
- System.setProperty("log4j.configurationFile","log4j2-testconfig.xml");
- LOGGER = LogManager.getLogger();
-
- 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(anyString())).thenReturn(Mono.just(json));
-
- }
-
- @Test
- public void processMessageTest() throws Exception {
-// System.out.println("test");
- LOGGER.info("test");
-
- Mono response = campaignConsumer.processMessage("d655cf03-1f6f-4510-acf6-d3f51b488a5e");
-
- StepVerifier.create(response).verifyComplete();
- }
-}
diff --git a/src/test/java/com/uci/orchestrator/Consumer/ReactiveConsumerTest.java b/src/test/java/com/uci/orchestrator/Consumer/ReactiveConsumerTest.java
new file mode 100644
index 0000000..d3ef2de
--- /dev/null
+++ b/src/test/java/com/uci/orchestrator/Consumer/ReactiveConsumerTest.java
@@ -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();
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/uci/orchestrator/IntegrationTest.java b/src/test/java/com/uci/orchestrator/IntegrationTest.java
index 2ce929d..25d33a5 100644
--- a/src/test/java/com/uci/orchestrator/IntegrationTest.java
+++ b/src/test/java/com/uci/orchestrator/IntegrationTest.java
@@ -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());
}
diff --git a/src/test/java/com/uci/orchestrator/User/CampaignServiceTest.java b/src/test/java/com/uci/orchestrator/User/CampaignServiceTest.java
deleted file mode 100644
index 10e73c6..0000000
--- a/src/test/java/com/uci/orchestrator/User/CampaignServiceTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.uci.orchestrator.User;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.uci.utils.CampaignService;
-import io.fusionauth.domain.Application;
-import org.junit.Assert;
-import org.junit.jupiter.api.Test;
-
-import java.util.ArrayList;
-import java.util.function.Function;
-
-public class CampaignServiceTest {
-
- @Test
- public void testRetrieveApplicationData() throws Exception {
-// JsonNode application = new CampaignService().getCampaignFromID("897fb6ea-cb07-4891-b714-1e86784ef610").map(new Function() {
-// @Override
-// public Object apply(JsonNode jsonNode) {
-// return null;
-// }
-// });
-// ArrayList transformers = (ArrayList)application.data.get("transformers");
-// Assert.assertNotEquals("The strings didn't match for the expected and actual transformers", "Broadcast::SMS_1", transformers.get(0));
- }
-}
diff --git a/src/test/java/com/uci/orchestrator/User/TestConfig.java b/src/test/java/com/uci/orchestrator/User/TestConfig.java
deleted file mode 100644
index a7eab9c..0000000
--- a/src/test/java/com/uci/orchestrator/User/TestConfig.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.uci.orchestrator.User;
-
-import io.fusionauth.client.FusionAuthClient;
-import org.springframework.boot.test.context.TestConfiguration;
-import org.springframework.context.annotation.Bean;
-
-@TestConfiguration
-public class TestConfig {
- @Bean
- public FusionAuthClient client() {
- return new FusionAuthClient("c0VY85LRCYnsk64xrjdXNVFFJ3ziTJ91r08Cm0Pcjbc", "http://134.209.150.161:9011");
- }
-}
\ No newline at end of file
diff --git a/src/test/java/com/uci/orchestrator/User/UserServiceTest.java b/src/test/java/com/uci/orchestrator/User/UserServiceTest.java
deleted file mode 100644
index 258695b..0000000
--- a/src/test/java/com/uci/orchestrator/User/UserServiceTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.uci.orchestrator.User;
-
-import com.uci.orchestrator.Consumer.CampaignConsumer;
-import io.fusionauth.domain.User;
-import lombok.SneakyThrows;
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.*;
-class UserServiceTest {
- String email = "chakshu@samagragovernance.in";
-
-// @Test
-// public void testFindByEmail(){
-// User user = UserService.findByEmail(email);
-// assertEquals("4ee2ab81-6c3f-460b-94b2-de49cf55f27f", user.id.toString());
-// }
-//
-// @Test
-// public void testFindUsersForCampaign() throws Exception {
-// List user = UserService.findUsersForCampaign("Campaign 1");
-// assertNotEquals(2, user.size());
-// }
-//
-// @SneakyThrows
-// @Test
-// public void testCampaignAddition() throws Exception {
-// // CampaignConsumer.processMessage("897fb6ea-cb07-4891-b714-1e86784ef610");
-// }
-}
\ No newline at end of file
diff --git a/src/test/resources/log4j2-testconfig.xml b/src/test/resources/log4j2-testconfig.xml
deleted file mode 100644
index c95590c..0000000
--- a/src/test/resources/log4j2-testconfig.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file