import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.context.SecurityContextImpl;
import org.unitils.UnitilsJUnit4;
import org.unitils.database.DatabaseUnitils;
import org.unitils.database.annotations.Transactional;
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
import eu.etaxonomy.taxeditor.session.CdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
-import eu.etaxonomy.taxeditor.session.ISessionEventListener;
/**
private static ICdmRemoteSource cdmRemoteSource;
private static CdmPersistentRemoteSource remotePersistentSource;
- public static boolean useManagedServer = true;
+ public static boolean useManagedServer = false;
public static final Resource CDMLIB_DISK_STORE_RESOURCE =
new ClassPathResource("/eu/etaxonomy/cache");
-
+
protected static ICdmEntitySessionManager cdmEntitySessionManager;
-
+
+
@BeforeClass
public static void initializeBaseRemotingTest() {
//NOTE: Run this the cdmTest H2 DB whenever it needs to be
// recreated e.g. after a model change
- //DatabaseUnitils.disableConstraints();
+ DatabaseUnitils.disableConstraints();
try {
System.setProperty("ehcache.disk.store.dir", CDMLIB_DISK_STORE_RESOURCE.getFile().getAbsolutePath());
} catch (IOException e) {
throw new CdmClientCacheException(e);
}
-
+
useManagedServer = (System.getProperty("use.managed.server") == null) ? useManagedServer : Boolean.valueOf(System.getProperty("use.managed.server"));
if(useManagedServer) {
try {
CDMServer.getInstance().getHost(),
CDMServer.getInstance().getPort(),
CDMServer.getInstance().getContextPath(),
- NomenclaturalCode.ICNAFP);
+ NomenclaturalCode.ICNAFP,
+ "admin",
+ "00000");
}
+
+
}
-
+
@Test
public void disableConstraints() {
// To be run on the src/test/resources/h2/cdmTest h2 db after
// updating the unitils.properties 'database.url' property
DatabaseUnitils.disableConstraints();
}
- public static void initializeController(String sourceName, String host, int port, String contextPath, NomenclaturalCode ncode) {
+
+ public static void initializeController(String sourceName, String host, int port, String contextPath, NomenclaturalCode ncode, String username, String password) {
cdmRemoteSource = CdmRemoteSource.NewInstance(sourceName, host, port, contextPath, ncode);
remoteApplicationController =
CdmApplicationRemoteController.NewInstance(cdmRemoteSource,
- false,
null,
null);
Assert.fail("Default Remote Persistent Source failed to load. Reason : " + e.getMessage());
}
cdmEntitySessionManager = getRemoteApplicationController().getCdmEntitySessionManager();
+
+ SecurityContextHolder.clearContext();
+ SecurityContextImpl sc = new SecurityContextImpl();
+ Authentication token = new UsernamePasswordAuthenticationToken(username,password);
+ Authentication authentication = getRemoteApplicationController().getAuthenticationManager().authenticate(token);
+ authentication = new UsernamePasswordAuthenticationToken(username,password, authentication.getAuthorities());
+ sc.setAuthentication(authentication);
+
+ SecurityContextHolder.setContext(sc);
}
protected static CdmPersistentRemoteSource getCdmPersistentRemoteSource() {
return remotePersistentSource;
}
-
+
protected static ICdmEntitySessionManager getCdmEntitySessionManager() {
return cdmEntitySessionManager;
}
-
-
- protected static CdmEntitySession getSession(ISessionEventListener sessionOwner) {
- Map<ISessionEventListener, CdmEntitySession> ownerSessionMap =
- (Map<ISessionEventListener, CdmEntitySession>) getFieldValueViaReflection(cdmEntitySessionManager, "ownerSessionMap");
+
+
+ protected static CdmEntitySession getSession(ICdmEntitySessionEnabled sessionOwner) {
+ Map<ICdmEntitySessionEnabled, CdmEntitySession> ownerSessionMap =
+ (Map<ICdmEntitySessionEnabled, CdmEntitySession>) getFieldValueViaReflection(cdmEntitySessionManager, "ownerSessionMap");
return ownerSessionMap.get(sessionOwner);
}
-
+
protected static CdmTransientEntityCacher getActiveSession() {
return (CdmTransientEntityCacher) getFieldValueViaReflection(cdmEntitySessionManager, "activeSession");
}
-
- protected static CdmTransientEntityCacher getCacher(ISessionEventListener sessionOwner) {
+
+ protected static CdmTransientEntityCacher getCacher(ICdmEntitySessionEnabled sessionOwner) {
return (CdmTransientEntityCacher) getFieldValueViaReflection(getSession(sessionOwner), "cdmTransientEntityCacher");
}