Search in sources :

Example 1 with JsonValidationService

use of com.icthh.xm.ms.entity.service.JsonValidationService 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 JsonValidationService

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

the class FunctionServiceImplUnitTest method validationFailOnInvalidFunctionWithEntityIdInputWhenValidationEnabled.

@Test
public void validationFailOnInvalidFunctionWithEntityIdInputWhenValidationEnabled() {
    exception.expect(JsonValidationService.InvalidJsonException.class);
    String exceptionMessage = "{\"pointer\":\"/numberArgument\"} |     domain: \"validation\" |     keyword: \"type\" |     found: \"string\" |     expected: [\"integer\",\"number\"] | ";
    exception.expectMessage(exceptionMessage);
    FunctionSpec spec = generateFunctionSpec(true);
    Map<String, Object> functionInput = Map.of("numberArgument", "stringValue");
    spec.setWithEntityId(true);
    when(xmEntitySpecService.findFunction(xmEntityTypeKey, VALIDATION_FUNCTION)).thenReturn(Optional.of(spec));
    when(xmEntityService.findStateProjectionById(SELF)).thenReturn(getProjection(SELF));
    functionService.execute(VALIDATION_FUNCTION, SELF, functionInput);
    verify(jsonValidationService).assertJson(eq(functionInput), eq(spec.getInputSpec()));
}
Also used : JsonValidationService(com.icthh.xm.ms.entity.service.JsonValidationService) FunctionSpec(com.icthh.xm.ms.entity.domain.spec.FunctionSpec) AbstractUnitTest(com.icthh.xm.ms.entity.AbstractUnitTest)

Example 3 with JsonValidationService

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

the class FunctionServiceImplUnitTest method validationFailOnInvalidFunctionInputWhenValidationEnabled.

@Test
public void validationFailOnInvalidFunctionInputWhenValidationEnabled() {
    exception.expect(JsonValidationService.InvalidJsonException.class);
    String exceptionMessage = "{\"pointer\":\"/numberArgument\"} |     domain: \"validation\" |     keyword: \"type\" |     found: \"string\" |     expected: [\"integer\",\"number\"] | ";
    exception.expectMessage(exceptionMessage);
    FunctionSpec spec = generateFunctionSpec(true);
    when(xmEntitySpecService.findFunction(VALIDATION_FUNCTION)).thenReturn(Optional.of(spec));
    Map<String, Object> functionInput = Map.of("numberArgument", "stringValue");
    functionService.execute(VALIDATION_FUNCTION, functionInput, null);
    verify(jsonValidationService).assertJson(eq(functionInput), eq(spec.getInputSpec()));
}
Also used : JsonValidationService(com.icthh.xm.ms.entity.service.JsonValidationService) FunctionSpec(com.icthh.xm.ms.entity.domain.spec.FunctionSpec) AbstractUnitTest(com.icthh.xm.ms.entity.AbstractUnitTest)

Aggregations

JsonValidationService (com.icthh.xm.ms.entity.service.JsonValidationService)3 AbstractUnitTest (com.icthh.xm.ms.entity.AbstractUnitTest)2 FunctionSpec (com.icthh.xm.ms.entity.domain.spec.FunctionSpec)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmEntityTenantConfigService (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService)1 XmEntityTenantConfig (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)1 DynamicPermissionCheckService (com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService)1 FunctionContextService (com.icthh.xm.ms.entity.service.FunctionContextService)1 FunctionExecutorService (com.icthh.xm.ms.entity.service.FunctionExecutorService)1 XmEntityService (com.icthh.xm.ms.entity.service.XmEntityService)1 XmEntitySpecService (com.icthh.xm.ms.entity.service.XmEntitySpecService)1