From 66f2b1f5d5f9628fa79027092e952be54182ea94 Mon Sep 17 00:00:00 2001 From: elrodro83 Date: Fri, 8 Nov 2024 10:28:57 -0300 Subject: [PATCH] Remove ArtifactDeclaration dependency --- api-changes.json | 17 + pom.xml | 14 +- src/main/java/module-info.java | 3 - .../ArtifactDeclarationJsonSerializer.java | 48 -- ...aultArtifactDeclarationJsonSerializer.java | 46 -- src/test/java/module-info.java | 3 - ...factDeclarationJsonSerializerTestCase.java | 492 ------------------ ...lementDeclarationLocationPathTestCase.java | 277 ---------- 8 files changed, 21 insertions(+), 879 deletions(-) delete mode 100644 src/main/java/org/mule/runtime/api/app/declaration/serialization/ArtifactDeclarationJsonSerializer.java delete mode 100644 src/main/java/org/mule/runtime/internal/app/declaration/serialization/DefaultArtifactDeclarationJsonSerializer.java delete mode 100644 src/test/java/org/mule/runtime/api/test/meta/model/ArtifactDeclarationJsonSerializerTestCase.java delete mode 100644 src/test/java/org/mule/runtime/api/test/meta/model/ElementDeclarationLocationPathTestCase.java diff --git a/api-changes.json b/api-changes.json index 0d0ef90c7..6e8543e23 100644 --- a/api-changes.json +++ b/api-changes.json @@ -1,4 +1,21 @@ { + "1.9.0": { + "revapi": { + "differences": { + "differences": [ + // 4.10 +// ------------------>> + { + "ignore": true, + "code": "java.class.removed", + "old": "interface org.mule.runtime.api.app.declaration.serialization.ArtifactDeclarationJsonSerializer", + "justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE" + } +// <<------------------ + ] + } + } + }, "1.7.0": { "revapi": { "ignore": [ diff --git a/pom.xml b/pom.xml index d49384360..4d7e9fbd8 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,10 @@ commons-io commons-io + + com.google.code.gson + gson + org.slf4j slf4j-api @@ -228,16 +232,6 @@ allure-junit4 test - - org.mule.runtime - mule-artifact-declaration - ${artifactDeclarationVersion} - - - org.mule.runtime - mule-artifact-declaration-persistence - ${artifactDeclarationVersion} - org.mule.runtime api-annotations diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index fc06ca7c7..aae43533e 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -22,8 +22,6 @@ requires transitive org.mule.runtime.api.annotations; requires org.mule.runtime.metadata.model.api; requires org.mule.runtime.metadata.model.message; - requires org.mule.runtime.artifact.declaration; - requires org.mule.runtime.artifact.declaration.persistence; requires jakarta.activation; requires java.naming; @@ -41,7 +39,6 @@ requires org.apache.commons.lang3; requires semver4j; - exports org.mule.runtime.api.app.declaration.serialization; exports org.mule.runtime.api.artifact; exports org.mule.runtime.api.bulk; exports org.mule.runtime.api.util.classloader; diff --git a/src/main/java/org/mule/runtime/api/app/declaration/serialization/ArtifactDeclarationJsonSerializer.java b/src/main/java/org/mule/runtime/api/app/declaration/serialization/ArtifactDeclarationJsonSerializer.java deleted file mode 100644 index be882a4c0..000000000 --- a/src/main/java/org/mule/runtime/api/app/declaration/serialization/ArtifactDeclarationJsonSerializer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.api.app.declaration.serialization; - -import org.mule.api.annotation.NoImplement; -import org.mule.runtime.app.declaration.api.ArtifactDeclaration; -import org.mule.runtime.internal.app.declaration.serialization.DefaultArtifactDeclarationJsonSerializer; - -/** - * Serializer that can convert an {@link ArtifactDeclaration} into a readable and processable JSON representation and from a JSON - * {@link String} to an {@link ArtifactDeclaration} instance - * - * @since 1.0 - */ -@NoImplement -public interface ArtifactDeclarationJsonSerializer { - - /** - * Creates a new instance of the {@link ArtifactDeclarationJsonSerializer}. This serializer is capable of serializing and - * deserializing {@link ArtifactDeclaration} from JSON ({@link #deserialize(String)} and to JSON ( - * {@link #serialize(ArtifactDeclaration)} - */ - static ArtifactDeclarationJsonSerializer getDefault(boolean prettyPrint) { - return new DefaultArtifactDeclarationJsonSerializer(prettyPrint); - } - - /** - * Serializes an {@link ArtifactDeclaration} into JSON - * - * @param declaration {@link ArtifactDeclaration} to be serialized - * @return {@link String} JSON representation of the {@link ArtifactDeclaration} - */ - String serialize(ArtifactDeclaration declaration); - - /** - * Deserializes a JSON representation of an {@link ArtifactDeclaration}, to an actual instance of it. - * - * @param declaration serialized {@link ArtifactDeclaration} - * @return an instance of {@link ArtifactDeclaration} based in the JSON - */ - ArtifactDeclaration deserialize(String declaration); - -} - diff --git a/src/main/java/org/mule/runtime/internal/app/declaration/serialization/DefaultArtifactDeclarationJsonSerializer.java b/src/main/java/org/mule/runtime/internal/app/declaration/serialization/DefaultArtifactDeclarationJsonSerializer.java deleted file mode 100644 index 90a17b841..000000000 --- a/src/main/java/org/mule/runtime/internal/app/declaration/serialization/DefaultArtifactDeclarationJsonSerializer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.internal.app.declaration.serialization; - -import org.mule.runtime.api.app.declaration.serialization.ArtifactDeclarationJsonSerializer; -import org.mule.runtime.app.declaration.api.ArtifactDeclaration; -import org.mule.runtime.app.declaration.serialization.api.ElementDeclarationJsonSerializer; - -/** - * Default implementation of an {@link ArtifactDeclarationJsonSerializer} - * - * @since 1.0 - */ -public class DefaultArtifactDeclarationJsonSerializer implements ArtifactDeclarationJsonSerializer { - - private ElementDeclarationJsonSerializer delegateSerializer; - - public DefaultArtifactDeclarationJsonSerializer(boolean prettyPrint) { - this.delegateSerializer = ElementDeclarationJsonSerializer.getDefault(prettyPrint); - } - - /** - * Serializes an {@link ArtifactDeclaration} into JSON - * - * @param declaration {@link ArtifactDeclaration} to be serialized - * @return {@link String} JSON representation of the {@link ArtifactDeclaration} - */ - public String serialize(ArtifactDeclaration declaration) { - return delegateSerializer.serialize(declaration); - } - - /** - * Deserializes a JSON representation of an {@link ArtifactDeclaration}, to an actual instance of it. - * - * @param declaration serialized {@link ArtifactDeclaration} - * @return an instance of {@link ArtifactDeclaration} based in the JSON - */ - public ArtifactDeclaration deserialize(String declaration) { - return delegateSerializer.deserialize(declaration, ArtifactDeclaration.class); - } -} - diff --git a/src/test/java/module-info.java b/src/test/java/module-info.java index cfe845cd1..55c087031 100644 --- a/src/test/java/module-info.java +++ b/src/test/java/module-info.java @@ -15,9 +15,6 @@ requires transitive org.mule.runtime.api.annotations; requires org.mule.runtime.metadata.model.api; requires org.mule.runtime.metadata.model.message; - requires org.mule.runtime.artifact.declaration; - requires org.mule.runtime.artifact.declaration.persistence; - requires com.github.benmanes.caffeine; requires com.google.common; diff --git a/src/test/java/org/mule/runtime/api/test/meta/model/ArtifactDeclarationJsonSerializerTestCase.java b/src/test/java/org/mule/runtime/api/test/meta/model/ArtifactDeclarationJsonSerializerTestCase.java deleted file mode 100644 index a8ca76849..000000000 --- a/src/test/java/org/mule/runtime/api/test/meta/model/ArtifactDeclarationJsonSerializerTestCase.java +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.api.test.meta.model; - -import static org.mule.runtime.api.component.Component.NS_MULE_DOCUMENTATION; -import static org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.CONNECTION; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newArtifact; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newListValue; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newObjectValue; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newParameterGroup; -import static org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue.cdata; -import static org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue.plain; -import static org.mule.runtime.app.declaration.api.fluent.SimpleValueType.BOOLEAN; -import static org.mule.runtime.app.declaration.api.fluent.SimpleValueType.NUMBER; -import static org.mule.runtime.app.declaration.api.fluent.SimpleValueType.STRING; - -import static java.util.concurrent.TimeUnit.MINUTES; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.core.IsNot.not; - -import org.mule.runtime.api.app.declaration.serialization.ArtifactDeclarationJsonSerializer; -import org.mule.runtime.app.declaration.api.ArtifactDeclaration; -import org.mule.runtime.app.declaration.api.ParameterValue; -import org.mule.runtime.app.declaration.api.fluent.ElementDeclarer; -import org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue; -import org.mule.runtime.app.declaration.api.fluent.SimpleValueType; - -import java.io.InputStreamReader; - -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.google.gson.stream.JsonReader; -import org.json.JSONException; -import org.junit.Before; -import org.junit.Test; -import org.skyscreamer.jsonassert.JSONAssert; - -public class ArtifactDeclarationJsonSerializerTestCase { - - private ArtifactDeclaration applicationDeclaration; - - @Before - public void setup() { - applicationDeclaration = createArtifact(); - } - - @Test - public void serializationTest() { - JsonParser parser = new JsonParser(); - JsonReader reader = - new JsonReader(new InputStreamReader(getClass().getResourceAsStream(getExpectedArtifactDeclarationJson()))); - JsonElement expected = parser.parse(reader); - JsonElement json = parser.parse(ArtifactDeclarationJsonSerializer.getDefault(true).serialize(applicationDeclaration)); - assertThat(json, is(equalTo(expected))); - } - - @Test - public void serializeDeserializeTest() { - ArtifactDeclarationJsonSerializer serializer = ArtifactDeclarationJsonSerializer.getDefault(true); - String json = serializer.serialize(applicationDeclaration); - - ArtifactDeclaration artifactDeclaration = serializer.deserialize(json); - assertThat(json, applicationDeclaration, is(equalTo(artifactDeclaration))); - } - - @Test - public void serializeDeserializeSerializeTest() throws JSONException { - ArtifactDeclarationJsonSerializer serializer = ArtifactDeclarationJsonSerializer.getDefault(true); - String originalJson = serializer.serialize(applicationDeclaration); - - ArtifactDeclaration loadedDeclaration = serializer.deserialize(originalJson); - - JsonParser parser = new JsonParser(); - JsonElement jsonElement = parser.parse(ArtifactDeclarationJsonSerializer.getDefault(true).serialize(loadedDeclaration)); - String generatedJson = jsonElement.toString(); - - JSONAssert.assertEquals(originalJson, generatedJson, true); - } - - @Test - public void equalsTopLevelParameterShouldIncludeParameters() { - ElementDeclarer core = ElementDeclarer.forExtension("mule"); - ParameterObjectValue parameterObjectValue = ParameterObjectValue.builder() - .withParameter("otherName", "simpleParam") - .build(); - - String globalParameterName = "globalParameterName"; - String globalTemplateRefName = "globalTemplateRefName"; - - ParameterObjectValue modifiedParameterObjectValue = ParameterObjectValue.builder() - .withParameter("otherName", "simpleParam") - .withParameter("myCamelCaseName", "someContent") - .build(); - - assertThat(newArtifact().withGlobalElement(core.newGlobalParameter(globalParameterName) - .withRefName(globalTemplateRefName) - .withValue(parameterObjectValue) - .getDeclaration()).getDeclaration(), - not(equalTo(newArtifact().withGlobalElement(core.newGlobalParameter(globalParameterName) - .withRefName(globalTemplateRefName) - .withValue(modifiedParameterObjectValue) - .getDeclaration()).getDeclaration()))); - - } - - private ArtifactDeclaration createArtifact() { - - ElementDeclarer core = ElementDeclarer.forExtension("mule"); - ElementDeclarer db = ElementDeclarer.forExtension("Database"); - ElementDeclarer http = ElementDeclarer.forExtension("HTTP"); - ElementDeclarer sockets = ElementDeclarer.forExtension("Sockets"); - ElementDeclarer wsc = ElementDeclarer.forExtension("Web Service Consumer"); - ElementDeclarer file = ElementDeclarer.forExtension("File"); - ElementDeclarer os = ElementDeclarer.forExtension("ObjectStore"); - - return newArtifact() - .withCustomParameter("xmlns:doc", NS_MULE_DOCUMENTATION) - .withGlobalElement(core.newConstruct("configuration") - .withParameterGroup(group -> group.withParameter("defaultErrorHandler-ref", - createStringParameter("referableHandler"))) - .getDeclaration()) - .withGlobalElement(core.newConstruct("errorHandler") - .withRefName("referableHandler") - .withComponent(core.newRoute("onErrorContinue") - .withParameterGroup(group -> group - .withParameter("type", createStringParameter("MULE:SOURCE_RESPONSE")) - .withParameter("logException", createBooleanParameter("false")) - .withParameter("enableNotifications", createBooleanParameter("false"))) - .withComponent(core.newOperation("logger") - .withParameterGroup(group -> group - .withParameter("level", createStringParameter("TRACE"))) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(os.newGlobalParameter("objectStore") - .withRefName("persistentStore") - .withValue(newObjectValue() - .ofType("org.mule.extension.objectstore.api.TopLevelObjectStore") - .withParameter("entryTtl", createNumberParameter("1")) - .withParameter("entryTtlUnit", createStringParameter("HOURS")) - .withParameter("maxEntries", createNumberParameter("10")) - .withParameter("persistent", createBooleanParameter("true")) - .withParameter("expirationInterval", createNumberParameter("2")) - .withParameter("expirationIntervalUnit", createStringParameter("HOURS")) - .withParameter("config-ref", createStringParameter("persistentConfig")) - .build()) - .getDeclaration()) - .withGlobalElement(os.newConfiguration("config") - .withRefName("persistentConfig") - .getDeclaration()) - .withGlobalElement(file.newConfiguration("config") - .withRefName("fileConfig") - .withConnection(file.newConnection("connection").getDeclaration()) - .getDeclaration()) - .withGlobalElement(wsc.newConfiguration("config") - .withRefName("wscConfig") - .withParameterGroup(newParameterGroup() - .withParameter("expirationPolicy", newObjectValue() - .ofType("org.mule.runtime.extension.api.ExpirationPolicy") - .withParameter("maxIdleTime", createNumberParameter("1")) - .withParameter("timeUnit", createStringParameter(MINUTES.name())) - .build()) - .getDeclaration()) - .withConnection(wsc.newConnection("connection") - .withParameterGroup(newParameterGroup() - .withParameter("soapVersion", createStringParameter("SOAP11")) - .withParameter("mtomEnabled", createBooleanParameter("false")) - .getDeclaration()) - .withParameterGroup(newParameterGroup("Connection") - .withParameter("wsdlLocation", createStringParameter("http://www.webservicex.com/globalweather.asmx?WSDL")) - .withParameter("address", createStringParameter("http://www.webservicex.com/globalweather.asmx")) - .withParameter("service", createStringParameter("GlobalWeather")) - .withParameter("port", createStringParameter("GlobalWeatherSoap")) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(db.newConfiguration("config") - .withRefName("dbConfig") - .withConnection(db - .newConnection("derby").withParameterGroup(newParameterGroup() - .withParameter("poolingProfile", newObjectValue() - .withParameter("maxPoolSize", createNumberParameter("10")) - .build()) - .getDeclaration()) - .withParameterGroup(newParameterGroup(CONNECTION) - .withParameter("connectionProperties", newObjectValue() - .withParameter("first", createStringParameter("propertyOne")) - .withParameter("second", createStringParameter("propertyTwo")) - .build()) - .withParameter("reconnection", newObjectValue() - .ofType("Reconnection") - .withParameter("failsDeployment", createBooleanParameter("true")) - .withParameter("reconnectionStrategy", newObjectValue() - .ofType("reconnect") - .withParameter("count", createNumberParameter("1")) - .withParameter("frequency", createNumberParameter("0")) - .build()) - .build()) - .withParameter("database", createStringParameter("target/muleEmbeddedDB")) - .withParameter("create", createBooleanParameter("true")) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(http.newConfiguration("listenerConfig") - .withRefName("httpListener") - .withParameterGroup(newParameterGroup() - .withParameter("basePath", createStringParameter("/")) - .getDeclaration()) - .withConnection(http.newConnection("listener") - .withParameterGroup(newParameterGroup() - .withParameter("tlsContext", newObjectValue() - .withParameter("key-store", newObjectValue() - .withParameter("path", createStringParameter("ssltest-keystore.jks")) - .withParameter("password", createStringParameter("changeit")) - .withParameter("keyPassword", createStringParameter("changeit")) - .build()) - .withParameter("trust-store", newObjectValue() - .withParameter("insecure", createBooleanParameter("true")) - .build()) - .withParameter("revocation-check", - newObjectValue() - .ofType("standard-revocation-check") - .withParameter("onlyEndEntities", createBooleanParameter("true")) - .build()) - .build()) - .getDeclaration()) - .withParameterGroup(group -> group.withName(CONNECTION) - .withParameter("host", createStringParameter("localhost")) - .withParameter("port", createNumberParameter("49019")) - .withParameter("protocol", createStringParameter("HTTPS"))) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(http.newConfiguration("requestConfig") - .withRefName("httpRequester") - .withConnection(http.newConnection("request") - .withParameterGroup(group -> group.withParameter("authentication", - newObjectValue() - .ofType("org.mule.extension.http.api.request.authentication.BasicAuthentication") - .withParameter("username", createStringParameter("user")) - .withParameter("password", createStringParameter("pass")) - .build())) - .withParameterGroup(newParameterGroup(CONNECTION) - .withParameter("host", createStringParameter("localhost")) - .withParameter("port", createNumberParameter("49020")) - .withParameter("clientSocketProperties", - newObjectValue() - .withParameter("connectionTimeout", createNumberParameter("1000")) - .withParameter("keepAlive", createBooleanParameter("true")) - .withParameter("receiveBufferSize", createNumberParameter("1024")) - .withParameter("sendBufferSize", createNumberParameter("1024")) - .withParameter("clientTimeout", createNumberParameter("1000")) - .withParameter("linger", createNumberParameter("1000")) - .build()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(core.newConstruct("flow") - .withRefName("testFlow") - .withCustomParameter("doc:id", "docUUID") - .withParameterGroup(group -> group.withParameter("initialState", createStringParameter("stopped"))) - .withComponent(http.newSource("listener") - .withConfig("httpListener") - .withCustomParameter("doc:id", "docUUID") - .withParameterGroup(newParameterGroup() - .withParameter("path", createStringParameter("testBuilder")) - .withParameter("redeliveryPolicy", - newObjectValue() - .withParameter("maxRedeliveryCount", createNumberParameter("2")) - .withParameter("useSecureHash", createBooleanParameter("true")) - .build()) - .getDeclaration()) - .withParameterGroup(group -> group.withName(CONNECTION) - .withParameter("reconnectionStrategy", - newObjectValue() - .ofType("reconnect") - .withParameter("count", createNumberParameter("1")) - .withParameter("frequency", createNumberParameter("0")) - .build())) - .withParameterGroup(newParameterGroup("Response") - .withParameter("headers", createStringCdataParameter("")) - .withParameter("body", createStringCdataParameter( - "")) - .getDeclaration()) - .getDeclaration()) - .withComponent(core.newConstruct("choice") - .withRoute(core.newRoute("when") - .withParameterGroup(newParameterGroup() - .withParameter("expression", createStringParameter("#[true]")) - .getDeclaration()) - .withComponent(db.newOperation("bulkInsert") - .withParameterGroup(newParameterGroup("Query") - .withParameter("sql", - createStringParameter("INSERT INTO PLANET(POSITION, NAME) VALUES (:position, :name)")) - .withParameter("parameterTypes", - newListValue() - .withValue(newObjectValue() - .withParameter("key", createStringParameter("name")) - .withParameter("type", createStringParameter("VARCHAR")) - .build()) - .withValue(newObjectValue() - .withParameter("key", createNumberParameter("position")) - .withParameter("type", createStringParameter("INTEGER")) - .build()) - .build()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withRoute(core.newRoute("otherwise") - .withComponent(core.newConstruct("foreach") - .withParameterGroup(newParameterGroup() - .withParameter("collection", createStringParameter("#[myCollection]")) - .getDeclaration()) - .withComponent(core.newOperation("logger") - .withParameterGroup(newParameterGroup() - .withParameter("message", createStringParameter("#[payload]")) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withComponent(db.newOperation("bulkInsert") - .withParameterGroup(newParameterGroup("Query") - .withParameter("sql", createStringParameter("INSERT INTO PLANET(POSITION, NAME) VALUES (:position, :name)")) - .withParameter("parameterTypes", - newListValue() - .withValue(newObjectValue() - .withParameter("key", createStringParameter("name")) - .withParameter("type", createStringParameter("VARCHAR")).build()) - .withValue(newObjectValue() - .withParameter("key", createStringParameter("position")) - .withParameter("type", createStringParameter("INTEGER")).build()) - .build()) - .getDeclaration()) - .getDeclaration()) - .withComponent(http.newOperation("request") - .withConfig("httpRequester") - .withParameterGroup(newParameterGroup("URI Settings") - .withParameter("path", createStringParameter("/nested")) - .getDeclaration()) - .withParameterGroup(newParameterGroup() - .withParameter("method", createStringParameter("POST")) - .getDeclaration()) - .getDeclaration()) - .withComponent(db.newOperation("insert") - .withConfig("dbConfig") - .withParameterGroup(newParameterGroup("Query") - .withParameter("sql", - createStringParameter("INSERT INTO PLANET(POSITION, NAME, DESCRIPTION) VALUES (777, 'Pluto', :description)")) - .withParameter("parameterTypes", - newListValue() - .withValue(newObjectValue() - .withParameter("key", createStringParameter("description")) - .withParameter("type", createStringParameter("CLOB")).build()) - .build()) - .withParameter("inputParameters", createStringParameter("#[{{'description' : payload}}]")) - .getDeclaration()) - .getDeclaration()) - .withComponent(sockets.newOperation("sendAndReceive") - .withParameterGroup(newParameterGroup() - .withParameter("streamingStrategy", - newObjectValue() - .ofType("repeatable-in-memory-stream") - .withParameter("bufferSizeIncrement", createNumberParameter("8")) - .withParameter("bufferUnit", createStringParameter("KB")) - .withParameter("initialBufferSize", createNumberParameter("51")) - .withParameter("maxBufferSize", createNumberParameter("1000")) - .build()) - .getDeclaration()) - .withParameterGroup(newParameterGroup("Output") - .withParameter("target", createStringParameter("myVar")) - .withParameter("targetValue", createStringParameter("#[message]")) - .getDeclaration()) - .getDeclaration()) - .withComponent(core.newConstruct("try") - .withComponent(wsc.newOperation("consume") - .withParameterGroup(newParameterGroup() - .withParameter("operation", createStringParameter("GetCitiesByCountry")) - .getDeclaration()) - .withParameterGroup(newParameterGroup("Message") - .withParameter("attachments", createStringParameter("#[{}]")) - .withParameter("headers", - createStringParameter("#[{\"headers\": {con#headerIn: \"Header In Value\",con#headerInOut: \"Header In Out Value\"}]")) - .withParameter("body", createStringParameter("#[payload]")) - .getDeclaration()) - .getDeclaration()) - .withComponent(core.newConstruct("errorHandler") - .withComponent(core.newRoute("onErrorContinue") - .withParameterGroup(newParameterGroup() - .withParameter("type", createStringParameter("MULE:ANY")) - .getDeclaration()) - .withComponent(core.newOperation("logger").getDeclaration()) - .getDeclaration()) - .withComponent(core.newRoute("onErrorPropagate") - .withParameterGroup(newParameterGroup() - .withParameter("type", createStringParameter("WSC:CONNECTIVITY")) - .withParameter("when", createStringParameter("#[e.cause == null]")) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(core.newConstruct("flow").withRefName("schedulerFlow") - .withComponent(core.newSource("scheduler") - .withParameterGroup(newParameterGroup() - .withParameter("schedulingStrategy", newObjectValue() - .ofType("org.mule.runtime.core.api.source.scheduler.FixedFrequencyScheduler") - .withParameter("frequency", createNumberParameter("50")) - .withParameter("startDelay", createNumberParameter("20")) - .withParameter("timeUnit", createStringParameter("SECONDS")) - .build()) - .getDeclaration()) - .getDeclaration()) - .withComponent(core.newOperation("logger") - .withParameterGroup(newParameterGroup() - .withParameter("message", createStringParameter("#[payload]")).getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(core.newConstruct("flow").withRefName("cronSchedulerFlow") - .withComponent(core.newSource("scheduler") - .withParameterGroup(newParameterGroup() - .withParameter("schedulingStrategy", newObjectValue() - .ofType("org.mule.runtime.core.api.source.scheduler.CronScheduler") - .withParameter("expression", createStringParameter("0/1 * * * * ?")) - .build()) - .getDeclaration()) - .getDeclaration()) - .withComponent(core.newOperation("logger") - .withParameterGroup(newParameterGroup() - .withParameter("message", createStringParameter("#[payload]")).getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration(); - } - - protected String getExpectedArtifactDeclarationJson() { - return "/declaration/artifact-declaration.json"; - } - - private ParameterValue createNumberParameter(String value) { - return createPlainParameter(value, NUMBER); - } - - private ParameterValue createBooleanParameter(String value) { - return createPlainParameter(value, BOOLEAN); - } - - private ParameterValue createStringParameter(String value) { - SimpleValueType type = STRING; - return createPlainParameter(value, type); - } - - private ParameterValue createStringCdataParameter(String value) { - return createCdataParameter(value, STRING); - } - - private ParameterValue createPlainParameter(String value, SimpleValueType type) { - return plain(value, type); - } - - private ParameterValue createCdataParameter(String value, SimpleValueType type) { - return cdata(value, type); - } -} diff --git a/src/test/java/org/mule/runtime/api/test/meta/model/ElementDeclarationLocationPathTestCase.java b/src/test/java/org/mule/runtime/api/test/meta/model/ElementDeclarationLocationPathTestCase.java deleted file mode 100644 index a6b69abfa..000000000 --- a/src/test/java/org/mule/runtime/api/test/meta/model/ElementDeclarationLocationPathTestCase.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.api.test.meta.model; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newArtifact; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newObjectValue; -import static org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newParameterGroup; -import static org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.CONNECTION; -import org.mule.runtime.app.declaration.api.ArtifactDeclaration; -import org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration; -import org.mule.runtime.app.declaration.api.ConnectionElementDeclaration; -import org.mule.runtime.app.declaration.api.ElementDeclaration; -import org.mule.runtime.app.declaration.api.fluent.ElementDeclarer; -import org.mule.runtime.app.declaration.api.component.location.Location; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; - -public class ElementDeclarationLocationPathTestCase { - - private ArtifactDeclaration multiFlowDeclaration; - - @Before - public void setup() throws Exception { - multiFlowDeclaration = createMultiFlowArtifactDeclaration(); - } - - @Test - public void globalConfig() throws Exception { - Location location = Location.builder().globalName("config").build(); - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getRefName(), is("config")); - } - - @Test - public void getConnection() throws Exception { - Location location = Location.builder().globalName("config").addConnectionPart().build(); - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getName(), is("active-mq-connection")); - } - - @Test - public void globalFlow() throws Exception { - Location location = Location.builder().globalName("bridge").build(); - assertThat(multiFlowDeclaration.findElement(location).isPresent(), is(true)); - } - - @Test - public void messageProcessor() throws Exception { - Location location = Location.builder().globalName("send-payload").addProcessorsPart().addIndexPart(0).build(); - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getName(), is("publish")); - } - - @Test - public void scope() throws Exception { - Location location = Location.builder().globalName("bridge").addProcessorsPart().addIndexPart(1).build(); - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getName(), is("foreach")); - } - - @Test - public void messageProcessorInScope() throws Exception { - Location location = Location.builder().globalName("bridge") - .addProcessorsPart().addIndexPart(1) - .addProcessorsPart().addIndexPart(1) - .build(); - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getName(), is("logger")); - } - - @Test - public void messageSource() throws Exception { - Location location = Location.builder().globalName("testFlow").addSourcePart().build(); - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getName(), is("listener")); - } - - @Test - public void messageProcessorParameter() throws Exception { - Location location = Location.builder().globalName("bridge") - .addProcessorsPart().addIndexPart(0) - .addParameterPart().addPart("destination") - .build(); - - Optional element = multiFlowDeclaration.findElement(location); - assertThat(element.isPresent(), is(true)); - assertThat(element.get().getName(), is("destination")); - } - - private static ArtifactDeclaration createMultiFlowArtifactDeclaration() { - ElementDeclarer jms = ElementDeclarer.forExtension("JMS"); - ElementDeclarer core = ElementDeclarer.forExtension("Mule Core"); - ElementDeclarer http = ElementDeclarer.forExtension("HTTP"); - - return newArtifact().withGlobalElement(jms.newConfiguration("config") - .withRefName("config") - .withConnection(jms.newConnection("active-mq-connection") - .withParameterGroup(newParameterGroup() - .withParameter("cachingStrategy", - newObjectValue() - .ofType("org.mule.extensions.jms.api.connection.caching.NoCachingConfiguration") - .build()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement( - core.newConstruct("flow") - .withRefName("send-payload") - .withComponent(jms.newOperation("publish") - .withConfig("config") - .withParameterGroup(newParameterGroup() - .withParameter("destination", "#[initialDestination]") - .getDeclaration()) - .withParameterGroup(newParameterGroup("Message") - .withParameter("body", "#[payload]") - .withParameter("properties", "#[{(initialProperty): propertyValue}]") - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement( - core.newConstruct("flow").withRefName("bridge") - .withComponent(jms.newOperation("consume") - .withConfig("config") - .withParameterGroup(newParameterGroup() - .withParameter("destination", "#[initialDestination]") - .withParameter("maximumWait", "1000") - .getDeclaration()) - .getDeclaration()) - .withComponent( - core.newConstruct("foreach") - .withComponent(jms.newOperation("publish") - .withConfig("config") - .withParameterGroup(newParameterGroup() - .withParameter("destination", "#[finalDestination]") - .getDeclaration()) - .withParameterGroup(newParameterGroup("Message") - .withParameter("jmsxProperties", - "#[attributes.properties.jmsxProperties]") - .withParameter("body", - "#[bridgePrefix ++ payload]") - .withParameter("properties", - "#[attributes.properties.userProperties]") - .getDeclaration()) - .getDeclaration()) - .withComponent(core.newOperation("logger") - .withParameterGroup(newParameterGroup() - .withParameter("message", "Message Sent") - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement(core.newConstruct("flow").withRefName("bridge-receiver") - .withComponent(jms.newOperation("consume") - .withConfig("config") - .withParameterGroup(newParameterGroup() - .withParameter("destination", "#[finalDestination]") - .withParameter("maximumWait", "1000") - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - - .withGlobalElement( - http.newConfiguration("listenerConfig") - .withRefName("httpListener") - .withParameterGroup(newParameterGroup() - .withParameter("basePath", "/") - .getDeclaration()) - .withConnection(http.newConnection("listener-connection") - .withParameterGroup(newParameterGroup(CONNECTION) - .withParameter("tlsContext", newObjectValue() - .withParameter("key-store", newObjectValue() - .withParameter("path", "ssltest-keystore.jks") - .withParameter("password", "changeit") - .withParameter("keyPassword", "changeit") - .build()) - .build()) - .getDeclaration()) - .withParameterGroup(newParameterGroup() - .withParameter("host", "localhost") - .withParameter("port", "49019") - .withParameter("protocol", "HTTPS") - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement( - http.newConfiguration("request-config") - .withRefName("httpRequester") - .withConnection(http.newConnection("request-connection") - .withParameterGroup(newParameterGroup() - .withParameter("host", "localhost") - .withParameter("port", "49020") - .withParameter("authentication", - newObjectValue() - .ofType( - "org.mule.extension.http.api.request.authentication.BasicAuthentication") - .withParameter("username", "user") - .withParameter("password", "pass") - .build()) - .getDeclaration()) - .withParameterGroup(newParameterGroup(CONNECTION) - .withParameter("clientSocketProperties", - newObjectValue() - .withParameter("connectionTimeout", "1000") - .withParameter("keepAlive", "true") - .withParameter("receiveBufferSize", "1024") - .withParameter("sendBufferSize", "1024") - .withParameter("clientTimeout", "1000") - .withParameter("linger", "1000") - .build()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withGlobalElement( - core.newConstruct("flow") - .withRefName("testFlow") - .withParameterGroup(newParameterGroup() - .withParameter("initialState", "stopped") - .getDeclaration()) - .withComponent(http.newSource("listener") - .withConfig("httpListener") - .withParameterGroup(newParameterGroup() - .withParameter("path", "testBuilder") - .getDeclaration()) - .withParameterGroup(newParameterGroup("Response") - .withParameter("headers", "#[{{'content-type' : 'text/plain'}}]") - .withParameter("body", "#[{'my': 'map'}]") - .getDeclaration()) - .getDeclaration()) - .withComponent( - core.newConstruct("choice") - .withRoute(core.newRoute("when") - .withParameterGroup(newParameterGroup() - .withParameter("expression", "#[true]") - .getDeclaration()) - .withComponent(jms.newOperation("publish") - .withConfig("config") - .withParameterGroup(newParameterGroup() - .withParameter("destination", "#[finalDestination]") - .getDeclaration()) - .withParameterGroup(newParameterGroup("Message") - .withParameter("body", - "#[bridgePrefix ++ payload]") - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .withRoute(core.newRoute("otherwise") - .withComponent(core.newConstruct("foreach") - .withParameterGroup(newParameterGroup() - .withParameter("collection", "#[myCollection]") - .getDeclaration()) - .withComponent(core.newOperation("logger") - .withParameterGroup(newParameterGroup() - .withParameter("message", "#[payload]") - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration()) - .getDeclaration(); - } -}