methodBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.PRIMARY)); methodBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
/** * This method returns the getXmlIdentityInfo() method. * * @return MethodMetadata that contains the getXmlIdentityInfoMethod */ public MethodMetadata getXmlIdentityInfoMethod() { // Check if already exists if (xmlIdentityInfoMethod != null) { return xmlIdentityInfoMethod; } // If not, generate a new one InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); // return getClass().getName() + ":" + getId(); bodyBuilder.appendFormalLine(String.format("return getClass().getName() + \":\" + %s();", identifierAccessor.getMethodName())); MethodMetadataBuilder method = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("getXmlIdentityInfo"), JavaType.STRING, bodyBuilder); method.addAnnotation(new AnnotationMetadataBuilder(JavaType.XML_ID)); AnnotationMetadataBuilder xmlAttributeAnnotation = new AnnotationMetadataBuilder(JavaType.XML_ATTRIBUTE); xmlAttributeAnnotation.addStringAttribute("name", "id"); method.addAnnotation(xmlAttributeAnnotation); CommentStructure comment = new CommentStructure(); comment.addComment(new JavadocComment("Must return an unique ID across all entities"), CommentLocation.BEGINNING); method.setCommentStructure(comment); xmlIdentityInfoMethod = method.build(); return xmlIdentityInfoMethod; }
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(JavaType.OVERRIDE));
AnnotationMetadataBuilder transactionalAnnotation = new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL); methodBuilder.addAnnotation(transactionalAnnotation);
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
parameterNames, bodyBuilder); methodBuilder.addAnnotation(ANN_MODEL_ATTRIBUTE);
/** * Builds a method to test count method. * * @return {@link MethodMetadata} */ private MethodMetadata getCountTestMethod() { MethodMetadata method = getGovernorMethod(COUNT_TEST_METHOD_NAME); if (method != null) { return method; } InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); // Verify bodyBuilder.appendFormalLine("// Verify"); // assertThat(repository.count()).as("Check there are available 'Pet' entries").isGreaterThan(0); bodyBuilder.appendFormalLine( "%s(%s().count()).as(\"Check there are available '%s' entries\").isGreaterThan(0);", getNameOfJavaType(ASSERT_THAT), getAccessorMethod(this.repositoryField).getMethodName(), getNameOfJavaType(this.entity)); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, COUNT_TEST_METHOD_NAME, JavaType.VOID_PRIMITIVE, bodyBuilder); // Add @Test methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST)); return methodBuilder.build(); }
new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName( StringUtils.uncapitalize(endpoint.getSimpleTypeName())), JavaType.ENDPOINT, bodyBuilder); endpointMethod.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));
/** * Obtains a method annotated with @After for doing the test class teardown phase * after finishing each test. * * @return {@link MethodMetadataBuilder} */ private MethodMetadataBuilder getCleanMethod() { final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.newLine(); bodyBuilder.appendFormalLine("// Clean needed after executing each test method"); bodyBuilder.appendFormalLine("// To be implemented by developer"); bodyBuilder.newLine(); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("clean"), JavaType.VOID_PRIMITIVE, bodyBuilder); // Add @After methodBuilder.addAnnotation(new AnnotationMetadataBuilder(AFTER).build()); // Add comment CommentStructure comment = new CommentStructure(); JavadocComment javaDocComment = new JavadocComment( "This method will be automatically executed after each test method for freeing resources allocated with @Before annotated method."); comment.addComment(javaDocComment, CommentLocation.BEGINNING); methodBuilder.setCommentStructure(comment); return methodBuilder; }
/** * Builds and returns a method used to instance a DataOnDemand class using * {@link EntityManager} and `@Bean` annotation. * * @param dodType * the class to inject in the Spring context. * @return the MethodMetadata to add to ITD. */ private MethodMetadata getDodTypeBeanCreationMethod(JavaType dodType) { // Define methodName final JavaSymbolName methodName = new JavaSymbolName(StringUtils.uncapitalize(dodType.getSimpleTypeName())); // Check if method exists MethodMetadata existingMethod = getGovernorMethod(methodName); if (existingMethod != null) { return existingMethod; } // Add body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("return new %s(%s());", getNameOfJavaType(dodType), getAccessorMethod(getEntityManagerField().build()).getMethodName()); // Create method MethodMetadataBuilder method = new MethodMetadataBuilder(this.getId(), Modifier.PUBLIC, methodName, dodType, bodyBuilder); // Add annotation method.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN)); return method.build(); }
/** * Builds a method annotated with `@Before` which checks if data-on-demand * field has initialized correctly. * * @return {@link MethodMetadata} */ private MethodMetadata getBeforeMethod() { MethodMetadata method = getGovernorMethod(BEFORE_METHOD_NAME); if (method != null) { return method; } InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); // assertThat(dod.getRandomPet()) bodyBuilder.appendFormalLine("%s(%s().%s())", getNameOfJavaType(ASSERT_THAT, true), getAccessorMethod(this.dodField).getMethodName(), this.getRandomMethodName); // .as("Check data on demand for 'Pet' initializes correctly by getting a random Pet") bodyBuilder.indent(); bodyBuilder.appendFormalLine( ".as(\"Check data on demand for '%1$s' initializes correctly by getting a random %1$s\")", getNameOfJavaType(this.entity)); // .isNotNull(); bodyBuilder.appendFormalLine(".isNotNull();"); bodyBuilder.reset(); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, BEFORE_METHOD_NAME, JavaType.VOID_PRIMITIVE, bodyBuilder); // Add @Before methodBuilder.addAnnotation(new AnnotationMetadataBuilder(BEFORE)); return methodBuilder.build(); }
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
methodBuilder.addAnnotation(new AnnotationMetadataBuilder(TEST));
new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName( "openEntityManagerInViewFilter"), filterRegistrationBeanType, bodyBuilder); method.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.BEAN));