diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/DummyTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/DummyTest.java deleted file mode 100644 index f791129f..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/DummyTest.java +++ /dev/null @@ -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"); - } -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java index 62c8f6ed..fdc58d8f 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java @@ -1,22 +1,40 @@ 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 java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.FileOutputStream; 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.junit.Before; import org.junit.Ignore; import org.junit.Test; 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.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.ResourceLoader; 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.RedactionResult; +import com.iqser.red.service.redaction.v1.server.client.RulesClient; import com.iqser.red.service.redaction.v1.server.controller.RedactionController; @Ignore @@ -27,7 +45,37 @@ public class RedactionIntegrationTest { @Autowired 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 public void redactionTest() throws IOException { @@ -49,7 +97,6 @@ public class RedactionIntegrationTest { System.out.println("numberOfPages: " + result.getNumberOfPages()); } - @Test public void classificationTest() throws IOException { @@ -64,7 +111,6 @@ public class RedactionIntegrationTest { } } - @Test 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); + } + + } + } \ No newline at end of file diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/resources/drools/rules.drl b/redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules.drl similarity index 100% rename from redaction-service-v1/redaction-service-server-v1/src/main/resources/drools/rules.drl rename to redaction-service-v1/redaction-service-server-v1/src/test/resources/drools/rules.drl