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
Show file tree
Hide file tree
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
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
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
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading