org.eclipse.microprofile.graphql.tck.dynamic.execution.TestData Java Examples

The following examples show how to use org.eclipse.microprofile.graphql.tck.dynamic.execution.TestData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestInterceptor.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
private Map<String, TestData> toMapOfTestData(Set<Path> testFolders) {
    Map<String, TestData> testDataMap = new HashMap<>();
    for (Path testFolder : testFolders) {
        if (!testFolder.getFileName().toString().startsWith("META-INF")) {// Ignore META-INF
            try {
                TestData testData = toTestData(testFolder);
                if (!testData.shouldIgnore()) {
                    testDataMap.put(testData.getName(), testData);
                }
            } catch (IOException ioe) {
                LOG.errorf("Could not add test case {0} - {1}",
                        new Object[] { testFolder.getFileName().toString(), ioe.getMessage() });
            }
        }
    }
    return testDataMap;
}
 
Example #2
Source File: TestInterceptor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private Map<String, TestData> toMapOfTestData(Set<Path> testFolders) {
    Map<String, TestData> testDataMap = new HashMap<>();
    for (Path testFolder : testFolders) {
        if (!testFolder.getFileName().toString().startsWith("META-INF")) {// Ignore META-INF
            try {
                TestData testData = toTestData(testFolder);
                if (!testData.shouldIgnore()) {
                    testDataMap.put(testData.getName(), testData);
                }
            } catch (IOException ioe) {
                LOG.errorf("Could not add test case {0} - {1}",
                        new Object[] { testFolder.getFileName().toString(), ioe.getMessage() });
            }
        }
    }
    return testDataMap;
}
 
Example #3
Source File: TestInterceptor.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
private TestData getExecutionTestData(Object[] parameters) {
    for (Object param : parameters) {
        if (TestData.class.isInstance(param)) {
            return TestData.class.cast(param);
        }
    }
    return null;
}
 
Example #4
Source File: TestInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private TestData getExecutionTestData(Object[] parameters) {
    for (Object param : parameters) {
        if (TestData.class.isInstance(param)) {
            return TestData.class.cast(param);
        }
    }
    return null;
}
 
Example #5
Source File: ExecutionDynamicTest.java    From microprofile-graphql with Apache License 2.0 4 votes vote down vote up
@RunAsClient
@Test(dataProvider="specification", dataProviderClass = GraphQLTestDataProvider.class)
public void testSpecificationPOST(TestData testData){
    runTest(testData, HttpMethod.POST);
}
 
Example #6
Source File: ExecutionDynamicTest.java    From microprofile-graphql with Apache License 2.0 4 votes vote down vote up
@RunAsClient
@Test(dataProvider="implementation", dataProviderClass = GraphQLTestDataProvider.class)
public void testImplementationSpecificPOST(TestData testData) {
    runTest(testData, HttpMethod.POST);
}
 
Example #7
Source File: ExecutionDynamicTest.java    From microprofile-graphql with Apache License 2.0 4 votes vote down vote up
@RunAsClient
@Test(dataProvider="specification", dataProviderClass = GraphQLTestDataProvider.class)
public void testSpecificationGET(TestData testData){
    runTest(testData, HttpMethod.GET);
}
 
Example #8
Source File: ExecutionDynamicTest.java    From microprofile-graphql with Apache License 2.0 4 votes vote down vote up
@RunAsClient
@Test(dataProvider="implementation", dataProviderClass = GraphQLTestDataProvider.class)
public void testImplementationSpecificGET(TestData testData) {
    runTest(testData,HttpMethod.GET);
}
 
Example #9
Source File: ExecutionDynamicTest.java    From microprofile-graphql with Apache License 2.0 4 votes vote down vote up
private void runTest(TestData testData, HttpMethod httpMethod){
    if(testData!=null && isValidInput(testData.getInput())) {
        LOG.info("Running test [" + httpMethod + " :: " + testData.getName() + "]");
        this.currentTestData = testData;
        this.currentHttpMethod = httpMethod;
        Map<String, String> httpHeaders = new HashMap<>();
        if(testData.getHttpHeaders()!=null && !testData.getHttpHeaders().isEmpty()){
            for(String headerName:testData.getHttpHeaders().stringPropertyNames()){
                String value = testData.getHttpHeaders().getProperty(headerName);
                LOG.info("setting header " + headerName + " to " + value);
                httpHeaders.put(headerName, value);
            }
        }

        // Prepare if needed
        if(isValidInput(testData.getPrepare())){
            executeHttpRequest(httpMethod.POST,testData.getPrepare(),testData.getVariables(),httpHeaders);
        }

        // We can only do Queries over GET
        if(testData.isMutation()){
            httpMethod = HttpMethod.POST;
        }
        
        // Run the actual test and get the response
        HttpResponse httpResponse = executeHttpRequest(httpMethod,testData.getInput(),testData.getVariables(),httpHeaders);
        this.currentOutput = httpResponse.getContent();
        if(httpResponse.isSuccessful()){

            // Validate the output structure
            validateResponseStructure();

            // Cleanup if needed
            if(isValidInput(testData.getCleanup())){
                executeHttpRequest(httpMethod.POST,testData.getCleanup(),testData.getVariables(),httpHeaders);
            }

            // Compare to expected output
            try{
                JSONAssert.assertEquals(testData.getFailMessage(),testData.getOutput(), this.currentOutput, testData.beStrict());
            } catch (JSONException ex) {
                clearGlobals();
                Assert.fail(ex.getMessage());
            }
        } else {
            Assert.assertEquals(httpResponse.status, testData.getExpectedHttpStatusCode(),httpResponse.getContent());
        }
        
    }else{
        clearGlobals();
        LOG.warning("Could not find any tests to run...");
    }
}
 
Example #10
Source File: TestInterceptor.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestStart(ITestResult itr) {

    if (itr.getTestClass().getName().equals(EXECUTION_TEST)) {
        TestData testData = getExecutionTestData(itr.getParameters());

        LOG.info("\n\t =================================================="
                + "\n\t Testing [" + testData.getName() + "]"
                + "\n\t =================================================="
                + "\n");

        if (itr.getName().startsWith(TEST_SPECIFICATION) && !testDataMap.isEmpty()
                && testDataMap.containsKey(testData.getName())) {

            TestData override = testDataMap.get(testData.getName());

            if (override.getCleanup() != null && !override.getCleanup().isEmpty()) {
                testData.setCleanup(override.getCleanup());
                LOG.warn("\n\t NOTE: Overriding Cleanup");
            }
            if (override.getHttpHeaders() != null && !override.getHttpHeaders().isEmpty()) {
                testData.setHttpHeaders(override.getHttpHeaders());
                LOG.warn("\n\t NOTE: Overriding HTTP Headers");
            }
            if (override.getInput() != null && !override.getInput().isEmpty()) {
                testData.setInput(override.getInput());
                LOG.warn("\n\t NOTE: Overriding Input");
            }
            if (override.getOutput() != null && !override.getOutput().isEmpty()) {
                testData.setOutput(override.getOutput());
                LOG.warn("\n\t NOTE: Overriding Output");
            }
            if (override.getPrepare() != null && !override.getPrepare().isEmpty()) {
                testData.setPrepare(override.getPrepare());
                LOG.warn("\n\t NOTE: Overriding Prepare");
            }
            if (override.getProperties() != null && !override.getProperties().isEmpty()) {
                testData.setProperties(override.getProperties());
                LOG.warn("\n\t NOTE: Overriding Properties");
            }
            if (override.getVariables() != null && !override.getVariables().isEmpty()) {
                testData.setVariables(override.getVariables());
                LOG.warn("\n\t NOTE: Overriding Variables");
            }
        }

    }
    super.onTestStart(itr);

}
 
Example #11
Source File: TestInterceptor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestStart(ITestResult itr) {

    if (itr.getTestClass().getName().equals(EXECUTION_TEST)) {
        TestData testData = getExecutionTestData(itr.getParameters());

        LOG.info("\n\t =================================================="
                + "\n\t Testing [" + testData.getName() + "]"
                + "\n\t =================================================="
                + "\n");

        if (itr.getName().startsWith(TEST_SPECIFICATION) && !testDataMap.isEmpty()
                && testDataMap.containsKey(testData.getName())) {

            TestData override = testDataMap.get(testData.getName());

            if (override.getCleanup() != null && !override.getCleanup().isEmpty()) {
                testData.setCleanup(override.getCleanup());
                LOG.warn("\n\t NOTE: Overriding Cleanup");
            }
            if (override.getHttpHeaders() != null && !override.getHttpHeaders().isEmpty()) {
                testData.setHttpHeaders(override.getHttpHeaders());
                LOG.warn("\n\t NOTE: Overriding HTTP Headers");
            }
            if (override.getInput() != null && !override.getInput().isEmpty()) {
                testData.setInput(override.getInput());
                LOG.warn("\n\t NOTE: Overriding Input");
            }
            if (override.getOutput() != null && !override.getOutput().isEmpty()) {
                testData.setOutput(override.getOutput());
                LOG.warn("\n\t NOTE: Overriding Output");
            }
            if (override.getPrepare() != null && !override.getPrepare().isEmpty()) {
                testData.setPrepare(override.getPrepare());
                LOG.warn("\n\t NOTE: Overriding Prepare");
            }
            if (override.getProperties() != null && !override.getProperties().isEmpty()) {
                testData.setProperties(override.getProperties());
                LOG.warn("\n\t NOTE: Overriding Properties");
            }
            if (override.getVariables() != null && !override.getVariables().isEmpty()) {
                testData.setVariables(override.getVariables());
                LOG.warn("\n\t NOTE: Overriding Variables");
            }
        }

    }
    super.onTestStart(itr);

}