Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2013-01-24 14:02:54 -0500
committerRoberto E. Escobar2013-01-24 14:02:54 -0500
commit2aa8d188d0b057e57fa11ce4c3170625f3f6c74f (patch)
tree1e2b84ddb810a19eab45f9a1aeadf2806c2f8972 /plugins/org.eclipse.osee.framework.core.server.test
parent7a9169ce9a15dc892a8f603185d48b89cdf60c7a (diff)
downloadorg.eclipse.osee-2aa8d188d0b057e57fa11ce4c3170625f3f6c74f.tar.gz
org.eclipse.osee-2aa8d188d0b057e57fa11ce4c3170625f3f6c74f.tar.xz
org.eclipse.osee-2aa8d188d0b057e57fa11ce4c3170625f3f6c74f.zip
bug[ats_37C5M]: Refactor session cache off of OseeAbstractCache
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.server.test')
-rw-r--r--plugins/org.eclipse.osee.framework.core.server.test/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionCacheTest.java116
-rw-r--r--plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionFactoryTest.java68
-rw-r--r--plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionManagerTest.java11
-rw-r--r--plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionTest.java84
5 files changed, 122 insertions, 161 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.server.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core.server.test/META-INF/MANIFEST.MF
index bdfc24edff..cdfc7dc67d 100644
--- a/plugins/org.eclipse.osee.framework.core.server.test/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.core.server.test/META-INF/MANIFEST.MF
@@ -6,7 +6,9 @@ Bundle-Version: 0.11.0.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
Fragment-Host: org.eclipse.osee.framework.core.server
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.junit
+Require-Bundle: org.junit,
+ org.mockito;bundle-version="1.9.0",
+ org.hamcrest.core
Import-Package: org.eclipse.osee.framework.core.model.cache,
org.eclipse.osee.framework.core.model.mocks,
org.eclipse.osee.framework.core.model.type
diff --git a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionCacheTest.java b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionCacheTest.java
index bbe66b5542..50caa8bcd0 100644
--- a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionCacheTest.java
+++ b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionCacheTest.java
@@ -10,75 +10,93 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server.test.internal.session;
-import java.util.ArrayList;
-import java.util.Date;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyList;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
-import org.eclipse.osee.framework.core.enums.StorageState;
+import java.util.Map;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache;
-import org.eclipse.osee.framework.core.model.cache.AbstractOseeCacheTest;
-import org.eclipse.osee.framework.core.model.cache.IOseeCache;
-import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor;
+import org.eclipse.osee.framework.core.server.internal.session.Cache;
+import org.eclipse.osee.framework.core.server.internal.session.CacheFactory;
+import org.eclipse.osee.framework.core.server.internal.session.ReadDataAccessor;
import org.eclipse.osee.framework.core.server.internal.session.Session;
-import org.eclipse.osee.framework.core.server.internal.session.SessionCache;
-import org.eclipse.osee.framework.jdk.core.util.GUID;
-import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
/**
* Test Case for {@link SessionCacheTest}
*
* @author Roberto E. Escobar
*/
-public class SessionCacheTest extends AbstractOseeCacheTest<String, Session> {
+public class SessionCacheTest {
- private static AbstractOseeCache<String, Session> cache;
- private static List<Session> sessionData;
+ private static Cache<String, Session> cache;
- @BeforeClass
- public static void prepareTestData() throws OseeCoreException {
- sessionData = new ArrayList<Session>();
+ @Mock
+ private ReadDataAccessor<String, Session> lda;
+ @Captor
+ private ArgumentCaptor<Iterable<? extends String>> idCaptor;
- SessionDataAccessor accessor = new SessionDataAccessor(sessionData);
- cache = new SessionCache(accessor);
- cache.ensurePopulated();
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
- Assert.assertTrue(accessor.wasLoaded());
+ CacheFactory factory = new CacheFactory();
+ cache = factory.create(lda);
}
- public SessionCacheTest() {
- super(sessionData, cache);
- }
+ @Test
+ public void testGet() throws OseeCoreException {
+ Session s = mock(Session.class);
+ when(s.getGuid()).thenReturn("id1");
+ when(lda.load("id1")).thenReturn(s);
- private final static class SessionDataAccessor extends MockOseeDataAccessor<String, Session> {
+ Session toCheck = cache.get("id1");
- private final List<Session> data;
+ assertEquals(s, toCheck);
+ verify(lda).load("id1");
+ }
- public SessionDataAccessor(List<Session> data) {
- super();
- this.data = data;
- }
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetAll() throws OseeCoreException {
+ List<String> allIds = new LinkedList<String>();
+ allIds.add("id1");
+ doReturn(allIds).when(lda).getAllKeys();
+ Map<String, Session> map = new HashMap<String, Session>();
+ Session session = mock(Session.class);
+ map.put("id1", session);
+ when(lda.load(anyList())).thenReturn(map);
+ Iterable<Session> all = cache.getAll();
+ verify(lda).getAllKeys();
+ verify(lda).load(idCaptor.capture());
+ assertEquals("id1", idCaptor.getValue().iterator().next());
+ assertEquals(session, all.iterator().next());
+ }
- @Override
- public void load(IOseeCache<String, Session> cache) throws OseeCoreException {
- super.load(cache);
- int typeId = 100;
- for (int index = 0; index < 10; index++) {
+ @Test
+ public void testReloadCache() throws OseeCoreException {
+ Session s1 = mock(Session.class);
+ Session s2 = mock(Session.class);
+ when(s1.getGuid()).thenReturn("id1");
+ when(s1.getGuid()).thenReturn("id1");
- String guid = GUID.create();
- Session item =
- new Session(guid, guid, "userId", new Date(), "serverX", "clientVersion", "clientMachine",
- "clientAddress", 4500, new Date(), "Test Data");
- item.setStorageState(StorageState.LOADED);
- data.add(item);
- item.setId(typeId++);
- cache.cache(item);
- }
- }
- }
+ when(lda.load("id1")).thenReturn(s1, s2);
+
+ Session toCheck = cache.get("id1");
+ assertEquals(s1, toCheck);
- @Override
- protected String createKey() {
- return GUID.create();
+ cache.invalidateAll();
+ toCheck = cache.get("id1");
+ assertEquals(s2, toCheck);
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionFactoryTest.java b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionFactoryTest.java
index d5f25931f7..9a8f593403 100644
--- a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionFactoryTest.java
+++ b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionFactoryTest.java
@@ -13,13 +13,7 @@ package org.eclipse.osee.framework.core.server.test.internal.session;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import org.eclipse.osee.framework.core.enums.StorageState;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.model.IOseeStorable;
-import org.eclipse.osee.framework.core.model.cache.IOseeCache;
-import org.eclipse.osee.framework.core.model.cache.IOseeDataAccessor;
import org.eclipse.osee.framework.core.server.internal.session.Session;
-import org.eclipse.osee.framework.core.server.internal.session.SessionCache;
import org.eclipse.osee.framework.core.server.internal.session.SessionFactory;
import org.eclipse.osee.framework.core.server.test.mocks.MockBuildTypeIdentifier;
import org.eclipse.osee.framework.core.server.test.mocks.MockLog;
@@ -67,8 +61,8 @@ public class SessionFactoryTest {
@Test
public void testCreate() {
Session session =
- factory.create(guid, userId, creationDate, managedByServerId, clientVersion, clientMachineName, clientAddress,
- clientPort, lastInteractionDate, lastInteractionDetails);
+ factory.createNewSession(guid, userId, creationDate, managedByServerId, clientVersion, clientMachineName,
+ clientAddress, clientPort, lastInteractionDate, lastInteractionDetails);
Assert.assertEquals(guid, session.getGuid());
Assert.assertEquals(userId, session.getUserId());
@@ -80,51 +74,6 @@ public class SessionFactoryTest {
Assert.assertEquals(clientPort, session.getClientPort());
Assert.assertEquals(lastInteractionDate, session.getLastInteractionDate());
Assert.assertEquals(lastInteractionDetails, session.getLastInteractionDetails());
-
- Assert.assertEquals("", session.getDescription());
- Assert.assertEquals(IOseeStorable.UNPERSISTED_VALUE.intValue(), session.getId());
- Assert.assertEquals(userId, session.getName());
- Assert.assertEquals(StorageState.CREATED, session.getStorageState());
-
- String unqual = userId.replaceAll("hello.", "");
- Assert.assertEquals(unqual, session.getUnqualifiedName());
-
- }
-
- @Test
- public void testCreateOrUpdate() throws OseeCoreException {
- SessionCache cache = new SessionCache(new MockSessionAccessor());
-
- Session session =
- factory.create(guid, userId, creationDate, managedByServerId, clientVersion, clientMachineName, clientAddress,
- clientPort, lastInteractionDate, lastInteractionDetails);
- session.setId(200);
- session.setStorageState(StorageState.LOADED);
-
- cache.cache(session);
-
- Session session2 =
- factory.createOrUpdate(cache, 200, StorageState.LOADED, guid, userId, creationDate, managedByServerId,
- clientVersion, clientMachineName, clientAddress, clientPort, lastInteractionDate, lastInteractionDetails);
- Assert.assertEquals(session, session2);
-
- session2 =
- factory.createOrUpdate(cache, 200, StorageState.MODIFIED, guid, userId, creationDate, managedByServerId,
- clientVersion, clientMachineName, clientAddress, clientPort, lastInteractionDate, lastInteractionDetails);
- Assert.assertEquals(session, session2);
- Assert.assertEquals(StorageState.MODIFIED, session2.getStorageState());
-
- Assert.assertEquals(guid, session.getGuid());
- Assert.assertEquals(userId, session.getUserId());
- Assert.assertEquals(creationDate, session.getCreationDate());
- Assert.assertEquals(managedByServerId, session.getManagedByServerId());
- Assert.assertEquals(clientVersion, session.getClientVersion());
- Assert.assertEquals(clientMachineName, session.getClientMachineName());
- Assert.assertEquals(clientAddress, session.getClientAddress());
- Assert.assertEquals(clientPort, session.getClientPort());
- Assert.assertEquals(lastInteractionDate, session.getLastInteractionDate());
- Assert.assertEquals(lastInteractionDetails, session.getLastInteractionDetails());
-
}
@Parameters
@@ -158,17 +107,4 @@ public class SessionFactoryTest {
return data;
}
- private static final class MockSessionAccessor implements IOseeDataAccessor<String, Session> {
-
- @Override
- public void load(IOseeCache<String, Session> cache) {
- // Do Nothing
- }
-
- @Override
- public void store(Collection<Session> types) {
- // Do Nothing
- }
-
- }
}
diff --git a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionManagerTest.java b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionManagerTest.java
index 89b651ee4d..38db896539 100644
--- a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionManagerTest.java
+++ b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionManagerTest.java
@@ -10,11 +10,8 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server.test.internal.session;
-import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor;
import org.eclipse.osee.framework.core.server.IAuthenticationManager;
import org.eclipse.osee.framework.core.server.internal.session.ISessionQuery;
-import org.eclipse.osee.framework.core.server.internal.session.Session;
-import org.eclipse.osee.framework.core.server.internal.session.SessionCache;
import org.eclipse.osee.framework.core.server.internal.session.SessionFactory;
import org.eclipse.osee.framework.core.server.internal.session.SessionManagerImpl;
import org.junit.Ignore;
@@ -27,15 +24,17 @@ import org.junit.Test;
*/
public class SessionManagerTest {
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Ignore
@Test
public void test() {
SessionFactory factory = null;
ISessionQuery query = null;
IAuthenticationManager authenticator = null;
- MockOseeDataAccessor<String, Session> accessor = new MockOseeDataAccessor<String, Session>();
- SessionCache sessionCache = new SessionCache(accessor);
- new SessionManagerImpl("ABCD", factory, query, sessionCache, authenticator);
+ // LoadDataAccessor lda = mock(LoadDataAccessor.class);
+ // StoreDataAccessor sda = mock(StoreDataAccessor.class);
+ // SessionCache sessionCache = new SessionCache(lda);
+ // new SessionManagerImpl("ABCD", factory, query, sessionCache, authenticator, sda);
// OseeSessionGrant grant = sessionManager.createSession(OseeCredential credential); throws OseeCoreException;
diff --git a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionTest.java b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionTest.java
index 69b5b808a1..476b3b1d24 100644
--- a/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionTest.java
+++ b/plugins/org.eclipse.osee.framework.core.server.test/src/org/eclipse/osee/framework/core/server/test/internal/session/SessionTest.java
@@ -13,9 +13,6 @@ package org.eclipse.osee.framework.core.server.test.internal.session;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import org.eclipse.osee.framework.core.enums.StorageState;
-import org.eclipse.osee.framework.core.model.mocks.ModelAsserts;
-import org.eclipse.osee.framework.core.model.type.AbstractOseeTypeTest;
import org.eclipse.osee.framework.core.server.internal.session.Session;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Assert;
@@ -30,9 +27,10 @@ import org.junit.runners.Parameterized.Parameters;
* @author Roberto E. Escobar
*/
@RunWith(Parameterized.class)
-public class SessionTest extends AbstractOseeTypeTest<String, Session> {
+public class SessionTest {
- private final int expectedId;
+ private final Session session;
+ private final String expectedGuid;
private final String expectedClientAddress;
private final String expectedClientMachine;
private final String expectedClientVersion;
@@ -41,11 +39,11 @@ public class SessionTest extends AbstractOseeTypeTest<String, Session> {
private final String expectedUserId;
private final Date expectedLastInteractionDate;
private final String expectedLastInteraction;
- private final String exepectedManagedByServerId;
+ private final String expectedManagedByServerId;
- public SessionTest(Session type, String guid, String name, int expectedId, String expectedClientAddress, String expectedClientMachine, String expectedClientVersion, int expectedClientPort, Date expectedCreationDate, String expectedUserId, Date expectedLastInteractionDate, String expectedLastInteraction, String exepectedManagedByServerId) {
- super(type, guid, name);
- this.expectedId = expectedId;
+ public SessionTest(Session session, String guid, String expectedClientAddress, String expectedClientMachine, String expectedClientVersion, int expectedClientPort, Date expectedCreationDate, String expectedUserId, Date expectedLastInteractionDate, String expectedLastInteraction, String exepectedManagedByServerId) {
+ this.session = session;
+ this.expectedGuid = guid;
this.expectedClientAddress = expectedClientAddress;
this.expectedClientMachine = expectedClientMachine;
this.expectedClientVersion = expectedClientVersion;
@@ -54,70 +52,87 @@ public class SessionTest extends AbstractOseeTypeTest<String, Session> {
this.expectedUserId = expectedUserId;
this.expectedLastInteractionDate = expectedLastInteractionDate;
this.expectedLastInteraction = expectedLastInteraction;
- this.exepectedManagedByServerId = exepectedManagedByServerId;
+ this.expectedManagedByServerId = exepectedManagedByServerId;
}
@Test
- public void testGuidAsInteger() {
- int actualId = Session.guidAsInteger(getType().getGuid());
- Assert.assertEquals(expectedId, actualId);
+ public void testGetGuid() {
+ Assert.assertEquals(expectedGuid, session.getGuid());
}
@Test
public void testGetClientVersion() {
- Assert.assertEquals(expectedClientVersion, getType().getClientVersion());
+ Assert.assertEquals(expectedClientVersion, session.getClientVersion());
}
@Test
public void testGetCreationDate() {
- Assert.assertEquals(expectedCreationDate, getType().getCreationDate());
+ Assert.assertEquals(expectedCreationDate, session.getCreationDate());
}
@Test
public void testGetUserId() {
- Assert.assertEquals(expectedUserId, getType().getUserId());
+ Assert.assertEquals(expectedUserId, session.getUserId());
}
@Test
public void testSetGetClientAddress() throws Exception {
String newValue = GUID.create();
- ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_CLIENT_ADDRESS, "getClientAddress", "setClientAddress",
- expectedClientAddress, newValue);
+
+ Assert.assertEquals(expectedClientAddress, session.getClientAddress());
+
+ session.setClientAddress(newValue);
+ Assert.assertEquals(newValue, session.getClientAddress());
}
@Test
public void testSetGetClientMachineName() throws Exception {
String newValue = GUID.create();
- ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_CLIENT_MACHINE_NAME, "getClientMachineName",
- "setClientMachineName", expectedClientMachine, newValue);
+
+ Assert.assertEquals(expectedClientMachine, session.getClientMachineName());
+
+ session.setClientMachineName(newValue);
+ Assert.assertEquals(newValue, session.getClientMachineName());
}
@Test
public void testSetGetClientPort() throws Exception {
int newValue = Integer.MAX_VALUE;
- ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_CLIENT_PORT, "getClientPort", "setClientPort",
- expectedClientPort, newValue);
+
+ Assert.assertEquals(expectedClientPort, session.getClientPort());
+
+ session.setClientPort(newValue);
+ Assert.assertEquals(newValue, session.getClientPort());
}
@Test
public void testSetGetLastInteractionDate() throws Exception {
Date newValue = new Date();
- ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_LAST_INTERACTION_DATE, "getLastInteractionDate",
- "setLastInteractionDate", expectedLastInteractionDate, newValue);
+
+ Assert.assertEquals(expectedLastInteractionDate, session.getLastInteractionDate());
+
+ session.setLastInteractionDate(newValue);
+ Assert.assertEquals(newValue, session.getLastInteractionDate());
}
@Test
public void testSetGetLastInteractionDetails() throws Exception {
String newValue = GUID.create();
- ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_LAST_INTERACTION_DETAILS, "getLastInteractionDetails",
- "setLastInteractionDetails", expectedLastInteraction, newValue);
+
+ Assert.assertEquals(expectedLastInteraction, session.getLastInteractionDetails());
+
+ session.setLastInteractionDetails(newValue);
+ Assert.assertEquals(newValue, session.getLastInteractionDetails());
}
@Test
public void testSetManagedByServerId() throws Exception {
String newValue = GUID.create();
- ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_MANAGED_BY_SERVER_ID, "getManagedByServerId",
- "setManagedByServerId", exepectedManagedByServerId, newValue);
+
+ Assert.assertEquals(expectedManagedByServerId, session.getManagedByServerId());
+
+ session.setManagedByServerId(newValue);
+ Assert.assertEquals(newValue, session.getManagedByServerId());
}
@Parameters
@@ -125,11 +140,6 @@ public class SessionTest extends AbstractOseeTypeTest<String, Session> {
Collection<Object[]> data = new ArrayList<Object[]>();
for (int index = 1; index <= 3; index++) {
String guid = "ABCD" + String.valueOf(index);
- int actualIndex = index - 1;
- int expectedId = 1946 + actualIndex * 20 + 4 * actualIndex;
-
- String name = "index-" + index;
-
String clientAddress = "addresss-" + index;
String clientMachine = "machine-" + index;
String clientVersion = "version-" + index;
@@ -141,16 +151,12 @@ public class SessionTest extends AbstractOseeTypeTest<String, Session> {
String managedByServerId = "serverId-" + index;
Session session =
- new Session(guid, name, userId, creationDate, managedByServerId, clientVersion, clientMachine,
- clientAddress, clientPort, lastInteractionDate, lastInteraction);
- session.setStorageState(StorageState.LOADED);
- session.clearDirty();
+ new Session(guid, userId, creationDate, managedByServerId, clientVersion, clientMachine, clientAddress,
+ clientPort, lastInteractionDate, lastInteraction);
data.add(new Object[] {
session,
guid,
- name,
- expectedId,
clientAddress,
clientMachine,
clientVersion,

Back to the top