Search in sources :

Example 1 with TestCollection

use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection in project IPK-BrAPI-Validator by plantbreeding.

the class WeeklyJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    LOGGER.info("Weekly is executing.");
    ObjectMapper mapper = new ObjectMapper();
    InputStream inJson = TestCollection.class.getResourceAsStream("/collections/CompleteBrapiTest." + Config.get("testedVersion") + ".json");
    TestCollection tc;
    try {
        tc = mapper.readValue(inJson, TestCollection.class);
        RunnerService.TestAllEndpointsWithFreq(tc, "weekly");
        RunnerService.TestAllPublicEndpoints(tc);
    } catch (IOException | SQLException e1) {
        e1.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) IOException(java.io.IOException) TestCollection(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with TestCollection

use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection in project IPK-BrAPI-Validator by plantbreeding.

the class AdminResource method generalTest.

/**
 * Run the default test on all public resources
 *
 * @return Empty response with status code
 */
@GET
@Path("/testallpublic")
public Response generalTest(@Context HttpHeaders headers, @QueryParam("version") @DefaultValue("") String version) {
    if (Config.get("advancedMode") == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    LOGGER.debug("New GET /admin/testallpublic call.");
    try {
        // Check auth header
        if (!auth(headers)) {
            String e = JsonMessageManager.jsonMessage(401, "unauthorized", 4002);
            return Response.status(Status.UNAUTHORIZED).entity(e).build();
        }
        if (!version.equals("v1.0") && !version.equals("v1.1")) {
            String jsonError = JsonMessageManager.jsonMessage(400, "Missing or invalid version parameter", 4202);
            return Response.status(Status.BAD_REQUEST).encoding(jsonError).build();
        }
        ObjectMapper mapper = new ObjectMapper();
        InputStream inJson = TestCollection.class.getResourceAsStream("/collections/CompleteBrapiTest." + version + ".json");
        TestCollection tc = mapper.readValue(inJson, TestCollection.class);
        List<Resource> publicResources = ResourceService.getAllPublicEndpoints();
        publicResources.forEach(resource -> {
            try {
                RunnerService.TestEndpointWithCallAndSaveReport(resource, tc);
            } catch (SQLException | JsonProcessingException e) {
                e.printStackTrace();
            }
        });
        System.out.println("Done");
        return Response.ok().build();
    } catch (SQLException | IOException e) {
        e.printStackTrace();
        String e1 = JsonMessageManager.jsonMessage(500, "internal server error", 5003);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1).build();
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) Resource(de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.Resource) IOException(java.io.IOException) TestCollection(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with TestCollection

use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection in project IPK-BrAPI-Validator by plantbreeding.

the class SingleTestResource method callTest.

/**
 * Run a call test
 *
 * @param url  Url of the BrAPI server. Example: https://test.brapi.org/brapi/v1/
 * @return Response with json report
 */
@GET
@Path("/call")
@Produces(MediaType.APPLICATION_JSON)
public Response callTest(@QueryParam("url") String url, @QueryParam("brapiversion") @DefaultValue("") String version) {
    LOGGER.debug("New GET /call call.");
    try {
        if (url.equals("")) {
            String jsonError = JsonMessageManager.jsonMessage(400, "Missing or invalid url parameter", 4202);
            return Response.status(Status.BAD_REQUEST).encoding(jsonError).build();
        }
        if (!version.equals("v1.0") && !version.equals("v1.1")) {
            String jsonError = JsonMessageManager.jsonMessage(400, "Missing or invalid version parameter", 4202);
            return Response.status(Status.BAD_REQUEST).encoding(jsonError).build();
        }
        String collectionResource;
        ObjectMapper mapper = new ObjectMapper();
        collectionResource = "/collections/CompleteBrapiTest." + version + ".json";
        InputStream inJson = TestCollection.class.getResourceAsStream(collectionResource);
        TestCollection tc = mapper.readValue(inJson, TestCollection.class);
        Resource res = new Resource(url);
        TestSuiteReport testSuiteReport = RunnerService.testEndpointWithCall(res, tc);
        TestReport report = new TestReport(res, mapper.writeValueAsString(testSuiteReport));
        return Response.ok().entity(report).build();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        String e1 = JsonMessageManager.jsonMessage(400, "invalid URL: port must be 80", 5201);
        return Response.status(Status.BAD_REQUEST).entity(e1).build();
    } catch (IOException e) {
        // Thrown by .getResourceAsStream(""). Most probably because of missing file or wrong config structure.
        e.printStackTrace();
        String e1 = JsonMessageManager.jsonMessage(500, "internal server error", 5201);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1).build();
    }
}
Also used : TestReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.TestReport) InputStream(java.io.InputStream) Resource(de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.Resource) TestSuiteReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestSuiteReport) IOException(java.io.IOException) TestCollection(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with TestCollection

use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection in project IPK-BrAPI-Validator by plantbreeding.

the class DailyJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    LOGGER.info("Daily is executing.");
    ObjectMapper mapper = new ObjectMapper();
    InputStream inJson = TestCollection.class.getResourceAsStream("/collections/CompleteBrapiTest." + Config.get("testedVersion") + ".json");
    TestCollection tc;
    try {
        tc = mapper.readValue(inJson, TestCollection.class);
        RunnerService.TestAllEndpointsWithFreq(tc, "daily");
    } catch (IOException | SQLException e1) {
        e1.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) IOException(java.io.IOException) TestCollection(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with TestCollection

use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection in project IPK-BrAPI-Validator by plantbreeding.

the class MonthlyJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    LOGGER.info("Monthly is executing.");
    ObjectMapper mapper = new ObjectMapper();
    InputStream inJson = TestCollection.class.getResourceAsStream("/collections/CompleteBrapiTest." + Config.get("testedVersion") + ".json");
    TestCollection tc;
    try {
        tc = mapper.readValue(inJson, TestCollection.class);
        RunnerService.TestAllEndpointsWithFreq(tc, "monthly");
    } catch (IOException | SQLException e1) {
        e1.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) IOException(java.io.IOException) TestCollection(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 TestCollection (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.TestCollection)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 SQLException (java.sql.SQLException)4 Resource (de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.Resource)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TestReport (de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.TestReport)1 TestSuiteReport (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestSuiteReport)1 Produces (javax.ws.rs.Produces)1