How to develop a JUnit test for a custom Auth Module?

This topic has 3 replies, 2 voices, and was last updated 5 years, 3 months ago by Peter Major.

  • Author
    Posts
  • #17114
     full2
    Participant

    Hello:
    I have made a custom auth module for OpenAm. It works ok, but I would like to do some Junit test to run it when building it.
    I havent found any reference or example or how to do it.
    The most I have found is this 7 years old message:
    https://java.net/projects/opensso/lists/users/archive/2010-02/message/215
    where it says it can’t be made.

    As the previous message says, when I try to run my test in Eclipse it seems to connect to a running server, but it fails. Even with a server running in my computer, I dont know how to “connect” to that server

    “ERROR: SMDataLayer:initLdapPool()-Error initializing connection pool server configuration XML file is not found. This instance is likely to be running in client mode
    LDAPServiceException code=19
    com.iplanet.services.ldap.LDAPServiceException: server configuration XML file is not found. This instance is likely to be running in client mode
    (….)

    ERROR: SMSEntry: Unable to initalize(exception):
    [no connection to the server in spanish:] Message:No se pudo establecer la conexión con el servidor: No se pudo establecer la conexión con el servidor

    at com.sun.identity.sm.ldap.SMSLdapObject.getConnection(SMSLdapObject.java:578)”

    “amNaming:04/25/2017 10:01:55:169 AM CEST: Thread[main,5,main]: TransactionId[unknown]
    ERROR: Failed to initialize naming service”
    “WARNING: JAXRPCHelper:getValidServerURL: Unable to get platform server”
    “amJAXRPC:04/25/2017 10:01:57:255 AM CEST: Thread[main,5,main]: TransactionId[unknown]
    WARNING: JAXRPCHelper: No vaild server found
    amNaming:04/25/2017 10:01:58:256 AM CEST: Thread[main,5,main]: TransactionId[unknown]
    ERROR: Failed to initialize naming service”

    Any ideas or sugestion? Someone was able to do it, even parcially or hardcoding/mocking something?
    Any example or reference?
    Thanks

    #17115
     Peter Major
    Moderator

    You need to extract your business logic to other classes and have the AMLoginModule delegate all of its responsibilities to these helper classes. Then you can unit test your business logic.
    Do not try to initialize an AMLoginModule instance in a unit test, it will not end well.

    You should also consider writing functional tests (with Arquillian for example) instead.

    #17121
     full2
    Participant

    Thanks for your fast response, Peter.

    I have tried to separate the bussiness logic to static methods inside my CustomAuth class, but even calling those static methods (that dont use any object of AuthLoginModule or whatever), it seems it is launching the constructor or initialization of AMLoginModule. Even if I am not instanciating a new instance of my auth module, only using a silly static method of it.

    Strange, I dont know. Maybe I am forgeting somehting about static, heritance and Java.

    I will try to do what you describe.

    #17123
     Peter Major
    Moderator

    As you are using static methods of the auth module class, you will load the class in question, and that classloading will result in running the static initializers of the parent class(es).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

©2022 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?