Examples of SpecException


Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

    }

    public Class<T> getContextTypeFromSubclassDeclaration() {
        Class<? extends JavaSpec> subClass = getClass();
        if(!(subClass.getSuperclass().equals(JavaSpec.class))){
            throw new SpecException("A java spec class["+ subClass+ "] must inherit directly from " +JavaSpec.class);
        }
        Type generifiedJavaSpec = subClass.getGenericSuperclass();
        if(!(generifiedJavaSpec instanceof ParameterizedType)){
            throw new SpecException("JavaSpec superclass must be generified with a type of TestContext. For example JavaSpec<TestContext>");
        }
        Type contextType = ((ParameterizedType) generifiedJavaSpec).getActualTypeArguments()[0];
        if(!(contextType instanceof Class)){
            throw new SpecException("JavaSpec parameter is not a class?");
        }
        return (Class<T>) contextType;
    }
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

    private Map<String, Object> variableValues;

    @Override
    public void let(String variableName, Supplier<?> valueDefinition) throws SpecException {
        if(this.containsValueFor(variableName)){
            throw new SpecException("Variable [" + variableName + "] cannot be re-defined once assigned. Current value: ["+get(variableName)+"]");
        }
        this.storeDefinitionFor(variableName, valueDefinition);
    }
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

            return getValueFor(variableName);
        }

        Supplier<Object> variableDefinition = getDefinitionFor(variableName);
        if(variableDefinition == null){
            throw new SpecException("Variable ["+variableName+"] cannot be accessed because it lacks a definition in this context[" + this.getVariableDefinitions() + "]");
        }
        Object variableValue = null;
        try {
            variableValue = variableDefinition.get();
        } catch (SpecException e){
            throw e;
        } catch(StackOverflowError e){
            throw new SpecException("Got a Stackoverflow when evaluating variable ["+variableName+"]. Do we have a cyclic dependency on its definition?",e);
        } catch (Exception e) {
            throw new SpecException("Definition for variable ["+variableName+"] failed to execute: " + e.getMessage(),e);
        }
        storeValueFor(variableName, variableValue);
        return (T) variableValue;
    }
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

        throw new UnsupportedOperationException("Null context cannot define variables: " + variableName);
    }

    @Override
    public <T> T get(String variableName) {
        throw new SpecException("Variable ["+variableName+"] cannot be accessed because lacks definition");
    }
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

            Method[] typeMethods = currentType.getDeclaredMethods();
            for (Method typeMethod : typeMethods) {
                String variableName = TypedContextMethodInvocation.extractVariableNameFrom(typeMethod);
                if(this.seemsLikeLetter(typeMethod)){
                    if(letters.containsKey(variableName)){
                        throw new SpecException("Let operation for variable ["+variableName+"] is duplicated");
                    }
                    letters.put(variableName, typeMethod);
                } else if (this.seemsLikeGetter(typeMethod)){
                    if(getters.containsKey(variableName)){
                        throw new SpecException("Get operation for variable ["+variableName+"] is duplicated");
                    }
                    getters.put(variableName, typeMethod);
                }else{
                    throw new SpecException("Method ["+typeMethod.getName()+"] declared in ["+currentType.getSimpleName()+"] does not conform to get or let operation signatures [no arg | void, Supplier]");
                }
            }
            Class<?>[] superInterfaces = currentType.getInterfaces();
            for (Class<?> superInterface : superInterfaces) {
                pendingTypes.add(superInterface);
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

    private JavaSpec instantiate(Class<? extends JavaSpec> specClass) {
        try {
            JavaSpec createdInstance = specClass.newInstance();
            return createdInstance;
        } catch( SecurityException e){
            throw new SpecException("Security forbids instantiation for spec["+specClass+"]",e);
        } catch( ExceptionInInitializerError e){
            throw new SpecException("Constructor failed for new spec["+specClass+"] instance", e);
        } catch (InstantiationException e) {
            throw new SpecException("Error creating the spec["+specClass+"] instance", e);
        } catch (IllegalAccessException e) {
            throw new SpecException("Unable to access spec["+specClass+"] constructor for new instance",e);
        }
    }
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

        } catch(InvocationTargetException e){
            Throwable cause = e.getCause();
            if(cause instanceof SpecException){
                throw (SpecException)cause;
            }
            throw new SpecException("Invocation on proxied context failed: " + cause.getMessage(),cause);
        } catch (Exception e) {
            throw new SpecException("Unexpected error on proxied context invocation: " + e.getMessage(),e);
        }
    }
