All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.blitz.maven.SprintMojo Maven / Gradle / Ivy

/*
 * The MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package io.blitz.maven;

import io.blitz.curl.Sprint;
import io.blitz.curl.exception.BlitzException;
import io.blitz.curl.sprint.ISprintListener;
import io.blitz.curl.sprint.SprintResult;
import org.apache.maven.plugin.MojoExecutionException;

import java.text.MessageFormat;

/**
 * Goal to run a http://blitz.io Sprint test.
 *
 * @goal sprint
 * 
 * @phase integration-test
 * 
 * @requiresOnline true
 */
public class SprintMojo extends BlitzMojo {

    /**
     * execute the spritn mojo test
     * @throws MojoExecutionException if the test fails or an error occur
     */
    public void execute() throws MojoExecutionException {
        
        Sprint sprint = new Sprint(username, apiKey);
        sprint.addListener(new ISprintListener() {
            public boolean onData(SprintResult result) {
                String template =  "{0} - {1}s response time from {2}.";
                String message = MessageFormat.format(template, url,
                        result.getDuration(), result.getRegion());
                getLog().info(message);
                return true;
            }
        });
        getLog().debug("Configuring test.");
        configure(sprint);
        getLog().debug("Starting test.");
        try {
            sprint.execute();
            getLog().debug("Sprint successfully executed.");
        }
        catch(BlitzException ex) {
            getLog().error(ex);
            String message = MessageFormat
                    .format("{0}: {1}", ex.getError(), ex.getReason());
            throw new MojoExecutionException(message);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy