Skip to content

Commit

Permalink
jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
elrodro83 committed Dec 4, 2023
1 parent ee676a5 commit 88c2457
Show file tree
Hide file tree
Showing 31 changed files with 6,167 additions and 1,242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
*/
package org.mule.runtime.module.extension.mule.internal.loader;

import static org.mule.runtime.api.util.MuleSystemProperties.SYSTEM_PROPERTY_PREFIX;
import static org.mule.runtime.api.util.Preconditions.checkArgument;
import static org.mule.runtime.core.api.util.FileUtils.stringToFile;
import static org.mule.runtime.core.api.util.IOUtils.getResourceAsUrl;
import static org.mule.test.allure.AllureConstants.ReuseFeature.REUSE;
import static org.mule.test.allure.AllureConstants.ReuseFeature.ReuseStory.APPLICATION_EXTENSION_MODEL;

import static java.lang.Boolean.getBoolean;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.mule.runtime.api.util.Preconditions.checkArgument;
import static org.mule.test.allure.AllureConstants.ReuseFeature.REUSE;
import static org.mule.test.allure.AllureConstants.ReuseFeature.ReuseStory.APPLICATION_EXTENSION_MODEL;

import org.mule.functional.junit4.MuleArtifactFunctionalTestCase;
import org.mule.runtime.api.meta.NamedObject;
Expand All @@ -33,23 +39,29 @@
import org.mule.runtime.core.api.util.IOUtils;
import org.mule.runtime.extension.api.persistence.ExtensionModelJsonSerializer;

import java.io.File;
import java.io.InputStream;

import javax.inject.Inject;

import org.skyscreamer.jsonassert.JSONAssert;

import org.junit.Test;

import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;

@Feature(REUSE)
@Story(APPLICATION_EXTENSION_MODEL)
public class ApplicationAsExtensionModelTestCase extends MuleArtifactFunctionalTestCase {

private static final boolean UPDATE_EXPECTED_FILES_ON_ERROR =
getBoolean(SYSTEM_PROPERTY_PREFIX + "extensionModelJson.updateExpectedFilesOnError");

@Inject
private ExtensionManager extensionManager;

private ExtensionModelJsonSerializer serializer = new ExtensionModelJsonSerializer();
private final ExtensionModelJsonSerializer serializer = new ExtensionModelJsonSerializer();

@Override
protected String getConfigFile() {
Expand All @@ -58,13 +70,25 @@ protected String getConfigFile() {

@Test
public void loadApplicationExtensionModel() throws Exception {
String expectedFilePath = "app-as-mule-extension.json";
ExtensionModel extensionModel = getAppExtensionModel();
String json = serializer.serialize(extensionModel);
String expected = getResource("/models/app-as-mule-extension.json");
String actual = serializer.serialize(extensionModel);
String expected = getResource("/models/" + expectedFilePath);
try {
JSONAssert.assertEquals(expected, json, true);
JSONAssert.assertEquals(expected, actual, true);
} catch (AssertionError e) {
System.out.println(json);
if (shouldUpdateExpectedFilesOnError()) {
File root = new File(getResourceAsUrl(getExpectedFilesDir() + expectedFilePath, getClass()).toURI());

for (root = root.getParentFile(); !root.getName().equals("target"); root = root.getParentFile());
root = root.getParentFile();

File testDir = new File(root, "src/test/resources/" + getExpectedFilesDir());
File target = new File(testDir, expectedFilePath);
stringToFile(target.getAbsolutePath(), actual);

System.out.println(expectedFilePath + " fixed");
}
throw e;
}
}
Expand Down Expand Up @@ -121,4 +145,12 @@ private String getResource(String path) {

return IOUtils.toString(in);
}

protected boolean shouldUpdateExpectedFilesOnError() {
return UPDATE_EXPECTED_FILES_ON_ERROR;
}

protected String getExpectedFilesDir() {
return "models/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -302,7 +306,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -453,7 +461,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -572,7 +584,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -719,7 +735,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -839,7 +859,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -986,7 +1010,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -1104,7 +1132,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -1583,7 +1615,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -1973,7 +2009,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -2124,7 +2164,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -2390,7 +2434,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -2739,7 +2787,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -2889,7 +2941,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -3153,7 +3209,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -3304,7 +3364,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -3390,7 +3454,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -3537,7 +3605,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -3836,7 +3908,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down Expand Up @@ -3987,7 +4063,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -4175,7 +4255,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
},
"outputAttributes": {
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Void"
},
"hasDynamicType": false,
Expand Down Expand Up @@ -199,7 +203,11 @@
"parameters": [
{
"type": {
"format": "java",
"format": {
"id": "muleInfra",
"label": "Mule Infrastructure",
"validMimeTypes": []
},
"type": "Array",
"annotations": {
"infrastructureType": {},
Expand Down
Loading

0 comments on commit 88c2457

Please sign in to comment.