Skip to content

Commit

Permalink
feat(junit5): mise a jour
Browse files Browse the repository at this point in the history
  • Loading branch information
opt-nc-dev committed Apr 27, 2021
1 parent f51b709 commit 7cb0895
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.1.0] - 28/04/2021
### Changed
- Migration test junit5


## [1.3.0] - 2018-03-15
### Changed
- Activation de l'autoconfiguration pour le bean LogMetierService
Expand Down
40 changes: 32 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
buildscript {
repositories {
<<<<<<< Updated upstream
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.owasp:dependency-check-gradle:2.0.1'
=======
mavenLocal()
maven { url "https://artifactory.intranet.opt/artifactory/gradle-virtual/" }
>>>>>>> Stashed changes
}
}


plugins {
id "org.sonarqube" version "2.5"
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'org.sonarqube'
apply plugin: 'org.owasp.dependencycheck'

sourceCompatibility = 1.8
targetCompatibility = 1.8

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

jar.baseName = projectName
Expand Down Expand Up @@ -53,9 +60,7 @@ sonarqube {

repositories {
mavenLocal()
mavenCentral()
maven { url 'https://artifactory.intranet.opt/artifactory/libs-snapshot/' }
maven { url 'https://artifactory.intranet.opt/artifactory/libs-release/' }
maven { url "https://artifactory.intranet.opt/artifactory/gradle-virtual/" }
}

configurations.all {
Expand All @@ -65,10 +70,20 @@ configurations.all {
}

dependencies {
compile 'net.logstash.logback:logstash-logback-encoder:5.3'
compile 'org.springframework.boot:spring-boot-starter:2.0.8.RELEASE'
compile 'org.openjdk.jol:jol-core:0.10'
testCompile 'org.springframework.boot:spring-boot-starter-test:2.0.8.RELEASE'
implementation 'net.logstash.logback:logstash-logback-encoder:6.6'
implementation 'org.springframework:spring-context:5.3.6'
implementation 'org.openjdk.jol:jol-core:0.15'
implementation 'ch.qos.logback:logback-classic:1.2.3'

testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'

testImplementation 'org.springframework.boot:spring-boot-starter-test:2.3.5.RELEASE'
}

test {
useJUnitPlatform()
}

task createPom {
Expand All @@ -91,3 +106,12 @@ task createPom {
}
}.writeTo("build/libs/${projectName}-${version}.pom")
}

publishing {
publications {
testing(MavenPublication) {
from components.java
artifact sourcesJar
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.0.2-SNAPSHOT
version=2.1.0
projectName=opt-logging
rootProject.name=opt-logging
group=nc.opt.core
Expand Down
47 changes: 22 additions & 25 deletions src/test/java/nc/opt/core/logging/LogMetierServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
Expand All @@ -20,11 +17,10 @@
import java.util.List;
import java.util.Map;

/**
* Created by 2816ARN on 15/12/2017.
*/
@SpringBootTest(classes = TestConfig.class)
@RunWith(SpringRunner.class)
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringBootTest(classes = LogMetierService.class)
public class LogMetierServiceTest {

@Autowired
Expand All @@ -35,30 +31,30 @@ public class LogMetierServiceTest {
private ByteArrayOutputStream myOut;

private void assertEqualsLog(String objectName, AbstractLogObject log, TestObject... objects) throws Exception {
Assert.assertNotNull(log);
Assert.assertNotNull(log.timestamp);
Assert.assertNotNull(log.version);
Assert.assertEquals("add log entry for " + objectName, log.message);
Assert.assertEquals(LogMetierService.LOGGER_NAME, log.loggerName);
Assert.assertNotNull(log.threadName);
Assert.assertEquals("INFO", log.level);
Assert.assertNotNull(log.levelValue);
assertNotNull(log);
assertNotNull(log.timestamp);
assertNotNull(log.version);
assertEquals("add log entry for " + objectName, log.message);
assertEquals(LogMetierService.LOGGER_NAME, log.loggerName);
assertNotNull(log.threadName);
assertEquals("INFO", log.level);
assertNotNull(log.levelValue);
if (objects != null) {
if (objects.length == 1) {
Assert.assertNotNull(((LogObject) log).test);
Assert.assertEquals(objects[0].name, ((LogObject) log).test.name);
assertNotNull(((LogObject) log).test);
assertEquals(objects[0].name, ((LogObject) log).test.name);
} else if (objects.length > 0) {
Assert.assertNotNull(((LogArray) log).test);
Assert.assertEquals(objects.length, ((LogArray) log).test.size());
assertNotNull(((LogArray) log).test);
assertEquals(objects.length, ((LogArray) log).test.size());
int i = 0;
for (TestObject o : objects) {
Assert.assertEquals(o.name, ((LogArray) log).test.get(i++).name);
assertEquals(o.name, ((LogArray) log).test.get(i++).name);
}
}
}
}

@Before
@BeforeEach
public void init() {
myOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(myOut));
Expand Down Expand Up @@ -99,7 +95,7 @@ public void testLogAttributes() throws Exception {
final String standardOutput = myOut.toString();
LogObject log = mapper.readValue(standardOutput, LogObject.class);
assertEqualsLog("class " + TestObject.class.getName(), log);
Assert.assertEquals("1", log.attributes.get("name"));
assertEquals("1", log.attributes.get("name"));
}

@Test
Expand Down Expand Up @@ -155,6 +151,7 @@ static abstract class AbstractLogObject {
private String level;
@JsonProperty("level_value")
private Integer levelValue;

public AbstractLogObject() {

}
Expand Down
15 changes: 0 additions & 15 deletions src/test/java/nc/opt/core/logging/TestConfig.java

This file was deleted.

0 comments on commit 7cb0895

Please sign in to comment.