Make testing possible again.
This commit is contained in:
parent
cc0d585c0b
commit
531e34c6d0
@ -1,14 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class DummyTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dummy(){
|
|
||||||
System.out.println("Hello World");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,22 +1,40 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server;
|
package com.iqser.red.service.redaction.v1.server;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.kie.api.KieServices;
|
||||||
|
import org.kie.api.builder.KieBuilder;
|
||||||
|
import org.kie.api.builder.KieFileSystem;
|
||||||
|
import org.kie.api.builder.KieModule;
|
||||||
|
import org.kie.api.runtime.KieContainer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.iqser.red.service.configuration.v1.api.model.RulesResponse;
|
||||||
import com.iqser.red.service.redaction.v1.model.RedactionRequest;
|
import com.iqser.red.service.redaction.v1.model.RedactionRequest;
|
||||||
import com.iqser.red.service.redaction.v1.model.RedactionResult;
|
import com.iqser.red.service.redaction.v1.model.RedactionResult;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
||||||
import com.iqser.red.service.redaction.v1.server.controller.RedactionController;
|
import com.iqser.red.service.redaction.v1.server.controller.RedactionController;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@ -27,7 +45,37 @@ public class RedactionIntegrationTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RedactionController redactionController;
|
private RedactionController redactionController;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private RulesClient rulesClient;
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
public static class RedactionIntegrationTestConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public KieContainer kieContainer() {
|
||||||
|
|
||||||
|
KieServices kieServices = KieServices.Factory.get();
|
||||||
|
|
||||||
|
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
|
||||||
|
InputStream input = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
|
||||||
|
kieFileSystem.write("src/main/resources/drools/rules.drl", kieServices.getResources().newInputStreamResource(input));
|
||||||
|
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
|
||||||
|
kieBuilder.buildAll();
|
||||||
|
KieModule kieModule = kieBuilder.getKieModule();
|
||||||
|
|
||||||
|
return kieServices.newKieContainer(kieModule.getReleaseId());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void stubRulesClient() {
|
||||||
|
|
||||||
|
when(rulesClient.getVersion()).thenReturn(0L);
|
||||||
|
when(rulesClient.getRules()).thenReturn(new RulesResponse(loadFromClassPath("drools/rules.drl")));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redactionTest() throws IOException {
|
public void redactionTest() throws IOException {
|
||||||
@ -49,7 +97,6 @@ public class RedactionIntegrationTest {
|
|||||||
System.out.println("numberOfPages: " + result.getNumberOfPages());
|
System.out.println("numberOfPages: " + result.getNumberOfPages());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void classificationTest() throws IOException {
|
public void classificationTest() throws IOException {
|
||||||
|
|
||||||
@ -64,7 +111,6 @@ public class RedactionIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sectionsTest() throws IOException {
|
public void sectionsTest() throws IOException {
|
||||||
|
|
||||||
@ -107,4 +153,25 @@ public class RedactionIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String loadFromClassPath(String path) {
|
||||||
|
|
||||||
|
URL resource = ResourceLoader.class.getClassLoader()
|
||||||
|
.getResource(path);
|
||||||
|
if (resource == null) {
|
||||||
|
throw new IllegalArgumentException("could not load classpath resource: drools/rules.drl");
|
||||||
|
}
|
||||||
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.openStream(), StandardCharsets.UTF_8))) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String str;
|
||||||
|
while ((str = br.readLine()) != null) {
|
||||||
|
sb.append(str)
|
||||||
|
.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException("could not load classpath resource: " + path, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user