View Full Code Here

Examples of ar.com.dgarcia.javaspec.impl.exceptions.SpecException

        Object firstArgument = this.args[0];
        Supplier<Object> variableDefinition = null;
        try {
            variableDefinition = (Supplier<Object>) firstArgument;
        } catch (ClassCastException e) {
            throw new SpecException("Invocation should have only a supplier argument",e);
        }
        return variableDefinition;
    }
View Full Code Here

Examples of com.bazaarvoice.jolt.exception.SpecException

    private final Traversr traversr;

    public PathEvaluatingTraversal( String dotNotation ) {

        if ( dotNotation.contains("*") || dotNotation.contains("$")) {
            throw new SpecException("DotNotation (write key) can not contain '*' or '$'.");
        }

        List<PathElement> paths;
        Traversr trav;

        if ( StringTools.isNotBlank( dotNotation ) ) {

            // Compute the path elements.
            paths = ShiftrSpec.parseDotNotationRHS( dotNotation );

            // Use the canonical versions of the path elements to create the Traversr
            List<String> traversrPaths = new ArrayList<String>( paths.size() );
            for ( PathElement pe : paths ) {
                traversrPaths.add( pe.getCanonicalForm() );
            }
            trav = createTraversr( traversrPaths );
        }
        else {
            paths = Collections.emptyList();
            trav = createTraversr( Arrays.asList( "" ) );
        }

        List<EvaluatablePathElement> evalPaths = new ArrayList<EvaluatablePathElement>( paths.size() );
        for( PathElement pe : paths ) {
            if ( ! ( pe instanceof EvaluatablePathElement ) ) {
                throw new SpecException( "RHS key=" + pe.getRawKey() + " is not a valid RHS key." );
            }

            evalPaths.add( (EvaluatablePathElement) pe );
        }

View Full Code Here

Examples of com.bazaarvoice.jolt.exception.SpecException

     * @param index the index of the chainrEntryObj, used in reporting errors
     */
    public ChainrEntry( int index, Object chainrEntryObj ) {

        if ( ! (chainrEntryObj instanceof Map ) ) {
            throw new SpecException( "JOLT ChainrEntry expects a JSON map - Malformed spec" + getErrorMessageIndexSuffix() );
        }

        @SuppressWarnings( "unchecked" ) // We know it is a Map due to the check above
        Map<String,Object> chainrEntryMap = (Map<String, Object>) chainrEntryObj;

        this.index = index;

        String opString = extractOperationString( ChainrEntry.OPERATION_KEY, chainrEntryMap );

        if ( opString == null ) {
            throw new SpecException( "JOLT Chainr 'operation' must implement Transform or ContextualTransform" + getErrorMessageIndexSuffix() );
        }

        if ( STOCK_TRANSFORMS.containsKey( opString ) ) {
            operationClassName = STOCK_TRANSFORMS.get( opString );
        }
        else {
            operationClassName = opString;
        }

        joltTransformClass = loadJoltTransformClass();

        spec = chainrEntryMap.get( ChainrEntry.SPEC_KEY );

        isSpecDriven = SpecDriven.class.isAssignableFrom( joltTransformClass );
        if ( isSpecDriven && ! chainrEntryMap.containsKey( SPEC_KEY ) ) {
            throw new SpecException( "JOLT Chainr - Transform className:" + joltTransformClass.getCanonicalName() + " requires a spec" + getErrorMessageIndexSuffix() );
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.