Search in sources :

Example 1 with FunctionContextService

use of com.icthh.xm.ms.entity.service.FunctionContextService in project xm-ms-entity by xm-online.

the class FunctionServiceImplUnitTest method setUp.

@Before
public void setUp() {
    xmEntitySpecService = Mockito.mock(XmEntitySpecService.class);
    xmEntityService = Mockito.mock(XmEntityService.class);
    functionExecutorService = Mockito.mock(FunctionExecutorService.class);
    functionContextService = Mockito.mock(FunctionContextService.class);
    dynamicPermissionCheckService = Mockito.mock(DynamicPermissionCheckService.class);
    xmEntityTenantConfigService = Mockito.mock(XmEntityTenantConfigService.class);
    jsonValidationService = spy(new JsonValidationService(new ObjectMapper()));
    functionService = new FunctionServiceImpl(xmEntitySpecService, xmEntityService, functionExecutorService, functionContextService, dynamicPermissionCheckService, jsonValidationService, xmEntityTenantConfigService);
    xmEntityTenantConfig = new XmEntityTenantConfig();
    when(xmEntityTenantConfigService.getXmEntityTenantConfig()).thenReturn(xmEntityTenantConfig);
}
Also used : XmEntityService(com.icthh.xm.ms.entity.service.XmEntityService) DynamicPermissionCheckService(com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService) XmEntitySpecService(com.icthh.xm.ms.entity.service.XmEntitySpecService) JsonValidationService(com.icthh.xm.ms.entity.service.JsonValidationService) FunctionContextService(com.icthh.xm.ms.entity.service.FunctionContextService) XmEntityTenantConfigService(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService) FunctionExecutorService(com.icthh.xm.ms.entity.service.FunctionExecutorService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)

Example 2 with FunctionContextService

use of com.icthh.xm.ms.entity.service.FunctionContextService in project xm-ms-entity by xm-online.

the class FunctionServiceImplUnitTest method executeWithSaveContext.

/**
 * Test in progress
 */
@Test
public void executeWithSaveContext() {
    FunctionSpec spec = getFunctionSpec(Boolean.TRUE);
    Map<String, Object> context = Maps.newHashMap();
    context.put("key1", "val1");
    Map<String, Object> data = Maps.newHashMap();
    data.put("KEY1", "VAL1");
    when(xmEntitySpecService.findFunction(functionName)).thenReturn(Optional.of(spec));
    when(functionExecutorService.execute(functionName, context, null)).thenReturn(data);
    when(functionContextService.save(any())).thenAnswer((Answer<FunctionContext>) invocation -> {
        Object[] args = invocation.getArguments();
        return (FunctionContext) args[0];
    });
    FunctionContext fc = functionService.execute(functionName, context, null);
    assertThat(fc.getTypeKey()).isEqualTo(functionName);
    assertThat(fc.getKey()).contains(functionName);
    assertThat(fc.getData().keySet()).containsSequence(data.keySet().toArray(new String[0]));
    verify(functionContextService, Mockito.times(1)).save(any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) XmEntityService(com.icthh.xm.ms.entity.service.XmEntityService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) FunctionSpec(com.icthh.xm.ms.entity.domain.spec.FunctionSpec) Answer(org.mockito.stubbing.Answer) XmEntityStateProjection(com.icthh.xm.ms.entity.projection.XmEntityStateProjection) FunctionContextService(com.icthh.xm.ms.entity.service.FunctionContextService) Map(java.util.Map) IdOrKey(com.icthh.xm.ms.entity.domain.ext.IdOrKey) ExpectedException(org.junit.rules.ExpectedException) DynamicPermissionCheckService(com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService) JsonValidationService(com.icthh.xm.ms.entity.service.JsonValidationService) XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Maps(com.google.common.collect.Maps) AdditionalAnswers(org.mockito.AdditionalAnswers) Mockito(org.mockito.Mockito) XmEntitySpecService(com.icthh.xm.ms.entity.service.XmEntitySpecService) Lists(org.assertj.core.util.Lists) XmEntityTenantConfigService(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService) Optional(java.util.Optional) FunctionExecutorService(com.icthh.xm.ms.entity.service.FunctionExecutorService) org.junit(org.junit) AbstractUnitTest(com.icthh.xm.ms.entity.AbstractUnitTest) NotNull(org.jetbrains.annotations.NotNull) SELF(com.icthh.xm.ms.entity.domain.ext.IdOrKey.SELF) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) FunctionSpec(com.icthh.xm.ms.entity.domain.spec.FunctionSpec) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) AbstractUnitTest(com.icthh.xm.ms.entity.AbstractUnitTest)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 XmEntityTenantConfigService (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService)2 XmEntityTenantConfig (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)2 DynamicPermissionCheckService (com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService)2 FunctionContextService (com.icthh.xm.ms.entity.service.FunctionContextService)2 FunctionExecutorService (com.icthh.xm.ms.entity.service.FunctionExecutorService)2 JsonValidationService (com.icthh.xm.ms.entity.service.JsonValidationService)2 XmEntityService (com.icthh.xm.ms.entity.service.XmEntityService)2 XmEntitySpecService (com.icthh.xm.ms.entity.service.XmEntitySpecService)2 Maps (com.google.common.collect.Maps)1 AbstractUnitTest (com.icthh.xm.ms.entity.AbstractUnitTest)1 FunctionContext (com.icthh.xm.ms.entity.domain.FunctionContext)1 IdOrKey (com.icthh.xm.ms.entity.domain.ext.IdOrKey)1 SELF (com.icthh.xm.ms.entity.domain.ext.IdOrKey.SELF)1 FunctionSpec (com.icthh.xm.ms.entity.domain.spec.FunctionSpec)1 XmEntityStateProjection (com.icthh.xm.ms.entity.projection.XmEntityStateProjection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1