-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed tests due to QanaryTripleStoreProxy, Added new test for QanaryP…
…ipelineCompoennt
- Loading branch information
Showing
6 changed files
with
464 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 39 additions & 25 deletions
64
qanary_pipeline-template/src/test/java/eu/wdaqua/qanary/QanaryPipelineComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,63 @@ | ||
package eu.wdaqua.qanary; | ||
|
||
import eu.wdaqua.qanary.commons.triplestoreconnectors.QanaryTripleStoreConnector; | ||
import org.apache.http.HttpResponse; | ||
import eu.wdaqua.qanary.commons.triplestoreconnectors.QanaryTripleStoreConnectorVirtuoso; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.ResourceFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Scanner; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.util.Objects; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@AutoConfigureWireMock(port = 8080) // | ||
public class QanaryPipelineComponentTest { | ||
|
||
private final String questionID = "http://localhost:8080"; | ||
private final String EXAMPLE_QUESTION = "Example question"; | ||
|
||
protected ClassLoader classLoader = this.getClass().getClassLoader(); | ||
@MockBean | ||
private QanaryTripleStoreConnector qanaryTripleStoreConnector; | ||
QanaryTripleStoreConnectorVirtuoso qanaryTripleStoreConnectorVirtuoso; | ||
@InjectMocks | ||
QanaryPipelineComponent qanaryPipelineComponent; | ||
URI testUri = new URI("testUri"); | ||
|
||
@Autowired | ||
private QanaryPipelineComponent qanaryPipelineComponent; | ||
public QanaryPipelineComponentTest() throws URISyntaxException { | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
//doNothing().when(qanaryTripleStoreConnector).connect(); | ||
WebClient webClient = WebClient.builder().build(); | ||
ReflectionTestUtils.setField(qanaryPipelineComponent, "webClient", webClient); | ||
doNothing().when(qanaryTripleStoreConnectorVirtuoso).connect(); | ||
} | ||
|
||
private String convertResponseToString(HttpResponse response) throws IOException { | ||
InputStream responseStream = response.getEntity().getContent(); | ||
Scanner scanner = new Scanner(responseStream, "UTF-8"); | ||
String responseString = scanner.useDelimiter("\\Z").next(); | ||
scanner.close(); | ||
return responseString; | ||
@Test | ||
public void constructQueryFromModelTest() throws IOException { | ||
Model model = ModelFactory.createDefaultModel(); | ||
model.add(ResourceFactory.createStatement( | ||
ResourceFactory.createResource("annotation"), | ||
ResourceFactory.createProperty("oa:annotatedBy"), | ||
ResourceFactory.createPlainLiteral("test") | ||
)); | ||
String query = qanaryPipelineComponent.constructQueryFromModel(model, testUri, "/insert_constructed_triples.rq"); | ||
String expectedResult = readFileFromTestResources("constructQueryFromModelTestResultQuery"); | ||
|
||
Assertions.assertNotEquals(expectedResult, query); | ||
} | ||
|
||
private String readFileFromTestResources(String path) throws IOException { | ||
File file = new File(Objects.requireNonNull(classLoader.getResource(path)).getFile()); | ||
return new String(Files.readAllBytes(file.toPath())); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.