Skip to content

Commit

Permalink
Added test for createDataset()
Browse files Browse the repository at this point in the history
  • Loading branch information
dschiese committed Oct 19, 2023
1 parent c9a765b commit 892474b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,34 @@
import com.wse.qanaryexplanationservice.pojos.automatedTestingObject.AnnotationType;
import com.wse.qanaryexplanationservice.pojos.automatedTestingObject.AutomatedTest;
import com.wse.qanaryexplanationservice.pojos.automatedTestingObject.TestDataObject;
import com.wse.qanaryexplanationservice.repositories.AutomatedTestingRepository;
import org.apache.jena.query.ResultSet;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import static org.mockito.ArgumentMatchers.any;

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class AutomatedTestingServiceTest {

private static ServiceDataForTests serviceDataForTests = new ServiceDataForTests();
private final Map<String, String[]> typeAndComponents = new HashMap<>() {{ // TODO: Replace placeholder
put(AnnotationType.annotationofinstance.name(), new String[]{"NED-DBpediaSpotlight", "DandelionNED", "OntoTextNED", "MeaningCloudNed", "TagmeNED"});
put(AnnotationType.annotationofspotinstance.name(), new String[]{"TagmeNER", "TextRazor", "NER-DBpediaSpotlight", "DandelionNER"});
Expand All @@ -34,23 +41,10 @@ public class AutomatedTestingServiceTest {
// put(AnnotationType.annotationofquestiontranslation.name(), new String[]{"mno", "pqr"});
put(AnnotationType.annotationofrelation.name(), new String[]{"FalconRELcomponent-dbpedia"});
}};

private final Logger logger = LoggerFactory.getLogger(AutomatedTestingService.class);
@Autowired
private AutomatedTestingService automatedTestingService;

@Test
public void createDatasetTest() {

}

@Test
public void selectComponentTest() {
// Happy path: 1) example null 2) not uniqueComponent


// Sad path: 1) uniqueComponent and not already existing 2) uniqueComponent and already existing (super sad)
}

@Nested
class selectComponentTests {
Expand All @@ -63,7 +57,7 @@ class selectComponentTests {
@EnumSource(AnnotationType.class)
public void selectComponentExampleNullTest(AnnotationType annotationType) {
example = null;

String component = automatedTestingService.selectComponent(annotationType, automatedTest, example);
logger.info("Selected component: {}", component);
Assertions.assertTrue(Arrays.stream(typeAndComponents.get(annotationType.name())).toList().contains(component));
Expand Down Expand Up @@ -103,6 +97,46 @@ public void selectComponentUniqueAndExisting() {
automatedTestingService.selectComponent(annotationType, automatedTest, example);
});
}
}

@Nested
class createDatasetTests {

/*
* Happy path: ResultSet not null
* Sad path: ResultSet is null
*/

@MockBean
private AutomatedTestingRepository automatedTestingRepository;


// Setup fetchTriples handling
private void setupTest(ResultSet resultSet) {
Mockito.when(automatedTestingRepository.executeSparqlQueryWithResultSet(any())).thenReturn(resultSet);
}

/*
@Test
public void createDatasetResultSetNotNullTest() throws Exception {
ResultSet resultSet = serviceDataForTests.createResultSet(serviceDataForTests.getQuerySolutionMapList());
setupTest(resultSet);
String resultDataset = automatedTestingService.createDataset("componentURI", "graphURI");
Assertions.assertFalse(resultDataset.isEmpty());
}
*/

@Test
public void createDatasetResultSetIsNullTest() throws Exception {
setupTest(null);

Exception exception = Assertions.assertThrows(RuntimeException.class, () -> {
automatedTestingService.createDataset("componentURI", "graphURI");
});

Assertions.assertEquals("ResultSet is null", exception.getMessage());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ServiceDataForTests {
put("end", "3");
put("hasTarget", "questionID:123f3rt3jrskdf324f");
}};

private Logger logger = LoggerFactory.getLogger(ServiceDataForTests.class);
private List<QuerySolutionMap> querySolutionMapList;

Expand Down

0 comments on commit 892474b

Please sign in to comment.