diff --git a/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoInitToWebVisitor.java b/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoInitToWebVisitor.java index bb13f0b..6c8e39c 100644 --- a/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoInitToWebVisitor.java +++ b/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoInitToWebVisitor.java @@ -1,35 +1,47 @@ package com.gepardec.wor.lord.stdh.v2.visitors; +import com.gepardec.wor.lord.stdh.v2.common.Accessor; import com.gepardec.wor.lord.stdh.v2.common.Accumulator; import com.gepardec.wor.lord.util.ParserUtil; import org.openrewrite.ExecutionContext; -import org.openrewrite.Tree; +import org.openrewrite.java.AddImport; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.RemoveImport; +import org.openrewrite.java.tree.CoordinateBuilder; import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaCoordinates; import org.openrewrite.java.tree.Statement; import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; + +import static org.openrewrite.java.JavaTemplate.apply; public class BinaryDtoInitToWebVisitor extends JavaIsoVisitor { private String variableName; - private boolean usesStdh; + private Accessor accessor; private Accumulator accumulator; + private List settersAdded = new LinkedList<>(); + private static final String OBJECT_FACTORY_NAME = "objectFactory"; - private static final String NEW_WEB_DTO = "#{} #{} = new #{}();"; + private static final String NEW_WEB_DTO = "%s %s = new %s();"; - public static final String SET_NEW_STDH_TEMPLATE = "\n#{}.setOmStandardRequestHeader(%s.createOmStandardRequestHeader());"; - private static final String NEW_WEB_DTO_WITH_STDH_TEMPLATE = NEW_WEB_DTO + SET_NEW_STDH_TEMPLATE; + public static final String SETTER_TEMPLATE = "%s.%s(%s);"; - public BinaryDtoInitToWebVisitor(String variableName, boolean usesStdh, Accumulator accumulator) { + public BinaryDtoInitToWebVisitor(String variableName, Accessor accessor, Accumulator accumulator) { + this.variableName = variableName; + this.accessor = accessor; + this.accumulator = accumulator; + } + + public BinaryDtoInitToWebVisitor(String variableName, Accumulator accumulator) { this.variableName = variableName; - this.usesStdh = usesStdh; this.accumulator = accumulator; } @@ -37,6 +49,8 @@ public BinaryDtoInitToWebVisitor(String variableName, boolean usesStdh, Accumula public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) { method = super.visitMethodDeclaration(method, ctx); List statements = method.getBody().getStatements(); + + boolean createsWebDto = false; Optional dtoDeclarationsOptional = statements.stream() .filter(J.VariableDeclarations.class::isInstance) .map(J.VariableDeclarations.class::cast) @@ -48,39 +62,91 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex } J.VariableDeclarations dtoDeclarations = dtoDeclarationsOptional.get(); - String binaryType = dtoDeclarations.getType().toString(); + String dtoType = dtoDeclarationsOptional + .map(declaration -> declaration.getTypeExpression().toString()) + .get(); - Optional wsdlTypeOptional = accumulator.getWsdlTypeFromBinary(binaryType); + String dtoShortType = Accumulator.shortNameOfFullyQualified(dtoType); - if (wsdlTypeOptional.isEmpty()) { + String wsdlType = null; + if (dtoShortType.contains("Dto")) { + createsWebDto = true; + String binaryType = dtoDeclarations.getType().toString(); + Optional wsdlTypeOptional = accumulator.getWsdlTypeFromBinary(binaryType); + + if (wsdlTypeOptional.isEmpty()) { + return method; + } + + wsdlType = wsdlTypeOptional.get(); + + doAfterVisit(new AddImport<>(wsdlType, null, false)); + doAfterVisit(new ClassUsingBinaryDtoToWebVisitor( + OBJECT_FACTORY_NAME, + wsdlType.substring(0, wsdlType.lastIndexOf('.')))); + doAfterVisit(new RemoveImport<>(binaryType, true)); + } + if (accumulator.getIOTypesShort().contains(dtoShortType)) { + wsdlType = dtoType; + } + + if (wsdlType == null) { return method; } - String wsdlType = wsdlTypeOptional.get(); - String shortWsdlType = Accumulator.shortNameOfFullyQualified(wsdlType); - if (usesStdh) { - doAfterVisit(new ClassUsingBinaryDtoToWebVisitor(OBJECT_FACTORY_NAME, packageOf(wsdlType))); + Optional template = getCreateDtoJavaTemplate(Accumulator.shortNameOfFullyQualified(wsdlType), createsWebDto); + + CoordinateBuilder.VariableDeclarations coordinateBuilder = dtoDeclarations.getCoordinates(); + JavaCoordinates coordinates = createsWebDto ? coordinateBuilder.replace() : coordinateBuilder.after(); + J.MethodDeclaration usedMethodDeclaration = method; + return template + .map(javaTemplate -> javaTemplate.apply(updateCursor(usedMethodDeclaration), coordinates)) + .map(J.MethodDeclaration.class::cast) + .orElse(method); + } + + + public String createSetterStatement(Accessor accessor) { + if (accessor.getParent().isEmpty()) { + return ""; } + String getter = accessor.getParent().get().getName(); + String setter = "set" + getter.substring(getter.startsWith("is") ? 2 : 3); +// settersAdded.add(setter); + + String[] typeParts = accessor.getClazz().split("\\."); + String objectFactoryCreate = "%s.create%s()".formatted(OBJECT_FACTORY_NAME, typeParts[typeParts.length - 1]); - maybeAddImport(wsdlType); - doAfterVisit(new RemoveImport<>(binaryType, true)); - J.MethodDeclaration declarationUsingWebDto = getCreateDtoJavaTemplate(wsdlType).apply( - updateCursor(method), - dtoDeclarations.getCoordinates().replace(), - getCreateDtoJavaTemplateParams(shortWsdlType) - ); - return declarationUsingWebDto; + return SETTER_TEMPLATE.formatted(variableName, setter, objectFactoryCreate); } private Object[] getCreateDtoJavaTemplateParams(String shortWsdlType) { - return usesStdh ? - new Object[]{shortWsdlType, variableName, shortWsdlType, variableName} : - new Object[]{shortWsdlType, variableName, shortWsdlType}; + return accessor == null ? + new Object[]{shortWsdlType, variableName, shortWsdlType} : + new Object[]{shortWsdlType, variableName, shortWsdlType, variableName}; + } - private JavaTemplate getCreateDtoJavaTemplate(String wsdlType) { - String template = usesStdh ? String.format(NEW_WEB_DTO_WITH_STDH_TEMPLATE, OBJECT_FACTORY_NAME) : NEW_WEB_DTO; - return javaTemplateOf(template, wsdlType); + private Optional getCreateDtoJavaTemplate(String wsdlType, boolean createsWebDto) { + StringBuilder template = new StringBuilder(); + + if (createsWebDto) { + template.append(NEW_WEB_DTO.formatted(wsdlType, variableName, wsdlType)); + } + if (accessor != null) + template + .append(createsWebDto ? "\n" : "") + .append(createSetterStatement((accessor))); + + if (template.isEmpty()) { + return Optional.empty(); + } + + return Optional.of(JavaTemplate.builder(template.toString()) + .javaParser(ParserUtil.createParserWithRuntimeClasspath()) + .imports(wsdlType) + .contextSensitive() + .build()); } private static JavaTemplate javaTemplateOf(String template, String wsdlType) { diff --git a/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoToWebVisitor.java b/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoToWebVisitor.java index b0338a1..e2265da 100644 --- a/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoToWebVisitor.java +++ b/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/BinaryDtoToWebVisitor.java @@ -20,8 +20,6 @@ public class BinaryDtoToWebVisitor extends JavaIsoVisitor { private static final String STDH_GETTER_NAME = "getOmStandardRequestHeader"; - private static final String BINARY_DTO_NAME = "LaqamhsuDto"; - private static final JavaTemplate STDH_SETTER = JavaTemplate .builder("#{}.#{}(#{});") .javaParser(ParserUtil.createParserWithRuntimeClasspath()) @@ -53,13 +51,17 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu String type = method.getSelect().getType().toString(); String methodName = method.getSimpleName(); - String newSetter = generateWebDtoSetter(methodName, type); + Optional accessor = findAccessor(methodName, type); + if (accessor.isEmpty()) { + return method; + } + String newSetter = generateWebDtoSetter(accessor.get(), methodName); if (isNotNested(methodName)) { - doAfterVisit(new BinaryDtoInitToWebVisitor(instanceName, false, accumulator)); + doAfterVisit(new BinaryDtoInitToWebVisitor(instanceName, accumulator)); return method; } - doAfterVisit(new BinaryDtoInitToWebVisitor(instanceName, true, accumulator)); + doAfterVisit(new BinaryDtoInitToWebVisitor(instanceName, accessor.get(), accumulator)); String argument = method.getArguments().get(0).printTrimmed(getCursor()); return STDH_SETTER.apply(updateCursor(method), @@ -70,13 +72,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu ); } - private String generateWebDtoSetter(String methodName, String methodType) { - Optional accessor = findAccessor(methodName, methodType); - if (accessor.isEmpty()) { - return methodName; - } - - Optional nextAccessor = accessor.get().getParent(); + private String generateWebDtoSetter(Accessor accessor, String methodName) { + Optional nextAccessor = accessor.getParent(); StringBuilder stringBuilder = new StringBuilder(); while (nextAccessor.isPresent()) { Accessor accessorIteration = nextAccessor.get(); diff --git a/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/IOTypesSearchVisitor.java b/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/IOTypesSearchVisitor.java index 956f4c4..bd639e7 100644 --- a/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/IOTypesSearchVisitor.java +++ b/src/main/java/com/gepardec/wor/lord/stdh/v2/visitors/IOTypesSearchVisitor.java @@ -3,6 +3,7 @@ import com.gepardec.wor.lord.stdh.v2.common.Accessor; import com.gepardec.wor.lord.stdh.v2.common.Accumulator; import com.gepardec.wor.lord.stdh.v2.common.Wsdl2JavaService; +import com.gepardec.wor.lord.util.LSTUtil; import org.jetbrains.annotations.NotNull; import org.openrewrite.ExecutionContext; import org.openrewrite.internal.lang.Nullable; @@ -26,102 +27,61 @@ public IOTypesSearchVisitor(Accumulator accumulator) { @Override public @Nullable J.ClassDeclaration visitClassDeclaration(@Nullable J.ClassDeclaration classDeclaration, ExecutionContext ctx) { - - classDeclaration = super.visitClassDeclaration(classDeclaration, ctx); - String className = classDeclaration.getSimpleName(); - - if (!isInterface(classDeclaration)) { + if (!LSTUtil.isInterface(classDeclaration)) { return classDeclaration; } - List methods = getMethods(classDeclaration); - - List requestTypes = getParameterTypes(methods); - List responseTypes = getReturnTypes(methods); - - - Wsdl2JavaService service = new Wsdl2JavaService(className, requestTypes, responseTypes); + Wsdl2JavaService service = createServiceWithAccessors(classDeclaration); accumulator.addService(service); - service.addAccessors(getAccessors(classDeclaration)); return classDeclaration; } - static boolean isInterface(J.ClassDeclaration classDeclaration) { - return classDeclaration.getKind().equals(J.ClassDeclaration.Kind.Type.Interface); - } - - static @NotNull List getMethods(J.ClassDeclaration classDeclaration) { - return classDeclaration.getBody().getStatements().stream() - .filter(J.MethodDeclaration.class::isInstance) - .map(J.MethodDeclaration.class::cast) - .collect(Collectors.toList()); - } - - static @NotNull List getReturnTypes(List methods) { - return methods.stream() - .map(m -> m.getReturnTypeExpression().toString()) - .collect(Collectors.toList()); + private @NotNull Wsdl2JavaService createServiceWithAccessors(J.ClassDeclaration classDeclaration) { + String className = classDeclaration.getSimpleName(); + Wsdl2JavaService service = createService(LSTUtil.getMethodDeclarations(classDeclaration), className); + service.addAccessors(createAccessors(classDeclaration)); + return service; } - static @NotNull List getParameterTypes(List methods) { - List requestTypes = methods.stream().flatMap(m -> m.getParameters().stream()) - .filter(J.VariableDeclarations.class::isInstance) - .map(J.VariableDeclarations.class::cast) - .map(J.VariableDeclarations::getType) - .map(type -> type.toString()) - .distinct() - .collect(Collectors.toList()); - return requestTypes; + private static @NotNull Wsdl2JavaService createService(List methods, String className) { + List requestTypes = LSTUtil.getParameterTypes(methods); + List responseTypes = LSTUtil.getReturnTypes(methods); + Wsdl2JavaService service = new Wsdl2JavaService(className, requestTypes, responseTypes); + return service; } - List getAccessors(J.ClassDeclaration classDeclaration) { + List createAccessors(J.ClassDeclaration classDeclaration) { List methods = classDeclaration.getType().getMethods(); - return getAccessors(methods, null, classDeclaration.getSimpleName()).stream() + return createAccessors(methods, null, classDeclaration.getSimpleName()).stream() .filter(accessor -> !accessor.getClazz().equals(classDeclaration.getType().toString())) .collect(Collectors.toList()); } - private static List getAccessors(List methods, Accessor parent, String rootName) { - List accessors = new LinkedList<>(); - - Accessor filteredParent = parent != null && parent.getClazz().contains(rootName) ? null : parent; - - List methodsReturningOtherTypes = methods.stream() - .filter(method -> !hasSubDtoReturnType(method)) - .collect(Collectors.toList()); + private static List createAccessors(List methods, Accessor parent, String rootName) { + Optional filteredParent = removeRootParent(parent, rootName); - methodsReturningOtherTypes.stream() - .filter(method -> method.getName().startsWith("get")) - .map(method -> new Accessor(method.getName(), method.getDeclaringType().getFullyQualifiedName(), filteredParent)) - .forEach(accessors::add); + List accessors = extractMethodsNotReturningSubDtos(methods, filteredParent); - List methodsReturningSubDtos = methods.stream() - .filter(method -> hasSubDtoReturnType(method) || (parent == null && - method.getParameterTypes().stream() - .anyMatch(IOTypesSearchVisitor::isDtoType))) - .collect(Collectors.toList()); + List methodsReturningSubDtos = extractMethodsReturningSubDtos(methods, parent); for (JavaType.Method method : methodsReturningSubDtos ) { JavaType returnType = method.getReturnType(); - List types = new LinkedList<>(); + List types = new LinkedList<>(); if (returnType instanceof JavaType.Class clazz) { types.add(clazz); } - if (parent == null) { - types.addAll(method.getParameterTypes().stream() - .filter(IOTypesSearchVisitor::isDtoType) - .map(JavaType.Class.class::cast) - .collect(Collectors.toList())); + types.addAll(getAllDtoParameters(method)); } - types.forEach(clazz -> accessors.addAll(getAccessors( + types.stream() + .map(clazz -> createAccessors( clazz.getMethods(), - new Accessor(method.getName(), method.getDeclaringType().getFullyQualifiedName(), filteredParent), - rootName) - )); + createParentAccessor(method, filteredParent.orElse(null)), + rootName)) + .forEach(accessors::addAll); } @@ -129,19 +89,62 @@ private static List getAccessors(List methods, Access return accessors; } - private static boolean hasSubDtoReturnType(JavaType.Method method) { - JavaType returnType = method.getReturnType(); - return isDtoType(returnType) && declaringTypeIsNotType(method, returnType); - } + private static @NotNull List extractMethodsReturningSubDtos(List methods, Accessor parent) { + return methods.stream() + .filter(method -> hasSubDtoReturnType(method) || (parent == null && + method.getParameterTypes().stream() + .anyMatch(IOTypesSearchVisitor::isDtoType))) + .collect(Collectors.toList()); + } - private static boolean declaringTypeIsNotType(JavaType.Method method, JavaType type) { - if (type instanceof JavaType.Class clazz) { - String className = clazz.getFullyQualifiedName(); - return !className.equals(method.getDeclaringType().toString()); - } - return false; + private static @NotNull List getAllDtoParameters(JavaType.Method method) { + return method.getParameterTypes().stream() + .filter(IOTypesSearchVisitor::isDtoType) + .map(JavaType.Class.class::cast) + .collect(Collectors.toList()); } + private static List extractMethodsNotReturningSubDtos(List methods, Optional filteredParent) { + List methodsReturningOtherTypes = methods.stream() + .filter(method -> !hasSubDtoReturnType(method)) + .collect(Collectors.toList()); + + return methodsReturningOtherTypes.stream() + .filter(method -> { + String get = "get"; + return LSTUtil.methodNameStartsWith(method, get); + }) + .map(method -> + filteredParent + .map(accessor -> createParentAccessor(method, accessor)) + .orElseGet(() -> createAccessor(method)) + ).collect(Collectors.toList()); + } + + private static @NotNull Accessor createParentAccessor(JavaType.Method method, Accessor filteredParent) { + return new Accessor(method.getName(), method.getDeclaringType().getFullyQualifiedName(), filteredParent); + } + + private static @NotNull Accessor createAccessor(JavaType.Method method) { + return new Accessor(method.getName(), method.getDeclaringType().getFullyQualifiedName()); + } + + private static Optional removeRootParent(Accessor parent, String rootName) { + return Optional.ofNullable(parent != null && + accessorHasName(parent, rootName) ? + null : + parent); + } + + private static boolean accessorHasName(Accessor parent, String rootName) { + return parent.getClazz().contains(rootName); + } + + private static boolean hasSubDtoReturnType(JavaType.Method method) { + JavaType returnType = method.getReturnType(); + return isDtoType(returnType) && LSTUtil.declaringTypeIsNotType(method, returnType); + } + private static boolean isDtoType(JavaType type) { if ( type instanceof JavaType.Class clazz) { String className = clazz.getFullyQualifiedName(); diff --git a/src/main/java/com/gepardec/wor/lord/util/LSTUtil.java b/src/main/java/com/gepardec/wor/lord/util/LSTUtil.java new file mode 100644 index 0000000..d6e1422 --- /dev/null +++ b/src/main/java/com/gepardec/wor/lord/util/LSTUtil.java @@ -0,0 +1,68 @@ +package com.gepardec.wor.lord.util; + +import org.jetbrains.annotations.NotNull; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; +import org.openrewrite.java.tree.Statement; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class LSTUtil { + public static boolean isInterface(J.ClassDeclaration classDeclaration) { + return classDeclaration.getKind().equals(J.ClassDeclaration.Kind.Type.Interface); + } + + public static @NotNull List getMethodDeclarations(J.ClassDeclaration classDeclaration) { + return extractMethodDeclarations(getStatements(classDeclaration)); + } + + public static List extractMethodDeclarations(List statements) { + return extractStatementsOfType(statements, J.MethodDeclaration.class); + } + + public static List extractStatementsOfType(List statements, Class type) { + return statements.stream() + .filter(type::isInstance) + .map(type::cast) + .collect(Collectors.toList()); + } + public static @NotNull List getStatements(J.ClassDeclaration classDeclaration) { + return classDeclaration.getBody().getStatements(); + } + + public static @NotNull List getReturnTypes(List methods) { + return methods.stream() + .map(m -> m.getReturnTypeExpression().toString()) + .collect(Collectors.toList()); + } + + public static @NotNull List getParameterTypes(List methods) { + return methods.stream() + .flatMap(LSTUtil::extractStatementsOfType) + .map(LSTUtil::getVariableDeclarationsType) + .distinct() + .collect(Collectors.toList()); + } + + private static Stream extractStatementsOfType(J.MethodDeclaration m) { + return extractStatementsOfType(m.getParameters(), J.VariableDeclarations.class).stream(); + } + + public static String getVariableDeclarationsType(J.VariableDeclarations variableDeclarations) { + return variableDeclarations.getType().toString(); + } + + public static boolean methodNameStartsWith(JavaType.Method method, String get) { + return method.getName().startsWith(get); + } + + public static boolean declaringTypeIsNotType(JavaType.Method method, JavaType type) { + if (type instanceof JavaType.Class clazz) { + String className = clazz.getFullyQualifiedName(); + return !className.equals(method.getDeclaringType().toString()); + } + return false; + } +} diff --git a/src/test/java/com/gepardec/wor/lord/stdh/v2/BinaryDtoToWebTest.java b/src/test/java/com/gepardec/wor/lord/stdh/v2/BinaryDtoToWebTest.java index fed20e4..438c920 100644 --- a/src/test/java/com/gepardec/wor/lord/stdh/v2/BinaryDtoToWebTest.java +++ b/src/test/java/com/gepardec/wor/lord/stdh/v2/BinaryDtoToWebTest.java @@ -55,7 +55,7 @@ public class Test { private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { Laqamhsu reqDto = new Laqamhsu(); - reqDto.setOmStandardRequestHeader(objectFactory.createOmStandardRequestHeader()); + reqDto.setStdh(objectFactory.createOmStandardRequestHeader()); reqDto.getStdh().setZvst("11"); } } @@ -91,7 +91,7 @@ public class Test { private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { Laqaumv4 request = new Laqaumv4(); - request.setOmStandardRequestHeader(objectFactory.createOmStandardRequestHeader()); + request.setStdh(objectFactory.createOmStandardRequestHeader()); request.getStdh().setZvst("11"); } } @@ -126,7 +126,7 @@ public class Test { private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { Laqaumv4 request = new Laqaumv4(); - request.setOmStandardRequestHeader(objectFactory.createOmStandardRequestHeader()); + request.setDatenv3(objectFactory.createLaqaumv4Datenv3()); request.getDatenv3().setPostleitzahl("1220"); } } @@ -135,36 +135,40 @@ public void test() { } @DocumentExample @Test - public void whenBinaryStdhSetWithObjectFactoryAlreadyThere_thenCreateWebStdh() { + public void whenNestedSetters_thenTransformNestedSetters() { LOG.info("Start Test"); rewriteRunWithWsdlClasses( //language=java java(""" package com.gepardec.wor.lord; - import com.gepardec.wor.lord.stubs.LaqamhsuDto; - import at.sozvers.stp.lgkk.a02.laaamhsu.ObjectFactory; + import com.gepardec.wor.lord.stubs.Laqaumv4Dto; public class Test { - private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { - LaqamhsuDto reqDto = new LaqamhsuDto(); - reqDto.setZvst("11"); + Laqaumv4Dto request = new Laqaumv4Dto(); + request.setPostleitzahl("1220"); + request.setCReserved("test"); + request.setZvst("11"); } } """, """ package com.gepardec.wor.lord; - import at.sozvers.stp.lgkk.a02.laaamhsu.Laqamhsu; - import at.sozvers.stp.lgkk.a02.laaamhsu.ObjectFactory; + import at.sozvers.stp.lgkk.a02.laaaumv4.Laqaumv4; + import at.sozvers.stp.lgkk.a02.laaaumv4.ObjectFactory; public class Test { private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { - Laqamhsu reqDto = new Laqamhsu(); - reqDto.setOmStandardRequestHeader(objectFactory.createOmStandardRequestHeader()); - reqDto.getStdh().setZvst("11"); + Laqaumv4 request = new Laqaumv4(); + request.setStdh(objectFactory.createOmStandardRequestHeader()); + request.setMxcb(objectFactory.createMxcb()); + request.setDatenv3(objectFactory.createLaqaumv4Datenv3()); + request.getDatenv3().setPostleitzahl("1220"); + request.getMxcb().setCReserved("test"); + request.getStdh().setZvst("11"); } } """) @@ -172,7 +176,7 @@ public void test() { } @DocumentExample @Test - public void whenNoBinaryStdhSetButDto_thenCreateWebDtoWithoutStdh() { + public void whenBinaryStdhSetWithObjectFactoryAlreadyThere_thenCreateWebStdh() { LOG.info("Start Test"); rewriteRunWithWsdlClasses( //language=java @@ -180,11 +184,13 @@ public void whenNoBinaryStdhSetButDto_thenCreateWebDtoWithoutStdh() { package com.gepardec.wor.lord; import com.gepardec.wor.lord.stubs.LaqamhsuDto; - + import at.sozvers.stp.lgkk.a02.laaamhsu.ObjectFactory; + public class Test { + private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { LaqamhsuDto reqDto = new LaqamhsuDto(); - reqDto.setDatenv3("blubb"); + reqDto.setZvst("11"); } } """, @@ -192,11 +198,14 @@ public void test() { package com.gepardec.wor.lord; import at.sozvers.stp.lgkk.a02.laaamhsu.Laqamhsu; + import at.sozvers.stp.lgkk.a02.laaamhsu.ObjectFactory; public class Test { + private static final ObjectFactory objectFactory = new ObjectFactory(); public void test() { Laqamhsu reqDto = new Laqamhsu(); - reqDto.setDatenv3("blubb"); + reqDto.setStdh(objectFactory.createOmStandardRequestHeader()); + reqDto.getStdh().setZvst("11"); } } """) @@ -204,6 +213,26 @@ public void test() { } @DocumentExample @Test + public void whenNoBinaryStdhSetButDto_thenCreateWebDtoWithoutStdh() { + LOG.info("Start Test"); + rewriteRunWithWsdlClasses( + //language=java + java(""" + package com.gepardec.wor.lord; + + import com.gepardec.wor.lord.stubs.LaqamhsuDto; + + public class Test { + public void test() { + LaqamhsuDto reqDto = new LaqamhsuDto(); + reqDto.toString(); + } + } + """) + ); + } + @DocumentExample + @Test public void whenNoWsdlService_thenDoNothing() { LOG.info("Start Test"); rewriteRunWithWsdlClasses( @@ -216,7 +245,7 @@ public void whenNoWsdlService_thenDoNothing() { public class Test { public void test() { LaqaumwtDto reqDto = new LaqaumwtDto(); - reqDto.setDatenv3("blubb"); + reqDto.toString(); } } """)