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();
}
}
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());
}
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());
}
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));
}
}
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());
}
Aggregations