Search in sources :

Example 1 with SPARQL11SEProperties

use of it.unibo.arces.wot.sepa.api.SPARQL11SEProperties in project SEPA by arces-wot.

the class SEPATest method main.

public static void main(String[] args) {
    boolean ret = false;
    try {
        properties = new SPARQL11SEProperties("client.jpar");
    } catch (SEPAPropertiesException e2) {
        logger.fatal("JSAP exception: " + e2.getMessage());
        System.exit(1);
    }
    try {
        client = new SPARQL11SEProtocol(properties, handler);
    } catch (SEPAProtocolException e2) {
        logger.fatal(e2.getLocalizedMessage());
        System.exit(1);
    }
    logger.warn("**********************************************************");
    logger.warn("***     SPARQL 1.1 SE Protocol Service test suite      ***");
    logger.warn("**********************************************************");
    logger.warn("***   WARNING: the RDF store content will be ERASED    ***");
    logger.warn("***         Do you want to continue (yes/no)?          ***");
    logger.warn("**********************************************************");
    logger.warn("SPARQL 1.1 SE Protocol Service parameters: " + client.toString());
    Scanner scanner = new Scanner(System.in);
    // "\\z" means end of input
    scanner.useDelimiter("\\n");
    String input = scanner.next();
    if (!input.equals("yes")) {
        scanner.close();
        logger.info("Bye bye! :-)");
        System.exit(0);
    }
    logger.warn("**********************************************************");
    logger.warn("***                Are you sure (yes/no)?              ***");
    logger.warn("**********************************************************");
    input = scanner.next();
    if (!input.equals("yes")) {
        scanner.close();
        logger.info("Bye bye! :-)");
        System.exit(0);
    }
    scanner.close();
    // UPDATE
    ret = updateTest("prefix test:<http://www.vaimee.com/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"測試\"} where {?s ?p ?o}", false);
    results.addResult("Update", ret);
    if (ret)
        logger.info("Update PASSED");
    else
        logger.error("Update FAILED");
    // QUERY
    ret = queryTest("select ?o where {?s ?p ?o}", "測試", false);
    results.addResult("Query", ret);
    if (ret)
        logger.info("Query PASSED");
    else
        logger.error("Query FAILED");
    // SUBSCRIBE
    ret = subscribeTest("select ?o where {?s ?p ?o}", false);
    results.addResult("Subscribe - request", ret);
    if (ret)
        logger.info("Subscribe PASSED");
    else
        logger.error("Subscribe FAILED");
    // PING
    ret = waitPing();
    results.addResult("Subscribe - ping", ret);
    if (ret)
        logger.info("Ping received PASSED");
    else
        logger.error("Ping recevied FAILED");
    // TRIGGER A NOTIFICATION
    ret = updateTest("prefix test:<http://www.vaimee.com/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"ვაიმეე\"} where {?s ?p ?o}", false);
    results.addResult("Subscribe - triggering", ret);
    if (ret)
        logger.info("Triggering update PASSED");
    else
        logger.error("Triggering update FAILED");
    // WAIT NOTIFICATION
    ret = waitNotification();
    results.addResult("Subscribe - notification", ret);
    if (ret)
        logger.info("Notification PASSED");
    else
        logger.error("Notification FAILED");
    // UNSUBSCRIBE
    ret = unsubscribeTest(spuid, false);
    results.addResult("Unsubscribe - request", ret);
    if (ret)
        logger.info("Unsubscribe PASSED");
    else
        logger.error("Unsubscribe FAILED");
    // PING
    ret = !waitPing();
    results.addResult("Unsubscribe - ping", ret);
    if (ret)
        logger.info("Ping not received PASSED");
    else
        logger.error("Ping not recevied FAILED");
    // **********************
    // Enable security
    // **********************
    logger.debug("Switch to secure mode");
    // REGISTRATION (registration not allowed)
    ret = !registrationTest("RegisterMePlease");
    results.addResult("Registration not allowed", ret);
    if (ret)
        logger.info("Registration not allowed PASSED");
    else
        logger.error("Registration not allowed FAILED");
    // REGISTRATION
    ret = registrationTest("SEPATest");
    results.addResult("Registration", ret);
    if (ret)
        logger.info("Registration PASSED");
    else
        logger.error("Registration FAILED");
    // REQUEST ACCESS TOKEN
    ret = requestAccessTokenTest();
    results.addResult("Access token", ret);
    if (ret)
        logger.info("Access token PASSED");
    else
        logger.error("Access token FAILED");
    // REQUEST ACCESS TOKEN (not expired);
    try {
        if (!properties.isTokenExpired())
            ret = !requestAccessTokenTest();
        else
            ret = false;
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
        ret = false;
    }
    results.addResult("Access token not expired", ret);
    if (ret)
        logger.info("Access token (not expired) PASSED");
    else
        logger.error("Access token (not expired) FAILED");
    // REQUEST ACCESS TOKEN (expired);
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            ret = requestAccessTokenTest();
        else
            ret = false;
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
        ret = false;
    }
    results.addResult("Access token expired", ret);
    if (ret)
        logger.info("Access token (expired) PASSED");
    else
        logger.error("Access token (expired) FAILED");
    // SECURE UPDATE
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e13) {
        logger.error(e13.getMessage());
    }
    ret = updateTest("prefix test:<http://wot.arces.unibo.it/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"ვაიმეე\"} where {?s ?p ?o}", true);
    results.addResult("Secure update ", ret);
    if (ret)
        logger.info("Secure update PASSED");
    else
        logger.error("Secure update FAILED");
    // SECURE UPDATE (expired token)
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e12) {
        logger.error(e12.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !updateTest("prefix test:<http://wot.arces.unibo.it/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"vaimee!\"} where {?s ?p ?o}", true);
    results.addResult("Secure update (expired)", ret);
    if (ret)
        logger.info("Secure update (expired) PASSED");
    else
        logger.error("Secure update (expired) FAILED");
    // SECURE QUERY
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e11) {
        logger.error(e11.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e10) {
        logger.error(e10.getMessage());
    }
    ret = queryTest("select ?o where {?s ?p ?o}", "ვაიმეე", true);
    results.addResult("Secure query", ret);
    if (ret)
        logger.info("Secure query PASSED");
    else
        logger.error("Secure query FAILED");
    // SECURE QUERY (expired token)
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e9) {
        logger.error(e9.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !queryTest("select ?o where {?s ?p ?o}", "ვაიმეე", true);
    results.addResult("Secure query (expired)", ret);
    if (ret)
        logger.info("Secure query (expired) PASSED");
    else
        logger.error("Secure query (expired) FAILED");
    // SECURE SUBSCRIBE
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e8) {
        logger.error(e8.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e7) {
        logger.error(e7.getMessage());
    }
    ret = subscribeTest("select ?o where {?s ?p ?o}", true);
    results.addResult("Secure subscribe - request", ret);
    if (ret)
        logger.info("Secure subscribe PASSED");
    else
        logger.error("Secure subscribe FAILED");
    // PING
    ret = waitPing();
    results.addResult("Secure subscribe - ping", ret);
    if (ret)
        logger.info("Secure ping received PASSED");
    else
        logger.error("Secure ping recevied FAILED");
    // TRIGGER A NOTIFICATION
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e6) {
        logger.error(e6.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e5) {
        logger.error(e5.getMessage());
    }
    ret = updateTest("prefix test:<http://wot.arces.unibo.it/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"卢卡\"} where {?s ?p ?o}", true);
    results.addResult("Secure subscribe - triggering", ret);
    if (ret)
        logger.info("Secure triggering update PASSED");
    else
        logger.error("Secure triggering update FAILED");
    // NOTIFICATION
    ret = waitNotification();
    results.addResult("Secure subscribe - notification", ret);
    if (ret)
        logger.info("Secure subscribe - notification PASSED");
    else
        logger.error("Secure subscribe - notification FAILED");
    // SECURE UNSUBSCRIBE (expired)
    try {
        logger.debug("Wait token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e4) {
        logger.error(e4.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !unsubscribeTest(spuid, true);
    results.addResult("Secure unsubscribe (expired) - request", ret);
    if (ret)
        logger.info("Secure unsubscribe (expired) - request PASSED");
    else
        logger.error("Secure unsubscribe (expired) - request FAILED");
    // UNSUBSCRIBE
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e3) {
        logger.error(e3.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
    }
    ret = unsubscribeTest(spuid, true);
    results.addResult("Secure unsubscribe - request", ret);
    if (ret)
        logger.info("Secure unsubscribe - request PASSED");
    else
        logger.error("Secure unsubscribe - request FAILED");
    // WAITING PING
    ret = !waitPing();
    results.addResult("Secure unsubscribe - ping", ret);
    if (ret)
        logger.info("Secure unsubscribe - ping PASSED");
    else
        logger.error("Secure unsubscribe - ping FAILED");
    // SECURE SUBSCRIBE (expired)
    try {
        logger.info("Wait token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e1) {
        logger.error(e1.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !subscribeTest("select ?o where {?s ?p ?o}", true);
    results.addResult("Secure subscribe (expired) - request", ret);
    if (ret)
        logger.info("Secure subscribe (expired) - request PASSED");
    else
        logger.error("Secure subscribe (expired) - request FAILED");
    results.print();
    System.exit(0);
}
Also used : SPARQL11SEProtocol(it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) Scanner(java.util.Scanner) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SPARQL11SEProperties(it.unibo.arces.wot.sepa.api.SPARQL11SEProperties) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)

Aggregations

SPARQL11SEProperties (it.unibo.arces.wot.sepa.api.SPARQL11SEProperties)1 SPARQL11SEProtocol (it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol)1 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)1 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 Scanner (java.util.Scanner)1