diff --git a/.github/workflows/ci-test-custom-script.yml b/.github/workflows/ci-test-custom-script.yml index 730ff6d7e7..83b77e55e7 100644 --- a/.github/workflows/ci-test-custom-script.yml +++ b/.github/workflows/ci-test-custom-script.yml @@ -145,9 +145,10 @@ jobs: sudo /etc/init.d/ssh stop ; mkdir -p ~/git-server/keys mkdir -p ~/git-server/repos + ted_tag="${{inputs.ted_tag}}" docker run --name test-event-driver -d -p 22:22 -p 5001:5001 -p 3306:3306 \ -p 5432:5432 -p 28017:27017 -p 25:25 -p 5000:5000 -p 3001:3000 -p 6001:6001 -p 8001:8000 --privileged --pid=host --ipc=host --volume /:/host -v ~/git-server/keys:/git-server/keys \ - -v ~/git-server/repos:/git-server/repos appsmith/test-event-driver:${{inputs.ted_tag}} + -v ~/git-server/repos:/git-server/repos "appsmith/test-event-driver:${ted_tag:-latest}" docker run --name cloud-services -d -p 8000:80 -p 8090:8090 \ --privileged --pid=host --ipc=host --add-host=host.docker.internal:host-gateway\ -e APPSMITH_CLOUD_SERVICES_MONGODB_URI=mongodb://host.docker.internal:27017 \ diff --git a/app/client/test/testUtils.tsx b/app/client/test/testUtils.tsx index 43da3527c5..1a472b88b5 100644 --- a/app/client/test/testUtils.tsx +++ b/app/client/test/testUtils.tsx @@ -15,6 +15,9 @@ import createSagaMiddleware from "redux-saga"; import store, { testStore } from "store"; import { sagasToRunForTests } from "./sagas"; import { all, call, spawn } from "redux-saga/effects"; +import type { FeatureFlags } from "@appsmith/entities/FeatureFlag"; +import { fetchFeatureFlagsSuccess } from "../src/actions/userActions"; +import { DEFAULT_FEATURE_FLAG_VALUE } from "@appsmith/entities/FeatureFlag"; const testSagaMiddleware = createSagaMiddleware(); @@ -44,13 +47,22 @@ const customRender = ( url?: string; initialState?: Partial; sagasToRun?: typeof sagasToRunForTests; + featureFlags?: Partial; }, options?: Omit, ) => { let reduxStore = store; window.history.pushState({}, "Appsmith", state?.url || "/"); - if (state && state.initialState) { + if (state && (state.initialState || state.featureFlags)) { reduxStore = testStore(state.initialState || {}); + if (state.featureFlags) { + reduxStore.dispatch( + fetchFeatureFlagsSuccess({ + ...DEFAULT_FEATURE_FLAG_VALUE, + ...state.featureFlags, + }), + ); + } } if (state && state.sagasToRun) { reduxStore = testStoreWithTestMiddleWare(reduxStore.getState()); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspect.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspect.java index 1eb718a112..63576b3ea4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspect.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspect.java @@ -81,6 +81,9 @@ public class FeatureFlaggedMethodInvokerAspect { Method superMethod = targetSuperClass.getMethod(method.getName(), method.getParameterTypes()); return superMethod.invoke(service, joinPoint.getArgs()); } catch (Throwable e) { + if (e instanceof AppsmithException) { + throw (AppsmithException) e; + } String errorMessage = "Exception while invoking super class method"; AppsmithException exception = getInvalidAnnotationUsageException(method, errorMessage); log.error(exception.getMessage(), e); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspectTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspectTest.java index 8a75128197..655c5d98ea 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspectTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/FeatureFlaggedMethodInvokerAspectTest.java @@ -1,6 +1,8 @@ package com.appsmith.server.aspect; import com.appsmith.server.aspect.component.TestComponent; +import com.appsmith.server.exceptions.AppsmithError; +import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.featureflags.CachedFeatures; import com.appsmith.server.featureflags.FeatureFlagEnum; import com.appsmith.server.services.FeatureFlagService; @@ -19,6 +21,7 @@ import reactor.test.StepVerifier; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; @SpringBootTest @@ -120,4 +123,30 @@ class FeatureFlaggedMethodInvokerAspectTest { String result = testComponent.ceEeSyncMethod("arg_"); assertEquals("arg_ce_impl_method", result); } + + @Test + void ceEeThrowAppsmithException_eeImplTest() { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.TENANT_TEST_FEATURE.name(), Boolean.TRUE)); + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()).thenReturn(cachedFeatures); + assertThrows( + AppsmithException.class, + () -> testComponent.ceEeThrowAppsmithException("arg_"), + AppsmithError.GENERIC_BAD_REQUEST.getMessage("This is a test exception")); + } + + @Test + void ceEeThrowNonAppsmithException_eeImplTest_throwExceptionFromAspect() { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.TENANT_TEST_FEATURE.name(), Boolean.TRUE)); + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()).thenReturn(cachedFeatures); + assertThrows( + AppsmithException.class, + () -> testComponent.ceEeThrowNonAppsmithException("arg_"), + AppsmithError.INVALID_METHOD_LEVEL_ANNOTATION_USAGE.getMessage( + "FeatureFlagged", + "TestComponentImpl", + "ceEeThrowNonAppsmithException", + "Exception while invoking super class method")); + } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/TestComponentImpl.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/TestComponentImpl.java index 83e459b7a4..702ea3754c 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/TestComponentImpl.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/TestComponentImpl.java @@ -2,6 +2,8 @@ package com.appsmith.server.aspect.component; import com.appsmith.server.annotations.FeatureFlagged; import com.appsmith.server.aspect.component.ce_compatible.TestComponentCECompatibleImpl; +import com.appsmith.server.exceptions.AppsmithError; +import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.featureflags.FeatureFlagEnum; import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; @@ -41,4 +43,16 @@ public class TestComponentImpl extends TestComponentCECompatibleImpl implements public String ceEeSyncMethod(String arg) { return arg + "ee_impl_method"; } + + @Override + @FeatureFlagged(featureFlagName = FeatureFlagEnum.TENANT_TEST_FEATURE) + public void ceEeThrowAppsmithException(String arg) { + throw new AppsmithException(AppsmithError.GENERIC_BAD_REQUEST, "This is a test exception"); + } + + @Override + @FeatureFlagged(featureFlagName = FeatureFlagEnum.TENANT_TEST_FEATURE) + public void ceEeThrowNonAppsmithException(String arg) { + throw new RuntimeException("This is a test exception"); + } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCE.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCE.java index 74569df11d..a0e5fa62f6 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCE.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCE.java @@ -14,4 +14,8 @@ public interface TestComponentCE { Flux ceEeDiffMethodReturnsFlux(); String ceEeSyncMethod(String arg); + + void ceEeThrowAppsmithException(String arg); + + void ceEeThrowNonAppsmithException(String arg); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCEImpl.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCEImpl.java index af4de93238..86755f406a 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCEImpl.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/aspect/component/ce/TestComponentCEImpl.java @@ -30,4 +30,10 @@ public class TestComponentCEImpl implements TestComponentCE { public String ceEeSyncMethod(String arg) { return arg + "ce_impl_method"; } + + @Override + public void ceEeThrowAppsmithException(String arg) {} + + @Override + public void ceEeThrowNonAppsmithException(String arg) {} }