Skip to content

Commit

Permalink
Differentiate unit, integration and e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flawmop committed Aug 18, 2024
1 parent 36b1267 commit 383b975
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 7 deletions.
57 changes: 57 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'jvm-test-suite'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'

Expand All @@ -23,6 +24,9 @@ ext {
}

configurations {
//testE2EImplementation.extendsFrom(testImplementation)
//testE2ERuntimeOnly.extendsFrom(testRuntimeOnly)

runtimeOnly {
// Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
exclude group: 'commons-logging', module: 'commons-logging'
Expand All @@ -44,6 +48,59 @@ dependencyManagement {
}
}

testing {
suites {
configureEach {
useJUnitJupiter()
dependencies {
implementation project()
implementation 'org.springframework.boot:spring-boot-starter-test'
}
}

i(JvmTestSuite) {
sources {
java {
srcDirs = ['src/test-i/java']
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
}

e2e(JvmTestSuite) {
sources {
java {
srcDirs = ['src/test-e2e/java']
}
}
}
}
}

tasks.named('check') {
dependsOn(test)
dependsOn(testing.suites.i)
dependsOn(testing.suites.e2e)
}

//sourceSets {
// testE2E {
// java {
// compileClasspath += main.output + test.output
// runtimeClasspath += main.output + test.output
// }
// }
//}

//task testE2E(type: Test) {
// description = "Run end-2-end tests"
// group = "verification"
// testClassesDirs = sourceSets.testE2E.output.classesDirs
// classpath = sourceSets.testE2E.runtimeClasspath
//}

// On deploy error of ....
// The current machine does not support all of the following CPU features that are required by the image: [CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, LZCNT, AVX, AVX2, BMI1, BMI2, FMA].
// Please rebuild the executable with an appropriate setting of the -march option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.RequestPart ;
import org.springframework.web.multipart.MultipartFile;

import com.insilicosoft.portal.svc.rip.FileProcessingException ;
import com.insilicosoft.portal.svc.rip.exception.FileProcessingException;
import com.insilicosoft.portal.svc.rip.service.InputProcessorService;

/**
Expand Down Expand Up @@ -42,8 +42,8 @@ public FileAsyncUploadController(InputProcessorService inputProcessorService) {

// TODO Remove GET mapping in /run endpoint controller
@GetMapping()
public CompletableFuture<ResponseEntity<String>> get() {
return CompletableFuture.completedFuture(ResponseEntity.ok("All good from FileAsyncUploadController!!"));
public ResponseEntity<String> get() {
return ResponseEntity.ok(inputProcessorService.get());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;

import com.insilicosoft.portal.svc.rip.FileProcessingException ;
import com.insilicosoft.portal.svc.rip.exception.FileProcessingException;

/**
* REST controller advice.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.insilicosoft.portal.svc.rip;
package com.insilicosoft.portal.svc.rip.exception;

/**
* File processing exception.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.insilicosoft.portal.svc.rip.service;

import com.insilicosoft.portal.svc.rip.FileProcessingException ;
import com.insilicosoft.portal.svc.rip.exception.FileProcessingException;

/**
* Interface to input processing.
Expand All @@ -9,6 +9,9 @@
*/
public interface InputProcessorService {

// TODO Remove
public String get();

/**
* Process a file (as a byte array).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.insilicosoft.portal.svc.rip.FileProcessingException ;
import com.insilicosoft.portal.svc.rip.event.SimulationMessage;
import com.insilicosoft.portal.svc.rip.exception.FileProcessingException;

enum FieldsSections {
simulations
Expand Down Expand Up @@ -45,6 +45,11 @@ public InputProcessorServiceImpl(StreamBridge streamBridge) {
this.streamBridge = streamBridge;
}

@Override
public String get() {
return "All good from FileAsyncUploadController->InputProcessorService!!";
}

@Override
@Async
public void process(final byte[] file) throws FileProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RipSvcApplicationTests {

@Test
void contextLoads() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.insilicosoft.portal.svc.rip.controller;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import com.insilicosoft.portal.svc.rip.service.InputProcessorService;

@WebMvcTest
public class FileSyncUploadControllerIT {

final static MediaType textWithCharset = new MediaType(MediaType.TEXT_PLAIN, StandardCharsets.UTF_8);

@Autowired
private MockMvc mockMvc;

@MockBean
private InputProcessorService mockInputProcessorService;

@Test
void testGet() throws Exception {
final String getMessage = "Message from get!";

given(mockInputProcessorService.get()).willReturn(getMessage);

mockMvc.perform(get("/run"))
.andExpect(status().isOk())
.andExpect(content().contentType(textWithCharset));

verify(mockInputProcessorService).get();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.insilicosoft.portal.svc.rip.exception;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class FileProcessingExceptionTest {

@DisplayName("Test the initialising constructor")
@Test
void testConstructor() {
final String message = "test exception message";
final FileProcessingException e = new FileProcessingException(message);
assertEquals(message, e.getMessage());
}

}

0 comments on commit 383b975

Please sign in to comment.