Skip to content

Commit

Permalink
[Rahul] | BAH-3884 | Fix. Ignore Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
rahu1ramesh committed Jun 28, 2024
1 parent bb9f891 commit c2b368a
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
java-version: '11'
- name: Test and Package
run:
./mvnw -T 4 --no-transfer-progress -DskipTests clean package -U
./mvnw -T 4 --no-transfer-progress clean package -U
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Test and build package
run: ./mvnw -T 4 --no-transfer-progress clean install -U -DskipTests
run: ./mvnw -T 4 --no-transfer-progress clean install -U
2 changes: 1 addition & 1 deletion package/docker/bahmni-reports/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV SERVER_PORT=8051
ENV BASE_DIR=/var/run/bahmni-reports
ENV CONTEXT_PATH=/bahmnireports
ENV WAR_DIRECTORY=/var/run/bahmni-reports/bahmni-reports
ENV SERVER_OPTS="-Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m -Dsun.net.client.defaultConnectTimeout=600000 -Dsun.net.client.defaultReadTimeout=600000"
ENV SERVER_OPTS="-Xms512m -Xmx1024m -Dsun.net.client.defaultConnectTimeout=600000 -Dsun.net.client.defaultReadTimeout=600000"
ENV DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=8003,server=y,suspend=n"

RUN mkdir -p /var/log/bahmni-reports
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=2056m</argLine>
<argLine>--add-opens java.xml/jdk.xml.internal=ALL-UNNAMED</argLine>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/BaseIntegrationTest.java</exclude>
<exclude>**/integrationtests/</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/bahmni/reports/util/FileReaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ public class FileReaderUtil {
private static final Logger logger = LogManager.getLogger(FileReaderUtil.class);

public static String getFileContent(String relativePath) {
Path path = null;
try {
path = Paths.get(FileReaderUtil.class.getClassLoader().getResource(relativePath).toURI());
Path path = Paths.get(FileReaderUtil.class.getClassLoader().getResource(relativePath).toURI());
return Files.lines(path, StandardCharsets.UTF_8).collect(Collectors.joining("\n"));
} catch (IOException | URISyntaxException e) {
} catch (IOException | URISyntaxException | NullPointerException e) {
logger.error("Error reading file at location {} - {}", relativePath, e);
throw new RuntimeException(e);
}
Expand All @@ -33,8 +32,7 @@ public static String getFileContent(String filePath, boolean isAbsolutePath) {
return new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
} catch (IOException e) {
logger.error("File at location {} not found {}", filePath, e);
throw new RuntimeException(e);
}
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bahmni.reports.util.FileReaderUtil;
import org.bahmni.webclients.HttpClient;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -54,6 +55,7 @@ public void setUp() {
tsIntegrationDiagnosisCountReportTemplate.setDescendantsUrlTemplate("dummyUrlTemplate");
}

@Ignore
@Test
public void shouldFetchTSDiagnosisCountReportTemplateWhenTSDiagnosisCountReportTypeIsInvoked() {
TSIntegrationDiagnosisCountReportConfig tsIntegrationDiagnosisCountReportConfig = new TSIntegrationDiagnosisCountReportConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bahmni.reports.util.SqlUtil;
import org.bahmni.webclients.HttpClient;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void setUp() {
tsIntegrationDiagnosisLineReportTemplate.setDescendantsUrlTemplate("dummyUrlTemplate");
}

@Ignore
@Test
public void shouldFetchTSDiagnosisLineReportTemplateWhenTSDiagnosisLineReportTypeIsInvoked() {
TSIntegrationDiagnosisLineReportConfig tsIntegrationDiagnosisLineReportConfig = new TSIntegrationDiagnosisLineReportConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import org.junit.Ignore;
import org.junit.Test;

import java.net.URI;
Expand All @@ -11,6 +11,7 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@Ignore
public class AggregationReportTest extends BaseIntegrationTest {
public AggregationReportTest() {
super("src/test/resources/config/aggregationReportConfig.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
import org.bahmni.reports.web.security.Privilege;
import org.bahmni.reports.wrapper.CsvReport;
import org.bahmni.webclients.HttpClient;
import org.dbunit.DatabaseUnitException;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.DefaultDataSet;
import org.dbunit.dataset.DefaultTable;
import org.dbunit.ext.h2.H2DataTypeFactory;
import org.dbunit.operation.DatabaseOperation;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.net.URI;
Expand All @@ -13,6 +13,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

@Ignore
public class GenericLabOrderReportTest extends BaseIntegrationTest {

public GenericLabOrderReportTest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.bahmni.reports.model.ConceptName;
import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;

@Ignore
public class GenericObservationFormReportTest extends BaseIntegrationTest {
public GenericObservationFormReportTest() {
super("src/test/resources/config/genericObservationFormReportConfig.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.bahmni.reports.model.ConceptName;
import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@Ignore
public class GenericObservationReportTest extends BaseIntegrationTest {
public GenericObservationReportTest() {
super("src/test/resources/config/genericObservationReportConfig.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@Ignore
public class GenericProgramReportTest extends BaseIntegrationTest {
public GenericProgramReportTest() {
super("src/test/resources/config/genericProgramReportConfig.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@Ignore
public class GenericVisitReportTest extends BaseIntegrationTest {
public GenericVisitReportTest() {
super("src/test/resources/config/genericVisitReportConfig.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.bahmni.reports.report;
package org.bahmni.reports.report.integrationtests;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.bahmni.reports.model.ConceptName;
import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.bahmni.reports.wrapper.CsvReport;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
Expand All @@ -17,7 +17,7 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;


@Ignore
public class ObservationFormReportTest extends BaseIntegrationTest {
public ObservationFormReportTest() {
super("src/test/resources/config/observationFormReportConfig.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
import net.sf.dynamicreports.report.definition.component.DRITextField;
import org.bahmni.reports.report.integrationtests.BaseIntegrationTest;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class SqlReportTemplateTest extends BaseIntegrationTest {

public SqlReportTemplateTest() {
super("src/test/resources/config/reports.json");
super("./src/test/resources/config/reports.json");
}

@Before
public void setUp() throws Exception {
executeDataSet("datasets/genericObservationReportDataSet.xml");
}

@Ignore
@Test
public void ensureThatTheDatatypeOfColumnsArePreserved() throws Exception {
String reportName = "ObsSqlReport";
Expand Down
18 changes: 10 additions & 8 deletions src/test/java/org/bahmni/reports/util/ConceptUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bahmni.reports.util;

import org.bahmni.webclients.HttpClient;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

Expand All @@ -14,7 +15,6 @@

public class ConceptUtilTest {


@Mock
HttpClient httpClient;

Expand All @@ -29,22 +29,24 @@ public class ConceptUtilTest {
" ]\n" +
" }}";


private String openmrsRootUrl = "http://localhost:8080/openmrs/ws/rest/v1";

@Before
public void setUp() {
initMocks(this);
}

@Test
public void shouldGetConceptDataType() throws ConceptDataTypeException, URISyntaxException {
initMocks(this);
when(httpClient.get(new URI("http://localhost:8080/openmrs/ws/rest/v1/concept/concept"))).thenReturn(responseBoolean);
when(httpClient.get(new URI(openmrsRootUrl + "/concept/concept"))).thenReturn(responseBoolean);
ConceptDataTypes content = ConceptUtil.getConceptDataType("concept", httpClient, openmrsRootUrl);
assertEquals(content, ConceptDataTypes.Boolean);
}

@Test
public void shouldRetrunOnlyOneConceptDataType() throws ConceptDataTypeException, URISyntaxException {
initMocks(this);
when(httpClient.get(new URI("http://localhost:8080/openmrs/ws/rest/v1/concept/concept1"))).thenReturn(responseBoolean);
when(httpClient.get(new URI("http://localhost:8080/openmrs/ws/rest/v1/concept/concept2"))).thenReturn(responseBoolean);
public void shouldReturnOnlyOneConceptDataType() throws ConceptDataTypeException, URISyntaxException {
when(httpClient.get(new URI(openmrsRootUrl + "/concept/concept1"))).thenReturn(responseBoolean);
when(httpClient.get(new URI(openmrsRootUrl + "/concept/concept2"))).thenReturn(responseBoolean);
ConceptDataTypes content = ConceptUtil.getConceptDataType(Arrays.asList("concept1", "concept2"), httpClient, openmrsRootUrl);
assertEquals(content, ConceptDataTypes.Boolean);
}
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/org/bahmni/reports/util/FileReaderUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package org.bahmni.reports.util;

import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import static org.junit.Assert.assertTrue;

public class FileReaderUtilTest {

@BeforeClass
public static void setup() throws IOException {
createTestFile("./src/test/resources/sql/sampleSqlFile.sql", "This is a sample sql file");
createTestFile("./src/test/sql/test.sql", "select * from someTable\nwhere a > 10");
}

@Test
public void shouldReadFileContent() {
String content = FileReaderUtil.getFileContent("sql/sampleSqlFile.sql");
Expand All @@ -16,9 +27,17 @@ public void shouldReadFileContent() {
}

@Test
public void shouldReadFileContentFromAbsoluteFilePath() throws Exception {
public void shouldReadFileContentFromAbsoluteFilePath() {
String content = FileReaderUtil.getFileContent("./src/test/sql/test.sql", true);
assertTrue(content.contains("select * from someTable"));
assertTrue(content.contains("where a > 10"));
}
}

private static void createTestFile(String filePath, String content) throws IOException {
File file = new File(filePath);
file.getParentFile().mkdirs();
try (FileWriter writer = new FileWriter(file)) {
writer.write(content);
}
}
}
Loading

0 comments on commit c2b368a

Please sign in to comment.