Package org.springframework.roo.classpath.itd

Examples of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder


        builder.getImportRegistrationResolver().addImport(EQUALS_BUILDER);

        final String typeName = destination.getSimpleTypeName();

        // Create the method
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine("if (!(" + OBJECT_NAME + " instanceof "
                + typeName + ")) {");
        bodyBuilder.indent();
        bodyBuilder.appendFormalLine("return false;");
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");
        bodyBuilder.appendFormalLine("if (this == " + OBJECT_NAME + ") {");
        bodyBuilder.indent();
        bodyBuilder.appendFormalLine("return true;");
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");
        bodyBuilder.appendFormalLine(typeName + " rhs = (" + typeName + ") "
                + OBJECT_NAME + ";");

        final StringBuilder builder = new StringBuilder(
                "return new EqualsBuilder()");
        if (annotationValues.isAppendSuper()) {
            builder.append(".appendSuper(super.equals(" + OBJECT_NAME + "))");
        }
        for (final FieldMetadata field : locatedFields) {
            builder.append(".append(" + field.getFieldName() + ", rhs."
                    + field.getFieldName() + ")");
        }
        builder.append(".isEquals();");

        bodyBuilder.appendFormalLine(builder.toString());

        return new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
                EQUALS_METHOD_NAME, BOOLEAN_PRIMITIVE,
                AnnotatedJavaType.convertFromJavaTypes(parameterType),
                parameterNames, bodyBuilder);
