|
| 1 | +package com.esendex.java.sdk.integration; |
| 2 | + |
| 3 | +import com.esendex.java.sdk.EsendexTestProperties; |
| 4 | +import esendex.sdk.java.EsendexException; |
| 5 | +import esendex.sdk.java.EsendexProperties; |
| 6 | +import esendex.sdk.java.ServiceFactory; |
| 7 | +import esendex.sdk.java.service.auth.UserPassword; |
| 8 | +import esendex.sdk.java.service.impl.IServiceFactory; |
| 9 | + |
| 10 | +public abstract class BaseTest { |
| 11 | + |
| 12 | + public static boolean IsSessionMode = false; |
| 13 | + |
| 14 | + public static final String USER; |
| 15 | + public static final String PASSWORD; |
| 16 | + public static final String ACCOUNT; |
| 17 | + public static final String DESTINATION_NUMBER; |
| 18 | + private static final UserPassword userPassword; |
| 19 | + |
| 20 | + |
| 21 | + static { |
| 22 | + EsendexTestProperties testProperties = EsendexTestProperties.instance(); |
| 23 | + |
| 24 | + USER = testProperties.getUsername(); |
| 25 | + PASSWORD = testProperties.getPassword(); |
| 26 | + ACCOUNT = testProperties.getAccount(); |
| 27 | + DESTINATION_NUMBER = testProperties.getDestinationNumber(); |
| 28 | + |
| 29 | + userPassword = new UserPassword(USER, PASSWORD); |
| 30 | + |
| 31 | + String domain = testProperties.getDomain(); |
| 32 | + |
| 33 | + EsendexProperties.instance().setProperty("esendex.secure", "false"); |
| 34 | + if (domain != null) |
| 35 | + EsendexProperties.instance().setProperty("esendex.domain", domain); |
| 36 | + } |
| 37 | + |
| 38 | + public static IServiceFactory getFactory() throws EsendexException { |
| 39 | + return IsSessionMode |
| 40 | + ? getBasicFactory() |
| 41 | + : getSessionFactory(); |
| 42 | + } |
| 43 | + |
| 44 | + private static IServiceFactory getBasicFactory() { |
| 45 | + |
| 46 | + if (basicFactory == null) |
| 47 | + basicFactory = ServiceFactory.createBasicAuthenticatingFactory(userPassword); |
| 48 | + return basicFactory; |
| 49 | + } |
| 50 | + private static IServiceFactory basicFactory; |
| 51 | + |
| 52 | + private static IServiceFactory getSessionFactory() throws EsendexException { |
| 53 | + |
| 54 | + if (sessionFactory == null) |
| 55 | + sessionFactory = ServiceFactory.createSessionAuthenticatingFactory(userPassword); |
| 56 | + return sessionFactory; |
| 57 | + } |
| 58 | + private static IServiceFactory sessionFactory; |
| 59 | +} |
0 commit comments