Search in sources :

Example 11 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testScriptRuntimeExceptionWithCatch.

@Test
public void testScriptRuntimeExceptionWithCatch() {
    String testString = "TEST-" + System.currentTimeMillis();
    // 
    Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> scripts = createThreeScripts();
    IdmScriptDto script1 = scripts.getFirst();
    IdmScriptDto script2 = scripts.getSecond();
    IdmScriptDto script3 = scripts.getThird();
    // 
    StringBuilder script1Body = new StringBuilder();
    script1Body.append("try {\n");
    script1Body.append(this.createScriptThatCallAnother(script2, IdmScriptCategory.DEFAULT, null, false));
    script1Body.append("} catch (Throwable e) {\n");
    script1Body.append("return \"" + testString + "\";\n");
    script1Body.append("}\n");
    script1Body.append("return null;\n");
    // 
    script1.setScript(script1Body.toString());
    script2.setScript(this.createScriptThatCallAnother(script3, IdmScriptCategory.DEFAULT, null, false));
    script3.setScript("throw new RuntimeException(\"" + testString + "\")");
    // 
    script1 = this.scriptService.save(script1);
    script2 = this.scriptService.save(script2);
    script3 = this.scriptService.save(script3);
    try {
        Object result = defaultScriptEvaluator.evaluate(script1.getCode());
        assertNotNull(result);
        assertEquals(testString, result);
    } catch (Throwable e) {
        fail();
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testCreateScript.

@Test
public void testCreateScript() {
    IdmScriptDto script = new IdmScriptDto();
    script.setCategory(IdmScriptCategory.DEFAULT);
    script.setCode("script_code_" + System.currentTimeMillis());
    script.setName("script_name_" + System.currentTimeMillis());
    // 
    IdmScriptDto script2 = scriptService.saveInternal(script);
    // 
    assertEquals(script.getCode(), script2.getCode());
    assertEquals(script.getName(), script2.getName());
    assertEquals(script.getCategory(), script2.getCategory());
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testEvaluateScriptWithAnotherCategory.

@Test(expected = ResultCodeException.class)
public void testEvaluateScriptWithAnotherCategory() {
    IdmScriptDto subScript = new IdmScriptDto();
    subScript.setCategory(IdmScriptCategory.SYSTEM);
    subScript.setCode("script_name_" + System.currentTimeMillis());
    subScript.setName("script_name_" + System.currentTimeMillis());
    // 
    subScript.setScript(createListScript(Boolean.TRUE));
    // 
    subScript = scriptService.saveInternal(subScript);
    // 
    createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmRole.class.getName(), null);
    // 
    IdmScriptDto parent = new IdmScriptDto();
    parent.setCategory(IdmScriptCategory.DEFAULT);
    parent.setCode("script_name_" + System.currentTimeMillis());
    parent.setName("script_name_" + System.currentTimeMillis());
    // 
    parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, false));
    parent = scriptService.saveInternal(parent);
    // 
    groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class ScriptEvaluatorTest method testScriptThrowableWithoutCatch.

@Test
public void testScriptThrowableWithoutCatch() {
    String testString = "TEST-" + System.currentTimeMillis();
    // 
    Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> scripts = createThreeScripts();
    IdmScriptDto script1 = scripts.getFirst();
    IdmScriptDto script2 = scripts.getSecond();
    IdmScriptDto script3 = scripts.getThird();
    // 
    script1.setScript(this.createScriptThatCallAnother(script2, IdmScriptCategory.DEFAULT, null, false));
    script2.setScript(this.createScriptThatCallAnother(script3, IdmScriptCategory.DEFAULT, null, false));
    script3.setScript("throw new Throwable(\"" + testString + "\")");
    // 
    script1 = this.scriptService.save(script1);
    script2 = this.scriptService.save(script2);
    script3 = this.scriptService.save(script3);
    try {
        // must throw exception
        defaultScriptEvaluator.evaluate(script1.getCode());
        fail();
    } catch (Throwable e) {
        assertTrue(e instanceof Throwable);
        assertTrue(e.getMessage().contains(testString));
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method removeAuthRedeploy.

@Test
public void removeAuthRedeploy() {
    configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, TEST_BACKUP_FOLDER);
    IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    assertNotNull(script1);
    IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
    filter.setScriptId(script1.getId());
    List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(4, authorities.size());
    scriptAuthorityService.deleteAllByScript(script1.getId());
    authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(0, authorities.size());
    scriptService.redeploy(script1);
    authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(4, authorities.size());
}
Also used : IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmScriptDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)39 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 Test (org.junit.Test)34 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)5 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)5 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)3 HashMap (java.util.HashMap)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)2 IdmScriptAuthorityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ResponseEntity (org.springframework.http.ResponseEntity)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1