-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-core): added StandaloneJavaCustomScriptManagerTest
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...t/java/io/jans/service/custom/script/test/java/StandaloneJavaCustomScriptManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.jans.service.custom.script.test.java; | ||
|
||
import io.jans.log.LoggingHelper; | ||
import io.jans.orm.PersistenceEntryManager; | ||
import io.jans.orm.ldap.impl.LdapEntryManager; | ||
import io.jans.orm.ldap.impl.LdapEntryManagerFactory; | ||
import io.jans.service.custom.script.StandaloneCustomScriptManager; | ||
import io.jans.service.custom.script.test.SampleContext; | ||
import org.apache.log4j.Logger; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.status.StatusLogger; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Properties; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
/** | ||
* @author Yuriy Zabrovarnyy | ||
*/ | ||
@SuppressWarnings("java:S2187") | ||
public class StandaloneJavaCustomScriptManagerTest { | ||
|
||
private static final Logger LOG = Logger.getLogger(StandaloneJavaCustomScriptManagerTest.class); | ||
|
||
static { | ||
StatusLogger.getLogger().setLevel(Level.OFF); | ||
LoggingHelper.configureConsoleAppender(); | ||
} | ||
|
||
private static Properties getSampleConnectionProperties() { | ||
Properties connectionProperties = new Properties(); | ||
|
||
connectionProperties.put("ldap#bindDN", "cn=Directory Manager"); | ||
connectionProperties.put("ldap#bindPassword", "secret"); | ||
connectionProperties.put("ldap#servers", "localhost:1636"); | ||
connectionProperties.put("ldap#useSSL", "true"); | ||
connectionProperties.put("ldap#maxconnections", "3"); | ||
|
||
return connectionProperties; | ||
} | ||
|
||
public static LdapEntryManager createLdapEntryManager() { | ||
LdapEntryManagerFactory ldapEntryManagerFactory = new LdapEntryManagerFactory(); | ||
Properties connectionProperties = getSampleConnectionProperties(); | ||
|
||
LdapEntryManager ldapEntryManager = ldapEntryManagerFactory.createEntryManager(connectionProperties); | ||
LOG.debug("Created LdapEntryManager: " + ldapEntryManager); | ||
|
||
return ldapEntryManager; | ||
} | ||
|
||
public static void main(String[] args) { | ||
PersistenceEntryManager persistenceEntryManager = createLdapEntryManager(); | ||
StandaloneCustomScriptManager customScriptManager = new StandaloneCustomScriptManager(persistenceEntryManager, "ou=scripts,o=jans"); | ||
|
||
try { | ||
// Register required external scripts | ||
SampleDiscoveryExternalScriptService javaScriptService = new SampleDiscoveryExternalScriptService(); | ||
customScriptManager.registerExternalScriptService(javaScriptService); | ||
|
||
// Init script manager and load scripts | ||
customScriptManager.init(); | ||
|
||
// Call script | ||
Object context = new SampleContext(System.currentTimeMillis()); | ||
|
||
JSONObject jsonObject = new JSONObject("{}"); | ||
assertTrue(javaScriptService.modifyDiscovery(jsonObject, context)); | ||
|
||
assertEquals(jsonObject.getString("key_from_java"), "value_from_script_on_java"); | ||
} finally { | ||
customScriptManager.destory(); | ||
} | ||
} | ||
} |