Skip to content

Commit

Permalink
LORD Wsdl classes added into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sgartner03 committed May 15, 2024
1 parent 6a9fad8 commit d3d25c4
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openrewrite.ExecutionContext;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;

Expand Down Expand Up @@ -66,10 +67,10 @@ private boolean hasCorrespondingWsdlType(J.MethodInvocation method) {
}

private static @NotNull String getWsdlTypeFromBinary(J.MethodInvocation method) {
JavaType type = method.getSelect().getType();
if (type == null) {
Expression select = method.getSelect();
if (select == null || select.getType() == null) {
return "";
}
return type.toString().replaceAll("Dto", "");
return select.getType().toString().replaceAll("Dto", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Wsdl2JavaServiceScanningVisitor(Accumulator accumulator) {
ExecutionContext ctx) {

classDeclaration = super.visitClassDeclaration(classDeclaration, ctx);
String serviceAlias = classDeclaration.getSimpleName();
String className = classDeclaration.getSimpleName();

if (!isInterface(classDeclaration)) {
return classDeclaration;
Expand All @@ -34,7 +34,7 @@ public Wsdl2JavaServiceScanningVisitor(Accumulator accumulator) {
List<String> requestTypes = getParameterTypes(methods);
List<String> responseTypes = getReturnTypes(methods);

Wsdl2JavaService service = new Wsdl2JavaService(serviceAlias, requestTypes, responseTypes);
Wsdl2JavaService service = new Wsdl2JavaService(className, requestTypes, responseTypes);
accumulator.addService(service);

return classDeclaration;
Expand Down
35 changes: 30 additions & 5 deletions src/test/java/com/gepardec/wor/helpers/SourceFileContents.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
package com.gepardec.wor.helpers;

import org.openrewrite.SourceFile;
import org.openrewrite.java.Assertions;
import org.openrewrite.test.SourceSpec;
import org.openrewrite.test.SourceSpecs;
import org.openrewrite.text.PlainText;

import java.io.BufferedReader;
import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SourceFileContents {
private static final String PATH = "target/generated-sources/cxf/";

private String serviceAlias;

public String[] forWsdl2JavaService(String serviceAlias) {
public SourceSpecs[] forWsdl2JavaService(SourceSpecs... additionalSources) {
this.serviceAlias = "";
List<SourceSpecs> wsdlSources = new ArrayList<>(readTreeUnderFile(new File(PATH), Objects::nonNull))
.stream()
.map(Assertions::java)
.collect(Collectors.toList());
wsdlSources.addAll(List.of(additionalSources));
return wsdlSources.toArray(new SourceSpecs[0]);
}


public SourceSpecs[] forWsdl2JavaService(String serviceAlias, SourceSpecs... additionalSources) {
this.serviceAlias = serviceAlias;
return readTreeUnderFile(new File(PATH), this::isNotWsdl2JavaService).toArray(new String[0]);
List<SourceSpecs> wsdlSources = new ArrayList<>(readTreeUnderFile(new File(PATH), this::isNotWsdl2JavaService))
.stream()
.map(Assertions::java)
.collect(Collectors.toList());
wsdlSources.addAll(List.of(additionalSources));
return wsdlSources.toArray(new SourceSpecs[0]);
}

public List<String> readTreeUnderFile(File file, Predicate<File> filter) {
Expand All @@ -34,10 +58,11 @@ public List<String> readTreeUnderFile(File file, Predicate<File> filter) {
}

private boolean isNotWsdl2JavaService(File file) {
return !file
String fileMatcher = file
.getName()
.toLowerCase()
.contains(serviceAlias);
.toLowerCase();

return !fileMatcher.contains("a02/") || fileMatcher.contains(serviceAlias);
}

private String readFile(File file) {
Expand Down
134 changes: 116 additions & 18 deletions src/test/java/com/gepardec/wor/lord/stdh/v2/BinaryDtoToWebTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@

import com.gepardec.wor.helpers.SourceFileContents;
import com.gepardec.wor.lord.call.ternaries.BinaryProxyToWebTernaryAndClassTest;
import com.gepardec.wor.lord.stdh.v2.recipes.BinaryDtoToWeb;
import com.gepardec.wor.lord.stdh.v2.recipes.BinaryDtoToWsdl2JavaServiceDto;
import com.gepardec.wor.lord.util.ParserUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.LargeSourceSet;
import org.openrewrite.RecipeRun;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.SourceSpecs;
import org.openrewrite.test.TypeValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.Stream;

import static org.openrewrite.java.Assertions.java;

public class BinaryDtoToWebTest implements RewriteTest {
Expand All @@ -30,7 +23,7 @@ public class BinaryDtoToWebTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec
.recipe(new BinaryDtoToWeb())
.recipe(new BinaryDtoToWsdl2JavaServiceDto())
.parser(ParserUtil.createParserWithRuntimeClasspath())
.typeValidationOptions(TypeValidation.none());
}
Expand All @@ -39,7 +32,89 @@ public void defaults(RecipeSpec spec) {
@Test
public void whenBinaryStdhSet_thenCreateWebStdh() {
LOG.info("Start Test");
rewriteRun(
rewriteRunWithWsdlClasses(
//language=java
java("""
package com.gepardec.wor.lord;
import com.gepardec.wor.lord.stubs.LaqamhsuDto;
import com.gepardec.wor.lord.stubs.Laqamhsu;
import com.gepardec.wor.lord.stubs.ObjectFactory;
import com.gepardec.wor.lord.stubs.OmStandardRequestHeader;
public class Test {
public void test() {
LaqamhsuDto reqDto = new LaqamhsuDto();
reqDto.setZvst("11");
}
}
""",
"""
package com.gepardec.wor.lord;
import com.gepardec.wor.lord.stubs.LaqamhsuDto;
import com.gepardec.wor.lord.stubs.Laqamhsu;
import com.gepardec.wor.lord.stubs.ObjectFactory;
import com.gepardec.wor.lord.stubs.OmStandardRequestHeader;
public class Test {
private static final ObjectFactory objectFactory = new ObjectFactory();
public void test() {
Laqamhsu reqDto = new Laqamhsu();
reqDto.setOmStandardRequestHeader(objectFactory.createOmStandardRequestHeader());
reqDto.getOmStandardRequestHeader().setZvst("11");
}
}
""")
);
}

@DocumentExample
@Test
@Disabled("Not supported yet")
public void whenBinaryStdhSetWithOtherNamesAndTyoe_thenCreateWebStdh() {
LOG.info("Start Test");
rewriteRunWithWsdlClasses(
//language=java
java("""
package com.gepardec.wor.lord;
import com.gepardec.wor.lord.stubs.LaqamhsuDto;
import com.gepardec.wor.lord.stubs.Laqamhsu;
import com.gepardec.wor.lord.stubs.ObjectFactory;
import com.gepardec.wor.lord.stubs.OmStandardRequestHeader;
public class Test {
public void test() {
Laqaumv4Dto request = new Laqaumv4Dto();
request.setZvst("11");
}
}
""",
"""
package com.gepardec.wor.lord;
import at.sozvers.stp.lgkk.a02.laaaumv4.Laqaumv4;import com.gepardec.wor.lord.stubs.LaqamhsuDto;
import com.gepardec.wor.lord.stubs.Laqamhsu;
import com.gepardec.wor.lord.stubs.ObjectFactory;
import com.gepardec.wor.lord.stubs.OmStandardRequestHeader;
public class Test {
private static final ObjectFactory objectFactory = new ObjectFactory();
public void test() {
Laqaumv4 request = new Laqaumv4();
request.setOmStandardRequestHeader(objectFactory.createOmStandardRequestHeader());
request.getOmStandardRequestHeader().setZvst("11");
}
}
""")
);
}
@DocumentExample
@Test
public void whenBinaryStdhSetWithObjectFactoryAlreadyThere_thenCreateWebStdh() {
LOG.info("Start Test");
rewriteRunWithWsdlClasses(
//language=java
java("""
package com.gepardec.wor.lord;
Expand All @@ -50,6 +125,7 @@ public void whenBinaryStdhSet_thenCreateWebStdh() {
import com.gepardec.wor.lord.stubs.OmStandardRequestHeader;
public class Test {
private static final ObjectFactory objectFactory = new ObjectFactory();
public void test() {
LaqamhsuDto reqDto = new LaqamhsuDto();
reqDto.setZvst("11");
Expand Down Expand Up @@ -79,7 +155,7 @@ public void test() {
@Test
public void whenNoBinaryStdhSetButDto_thenCreateWebDtoWithoutStdh() {
LOG.info("Start Test");
rewriteRun(
rewriteRunWithWsdlClasses(
//language=java
java("""
package com.gepardec.wor.lord;
Expand Down Expand Up @@ -115,9 +191,32 @@ public void test() {
}
@DocumentExample
@Test
public void whenNoWsdlService_thenDoNothing() {
LOG.info("Start Test");
rewriteRunWithWsdlClasses(
//language=java
java("""
package com.gepardec.wor.lord;
import com.gepardec.wor.lord.stubs.LaqamhsuDto;
import com.gepardec.wor.lord.stubs.Laqamhsu;
import com.gepardec.wor.lord.stubs.ObjectFactory;
import com.gepardec.wor.lord.stubs.OmStandardRequestHeader;
public class Test {
public void test() {
LaqaumwtDto reqDto = new LaqaumwtDto();
reqDto.setDatenv3("blubb");
}
}
""")
);
}
@DocumentExample
@Test
public void whenNoDtoUsed_thenDoNothing() {
LOG.info("Start Test");
rewriteRun(
rewriteRunWithWsdlClasses(
//language=java
java("""
package com.gepardec.wor.lord;
Expand All @@ -136,11 +235,10 @@ public void test() {
);
}

@Test
public void withWsdl() {
Stream<SourceFile> sourceFiles = JavaParser.fromJavaVersion().build().parse(new SourceFileContents().forWsdl2JavaService("laaamhsu"));
LargeSourceSet sourceSet = new InMemoryLargeSourceSet(sourceFiles.toList());
RecipeRun testResults = new BinaryDtoToWsdl2JavaServiceDto().run(sourceSet, new InMemoryExecutionContext());
private void rewriteRunWithWsdlClasses(SourceSpecs... sourceSpecs) {
rewriteRun(
new SourceFileContents().forWsdl2JavaService(sourceSpecs)
);
}
}

0 comments on commit d3d25c4

Please sign in to comment.