diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java index 0298305978..e367122bdd 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java @@ -31,4 +31,6 @@ public interface PluginExecutor extends ExtensionPoint { * @param connection */ void datasourceDestroy(Object connection); + + Boolean isDatasourceValid(DatasourceConfiguration datasourceConfiguration); } diff --git a/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java b/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java index b3b2d444e1..238d412167 100644 --- a/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java +++ b/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java @@ -125,6 +125,11 @@ public class MongoPlugin extends BasePlugin { } } + @Override + public Boolean isDatasourceValid(DatasourceConfiguration datasourceConfiguration) { + return true; + } + } } diff --git a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java index f951663205..a104081234 100644 --- a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java +++ b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java @@ -116,6 +116,11 @@ public class PostgresPlugin extends BasePlugin { } } + @Override + public Boolean isDatasourceValid(DatasourceConfiguration datasourceConfiguration) { + return true; + } + } } diff --git a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java index 9db30a1486..b3a9ce1699 100644 --- a/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java +++ b/app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/plugins/RestApiPlugin.java @@ -19,8 +19,10 @@ import org.springframework.web.util.UriComponentsBuilder; import reactor.core.publisher.Mono; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import java.util.List; public class RestApiPlugin extends BasePlugin { @@ -112,6 +114,22 @@ public class RestApiPlugin extends BasePlugin { } + @Override + public Boolean isDatasourceValid(DatasourceConfiguration datasourceConfiguration) { + if (datasourceConfiguration.getUrl() == null) { + System.out.println("URL is null. Data validation failed"); + return false; + } + // Check for URL validity + try { + new URL(datasourceConfiguration.getUrl()).toURI(); + return true; + } catch (Exception e) { + System.out.println("URL is invalid. Data validation failed"); + return false; + } + } + private void addHeadersToRequest(WebClient.Builder webClientBuilder, List headers) { for (Property header : headers) { if (header.getKey() != null && !header.getKey().isEmpty()) { diff --git a/app/server/appsmith-server/pom.xml b/app/server/appsmith-server/pom.xml index fc60ba8562..3c9328f6c4 100644 --- a/app/server/appsmith-server/pom.xml +++ b/app/server/appsmith-server/pom.xml @@ -168,6 +168,10 @@ rollbar-java 1.5.2 + + org.mockito + mockito-core + diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java index 7af14b8d2f..9edcb56525 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java @@ -7,5 +7,6 @@ public class FieldName { public static String PAGEID = "pageId"; public static String LAYOUTID = "layoutId"; public static String APPLICATIONID = "applicationId"; + public static String DATASOURCE = "datasource"; public static String CONFIG = "config"; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index 8a01438fd9..da223c554c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -22,6 +22,7 @@ public enum AppsmithError { UNAUTHORIZED_DOMAIN(401, 4012, "Invalid email domain provided. Please sign in with a valid work email ID"), UNAUTHORIZED_ACCESS(401, 4013, "Unauthorized access"), INVALID_ACTION_NAME(401, 4014, "Action name is invalid. Please input syntactically correct name"), + INVALID_DATASOURCE_CONFIGURATION(400, 4015, "Datasource configuration is invalid"), INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request"), REPOSITORY_SAVE_FAILED(500, 5001, "Repository save failed"), PLUGIN_INSTALLATION_FAILED_DOWNLOAD_ERROR(500, 5002, "Due to error in downloading the plugin from remote repository, plugin installation has failed. Check the jar location and try again"), diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/PluginExecutorHelper.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/PluginExecutorHelper.java new file mode 100644 index 0000000000..6df358083c --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/PluginExecutorHelper.java @@ -0,0 +1,34 @@ +package com.appsmith.server.helpers; + +import com.appsmith.external.plugins.PluginExecutor; +import com.appsmith.server.domains.Plugin; +import com.appsmith.server.exceptions.AppsmithError; +import com.appsmith.server.exceptions.AppsmithException; +import org.pf4j.PluginManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Component +public class PluginExecutorHelper { + + private PluginManager pluginManager; + + @Autowired + public PluginExecutorHelper(PluginManager pluginManager) { + this.pluginManager = pluginManager; + } + + public Mono getPluginExecutor(Mono pluginMono) { + return pluginMono.flatMap(plugin -> { + List executorList = pluginManager.getExtensions(PluginExecutor.class, plugin.getExecutorClass()); + if (executorList.isEmpty()) { + return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin", plugin.getExecutorClass())); + } + return Mono.just(executorList.get(0)); + } + ); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java index 22f829cfb7..922db70162 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java @@ -7,14 +7,11 @@ import com.appsmith.external.models.Param; import com.appsmith.external.plugins.PluginExecutor; import com.appsmith.server.constants.AnalyticsEvents; import com.appsmith.server.constants.FieldName; -import com.appsmith.server.domains.Action; -import com.appsmith.server.domains.Datasource; -import com.appsmith.server.domains.Page; -import com.appsmith.server.domains.PageAction; -import com.appsmith.server.domains.Plugin; +import com.appsmith.server.domains.*; import com.appsmith.server.dtos.ExecuteActionDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.repositories.ActionRepository; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -22,7 +19,6 @@ import com.github.mustachejava.DefaultMustacheFactory; import com.github.mustachejava.Mustache; import com.github.mustachejava.MustacheFactory; import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.ReactiveMongoTemplate; import org.springframework.data.mongodb.core.convert.MongoConverter; @@ -37,11 +33,7 @@ import javax.validation.constraints.NotNull; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static com.appsmith.server.helpers.BeanCopyUtils.copyNewFieldValuesIntoOldObject; @@ -56,9 +48,9 @@ public class ActionServiceImpl extends BaseService pluginService.findById(datasource.getPluginId())) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin"))); - Mono pluginExecutorMono = pluginMono.flatMap(plugin -> { - List executorList = pluginManager.getExtensions(PluginExecutor.class, plugin.getExecutorClass()); - if (executorList.isEmpty()) { - return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin", plugin.getExecutorClass())); - } - return Mono.just(executorList.get(0)); - } - ); + Mono pluginExecutorMono = pluginExecutorHelper.getPluginExecutor(pluginMono); // 4. Execute the query return actionMono diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceContextServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceContextServiceImpl.java index cb2ae9a3f3..ba2bfa5386 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceContextServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceContextServiceImpl.java @@ -2,18 +2,15 @@ package com.appsmith.server.services; import com.appsmith.external.plugins.PluginExecutor; import com.appsmith.server.domains.Datasource; -import com.appsmith.server.domains.DatasourceContext; import com.appsmith.server.domains.Plugin; -import com.appsmith.server.exceptions.AppsmithError; -import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.domains.DatasourceContext; +import com.appsmith.server.helpers.PluginExecutorHelper; import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; import java.util.HashMap; -import java.util.List; import java.util.Map; @Service @@ -23,14 +20,16 @@ public class DatasourceContextServiceImpl implements DatasourceContextService { //This is DatasourceId mapped to the DatasourceContext Map datasourceContextMap; private final DatasourceService datasourceService; - private final PluginManager pluginManager; private final PluginService pluginService; + private final PluginExecutorHelper pluginExecutorHelper; @Autowired - public DatasourceContextServiceImpl(DatasourceService datasourceService, PluginManager pluginManager, PluginService pluginService) { + public DatasourceContextServiceImpl(DatasourceService datasourceService, + PluginService pluginService, + PluginExecutorHelper pluginExecutorHelper) { this.datasourceService = datasourceService; - this.pluginManager = pluginManager; this.pluginService = pluginService; + this.pluginExecutorHelper = pluginExecutorHelper; this.datasourceContextMap = new HashMap<>(); } @@ -57,14 +56,7 @@ public class DatasourceContextServiceImpl implements DatasourceContextService { .flatMap(resource -> pluginService.findById(resource.getPluginId())); //Datasource Context has not been created for this resource on this machine. Create one now. - Mono pluginExecutorMono = pluginMono.flatMap(plugin -> { - List executorList = pluginManager.getExtensions(PluginExecutor.class, plugin.getExecutorClass()); - if (executorList.isEmpty()) { - return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin", plugin.getExecutorClass())); - } - return Mono.just(executorList.get(0)); - } - ); + Mono pluginExecutorMono = pluginExecutorHelper.getPluginExecutor(pluginMono); return Mono.zip(datasourceMono, pluginExecutorMono, ((datasource1, pluginExecutor) -> { Object connection = pluginExecutor.datasourceCreate(datasource1.getDatasourceConfiguration()); @@ -92,14 +84,7 @@ public class DatasourceContextServiceImpl implements DatasourceContextService { .flatMap(datasource -> pluginService.findById(datasource.getPluginId())); //Datasource Context has not been created for this resource on this machine. Create one now. - Mono pluginExecutorMono = pluginMono.flatMap(plugin -> { - List executorList = pluginManager.getExtensions(PluginExecutor.class, plugin.getExecutorClass()); - if (executorList.isEmpty()) { - return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin", plugin.getExecutorClass())); - } - return Mono.just(executorList.get(0)); - } - ); + Mono pluginExecutorMono = pluginExecutorHelper.getPluginExecutor(pluginMono); return Mono.zip(datasourceMono, pluginExecutorMono, ((datasource, pluginExecutor) -> { pluginExecutor.datasourceDestroy(datasourceContext.getConnection()); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java index c1547f8b63..32b0355385 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java @@ -1,11 +1,13 @@ package com.appsmith.server.services; +import com.appsmith.external.plugins.PluginExecutor; import com.appsmith.server.constants.FieldName; import com.appsmith.server.domains.Datasource; import com.appsmith.server.domains.Organization; import com.appsmith.server.domains.User; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.repositories.DatasourceRepository; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -32,6 +34,8 @@ public class DatasourceServiceImpl extends BaseService pluginExecutorMono = pluginExecutorHelper.getPluginExecutor(pluginService.findById(datasource.getPluginId())); Mono userMono = sessionUserService.getCurrentUser(); - Mono organizationMono = userMono.flatMap(user -> organizationService.findByIdAndPluginsPluginId(user.getCurrentOrganizationId(), datasource.getPluginId())); + Mono organizationMono = userMono + .flatMap(user -> organizationService.findByIdAndPluginsPluginId(user.getCurrentOrganizationId(), datasource.getPluginId())) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.PLUGIN_NOT_INSTALLED, datasource.getPluginId()))); //Add organization id to the datasource. Mono updatedDatasourceMono = organizationMono @@ -73,12 +84,42 @@ public class DatasourceServiceImpl extends BaseService { + Datasource datasource1 = tuple.getT1(); + PluginExecutor pluginExecutor = tuple.getT2(); + Boolean isValid = pluginExecutor.isDatasourceValid(datasource1.getDatasourceConfiguration()); + if (isValid) { + return Mono.just(datasource1); + } + return Mono.error(new AppsmithException(AppsmithError.INVALID_DATASOURCE_CONFIGURATION)); + }) .flatMap(super::create); } + @Override + public Mono update(String id, Datasource datasource) { + if (datasource.getDatasourceConfiguration() != null) { + + Mono datasourceMono = repository.findById(id) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, id))); + + Mono pluginExecutorMono = datasourceMono + .flatMap(datasource1 -> pluginExecutorHelper.getPluginExecutor(pluginService.findById(datasource1.getPluginId()))); + + return pluginExecutorMono + .flatMap(pluginExecutor -> { + Boolean isValid = pluginExecutor.isDatasourceValid(datasource.getDatasourceConfiguration()); + if (!isValid) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_DATASOURCE_CONFIGURATION)); + } + return Mono.just(datasource); + }) + .flatMap(datasource1 -> super.update(id, datasource1)); + } + return super.update(id, datasource); + } + @Override public Mono findByName(String name) { return repository.findByName(name); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/SeedMongoData.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/SeedMongoData.java index 8c7c33d0cb..855fbd09e6 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/SeedMongoData.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/SeedMongoData.java @@ -119,7 +119,7 @@ public class SeedMongoData { }) .flatMap(pageRepository::save) ) - .subscribe(obj -> log.info("Last Saved Object: " + obj)); + .blockLast(); }; } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java index d994c3538f..7572f64ee6 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationServiceTest.java @@ -10,6 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -19,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j +@DirtiesContext public class ApplicationServiceTest { @Autowired diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/DatasourceServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/DatasourceServiceTest.java index d396032c83..6d74b5dac5 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/DatasourceServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/DatasourceServiceTest.java @@ -1,18 +1,26 @@ package com.appsmith.server.services; +import com.appsmith.external.models.ActionConfiguration; +import com.appsmith.external.models.ActionExecutionResult; import com.appsmith.external.models.DatasourceConfiguration; +import com.appsmith.external.plugins.PluginExecutor; import com.appsmith.server.constants.FieldName; import com.appsmith.server.domains.Datasource; import com.appsmith.server.domains.Plugin; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.PluginExecutorHelper; import lombok.extern.slf4j.Slf4j; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -22,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j +@DirtiesContext public class DatasourceServiceTest { @Autowired @@ -30,12 +39,43 @@ public class DatasourceServiceTest { @Autowired PluginService pluginService; + @MockBean + PluginExecutorHelper pluginExecutorHelper; + + class TestPluginExecutor implements PluginExecutor { + + @Override + public Mono execute(Object connection, DatasourceConfiguration datasourceConfiguration, ActionConfiguration actionConfiguration) { + System.out.println("In the execute"); + return null; + } + + @Override + public Object datasourceCreate(DatasourceConfiguration datasourceConfiguration) { + System.out.println("In the datasourceCreate"); + return null; + } + + @Override + public void datasourceDestroy(Object connection) { + System.out.println("In the datasourceDestroy"); + + } + + @Override + public Boolean isDatasourceValid(DatasourceConfiguration datasourceConfiguration) { + System.out.println("In the datasourceValidate"); + return true; + } + } + @Before public void setup() { + } @Test - @WithMockUser(username = "api_user") + @WithMockUser(username = "api_user", roles = "USER") public void createDatasourceWithNullPluginId() { Datasource datasource = new Datasource(); Mono datasourceMono = Mono.just(datasource) @@ -48,7 +88,7 @@ public class DatasourceServiceTest { } @Test - @WithMockUser(username = "api_user") + @WithMockUser(username = "api_user", roles = "USER") public void createDatasourceWithId() { Datasource datasource = new Datasource(); datasource.setId("randomId"); @@ -62,12 +102,14 @@ public class DatasourceServiceTest { } @Test - @WithMockUser(username = "api_user") + @WithMockUser(username = "api_user", roles = "USER") public void createDatasourceNotInstalledPlugin() { + Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(new TestPluginExecutor())); + Mono pluginMono = pluginService.findByName("Not Installed Plugin Name"); Datasource datasource = new Datasource(); DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration(); - datasourceConfiguration.setDatabaseName("randomDbname"); + datasourceConfiguration.setUrl("http://test.com"); datasource.setDatasourceConfiguration(datasourceConfiguration); Mono datasourceMono = pluginMono.map(plugin -> { @@ -83,13 +125,16 @@ public class DatasourceServiceTest { } @Test - @WithMockUser(username = "api_user") + @WithMockUser(username = "api_user", roles = "USER") public void createDatasourceValid() { + + Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(new TestPluginExecutor())); + Mono pluginMono = pluginService.findByName("Installed Plugin Name"); Datasource datasource = new Datasource(); datasource.setName("test datasource name"); DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration(); - datasourceConfiguration.setDatabaseName("randomDbname"); + datasourceConfiguration.setUrl("http://test.com"); datasource.setDatasourceConfiguration(datasourceConfiguration); Mono datasourceMono = pluginMono.map(plugin -> { datasource.setPluginId(plugin.getId()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java index 82d3239363..33d6ac72cd 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java @@ -15,6 +15,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -26,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j +@DirtiesContext public class LayoutServiceTest { @Autowired LayoutService layoutService; diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/OrganizationServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/OrganizationServiceTest.java index 99cd5c36f3..56e22b4a96 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/OrganizationServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/OrganizationServiceTest.java @@ -10,14 +10,17 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest +@DirtiesContext public class OrganizationServiceTest { @Autowired diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/PageServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/PageServiceTest.java index c364f76545..294b967f1f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/PageServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/PageServiceTest.java @@ -13,15 +13,18 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest @Slf4j +@DirtiesContext public class PageServiceTest { @Autowired PageService pageService; diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java index 6dd568c1fb..a3162f5872 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java @@ -9,6 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -17,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest +@DirtiesContext public class UserServiceTest { @Autowired