public static void assertScripts(List<ScriptHistoryEntry> scriptsHistory, ProvisioningScriptSpec... expectedScripts) { displayScripts(scriptsHistory); assertEquals("Wrong number of scripts executed", expectedScripts.length, scriptsHistory.size()); Iterator<ScriptHistoryEntry> historyIter = scriptsHistory.iterator(); for (ProvisioningScriptSpec expecedScript: expectedScripts) { ScriptHistoryEntry actualScript = historyIter.next(); assertEquals("Wrong script code", expecedScript.getCode(), actualScript.getCode()); if (expecedScript.getLanguage() == null) { assertEquals("We talk only gibberish here", "Gibberish", actualScript.getLanguage()); } else { assertEquals("Wrong script language", expecedScript.getLanguage(), actualScript.getLanguage()); } assertEquals("Wrong number of arguments", expecedScript.getArgs().size(), actualScript.getParams().size()); for (java.util.Map.Entry<String,Object> expectedEntry: expecedScript.getArgs().entrySet()) { Object expectedValue = expectedEntry.getValue(); Object actualVal = actualScript.getParams().get(expectedEntry.getKey()); assertEquals("Wrong value for argument '"+expectedEntry.getKey()+"'", expectedValue, actualVal); } } }
/** * Pretend to run script on the resource. * The script is actually not executed, it is only recorded in the script history * and can be fetched by getScriptHistory(). * * @param scriptCode code of the script */ public String runScript(String language, String scriptCode, Map<String, Object> params) throws FileNotFoundException { scriptHistory.add(new ScriptHistoryEntry(language, scriptCode, params)); if (SCRIPT_LANGUAGE_POWERFAIL.equals(language)) { Object errorArg = params.get(POWERFAIL_ARG_ERROR); if (POWERFAIL_ARG_ERROR_GENERIC.equals(errorArg)) { // The connector will react with generic exception throw new IllegalArgumentException("Booom! PowerFail script failed (generic)"); } else if (POWERFAIL_ARG_ERROR_RUNTIME.equals(errorArg)) { // The connector will just pass this up throw new RuntimeException("Booom! PowerFail script failed (runtime)"); } else if (POWERFAIL_ARG_ERROR_IO.equals(errorArg)) { throw new FileNotFoundException("Booom! PowerFail script failed (IO)"); } } else if (SCRIPT_LANGUAGE_PARROT.equals(language)) { return scriptCode.toUpperCase(); } return null; }
@Test public void test002testReconcileScriptsWhenReconciling() throws Exception{ final String TEST_NAME = "test002testReconcileScriptsWhenReconciling"; displayTestTitle(TEST_NAME); getDummyResource().getScriptHistory().clear(); importObjectFromFile(new File(TASK_RECON_DUMMY_FILENAME)); waitForTaskStart(TASK_RECON_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT); waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT); waitForTaskFinish(TASK_RECON_DUMMY_OID, false); for (ScriptHistoryEntry script : getDummyResource().getScriptHistory()){ String userName = (String) script.getParams().get("midpoint_usercn"); String idPath = (String) script.getParams().get("midpoint_idpath"); String tempPath = (String) script.getParams().get("midpoint_temppath"); LOGGER.trace("userName {} idPath {} tempPath {}", new Object[]{userName,idPath,tempPath}); if (!idPath.contains(userName)){ AssertJUnit.fail("Expected that idPath will contain userName [idPath: " + idPath + ", userName " + userName +"]"); } if (!tempPath.contains(userName)){ AssertJUnit.fail("Expected that tempPath will contain userName [idPath: " + idPath + ", userName " + userName +"]"); } } }
String userName = (String) script.getParams().get("midpoint_usercn"); String idPath = (String) script.getParams().get("midpoint_idpath"); String tempPath = (String) script.getParams().get("midpoint_temppath"); LOGGER.trace("userName {} idPath {} tempPath {}", new Object[]{userName,idPath,tempPath}); if (!idPath.contains(userName)){
String userName = (String) script.getParams().get("midpoint_usercn"); String idPath = (String) script.getParams().get("midpoint_idpath"); String tempPath = (String) script.getParams().get("midpoint_temppath"); LOGGER.trace("userName {} idPath {} tempPath {}", new Object[]{userName,idPath,tempPath}); if (!idPath.contains(userName)){