From 2741e202337040b15e9a9dbbc156e8827ee749d0 Mon Sep 17 00:00:00 2001 From: Florian Bossert Date: Sat, 2 Mar 2024 08:39:28 +0100 Subject: [PATCH] First attempt --- .../extraction/rules/EcmaScriptRules.xtend | 6 +- .../extraction/rules/JaxRSRules.xtend | 6 +- .../extraction/rules/SpringRules.xtend | 20 ++- .../extraction/rules/data/GatewayRoute.xtend | 3 +- .../extraction/commonalities/HTTPMethod.java | 21 ++- .../extraction/commonalities/RESTName.java | 84 +--------- .../commonalities/RESTOperationName.java | 158 ++++++++++++++++++ .../commonalities/RESTOperationUnion.java | 27 +++ .../extraction/engine/PCMDetector.java | 8 +- .../retriever/test/model/InterfaceTest.java | 11 +- .../retriever/test/model/PathTest.java | 26 ++- 11 files changed, 246 insertions(+), 124 deletions(-) create mode 100644 bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java create mode 100644 bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend index 04b3820e..7a586c6b 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend @@ -24,7 +24,7 @@ import org.palladiosimulator.retriever.extraction.commonalities.CompUnitOrName import org.palladiosimulator.retriever.extraction.engine.Rule import org.palladiosimulator.retriever.extraction.rules.data.GatewayRoute import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard -import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod +import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName class EcmaScriptRules implements Rule { @@ -86,7 +86,7 @@ class EcmaScriptRules implements Rule { pcmDetector.detectRequiredInterface(GATEWAY_NAME, mappedURL) } pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, - new RESTName(hostname, "/" + url, HTTPMethod.any)) + new RESTOperationName(hostname, "/" + url)) } } } @@ -279,7 +279,7 @@ class EcmaScriptRules implements Rule { return route.applyTo(url) } } - return new RESTName(host, url, HTTPMethod.any) + return new RESTName(host, url) } override isBuildRule() { diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSRules.xtend index 5dde48b0..2a53da7e 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSRules.xtend @@ -6,11 +6,11 @@ import static org.palladiosimulator.retriever.extraction.engine.RuleHelper.* import org.palladiosimulator.retriever.extraction.commonalities.CompUnitOrName import java.util.Set import org.palladiosimulator.retriever.extraction.engine.Rule -import org.palladiosimulator.retriever.extraction.commonalities.RESTName import org.palladiosimulator.retriever.extraction.rules.util.RESTHelper import java.util.Map import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard +import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName class JaxRSRules implements Rule { @@ -67,7 +67,7 @@ class JaxRSRules implements Rule { methodPath = RESTHelper.replaceArgumentsWithWildcards(methodPath) // TODO: HTTP method switch-case pcmDetector.detectCompositeProvidedOperation(identifier, m.resolveBinding, - new RESTName("SERVICE-HOST", methodPath, HTTPMethod.all)) + new RESTOperationName("SERVICE-HOST", methodPath)) } ] getFields(unit).forEach[f|pcmDetector.detectRequiredInterfaceWeakly(identifier, f)] @@ -82,7 +82,7 @@ class JaxRSRules implements Rule { getMethods(unit).forEach [ m | if (SERVLET_METHODS.containsKey(m.name.identifier)) { pcmDetector.detectProvidedOperation(identifier, m.resolveBinding, - new RESTName("SERVICE-HOST", path, Set.of(SERVLET_METHODS.get(m.name.identifier)))) + new RESTOperationName("SERVICE-HOST", path, Set.of(SERVLET_METHODS.get(m.name.identifier)))) } ] getFields(unit).forEach[f|pcmDetector.detectRequiredInterfaceWeakly(identifier, f)] diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend index 7487c59e..e615bc0d 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/SpringRules.xtend @@ -21,6 +21,7 @@ import org.palladiosimulator.retriever.extraction.engine.Rule import org.palladiosimulator.retriever.extraction.rules.util.SpringHelper import org.palladiosimulator.retriever.extraction.rules.util.RESTHelper import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard +import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName class SpringRules implements Rule { static final Logger LOG = Logger.getLogger(SpringRules) @@ -188,7 +189,7 @@ class SpringRules implements Rule { methodName = RESTHelper.replaceArgumentsWithWildcards(methodName); val httpMethod = getHTTPMethod(m); pcmDetector.detectCompositeProvidedOperation(identifier, m.resolveBinding, - new RESTName(applicationName, methodName, httpMethod)); + new RESTOperationName(applicationName, methodName, httpMethod)); } } } @@ -210,9 +211,10 @@ class SpringRules implements Rule { requestedMapping = substituteVariables(requestedMapping, contextVariables); var methodName = ifaceName + "/" + requestedMapping; methodName = RESTHelper.replaceArgumentsWithWildcards(methodName); - val httpMethod = getHTTPMethod(m); + // Ignore HTTPMethod, only entire interfaces can be required right now. + // TODO: Find a way around this. pcmDetector.detectCompositeRequiredInterface(identifier, - new RESTName(serviceIdentifier, methodName, httpMethod)); + new RESTName(serviceIdentifier, methodName)); } } } @@ -292,32 +294,32 @@ class SpringRules implements Rule { def getHTTPMethod(MethodDeclaration m) { val requestMapping = getMappingString(m, "RequestMapping"); if (requestMapping !== null) { - return HTTPMethod.any(); + return HTTPMethod.WILDCARD; } val getMapping = getMappingString(m, "GetMapping"); if (getMapping !== null) { - return Set.of(HTTPMethod.GET); + return HTTPMethod.GET; } val postMapping = getMappingString(m, "PostMapping"); if (postMapping !== null) { - return Set.of(HTTPMethod.POST); + return HTTPMethod.POST; } val putMapping = getMappingString(m, "PutMapping"); if (putMapping !== null) { - return Set.of(HTTPMethod.PUT); + return HTTPMethod.PUT; } val deleteMapping = getMappingString(m, "DeleteMapping"); if (deleteMapping !== null) { - return Set.of(HTTPMethod.DELETE); + return HTTPMethod.DELETE; } val patchMapping = getMappingString(m, "PatchMapping"); if (patchMapping !== null) { - return Set.of(HTTPMethod.PATCH); + return HTTPMethod.PATCH; } return null; diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/data/GatewayRoute.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/data/GatewayRoute.xtend index 85ff295f..2291d9ca 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/data/GatewayRoute.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/data/GatewayRoute.xtend @@ -1,7 +1,6 @@ package org.palladiosimulator.retriever.extraction.rules.data import org.palladiosimulator.retriever.extraction.commonalities.RESTName -import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod class GatewayRoute { static final String TRAILING_WILDCARD = "/**" @@ -42,7 +41,7 @@ class GatewayRoute { val newUrlSegments = urlSegments.subList(stripPrefixLength, urlSegments.length) newUrl = toPath(newUrlSegments) } - return new RESTName(targetHost, newUrl, HTTPMethod.any) + return new RESTName(targetHost, newUrl) } private static def calculateStripPrefixLength(String pathPattern) { diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/HTTPMethod.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/HTTPMethod.java index 8cfdf72f..9d198ae7 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/HTTPMethod.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/HTTPMethod.java @@ -1,20 +1,23 @@ package org.palladiosimulator.retriever.extraction.commonalities; import java.util.Collection; +import java.util.HashSet; import java.util.Set; public enum HTTPMethod { - GET, POST, PUT, DELETE, PATCH; + GET, POST, PUT, DELETE, PATCH, + /** + * Special value signaling all HTTPMethods are provided/required. + */ + WILDCARD; public static boolean areAllPresent(Collection httpMethods) { - return httpMethods.containsAll(all()); - } - - public static Set all() { - return Set.of(values()); - } + if (httpMethods.contains(HTTPMethod.WILDCARD)) { + return true; + } - public static Set any() { - return Set.of(); + Set normalValues = new HashSet<>(Set.of(values())); + normalValues.remove(WILDCARD); + return httpMethods.containsAll(normalValues); } } diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java index b3505433..42945d0a 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTName.java @@ -8,17 +8,13 @@ import java.util.Set; import java.util.Stack; import java.util.stream.Collectors; -import java.util.stream.Stream; -public class RESTName implements InterfaceName, OperationName { +public class RESTName implements InterfaceName { private final String host; private final List path; - private final Set httpMethods; - public RESTName(final String host, final String path, final Set httpMethods) - throws IllegalArgumentException { + public RESTName(final String host, final String path) throws IllegalArgumentException { this.host = host; - this.httpMethods = httpMethods; final Optional> parsedPath = parsePath(host + path); if (parsedPath.isEmpty()) { throw new IllegalArgumentException("Could not parse path due to illegal format: \"" + path + "\""); @@ -29,30 +25,11 @@ public RESTName(final String host, final String path, final Set http this.path.remove(0); } - public RESTName(final String host, final String path, final HTTPMethod... httpMethods) - throws IllegalArgumentException { - this(host, path, Set.of(httpMethods)); - } - @Override public String getName() { - return this.getInterface(); - } - - @Override - public String getInterface() { return this.toString(); } - @Override - public Optional forInterface(final String baseInterface) { - if (!this.isPartOf(baseInterface)) { - return Optional.empty(); - } - - return Optional.of(this.getInterface()); - } - @Override public List getInterfaces() { final Stack> prefixes = new Stack<>(); @@ -68,10 +45,6 @@ public List getInterfaces() { final List interfaces = new ArrayList<>(prefixes.size()); - if (!this.httpMethods.isEmpty()) { - interfaces.add(this.getInterface()); - } - // Insert the prefixes in reverse since the most specific element is at index 0 there. while (!prefixes.empty()) { interfaces.add(this.toName(prefixes.pop())); @@ -102,23 +75,7 @@ private String toName(final List path) { @Override public String toString() { - final String pathString = this.toName(this.path); - - String methodString = ""; - if (!this.httpMethods.isEmpty()) { - methodString = "["; - if (HTTPMethod.areAllPresent(this.httpMethods)) { - methodString += "*"; - } else { - List httpMethodNames = this.httpMethods.stream() - .map(HTTPMethod::toString) - .collect(Collectors.toList()); - methodString += String.join(",", httpMethodNames); - } - methodString += "]"; - } - - return pathString + methodString; + return this.toName(this.path); } private static Optional> parsePath(final String string) { @@ -138,7 +95,7 @@ private static Optional> parsePath(final String string) { @Override public int hashCode() { - return Objects.hash(this.host, this.path, this.httpMethods); + return Objects.hash(this.host, this.path); } @Override @@ -150,8 +107,7 @@ public boolean equals(final Object obj) { return false; } final RESTName other = (RESTName) obj; - return Objects.equals(this.host, other.host) && Objects.equals(this.path, other.path) - && Objects.equals(this.httpMethods, other.httpMethods); + return Objects.equals(this.host, other.host) && Objects.equals(this.path, other.path); } @Override @@ -170,10 +126,7 @@ public Optional getCommonInterface(final Name other) { return Optional.empty(); } String commonPath = toName(this.path.subList(0, commonSegments)); - Set httpMethodUnion = new HashSet<>(); - httpMethodUnion.addAll(this.httpMethods); - httpMethodUnion.addAll(otherREST.httpMethods); - return Optional.of(new RESTName(this.host, commonPath, httpMethodUnion).toString()); + return Optional.of(new RESTName(this.host, commonPath).toString()); } else { // Implementation from Name final Set interfaces = new HashSet<>(this.getInterfaces()); @@ -207,36 +160,17 @@ public boolean isPartOf(final String iface) { return false; } } - if (restIface.path.size() == this.path.size() && !restIface.httpMethods.containsAll(this.httpMethods)) { - return false; - } return true; } - private static Optional parse(final String iface) { - final String[] parts = iface.split("\\["); - final Optional> interfacePathOption = parsePath(parts[0]); + public static Optional parse(final String iface) { + final Optional> interfacePathOption = parsePath(iface); if (interfacePathOption.isEmpty()) { return Optional.empty(); } final List path = interfacePathOption.get(); final String host = path.remove(0); - // If no HTTP method is specified, handle it like a wildcard. - Set httpMethods = HTTPMethod.all(); - if (parts.length > 1) { - // Assume that a '[' implies a ']'. - final int end = parts[1].lastIndexOf(']'); - final String httpMethodNames = parts[1].substring(0, end); - - if (!httpMethodNames.equals("*")) { - // Narrow the scope. - httpMethods = Stream.of(httpMethodNames.split(",")) - .map(HTTPMethod::valueOf) - .collect(Collectors.toSet()); - } - } - - return Optional.of(new RESTName(host, "/" + String.join("/", path), httpMethods)); + return Optional.of(new RESTName(host, "/" + String.join("/", path))); } } \ No newline at end of file diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java new file mode 100644 index 00000000..e2590bf7 --- /dev/null +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationName.java @@ -0,0 +1,158 @@ +package org.palladiosimulator.retriever.extraction.commonalities; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class RESTOperationName implements OperationName { + private RESTName restName; + /** + * This set must never be empty. + */ + private final Set httpMethods; + + public RESTOperationName(final String host, final String path, final Set httpMethods) + throws IllegalArgumentException { + this(new RESTName(host, path), httpMethods); + } + + public RESTOperationName(final String host, final String path, final HTTPMethod... httpMethods) + throws IllegalArgumentException { + this(host, path, Set.of(httpMethods)); + } + + private RESTOperationName(final RESTName restName, final Set httpMethods) { + this.restName = restName; + if (httpMethods.isEmpty()) { + this.httpMethods = Set.of(HTTPMethod.WILDCARD); + } else { + this.httpMethods = Collections.unmodifiableSet(httpMethods); + } + } + + @Override + public String getInterface() { + return this.toString(); + } + + @Override + public Optional forInterface(final String baseInterface) { + if (!this.isPartOf(baseInterface)) { + return Optional.empty(); + } + + return Optional.of(this.getInterface()); + } + + @Override + public List getInterfaces() { + return restName.getInterfaces(); + } + + @Override + public InterfaceName createInterface(final String name) { + return RESTName.parse(name) + .orElseThrow(); + } + + @Override + public String toString() { + final String pathString = this.restName.toString(); + + if (this.httpMethods.isEmpty() || HTTPMethod.areAllPresent(this.httpMethods)) { + return pathString; + } + + String httpMethodString = ""; + List httpMethodNames = this.httpMethods.stream() + .map(HTTPMethod::toString) + .collect(Collectors.toList()); + httpMethodString = "["; + httpMethodString += String.join(",", httpMethodNames); + httpMethodString += "]"; + + return pathString + httpMethodString; + } + + @Override + public int hashCode() { + return Objects.hash(this.restName, this.httpMethods); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if ((obj == null) || (this.getClass() != obj.getClass())) { + return false; + } + final RESTOperationName other = (RESTOperationName) obj; + return Objects.equals(this.restName, other.restName) && Objects.equals(this.httpMethods, other.httpMethods); + } + + @Override + public Optional getCommonInterface(final Name other) { + if (other instanceof RESTOperationName otherREST) { + if (this.restName.equals(otherREST.restName)) { + Set httpMethodUnion = new HashSet<>(this.httpMethods); + httpMethodUnion.addAll(otherREST.httpMethods); + return Optional.of(new RESTOperationName(this.restName, httpMethodUnion).toString()); + } else { + return this.restName.getCommonInterface(otherREST.restName); + } + } else { + return OperationName.super.getCommonInterface(other); + } + } + + @Override + public boolean isPartOf(final String iface) { + Optional parsedIface = parse(iface); + if (parsedIface.isEmpty()) { + return false; + } + + RESTOperationName restIface = parsedIface.get(); + + if (!this.restName.isPartOf(restIface.restName.toString())) { + return false; + } + + Set normalHttpMethods = new HashSet<>(this.httpMethods); + normalHttpMethods.remove(HTTPMethod.WILDCARD); + + if (this.restName.equals(restIface.restName) && !restIface.httpMethods.contains(HTTPMethod.WILDCARD) + && !restIface.httpMethods.containsAll(this.httpMethods)) { + return false; + } + return true; + } + + public static Optional parse(final String iface) { + final String[] parts = iface.split("\\["); + final Optional restNameOption = RESTName.parse(parts[0]); + if (restNameOption.isEmpty()) { + return Optional.empty(); + } + + Set httpMethods = Set.of(HTTPMethod.WILDCARD); + if (parts.length > 1) { + // Assume that a '[' implies a ']'. + final int end = parts[1].lastIndexOf(']'); + final String httpMethodNames = parts[1].substring(0, end); + + // Narrow the scope. + httpMethods = Stream.of(httpMethodNames.split(",")) + .map(HTTPMethod::valueOf) + .collect(Collectors.toSet()); + } + + return Optional.of(new RESTOperationName(restNameOption.get(), httpMethods)); + } +} \ No newline at end of file diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java new file mode 100644 index 00000000..8c5ab9cd --- /dev/null +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/commonalities/RESTOperationUnion.java @@ -0,0 +1,27 @@ +package org.palladiosimulator.retriever.extraction.commonalities; + +import java.util.Map; +import java.util.Set; + +public class RESTOperationUnion implements OperationInterface { + private RESTOperationName name; + + public RESTOperationUnion(RESTOperationName name) { + this.name = name; + } + + @Override + public Name getName() { + return name; + } + + @Override + public Map> simplified() { + return Map.of(this, Set.of()); + } + + @Override + public String getInterface() { + return name.getInterface(); + } +} diff --git a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMDetector.java b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMDetector.java index 492d6a15..1002d9b3 100644 --- a/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMDetector.java +++ b/bundles/org.palladiosimulator.retriever.extraction/src/org/palladiosimulator/retriever/extraction/engine/PCMDetector.java @@ -120,7 +120,7 @@ private void detectRequiredInterface(final CompUnitOrName unit, final FieldDecla .map(x -> x.getType()) .map(x -> new EntireInterface(x, new JavaInterfaceName(NameConverter.toPCMIdentifier(x)))) .collect(Collectors.toList()); - this.detectRequiredInterface(unit, compositeRequired, detectWeakly, ifaces); + this.detectRequired(unit, compositeRequired, detectWeakly, ifaces); } public void detectRequiredInterface(final CompUnitOrName unit, final SingleVariableDeclaration parameter) { @@ -141,11 +141,11 @@ public void detectRequiredInterface(final CompUnitOrName unit, final SingleVaria private void detectRequiredInterface(final CompUnitOrName unit, final boolean compositeRequired, final boolean detectWeakly, final OperationInterface iface) { - this.detectRequiredInterface(unit, compositeRequired, detectWeakly, List.of(iface)); + this.detectRequired(unit, compositeRequired, detectWeakly, List.of(iface)); } - private void detectRequiredInterface(final CompUnitOrName unit, final boolean compositeRequired, - final boolean detectWeakly, final Collection ifaces) { + private void detectRequired(final CompUnitOrName unit, final boolean compositeRequired, final boolean detectWeakly, + final Collection ifaces) { for (final OperationInterface iface : ifaces) { final boolean isProvided = this.compositeProvisions.containsRelated(iface) || this.components.values() .stream() diff --git a/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java b/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java index 5b380273..5f987398 100644 --- a/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java +++ b/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/InterfaceTest.java @@ -20,6 +20,7 @@ import org.palladiosimulator.retriever.extraction.commonalities.Operation; import org.palladiosimulator.retriever.extraction.commonalities.OperationInterface; import org.palladiosimulator.retriever.extraction.commonalities.RESTName; +import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName; public class InterfaceTest { @@ -65,7 +66,8 @@ void singleJavaOperation() { @Test void singlePathOperation() { final ComponentBuilder builder = new ComponentBuilder(null); - final Operation expectedOperation = new Operation(null, new RESTName("test-host", "/method", HTTPMethod.GET)); + final Operation expectedOperation = new Operation(null, + new RESTOperationName("test-host", "/method", HTTPMethod.GET)); builder.provisions() .add(expectedOperation); @@ -158,9 +160,9 @@ void entireJavaInterface() { void entirePathInterface() { final ComponentBuilder builder = new ComponentBuilder(null); final Operation firstMethod = new Operation(null, - new RESTName("test-host", "/common_interface/first_method", HTTPMethod.GET)); + new RESTOperationName("test-host", "/common_interface/first_method", HTTPMethod.GET)); final Operation secondMethod = new Operation(null, - new RESTName("test-host", "/common_interface/second_method", HTTPMethod.GET)); + new RESTOperationName("test-host", "/common_interface/second_method", HTTPMethod.GET)); builder.provisions() .add(firstMethod); builder.provisions() @@ -170,8 +172,7 @@ void entirePathInterface() { final List visibleProvisions = List.of(firstMethod, secondMethod); final Component builtComponent = builder.create(allDependencies, visibleProvisions); - final EntireInterface expectedInterface = new EntireInterface( - new RESTName("test-host", "/common_interface", HTTPMethod.GET)); + final EntireInterface expectedInterface = new EntireInterface(new RESTName("test-host", "/common_interface")); assertTrue(builtComponent.provisions() .containsPartOf(expectedInterface)); diff --git a/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/PathTest.java b/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/PathTest.java index da64f38b..2fd5ea25 100644 --- a/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/PathTest.java +++ b/tests/org.palladiosimulator.retriever.test/src/org/palladiosimulator/retriever/test/model/PathTest.java @@ -8,6 +8,7 @@ import org.palladiosimulator.retriever.extraction.commonalities.HTTPMethod; import org.palladiosimulator.retriever.extraction.commonalities.Operation; import org.palladiosimulator.retriever.extraction.commonalities.RESTName; +import org.palladiosimulator.retriever.extraction.commonalities.RESTOperationName; public class PathTest { @@ -15,15 +16,15 @@ public class PathTest { void pathNamesAreReflective() { final String host = "test-host"; final String path = "/some/path"; - final RESTName pathName = new RESTName(host, path, HTTPMethod.any()); + final RESTName pathName = new RESTName(host, path); assertTrue(pathName.isPartOf(host + path)); } @Test void pathsArePartOfTheirPrefixes() { final String path = "/some/path"; - final RESTName interfaceName = new RESTName("test-host", path, HTTPMethod.any()); - final RESTName specificName = new RESTName("test-host", path + "/that/is/more/specific", HTTPMethod.GET); + final RESTName interfaceName = new RESTName("test-host", path); + final RESTName specificName = new RESTName("test-host", path + "/that/is/more/specific"); assertTrue(specificName.isPartOf(interfaceName.getName()), "specific path is not part of its prefix"); assertFalse(interfaceName.isPartOf(specificName.getName()), "prefix is part of a longer path"); @@ -33,10 +34,9 @@ void pathsArePartOfTheirPrefixes() { void prefixesAreSeparatorAware() { // This is NOT a legal prefix of "/some/path/..." final String somePath = "/some/pa"; - final EntireInterface entireInterface = new EntireInterface( - new RESTName("test-host", somePath, HTTPMethod.any())); - final RESTName specificPathName = new RESTName("test-host", "/some/path/that/is/more/specific", - HTTPMethod.all()); + final EntireInterface entireInterface = new EntireInterface(new RESTName("test-host", somePath)); + final RESTOperationName specificPathName = new RESTOperationName("test-host", + "/some/path/that/is/more/specific"); final Operation operation = new Operation(null, specificPathName); assertFalse(operation.isPartOf(entireInterface), "operation is part of illegal prefix"); @@ -45,15 +45,13 @@ void prefixesAreSeparatorAware() { @Test void httpMethodsAreSpecializations() { final String path = "/some/path"; - final RESTName generalRequirementName = new RESTName("test-host", path, HTTPMethod.any()); - final RESTName specificName = new RESTName("test-host", path, HTTPMethod.GET); - final RESTName generalProvisionName = new RESTName("test-host", path, HTTPMethod.all()); + final RESTOperationName generalName = new RESTOperationName("test-host", path); + final RESTOperationName specificName = new RESTOperationName("test-host", path, HTTPMethod.GET); - final Operation generalRequirementOperation = new Operation(null, generalRequirementName); + final Operation generalOperation = new Operation(null, generalName); final Operation specificOperation = new Operation(null, specificName); - final Operation generalProvisionOperation = new Operation(null, generalProvisionName); - assertTrue(specificOperation.isPartOf(generalRequirementOperation)); - assertFalse(generalProvisionOperation.isPartOf(specificOperation)); + assertTrue(specificOperation.isPartOf(generalOperation)); + assertFalse(generalOperation.isPartOf(specificOperation)); } }