View Full Code Here


        }

        builder.getImportRegistrationResolver().addImport(HASH_CODE_BUILDER);

        // Create the method
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

        final StringBuilder builder = new StringBuilder(
                "return new HashCodeBuilder()");
        if (annotationValues.isAppendSuper()) {
            builder.append(".appendSuper(super.hashCode())");
        }
        for (final FieldMetadata field : locatedFields) {
            builder.append(".append(" + field.getFieldName() + ")");
        }
        builder.append(".toHashCode();");

        bodyBuilder.appendFormalLine(builder.toString());

        return new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
                HASH_CODE_METHOD_NAME, INT_PRIMITIVE, bodyBuilder);
    }
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", dod."
                        + dataOnDemandMetadata
                                .getRandomPersistentEntityMethod()
                                .getMethodName().getSymbolName() + "());");
        bodyBuilder.appendFormalLine("long count = "
                + countMethod.getMethodCall() + ";");
        bodyBuilder
                .appendFormalLine("Assert.assertTrue(\"Counter for '"
                        + entityName
                        + "' incorrectly reported there were no entries\", count > 0);");

        countMethod.copyAdditionsTo(builder, governorTypeDetails);
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", dod."
                        + dataOnDemandMetadata
                                .getRandomPersistentEntityMethod()
                                .getMethodName().getSymbolName() + "());");
        bodyBuilder.appendFormalLine("long count = "
                + countMethod.getMethodCall() + ";");
        bodyBuilder
                .appendFormalLine("Assert.assertTrue(\"Too expensive to perform a find all test for '"
                        + entityName
                        + "', as there are \" + count + \" entries; set the findAllMaximum to exceed this value or set findAll=false on the integration test annotation to disable the test\", count < "
                        + annotationValues.getFindAllMaximum() + ");");
        bodyBuilder.appendFormalLine("List<" + entityName + "> result = "
                + findAllMethod.getMethodCall() + ";");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Find all method for '"
                        + entityName + "' illegally returned null\", result);");
        bodyBuilder
                .appendFormalLine("Assert.assertTrue(\"Find all method for '"
                        + entityName
                        + "' failed to return any data\", result.size() > 0);");

        findAllMethod.copyAdditionsTo(builder, governorTypeDetails);
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", dod."
                        + dataOnDemandMetadata
                                .getRandomPersistentEntityMethod()
                                .getMethodName().getSymbolName() + "());");
        bodyBuilder.appendFormalLine("long count = "
                + countMethod.getMethodCall() + ";");
        bodyBuilder.appendFormalLine("if (count > 20) count = 20;");
        bodyBuilder.appendFormalLine("int firstResult = 0;");
        bodyBuilder.appendFormalLine("int maxResults = (int) count;");
        bodyBuilder.appendFormalLine("List<" + entityName + "> result = "
                + findEntriesMethod.getMethodCall() + ";");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Find entries method for '"
                        + entityName + "' illegally returned null\", result);");
        bodyBuilder
                .appendFormalLine("Assert.assertEquals(\"Find entries method for '"
                        + entityName
                        + "' returned an incorrect number of entries\", count, result.size());");

        findEntriesMethod.copyAdditionsTo(builder, governorTypeDetails);
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine(entityName
                + " obj = dod."
                + dataOnDemandMetadata.getRandomPersistentEntityMethod()
                        .getMethodName().getSymbolName() + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", obj);");
        bodyBuilder.appendFormalLine(identifierAccessorMethod.getReturnType()
                .getSimpleTypeName()
                + " id = obj."
                + identifierAccessorMethod.getMethodName().getSymbolName()
                + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to provide an identifier\", id);");
        bodyBuilder.appendFormalLine("obj = " + findMethod.getMethodCall()
                + ";");
        bodyBuilder.appendFormalLine("Assert.assertNotNull(\"Find method for '"
                + entityName
                + "' illegally returned null for id '\" + id + \"'\", obj);");
        bodyBuilder.appendFormalLine("Assert.assertEquals(\"Find method for '"
                + entityName
                + "' returned the incorrect identifier\", id, obj."
                + identifierAccessorMethod.getMethodName().getSymbolName()
                + "());");
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine(entityName
                + " obj = dod."
                + dataOnDemandMetadata.getRandomPersistentEntityMethod()
                        .getMethodName().getSymbolName() + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", obj);");
        bodyBuilder.appendFormalLine(identifierAccessorMethod.getReturnType()
                .getSimpleTypeName()
                + " id = obj."
                + identifierAccessorMethod.getMethodName().getSymbolName()
                + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to provide an identifier\", id);");
        bodyBuilder.appendFormalLine("obj = " + findMethod.getMethodCall()
                + ";");
        bodyBuilder.appendFormalLine("Assert.assertNotNull(\"Find method for '"
                + entityName
                + "' illegally returned null for id '\" + id + \"'\", obj);");
        bodyBuilder.appendFormalLine("boolean modified =  dod."
                + dataOnDemandMetadata.getModifyMethod().getMethodName()
                        .getSymbolName() + "(obj);");

        bodyBuilder
                .appendFormalLine(versionAccessorMethod.getReturnType()
                        .getSimpleTypeName()
                        + " currentVersion = obj."
                        + versionAccessorMethod.getMethodName().getSymbolName()
                        + "();");
        bodyBuilder.appendFormalLine(flushMethod.getMethodCall() + ";");
        if (JdkJavaType.isDateField(versionType)) {
            bodyBuilder
                    .appendFormalLine("Assert.assertTrue(\"Version for '"
                            + entityName
                            + "' failed to increment on flush directive\", (currentVersion != null && obj."
                            + versionAccessorMethod.getMethodName()
                                    .getSymbolName()
                            + "().after(currentVersion)) || !modified);");
        }
        else if (JavaType.STRING.equals(versionType)) {
            bodyBuilder
                    .appendFormalLine("Assert.assertTrue(\"Version for '"
                            + entityName
                            + "' failed to increment on flush directive\", (currentVersion != null && !currentVersion.equals(obj."
                            + versionAccessorMethod.getMethodName()
                                    .getSymbolName() + "())) || !modified);");
        }
        else {
            bodyBuilder
                    .appendFormalLine("Assert.assertTrue(\"Version for '"
                            + entityName
                            + "' failed to increment on flush directive\", (currentVersion != null && obj."
                            + versionAccessorMethod.getMethodName()
                                    .getSymbolName()
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine(entityName
                + " obj = dod."
                + dataOnDemandMetadata.getRandomPersistentEntityMethod()
                        .getMethodName().getSymbolName() + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", obj);");
        bodyBuilder.appendFormalLine(identifierAccessorMethod.getReturnType()
                .getSimpleTypeName()
                + " id = obj."
                + identifierAccessorMethod.getMethodName().getSymbolName()
                + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to provide an identifier\", id);");
        bodyBuilder.appendFormalLine("obj = " + findMethod.getMethodCall()
                + ";");
        bodyBuilder.appendFormalLine("boolean modified =  dod."
                + dataOnDemandMetadata.getModifyMethod().getMethodName()
                        .getSymbolName() + "(obj);");

        bodyBuilder
                .appendFormalLine(versionAccessorMethod.getReturnType()
                        .getSimpleTypeName()
                        + " currentVersion = obj."
                        + versionAccessorMethod.getMethodName().getSymbolName()
                        + "();");

        final String castStr = entityHasSuperclass ? "(" + entityName + ")"
                : "";
        bodyBuilder.appendFormalLine(entityName + " merged = " + castStr
                + mergeMethod.getMethodCall() + ";");

        if (flushMethod != null) {
            bodyBuilder.appendFormalLine(flushMethod.getMethodCall() + ";");
            flushMethod.copyAdditionsTo(builder, governorTypeDetails);
        }

        bodyBuilder
                .appendFormalLine("Assert.assertEquals(\"Identifier of merged object not the same as identifier of original object\", merged."
                        + identifierAccessorMethod.getMethodName()
                                .getSymbolName() + "(), id);");
        if (JdkJavaType.isDateField(versionType)) {
            bodyBuilder
                    .appendFormalLine("Assert.assertTrue(\"Version for '"
                            + entityName
                            + "' failed to increment on merge and flush directive\", (currentVersion != null && obj."
                            + versionAccessorMethod.getMethodName()
                                    .getSymbolName()
                            + "().after(currentVersion)) || !modified);");
        }
        else if (JavaType.STRING.equals(versionType)) {
            bodyBuilder
                    .appendFormalLine("Assert.assertTrue(\"Version for '"
                            + entityName
                            + "' failed to increment on flush directive\", (currentVersion != null && !currentVersion.equals(obj."
                            + versionAccessorMethod.getMethodName()
                                    .getSymbolName() + "())) || !modified);");
        }
        else {
            bodyBuilder
                    .appendFormalLine("Assert.assertTrue(\"Version for '"
                            + entityName
                            + "' failed to increment on merge and flush directive\", (currentVersion != null && obj."
                            + versionAccessorMethod.getMethodName()
                                    .getSymbolName()
View Full Code Here

        annotations.add(new AnnotationMetadataBuilder(TEST));

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", dod."
                        + dataOnDemandMetadata
                                .getRandomPersistentEntityMethod()
                                .getMethodName().getSymbolName() + "());");
        bodyBuilder.appendFormalLine(entityName
                + " obj = dod."
                + dataOnDemandMetadata.getNewTransientEntityMethod()
                        .getMethodName().getSymbolName()
                + "(Integer.MAX_VALUE);");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to provide a new transient entity\", obj);");

        if (!hasEmbeddedIdentifier) {
            bodyBuilder.appendFormalLine("Assert.assertNull(\"Expected '"
                    + entityName + "' identifier to be null\", obj."
                    + identifierAccessorMethod.getMethodName().getSymbolName()
                    + "());");
        }

        bodyBuilder.appendFormalLine("try {");
        bodyBuilder.indent();
        bodyBuilder.appendFormalLine(persistMethod.getMethodCall() + ";");
        bodyBuilder.indentRemove();
        bodyBuilder
                .appendFormalLine("} catch (final ConstraintViolationException e) {");
        bodyBuilder.indent();
        bodyBuilder
                .appendFormalLine("final StringBuilder msg = new StringBuilder();");
        bodyBuilder
                .appendFormalLine("for (Iterator<ConstraintViolation<?>> iter = e.getConstraintViolations().iterator(); iter.hasNext();) {");
        bodyBuilder.indent();
        bodyBuilder
                .appendFormalLine("final ConstraintViolation<?> cv = iter.next();");
        bodyBuilder
                .appendFormalLine("msg.append(\"[\").append(cv.getRootBean().getClass().getName()).append(\".\").append(cv.getPropertyPath()).append(\": \").append(cv.getMessage()).append(\" (invalid value = \").append(cv.getInvalidValue()).append(\")\").append(\"]\");");
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");
        bodyBuilder
                .appendFormalLine("throw new IllegalStateException(msg.toString(), e);");
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");

        if (flushMethod != null) {
            bodyBuilder.appendFormalLine(flushMethod.getMethodCall() + ";");
            flushMethod.copyAdditionsTo(builder, governorTypeDetails);
        }

        bodyBuilder.appendFormalLine("Assert.assertNotNull(\"Expected '"
                + entityName + "' identifier to no longer be null\", obj."
                + identifierAccessorMethod.getMethodName().getSymbolName()
                + "());");

        persistMethod.copyAdditionsTo(builder, governorTypeDetails);
View Full Code Here

        }

        final String entityName = annotationValues.getEntity()
                .getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        bodyBuilder.appendFormalLine(entityName
                + " obj = dod."
                + dataOnDemandMetadata.getRandomPersistentEntityMethod()
                        .getMethodName().getSymbolName() + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to initialize correctly\", obj);");
        bodyBuilder.appendFormalLine(identifierAccessorMethod.getReturnType()
                .getSimpleTypeName()
                + " id = obj."
                + identifierAccessorMethod.getMethodName().getSymbolName()
                + "();");
        bodyBuilder
                .appendFormalLine("Assert.assertNotNull(\"Data on demand for '"
                        + entityName
                        + "' failed to provide an identifier\", id);");
        bodyBuilder.appendFormalLine("obj = " + findMethod.getMethodCall()
                + ";");
        bodyBuilder.appendFormalLine(removeMethod.getMethodCall() + ";");

        if (flushMethod != null) {
            bodyBuilder.appendFormalLine(flushMethod.getMethodCall() + ";");
            flushMethod.copyAdditionsTo(builder, governorTypeDetails);
        }

        bodyBuilder.appendFormalLine("Assert.assertNull(\"Failed to remove '"
                + entityName + "' with identifier '\" + id + \"'\", "
                + findMethod.getMethodCall() + ");");

        removeMethod.copyAdditionsTo(builder, governorTypeDetails);
        findMethod.copyAdditionsTo(builder, governorTypeDetails);
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder

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.