Package net.mindengine.galen.validation

Examples of net.mindengine.galen.validation.ValidationErrorException


    }


    protected void checkIs(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {
        if (!realText.equals(text)) {
            throw new ValidationErrorException(asList(new ErrorArea(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should be \"%s\"", objectName, checkEntity, realText, text)));
        }
    }
View Full Code Here


        }
    }

    protected void checkStarts(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {
        if (!realText.startsWith(text)) {
          throw new ValidationErrorException(asList(new ErrorArea(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should start with \"%s\"", objectName, checkEntity, realText, text)));
        }
    }
View Full Code Here

        }
    }
   
    protected void checkEnds(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {
        if (!realText.endsWith(text)) {
          throw new ValidationErrorException(asList(new ErrorArea(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should end with \"%s\"", objectName, checkEntity, realText, text)));
        }
    }
View Full Code Here

    }
   
    protected void checkMatches(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {
        Pattern regex = Pattern.compile(text, Pattern.DOTALL);
        if (!regex.matcher(realText).matches()) {
          throw new ValidationErrorException(asList(new ErrorArea(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should match \"%s\"", objectName, checkEntity, realText, text)));
        }
    }
View Full Code Here

        }
    }

    protected void checkContains(String objectName, Rect area, String realText, String text, String checkEntity) throws ValidationErrorException {
        if (!realText.contains(text)) {
          throw new ValidationErrorException(asList(new ErrorArea(area, objectName)), asList(format("\"%s\" %s is \"%s\" but should contain \"%s\"", objectName, checkEntity, realText, text)));
        }
    }
View Full Code Here

       
       
        Range range = convertRange(spec.getRange(), pageValidation);
       
        if (!range.holds(offset)) {
          throw new ValidationErrorException().withMessage(
              String.format("\"%s\" is %dpx %s \"%s\" %s",
                  objectName,
                  offset,
                  direction.toString(),
                  spec.getObject(),
View Full Code Here

       
        BufferedImage pageImage = pageValidation.getPage().getScreenshotImage();
       
        Rect area = mainObject.getArea();
        if (pageImage.getWidth() < area.getLeft() + area.getWidth() || pageImage.getHeight() < area.getTop() + area.getHeight()) {
            throw new ValidationErrorException()
                .withErrorArea(new ErrorArea(area, objectName))
                .withMessage("Can't fetch image for \"object\" as it is outside of screenshot");
        }
       
       
       
       
       
        Spectrum spectrum;
        try {
            spectrum = Rainbow4J.readSpectrum(pageImage, new Rectangle(area.getLeft(), area.getTop(), area.getWidth(), area.getHeight()), PRECISION);
        } catch (Exception e) {
            throw new ValidationErrorException(String.format("Couldn't fetch spectrum for \"%s\"", objectName));
        }
       
        List<String> messages = new LinkedList<String>();
       
        for (ColorRange colorRange : spec.getColorRanges()) {
            Color color = colorRange.getColor();
            int percentage = (int)spectrum.getPercentage(color.getRed(), color.getGreen(), color.getBlue(), TEST_RANGE);
           
            if (!colorRange.getRange().holds(percentage)) {
                messages.add(String.format("color %s on \"%s\" is %d%% %s", toHexColor(color), objectName, (int)percentage, colorRange.getRange().getErrorMessageSuffix("%")));
            }
        }
       
        if (messages.size() > 0) {
            throw new ValidationErrorException()
                    .withErrorArea(new ErrorArea(area, objectName))
                    .withMessages(messages);
        }
    }
View Full Code Here

        int realValue = getSizeValue(mainObject);
       
        Range range = convertRange(spec.getRange(), pageValidation);
       
        if (!range.holds(realValue)) {
                throw new ValidationErrorException()
                    .withErrorArea(new ErrorArea(mainObject.getArea(), objectName))
                    .withMessage(format("\"%s\" %s is %dpx %s", objectName, getUnitName(), realValue, range.getErrorMessageSuffix()));
        }
    }
View Full Code Here

       
        for (String childObjectName : childObjects) {
            PageElement childObject = pageValidation.findPageElement(childObjectName);
            if (childObject != null) {
                if (!childObject.isPresent()) {
                    throw new ValidationErrorException()
                        .withMessage(format(OBJECT_S_IS_ABSENT_ON_PAGE, childObjectName));
                }
                else if (!childObject.isVisible()) {
                    throw new ValidationErrorException()
                        .withMessage(format(OBJECT_S_IS_NOT_VISIBLE_ON_PAGE, childObjectName));
                }
                else {
                    Rect childObjectArea = childObject.getArea();
                    if (!childObjectMatches(spec, objectArea, childObjectArea)) {
                        errorAreas.add(new ErrorArea(childObjectArea, childObjectName));
                        errorMessages.add(format("\"%s\" is outside \"%s\"", childObjectName, objectName));
                    }
                }
            }
            else {
                throw new ValidationErrorException()
                    .withMessage(format(OBJECT_WITH_NAME_S_IS_NOT_DEFINED_IN_PAGE_SPEC, childObjectName));
            }
        }
       
        if (errorMessages.size() > 0 ) {
            throw new ValidationErrorException(errorAreas, errorMessages).withErrorArea(new ErrorArea(objectArea, objectName));
        }
    }
View Full Code Here

    @Override
    public void check(PageValidation pageValidation, String objectName, SpecAbsent spec) throws ValidationErrorException {
        PageElement mainObject = pageValidation.findPageElement(objectName);
        if (mainObject == null) {
            throw new ValidationErrorException(String.format(OBJECT_WITH_NAME_S_IS_NOT_DEFINED_IN_PAGE_SPEC, objectName));
        }
        else if (mainObject.isPresent() && mainObject.isVisible()) {
            throw new ValidationErrorException()
                .withErrorArea(new ErrorArea(mainObject.getArea(), objectName))
                .withMessage(format("\"%s\" is not absent on page", objectName));
        }
    }
View Full Code Here

TOP

Related Classes of net.mindengine.galen.validation.ValidationErrorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.