diff --git a/pom.xml b/pom.xml
index d28dd21a5..a9e148278 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,16 +43,17 @@
src/test/munit
${basedir}/target/test-mule/munit
- 1.1.2
- 2.3.0
- 2.3.0
+ 1.2.0-SNAPSHOT
+ 3.1.0-SNAPSHOT
+ 3.1.0-SNAPSHOT
3.0.2
5.8.0
- 0.8.6
+ 0.8.10
2.13.5
2.3.4
2.10.0
4.13.2
+ 4.11.0
@@ -369,6 +370,13 @@
1.4.01
test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ ${mockito-junit-jupiter.version}
+ test
+
diff --git a/src/test/java/org/mule/module/apikit/ExtensionDeclarerTestCase.java b/src/test/java/org/mule/module/apikit/ExtensionDeclarerTestCase.java
deleted file mode 100644
index d2bfcd3f2..000000000
--- a/src/test/java/org/mule/module/apikit/ExtensionDeclarerTestCase.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit;
-
-import static java.util.Collections.emptySet;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.mule.runtime.api.dsl.DslResolvingContext;
-import org.mule.runtime.api.meta.model.ExtensionModel;
-import org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer;
-import org.mule.runtime.extension.api.loader.ExtensionLoadingContext;
-import org.mule.runtime.extension.api.persistence.ExtensionModelJsonSerializer;
-import org.mule.runtime.extension.internal.loader.DefaultExtensionLoadingContext;
-import org.mule.runtime.extension.internal.loader.ExtensionModelFactory;
-
-import org.junit.Test;
-
-public class ExtensionDeclarerTestCase {
-
- @Test
- public void getApikitExtensionDeclarer() {
- ApikitExtensionLoadingDelegate apikitExtensionLoadingDelegate = new ApikitExtensionLoadingDelegate();
- ExtensionDeclarer extensionDeclarer = new ExtensionDeclarer();
- apikitExtensionLoadingDelegate.accept(extensionDeclarer, null);
- ExtensionModelJsonSerializer serializer = new ExtensionModelJsonSerializer(true);
- ExtensionLoadingContext ctx =
- new DefaultExtensionLoadingContext(extensionDeclarer, Thread.currentThread().getContextClassLoader(),
- DslResolvingContext.getDefault(emptySet()));
- ExtensionModel extensionModel = new ExtensionModelFactory().create(ctx);
- String jsonContent = serializer.serialize(extensionModel);
- assertNotNull(jsonContent);
- assertEquals(2, countOccurences(jsonContent, "BAD_REQUEST"));
- assertEquals(3, countOccurences(jsonContent, "NOT_FOUND"));
- assertEquals(2, countOccurences(jsonContent, "METHOD_NOT_ALLOWED"));
- assertEquals(2, countOccurences(jsonContent, "UNSUPPORTED_MEDIA_TYPE"));
- assertEquals(2, countOccurences(jsonContent, "NOT_ACCEPTABLE"));
- }
-
- private static int countOccurences(String str, String substring) {
- int lastIndex = 0;
- int count = 0;
- while (lastIndex >= 0) {
- lastIndex = str.indexOf(substring, lastIndex);
- if (lastIndex >= 0) {
- count++;
- lastIndex += substring.length();
- }
- }
- return count;
- }
-}
diff --git a/src/test/java/org/mule/module/apikit/MockingUtils.java b/src/test/java/org/mule/module/apikit/MockingUtils.java
deleted file mode 100644
index 0d2e299cd..000000000
--- a/src/test/java/org/mule/module/apikit/MockingUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit;
-
-import sun.reflect.ConstructorAccessor;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-public class MockingUtils {
-
- public static T createEnumValue(Class enumClass, String name, int ordinal, String description) throws Exception {
- Class monsterClass = enumClass;
- Constructor> constructor = monsterClass.getDeclaredConstructors()[0];
- constructor.setAccessible(true);
-
- Field constructorAccessorField = Constructor.class.getDeclaredField("constructorAccessor");
- constructorAccessorField.setAccessible(true);
- ConstructorAccessor ca = (ConstructorAccessor) constructorAccessorField.get(constructor);
- if (ca == null) {
- Method acquireConstructorAccessorMethod = Constructor.class.getDeclaredMethod("acquireConstructorAccessor");
- acquireConstructorAccessorMethod.setAccessible(true);
- ca = (ConstructorAccessor) acquireConstructorAccessorMethod.invoke(constructor);
- }
- T enumValue =
- (T) ca.newInstance(description != null ? new Object[] {name, ordinal, description} : new Object[] {name, ordinal});
- return enumValue;
- }
-
- public static void setAccessible(Field field, Object newValue) throws Exception {
- field.setAccessible(true);
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- field.set(null, newValue);
- }
-}
diff --git a/src/test/java/org/mule/module/apikit/MuleVersionUtilsTest.java b/src/test/java/org/mule/module/apikit/MuleVersionUtilsTest.java
deleted file mode 100644
index 30e280907..000000000
--- a/src/test/java/org/mule/module/apikit/MuleVersionUtilsTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit;
-
-import org.junit.Test;
-import org.mule.module.apikit.utils.MuleVersionUtils;
-import org.mule.runtime.core.api.config.MuleManifest;
-
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mule.module.apikit.MockingUtils.setAccessible;
-
-public class MuleVersionUtilsTest {
-
- @Test
- public void newerVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.3.0");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void newerSnapshotVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.3.0-SNAPSHOT");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void olderVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.1.0");
- assertFalse(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void olderSnapshotVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.1.0-SNAPSHOT");
- assertFalse(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void sameVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void snapshotVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0-SNAPSHOT");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void hotFixVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0-hf1");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void hotFixWithDateSuffixVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0-20200525");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void releaseCandidateVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0-rc1");
- assertTrue(MuleVersionUtils.isAtLeast("4.2.0"));
- }
-
- @Test
- public void invalidVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0");
- assertFalse(MuleVersionUtils.isAtLeast("a.b.3"));
- }
-
- @Test
- public void blankVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0");
- assertFalse(MuleVersionUtils.isAtLeast(" "));
- }
-
- @Test
- public void nullVersionIsAtLeastTest() throws Exception {
- setManifestImplementationVersion("4.2.0");
- assertFalse(MuleVersionUtils.isAtLeast(null));
- }
-
- private void setManifestImplementationVersion(String version) throws Exception {
- Manifest manifestMock = mock(Manifest.class);
- when(manifestMock.getMainAttributes()).thenReturn(mock(Attributes.class));
- when(manifestMock.getMainAttributes().getValue(new Attributes.Name("Implementation-Version"))).thenReturn(version);
- setAccessible(MuleManifest.class.getDeclaredField("manifest"), manifestMock);
- }
-
-
-}
diff --git a/src/test/java/org/mule/module/apikit/RamlHandlerTestCase.java b/src/test/java/org/mule/module/apikit/RamlHandlerTestCase.java
deleted file mode 100644
index 1295ce271..000000000
--- a/src/test/java/org/mule/module/apikit/RamlHandlerTestCase.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mule.apikit.model.ApiSpecification;
-import org.mule.apikit.model.ApiVendor;
-import org.mule.module.apikit.api.RamlHandler;
-import org.mule.parser.service.ParserMode;
-import org.mule.parser.service.result.DefaultParsingIssue;
-import org.mule.parser.service.result.ParsingIssue;
-import org.mule.parser.service.result.UnsupportedParsingIssue;
-import org.mule.runtime.core.api.MuleContext;
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Supplier;
-import java.util.stream.Stream;
-
-import static java.util.stream.Collectors.toList;
-import static junit.framework.TestCase.assertTrue;
-import static junit.framework.TestCase.fail;
-import static org.hamcrest.core.StringContains.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mule.apikit.ApiType.AMF;
-import static org.mule.apikit.ApiType.RAML;
-import static org.mule.parser.service.ParserMode.AUTO;
-
-public class RamlHandlerTestCase {
-
- private static final String UNSUPPORTED_FEATURE_CAUSE = "Unsupported Feature Cause";
- private static final String TEST_CAUSE = "Test Cause";
- private static MuleContext muleContext;
-
- @BeforeClass
- public static void beforeAll() {
- muleContext = mock(MuleContext.class);
- when(muleContext.getExecutionClassLoader()).thenReturn(Thread.currentThread().getContextClassLoader());
- }
-
- @Test
- public void apiVendorForRaml08() {
- String ramlLocation = "unit/raml-handler/simple08.raml";
- String apiServer = "unused";
- RamlHandler handler = createRamlHandler(ramlLocation, true);
- handler.setApiServer(apiServer);
- assertTrue(handler.getApiVendor().equals(ApiVendor.RAML_08));
- }
-
- @Test
- public void isParserV2TrueUsingRaml10() {
- String ramlLocation = "unit/raml-handler/simple10.raml";
- String apiServer = "unused";
- RamlHandler handler = createRamlHandler(ramlLocation);
- handler.setApiServer(apiServer);
- assertTrue(handler.isParserV2());
- assertTrue(handler.getApiVendor().equals(ApiVendor.RAML_10));
- }
-
- @Test
- public void addLocalHostAsServerWhenIsNotDefined() {
- String ramlLocation = "unit/raml-handler/simple10.raml";
- boolean keepRamlBaseUri = false;
- RamlHandler handler = createRamlHandler(ramlLocation, keepRamlBaseUri);
- handler.setApiServer("localhost:8081/");
- String rootRaml = handler.getAMFModel();
- assertThat(rootRaml, containsString("localhost:8081/"));
- }
-
- @Test
- public void streamAMFModelReplacingUrl() throws IOException {
- RamlHandler handler = createRamlHandler("unit/raml-handler/simple10.raml", false);
- PipedOutputStream pipedOutputStream = new PipedOutputStream();
- PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream);
- Thread thread = new Thread(() -> handler.writeAMFModel("http://google.com", pipedOutputStream));
- thread.start();
- String model = IOUtils.toString(pipedInputStream);
- assertThat(model, containsString("http://google.com"));
- }
-
- @Test
- public void getRamlV2KeepRamlBaseUriTrue() {
- String ramlLocation = "unit/raml-handler/simple10-with-example.raml";
- boolean keepRamlBaseUri = true;
- String apiServer = "http://www.newBaseUri.com";
- RamlHandler handler = createRamlHandler(ramlLocation, keepRamlBaseUri);
- handler.setApiServer(apiServer);
- String rootRaml = handler.getRamlV2("unit/raml-handler/?raml");
- assertTrue(rootRaml.contains("RAML 1.0"));
- assertTrue(!rootRaml.contains(apiServer));
- assertTrue(rootRaml.contains("baseUri: http://localhost/myapi"));
- }
-
-
-
- @Test
- public void getRamlV2KeepRamlBaseUriFalse() {
- String ramlLocation = "unit/raml-handler/simple10-with-example.raml";// this.getClass().getResource("../../../../org/mule/module/apikit/simple-raml/simple10-with-example.raml").toString();
- String apiServer = "http://pepe.com";
- RamlHandler handler = createRamlHandler(ramlLocation, false);
- handler.setApiServer(apiServer);
-
- String ramlV1 = handler.getRamlV1();
- assertTrue(ramlV1.contains("baseUri: " + apiServer));
-
- String ramlV2 = handler.getRamlV2("unit/raml-handler/?raml");
- assertTrue(ramlV2.contains("baseUri: " + apiServer));
-
- String ramlAmf = handler.getAMFModel();
- assertThat(ramlAmf, containsString("\"" + apiServer + "\""));
- }
-
- @Test
- public void getRamlV2Example() {
- String ramlLocation = "unit/raml-handler/simple10-with-example.raml";
- String apiServer = "unused";
- RamlHandler handler = createRamlHandler(ramlLocation);
- handler.setApiServer(apiServer);
- assertTrue(handler.getRamlV2("unit/raml-handler/example.json/?raml").contains("{\"name\":\"jane\"}"));
- }
-
- @Test
- public void testInitializationUsingAUTO() {
- RamlHandler handler;
-
- final boolean keepRamlBaseUri = true;
-
- handler = createRamlHandler("unit/raml-handler/amf-only.raml", keepRamlBaseUri, ParserMode.AUTO);
- assertEquals(AMF, handler.getApi().getType());
-
- assertException("Invalid reference 'SomeTypo'",
- () -> createRamlHandler("unit/raml-handler/failing-api.raml", keepRamlBaseUri, ParserMode.AUTO));
- }
-
- @Test
- public void testInitializationUsingAMF() {
- RamlHandler handler;
-
- final boolean keepRamlBaseUri = true;
-
- handler = createRamlHandler("unit/raml-handler/amf-only.raml", keepRamlBaseUri, ParserMode.AMF);
- assertEquals(AMF, handler.getApi().getType());
-
- assertException("Unresolved reference 'SomeTypo'",
- () -> createRamlHandler("unit/raml-handler/failing-api.raml", keepRamlBaseUri, ParserMode.AMF));
- }
-
- @Test
- public void testInitializationUsingRAML() {
- RamlHandler handler;
-
- final boolean keepRamlBaseUri = true;
-
- handler = createRamlHandler("unit/raml-handler/raml-parser-only.raml", keepRamlBaseUri, ParserMode.RAML);
- assertEquals(RAML, handler.getApi().getType());
-
- assertException("Invalid reference 'SomeTypo'",
- () -> createRamlHandler("unit/raml-handler/failing-api.raml", keepRamlBaseUri, ParserMode.RAML));
- }
-
- @Test
- public void ramlWithSpacesInPath() {
- RamlHandler handler = createRamlHandler("unit/space in path api/api.raml", true, ParserMode.RAML);
- ApiSpecification api = handler.getApi();
- assertEquals(RAML, api.getType());
- List refs = api.getAllReferences();
- assertTrue(refs.stream().anyMatch(ref -> ref.endsWith("unit/space%20in%20path%20api/example.json")));
- assertTrue(refs.stream().anyMatch(ref -> ref.endsWith("unit/space%20in%20path%20api/more%20spaces/schema.json")));
- }
-
- @Test
- public void oas30WithUnsupportedFeatures() {
- assertNotNull(createRamlHandler("unit/raml-handler/oas30-api.yaml", true, ParserMode.AMF));
- }
-
- @Test
- public void testFilteringOutUnsupportedParsingIssue() throws Exception {
- RamlHandler ramlHandler = mock(RamlHandler.class);
- Class[] cArg = new Class[2];
- cArg[0] = List.class;
- cArg[1] = boolean.class;
- Method getFilteredParsingIssueStream = RamlHandler.class.getDeclaredMethod("getFilteredParsingIssueStream", cArg);
- getFilteredParsingIssueStream.setAccessible(true);
- List parsingIssues =
- Arrays.asList(new DefaultParsingIssue(TEST_CAUSE), new UnsupportedParsingIssue(UNSUPPORTED_FEATURE_CAUSE));
- Stream result = (Stream) getFilteredParsingIssueStream.invoke(ramlHandler, parsingIssues, true);
- List collectedResults = result.map(e -> e.cause()).collect(toList());
- assertEquals(1, collectedResults.size());
- assertEquals(TEST_CAUSE, collectedResults.get(0));
- result = (Stream) getFilteredParsingIssueStream.invoke(ramlHandler, parsingIssues, false);
- collectedResults = result.map(e -> e.cause()).collect(toList());
- assertEquals(2, collectedResults.size());
- assertEquals(TEST_CAUSE, collectedResults.get(0));
- assertEquals(UNSUPPORTED_FEATURE_CAUSE, collectedResults.get(1));
- }
-
- private void assertException(String message, Supplier supplier) {
- try {
- supplier.get();
- fail("an exception was expected");
- } catch (Exception e) {
- assertThat(e.getMessage(), containsString(message));
- }
- }
-
- private RamlHandler createRamlHandler(String ramlPath) {
- return createRamlHandler(ramlPath, true, AUTO);
- }
-
- private RamlHandler createRamlHandler(String ramlPath, boolean keepRamlBaseUri) {
- return createRamlHandler(ramlPath, keepRamlBaseUri, AUTO);
- }
-
- private RamlHandler createRamlHandler(String ramlPath, boolean keepRamlBaseUri, ParserMode parser) {
- return createRamlHandler(ramlPath, keepRamlBaseUri, parser, false);
- }
-
- private RamlHandler createRamlHandler(String ramlPath, boolean keepRamlBaseUri, ParserMode parser,
- boolean filterUnsupportedLogging) {
- try {
- return new RamlHandler(null, ramlPath, keepRamlBaseUri, muleContext.getErrorTypeRepository(), parser,
- filterUnsupportedLogging);
- } catch (IOException e) {
- throw new RuntimeException("Error creating RamlHandler", e);
- }
- }
-}
diff --git a/src/test/java/org/mule/module/apikit/RoutingTableTestCase.java b/src/test/java/org/mule/module/apikit/RoutingTableTestCase.java
deleted file mode 100644
index 432936175..000000000
--- a/src/test/java/org/mule/module/apikit/RoutingTableTestCase.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit;
-
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mule.module.apikit.api.RamlHandler;
-import org.mule.module.apikit.api.RoutingTable;
-import org.mule.module.apikit.api.uri.URIPattern;
-import org.mule.module.apikit.api.uri.URIResolver;
-import org.mule.module.apikit.uri.URIResolveResult;
-import org.mule.runtime.core.api.MuleContext;
-
-public class RoutingTableTestCase {
-
- private static RamlHandler ramlHandler;
- private static MuleContext muleContext;
-
- @BeforeClass
- public static void beforeAll() throws IOException {
- muleContext = mock(MuleContext.class);
- when(muleContext.getExecutionClassLoader()).thenReturn(Thread.currentThread().getContextClassLoader());
- ramlHandler = new RamlHandler("unit/routing-table-sample.raml", true, muleContext.getErrorTypeRepository());
- }
-
- public RoutingTableTestCase() {}
-
- @Test
- public void testResourceFlattenedTree() {
- RoutingTable routingTable = new RoutingTable(ramlHandler.getApi());
-
- Assert.assertThat(routingTable.keySet(), hasItems(new URIPattern("/single-resource"),
- new URIPattern("/api"),
- new URIPattern("/api/sub-resource"),
- new URIPattern("/api/sub-resource-types")));
- }
-
- @Test
- public void emptyParametersAreMatchedButNotResolved() {
- URIPattern pattern = new URIPattern("/api/{parameter}/list");
- Assert.assertTrue(pattern.match("/api//list"));
- URIResolver resolver = new URIResolver("/api//list");
- Assert.assertEquals(URIResolveResult.Status.ERROR, resolver.resolve(pattern).getStatus());
- }
-
- @Test
- public void getResourceByPattern() {
- RoutingTable routingTable = new RoutingTable(ramlHandler.getApi());
-
- Assert.assertNotNull(routingTable.getResource(new URIPattern("/single-resource")));
- Assert.assertNotNull(routingTable.getResource(new URIPattern("/api/sub-resource")));
- }
-
- @Test
- public void getResourceByString() {
- RoutingTable routingTable = new RoutingTable(ramlHandler.getApi());
-
- Assert.assertNotNull(routingTable.getResource("/single-resource"));
- Assert.assertNotNull(routingTable.getResource("/api/sub-resource"));
- }
-}
diff --git a/src/test/java/org/mule/module/apikit/console/BaseUriReplacementTestCase.java b/src/test/java/org/mule/module/apikit/console/BaseUriReplacementTestCase.java
deleted file mode 100644
index 6217c796c..000000000
--- a/src/test/java/org/mule/module/apikit/console/BaseUriReplacementTestCase.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit.console;
-
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mule.module.apikit.api.RamlHandler;
-import org.mule.module.apikit.api.UrlUtils;
-import org.mule.runtime.api.exception.ErrorTypeRepository;
-import org.mule.runtime.core.api.MuleContext;
-
-import static java.lang.System.clearProperty;
-import static java.lang.System.setProperty;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mule.module.apikit.api.UrlUtils.getBaseUriReplacement;
-import static org.mule.module.apikit.api.UrlUtils.replaceHostInURL;
-import static org.mule.parser.service.ParserMode.AUTO;
-
-public class BaseUriReplacementTestCase {
-
- private static final String FULL_DOMAIN = UrlUtils.FULL_DOMAIN;
-
- private static MuleContext muleContext;
-
- @BeforeClass
- public static void beforeAll() {
- muleContext = mock(MuleContext.class);
- when(muleContext.getExecutionClassLoader()).thenReturn(Thread.currentThread().getContextClassLoader());
- }
-
- @Test
- public void baseUriReplacementTest() throws Exception {
- ErrorTypeRepository errorRepo = muleContext.getErrorTypeRepository();
- RamlHandler ramlHandler = new RamlHandler(null, "unit/console/simple-with-baseuri10.raml", false, errorRepo, AUTO);
- assertEquals("http://localhost:8081/api", ramlHandler.getBaseUriReplacement("http://localhost:8081/api"));
- assertEquals("http://localhost:8081/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io");
- assertEquals("http://localhost:8081/api", ramlHandler.getBaseUriReplacement("http://localhost:8081/api"));
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io");
- assertEquals("http://localhost:8081/api", ramlHandler.getBaseUriReplacement("http://localhost:8081/api"));
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io/");
- assertEquals("http://localhost:8081/api", ramlHandler.getBaseUriReplacement("http://localhost:8081/api"));
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io/");
- assertEquals("http://localhost:8081/api", ramlHandler.getBaseUriReplacement("http://localhost:8081/api"));
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io");
- assertEquals("http://localhost:8081/api/", ramlHandler.getBaseUriReplacement("http://localhost:8081/api/"));
- assertEquals("http://pepe.cloudhub.io/api/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api/"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io");
- assertEquals("http://pepe.cloudhub.io/api/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api/"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io/");
- assertEquals("http://pepe.cloudhub.io/api/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api/"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io/");
- assertEquals("http://pepe.cloudhub.io/api/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/api/"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io");
- assertEquals("http://localhost:8081/", ramlHandler.getBaseUriReplacement("http://localhost:8081/"));
- assertEquals("http://pepe.cloudhub.io/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io");
- assertEquals("http://pepe.cloudhub.io/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io/");
- assertEquals("http://pepe.cloudhub.io/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io/");
- assertEquals("http://pepe.cloudhub.io/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081/"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io");
- assertEquals("http://localhost:8081", ramlHandler.getBaseUriReplacement("http://localhost:8081"));
- assertEquals("http://pepe.cloudhub.io", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io");
- assertEquals("http://pepe.cloudhub.io", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io/");
- assertEquals("http://pepe.cloudhub.io/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io/");
- assertEquals("http://pepe.cloudhub.io/", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io/api");
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io/api");
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "http://pepe.cloudhub.io/api");
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
-
- setProperty(FULL_DOMAIN, "pepe.cloudhub.io/api");
- assertEquals("http://pepe.cloudhub.io/api", ramlHandler.getBaseUriReplacement("http://0.0.0.0:8081"));
- }
-
- @Test
- public void consoleUriReplacementTest() {
- assertEquals("http://localhost:8081/console", getBaseUriReplacement("http://localhost:8081/console"));
- assertEquals("http://localhost:8081/console/", getBaseUriReplacement("http://localhost:8081/console/"));
-
- setProperty(FULL_DOMAIN, "http://aamura.cloudhub.io/api");
- assertEquals("http://aamura.cloudhub.io/api/console", getBaseUriReplacement("http://0.0.0.0:8081/console"));
- assertEquals("http://aamura.cloudhub.io/api/console/", getBaseUriReplacement("http://0.0.0.0:8081/console/"));
-
- setProperty(FULL_DOMAIN, "http://aamura.cloudhub.io/api/");
- assertEquals("http://aamura.cloudhub.io/api/console", getBaseUriReplacement("http://0.0.0.0:8081/console"));
- assertEquals("http://aamura.cloudhub.io/api/console/", getBaseUriReplacement("http://0.0.0.0:8081/console/"));
-
- setProperty(FULL_DOMAIN, "https://aamura.cloudhub.io/api");
- assertEquals("https://aamura.cloudhub.io/api/console", getBaseUriReplacement("http://0.0.0.0:8081/console"));
- assertEquals("https://aamura.cloudhub.io/api/console/", getBaseUriReplacement("http://0.0.0.0:8081/console/"));
-
- setProperty(FULL_DOMAIN, "https://aamura.cloudhub.io/api/");
- assertEquals("https://aamura.cloudhub.io/api/console", getBaseUriReplacement("http://0.0.0.0:8081/console"));
- assertEquals("https://aamura.cloudhub.io/api/console/", getBaseUriReplacement("http://0.0.0.0:8081/console/"));
-
- setProperty(FULL_DOMAIN, "https://aamura.cloudhub.io/api/v1");
- assertEquals("https://aamura.cloudhub.io/api/v1/console", getBaseUriReplacement("http://0.0.0.0:8081/console"));
- assertEquals("https://aamura.cloudhub.io/api/v1/console/", getBaseUriReplacement("http://0.0.0.0:8081/console/"));
-
- setProperty(FULL_DOMAIN, "aamura.cloudhub.io/api/v1");
- assertEquals("https://aamura.cloudhub.io/api/v1/console", getBaseUriReplacement("https://0.0.0.0:8081/console"));
- assertEquals("https://aamura.cloudhub.io/api/v1/console/", getBaseUriReplacement("https://0.0.0.0:8081/console/"));
-
- assertEquals("http://aamura.cloudhub.io/api/v1/console", getBaseUriReplacement("http://0.0.0.0:8081/console"));
- assertEquals("http://aamura.cloudhub.io/api/v1/console/", getBaseUriReplacement("http://0.0.0.0:8081/console/"));
- }
-
- @Test
- public void withoutSystemProperty() {
- assertEquals("http://localhost:48518/api/", getBaseUriReplacement("http://0.0.0.0:48518/api/"));
- assertEquals("http://localhost:48518/api/", getBaseUriReplacement("http://localhost:48518/api/"));
- assertNull(getBaseUriReplacement(null));
-
- }
-
- @Test
- public void replaceHostWithIncomingRequestHost() {
- assertEquals("http://localhost:48518/api", replaceHostInURL("http://0.0.0.0:48518/api", "http://localhost:48518"));
- assertEquals("http://localhost:48518/api/", replaceHostInURL("http://0.0.0.0:48518/api/", "http://localhost:48518"));
- assertEquals("http://localhost:48518/api/", replaceHostInURL("http://0.0.0.0:48518/api/", "localhost:48518"));
- assertEquals("https://127.0.0.1:48518/api/", replaceHostInURL("https://0.0.0.0:48518/api/", "https://127.0.0.1:48518"));
- assertEquals("http://192.168.0.196:48518/api/", replaceHostInURL("http://0.0.0.0:48518/api/", "http://192.168.0.196:48518"));
- assertEquals("https://192.168.0.196:48518/api/",
- replaceHostInURL("https://0.0.0.0:48518/api/", "https://192.168.0.196:48518"));
- assertEquals("https://192.168.0.196:48518/api/", replaceHostInURL("https://0.0.0.0:48518/api/", "192.168.0.196:48518"));
- }
-
- @Test
- public void replaceHostWithSystemProperty() {
- // using host from system property, instead from incoming request
- setProperty(FULL_DOMAIN, "aamura.cloudhub.io/v1");
- assertEquals("https://aamura.cloudhub.io/v1/api/", replaceHostInURL("https://0.0.0.0:48518/api/", "192.168.0.196:48518"));
- setProperty(FULL_DOMAIN, "https://aamura.cloudhub.io/v1");
- assertEquals("https://aamura.cloudhub.io/v1/api/", replaceHostInURL("https://0.0.0.0:48518/api/", "192.168.0.196:48518"));
- }
-
- @After
- public void after() {
- clearProperty(FULL_DOMAIN);
- }
-
-}
diff --git a/src/test/java/org/mule/module/apikit/deserializing/AttributeDeserializerTest.java b/src/test/java/org/mule/module/apikit/deserializing/AttributeDeserializerTest.java
deleted file mode 100644
index f18a06d68..000000000
--- a/src/test/java/org/mule/module/apikit/deserializing/AttributeDeserializerTest.java
+++ /dev/null
@@ -1,644 +0,0 @@
-/*
- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
- * 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.module.apikit.deserializing;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.mule.module.apikit.api.deserializing.ArrayHeaderDelimiter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mule.module.apikit.MockingUtils.createEnumValue;
-import static org.mule.module.apikit.api.deserializing.ArrayHeaderDelimiter.COMMA;
-import static org.mule.module.apikit.deserializing.DeserializerTestBuilder.when;
-
-@RunWith(Parameterized.class)
-public class AttributeDeserializerTest {
-
- protected static final String TWO_LEVEL_OBJECT =
- "{\"color\": \"RED\", \"manufacturer\": {\"brand\": \"Ferrari\"}, \"reseller\": {\"name\": \"YourCar\"}}";
- protected static final String ESCAPED_TWO_LEVEL_OBJECT =
- "{\\\"color\\\": \\\"RED\\\", \\\"manufacturer\\\": {\\\"brand\\\": \\\"Ferrari\\\"}, \\\"reseller\\\": {\\\"name\\\": \\\"YourCar\\\"}}";
-
- protected static final String TWO_LEVEL_OBJECT_WITH_LINE_FEEDS = "{\n" +
- " \"color\": \"RED\",\n" +
- " \"manufacturer\": {\n" +
- " \"brand\": \"Ferrari\"\n" +
- " }\n" +
- " \"reseller\": {\n" +
- " \"name\": \"YourCar\"\n" +
- " }\n" +
- "}";
-
- protected static final String TWO_LEVEL_OBJECT_BETWEEN_QUOTES = "\"" + ESCAPED_TWO_LEVEL_OBJECT + "\"";
-
- @Parameterized.Parameter
- public ArrayHeaderDelimiter arrayHeaderDelimiter;
- @Parameterized.Parameter(1)
- public AttributeDeserializer deserializer;
-
- @Parameterized.Parameters(name = "Delimiter = {0} - {1}")
- public static Iterable