Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormegumi.telles2013-09-05 18:13:14 -0400
committerRoberto E. Escobar2013-09-17 19:28:51 -0400
commit361e47e07c06baaaffdc32d0c7350af13e00a5be (patch)
tree14ee44d66eb3b6b598625522832ba991fd3a6347 /plugins/org.eclipse.osee.orcs.core.test
parentfe95c0472a4440d747930e647e9abd96aab4bd4d (diff)
downloadorg.eclipse.osee-361e47e07c06baaaffdc32d0c7350af13e00a5be.tar.gz
org.eclipse.osee-361e47e07c06baaaffdc32d0c7350af13e00a5be.tar.xz
org.eclipse.osee-361e47e07c06baaaffdc32d0c7350af13e00a5be.zip
feature[ats_7SNLZ]: Convert transaction API
Remove ArtifactWriteable idea and make changes directly on the transaction object. Supporting changes: 1. Create Artifact interface 2. Create Attribute interface 3. Delete Writeable interfaces 4. Delete unused classes 5. Separate transaction logic 6. Rename OrcsTransaction to TransactionBuilder Change-Id: I88a5a1996aca72fbebfe80436621a22789e536a6
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.core.test')
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/InternalTestSuite.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java174
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactBuilderImplTest.java9
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactLoaderFactoryImplTest.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ArtifactProxyFactoryTest.java194
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ProxyTestSuite.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ArtifactWriteableInvocationHandlerTest.java266
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyInvocationHandlerTestSuite.java26
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyTestHelper.java101
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ReadableInvocationHandlerTest.java67
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/WriteableInvocationHandlerTest.java97
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ExternalArtifactManagerTest.java94
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/CollectDirtyDataTest.java (renamed from plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyDataTest.java)2
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionImplTest.java340
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionBuilderImplTest.java361
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java39
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionTestSuite.java8
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxCallableFactoryTest.java159
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerImplTest.java175
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerTest.java367
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/ResultSetIterableTest.java133
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/UtilTestSuite.java2
23 files changed, 1241 insertions, 1407 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/InternalTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/InternalTestSuite.java
index fd5c84ebca..d80e8c767d 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/InternalTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/InternalTestSuite.java
@@ -19,6 +19,7 @@ import org.eclipse.osee.orcs.core.internal.relation.RelationTestSuite;
import org.eclipse.osee.orcs.core.internal.search.QueryTestSuite;
import org.eclipse.osee.orcs.core.internal.transaction.TransactionTestSuite;
import org.eclipse.osee.orcs.core.internal.types.TypesTestSuite;
+import org.eclipse.osee.orcs.core.internal.util.UtilTestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -35,7 +36,8 @@ import org.junit.runners.Suite;
RelationTestSuite.class,
QueryTestSuite.class,
TransactionTestSuite.class,
- TypesTestSuite.class})
+ TypesTestSuite.class,
+ UtilTestSuite.class})
public class InternalTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
index 7638227257..19c1d658ee 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
@@ -33,10 +33,10 @@ import org.eclipse.osee.orcs.core.ds.AttributeData;
import org.eclipse.osee.orcs.core.ds.OrcsData;
import org.eclipse.osee.orcs.core.ds.VersionData;
import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
+import org.eclipse.osee.orcs.core.internal.artifact.ArtifactImpl;
import org.eclipse.osee.orcs.core.internal.relation.RelationContainer;
import org.eclipse.osee.orcs.core.internal.util.ValueProvider;
import org.eclipse.osee.orcs.data.ArtifactTypes;
-import org.eclipse.osee.orcs.data.AttributeReadable;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -54,7 +54,7 @@ public class ArtifactTest {
public ExpectedException thrown = ExpectedException.none();
// @formatter:off
- @Mock private Artifact artifactImpl;
+ @Mock private Artifact artifact;
@Mock private ArtifactData artifactData;
@Mock private AttributeFactory attributeFactory;
@Mock private RelationContainer relationContainer;
@@ -83,7 +83,7 @@ public class ArtifactTest {
@Before
public void init() throws OseeCoreException {
MockitoAnnotations.initMocks(this);
- artifactImpl = new Artifact(types, artifactData, attributeFactory, relationContainer, branchProvider);
+ artifact = new ArtifactImpl(types, artifactData, attributeFactory, relationContainer, branchProvider);
when(types.isValidAttributeType(any(IArtifactType.class), any(Branch.class), any(IAttributeType.class))).thenReturn(
true);
@@ -112,13 +112,13 @@ public class ArtifactTest {
@Test
@SuppressWarnings("unchecked")
- public void testAddAndGet() {
+ public void testAddAndGet() throws OseeCoreException {
Attribute<Object> attribute = mock(Attribute.class);
when(attribute.getOrcsData()).thenReturn(attributeData);
- Assert.assertEquals(0, artifactImpl.getAllAttributes().size());
- artifactImpl.add(CoreAttributeTypes.City, attribute);
- Assert.assertTrue(artifactImpl.getAllAttributes().contains(attribute));
- Assert.assertEquals(1, artifactImpl.getAllAttributes().size());
+ Assert.assertEquals(0, artifact.getAttributes().size());
+ artifact.add(CoreAttributeTypes.City, attribute);
+ Assert.assertTrue(artifact.getAttributes().contains(attribute));
+ Assert.assertEquals(1, artifact.getAttributes().size());
}
@Test
@@ -130,9 +130,9 @@ public class ArtifactTest {
when(two.getOrcsData()).thenReturn(attributeData);
when(attributeFactory.getMaxOccurrenceLimit(attributeType)).thenReturn(1);
- artifactImpl.add(attributeType, one);
- artifactImpl.add(attributeType, two);
- Assert.assertEquals(2, artifactImpl.getAttributes(attributeType).size());
+ artifact.add(attributeType, one);
+ artifact.add(attributeType, two);
+ Assert.assertEquals(2, artifact.getAttributes(attributeType).size());
}
@Test
@@ -140,64 +140,58 @@ public class ArtifactTest {
public void testAreAttributesDirty() {
Attribute<Object> attribute = mock(Attribute.class);
when(attribute.getOrcsData()).thenReturn(attributeData);
- artifactImpl.add(CoreAttributeTypes.City, attribute);
- Assert.assertFalse(artifactImpl.areAttributesDirty());
+ artifact.add(CoreAttributeTypes.City, attribute);
+ Assert.assertFalse(artifact.areAttributesDirty());
when(attribute.isDirty()).thenReturn(true);
- Assert.assertTrue(artifactImpl.areAttributesDirty());
+ Assert.assertTrue(artifact.areAttributesDirty());
}
@Test
public void testCreateAttribute() throws OseeCoreException {
- artifactImpl.createAttribute(CoreAttributeTypes.City);
- verify(attributeFactory).createAttributeWithDefaults(artifactImpl, artifactData, CoreAttributeTypes.City);
+ artifact.createAttribute(CoreAttributeTypes.City);
+ verify(attributeFactory).createAttributeWithDefaults(artifact, artifactData, CoreAttributeTypes.City);
}
@Test
public void testSetOrcsData() {
ArtifactData newOrcsData = mock(ArtifactData.class);
- artifactImpl.setOrcsData(newOrcsData);
+ artifact.setOrcsData(newOrcsData);
verify(branchProvider).setOrcsData(newOrcsData);
}
@Test
- public void testGetModificationType() {
- artifactImpl.getModificationType();
- verify(artifactData).getModType();
- }
-
- @Test
public void testGetLocalId() {
- artifactImpl.getLocalId();
+ artifact.getLocalId();
verify(artifactData).getLocalId();
}
@Test
public void testGetGuid() {
- artifactImpl.getGuid();
+ artifact.getGuid();
verify(artifactData).getGuid();
}
@Test
public void testGetHumanReadableId() {
- artifactImpl.getHumanReadableId();
+ artifact.getHumanReadableId();
verify(artifactData).getHumanReadableId();
}
@Test
public void testGetTransactionId() {
- artifactImpl.getTransaction();
+ artifact.getTransaction();
verify(version).getTransactionId();
}
@Test
public void testGetBranch() throws OseeCoreException {
- artifactImpl.getBranch();
+ artifact.getBranch();
verify(branchProvider).get();
}
@Test
public void testArtifactType() throws OseeCoreException {
- artifactImpl.getArtifactType();
+ artifact.getArtifactType();
verify(types).getByUuid(artifactData.getTypeUuid());
}
@@ -209,7 +203,7 @@ public class ArtifactTest {
when(
attributeFactory.createAttributeWithDefaults(any(AttributeManager.class), any(ArtifactData.class),
eq(CoreAttributeTypes.Name))).thenReturn(attr);
- artifactImpl.setName("test");
+ artifact.setName("test");
verify(attr).setFromString("test");
}
@@ -217,7 +211,7 @@ public class ArtifactTest {
public void testSetArtifactType() throws OseeCoreException {
when(version.isInStorage()).thenReturn(true);
- artifactImpl.setArtifactType(CoreArtifactTypes.CodeUnit);
+ artifact.setArtifactType(CoreArtifactTypes.CodeUnit);
verify(artifactData).setTypeUuid(CoreArtifactTypes.CodeUnit.getGuid());
verify(artifactData).setModType(ModificationType.MODIFIED);
@@ -230,13 +224,13 @@ public class ArtifactTest {
when(artifactData.getVersion()).thenReturn(version);
when(artifactData.getTypeUuid()).thenReturn(artifactType.getGuid());
- artifactImpl.setArtifactType(CoreArtifactTypes.CodeUnit);
+ artifact.setArtifactType(CoreArtifactTypes.CodeUnit);
verify(artifactData, never()).setModType(ModificationType.MODIFIED);
}
@Test
public void testIsOfType() throws OseeCoreException {
- artifactImpl.isOfType(CoreArtifactTypes.CodeUnit);
+ artifact.isOfType(CoreArtifactTypes.CodeUnit);
verify(types).inheritsFrom(CoreArtifactTypes.GeneralData, CoreArtifactTypes.CodeUnit);
}
@@ -244,26 +238,26 @@ public class ArtifactTest {
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void testIsDirty() throws OseeCoreException {
- Assert.assertFalse(artifactImpl.isDirty());
+ Assert.assertFalse(artifact.isDirty());
// add dirty attribute
Attribute dirty = mock(Attribute.class);
when(dirty.getOrcsData()).thenReturn(attributeData);
when(dirty.isDirty()).thenReturn(true);
- artifactImpl.add(CoreAttributeTypes.Active, dirty);
- Assert.assertTrue(artifactImpl.isDirty());
+ artifact.add(CoreAttributeTypes.Active, dirty);
+ Assert.assertTrue(artifact.isDirty());
// change artifactType
reset(dirty);
- Assert.assertFalse(artifactImpl.isDirty());
- artifactImpl.setArtifactType(CoreArtifactTypes.CodeUnit);
- Assert.assertTrue(artifactImpl.isDirty());
+ Assert.assertFalse(artifact.isDirty());
+ artifact.setArtifactType(CoreArtifactTypes.CodeUnit);
+ Assert.assertTrue(artifact.isDirty());
// set mod type to replace with version
- artifactImpl.setOrcsData(artifactData);
- Assert.assertFalse(artifactImpl.isDirty());
+ artifact.setOrcsData(artifactData);
+ Assert.assertFalse(artifact.isDirty());
when(artifactData.getModType()).thenReturn(ModificationType.REPLACED_WITH_VERSION);
- Assert.assertTrue(artifactImpl.isDirty());
+ Assert.assertTrue(artifact.isDirty());
}
@Test
@@ -271,19 +265,19 @@ public class ArtifactTest {
for (ModificationType modType : ModificationType.values()) {
reset(artifactData);
when(artifactData.getModType()).thenReturn(modType);
- Assert.assertEquals(modType.isDeleted(), artifactImpl.isDeleted());
+ Assert.assertEquals(modType.isDeleted(), artifact.isDeleted());
}
}
@Test
public void testIsAttributeTypeValid() throws OseeCoreException {
- artifactImpl.isAttributeTypeValid(CoreAttributeTypes.Afha);
+ artifact.isAttributeTypeValid(CoreAttributeTypes.Afha);
verify(types).isValidAttributeType(artifactType, branch, CoreAttributeTypes.Afha);
}
@Test
public void testGetValidAttributeTypes() throws OseeCoreException {
- artifactImpl.getValidAttributeTypes();
+ artifact.getValidAttributeTypes();
verify(types).getAttributeTypes(artifactType, branch);
}
@@ -294,9 +288,9 @@ public class ArtifactTest {
Attribute two = mock(Attribute.class);
when(one.getOrcsData()).thenReturn(attributeData);
when(two.getOrcsData()).thenReturn(attributeData);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, one);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, two);
- artifactImpl.setAttributesNotDirty();
+ artifact.add(CoreAttributeTypes.AccessContextId, one);
+ artifact.add(CoreAttributeTypes.AccessContextId, two);
+ artifact.setAttributesNotDirty();
verify(one).clearDirty();
verify(two).clearDirty();
}
@@ -304,7 +298,7 @@ public class ArtifactTest {
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void testGetName() throws OseeCoreException {
- String name = artifactImpl.getName();
+ String name = artifact.getName();
Assert.assertTrue(name.contains("AttributeDoesNotExist"));
Attribute attr = mock(Attribute.class);
@@ -313,9 +307,9 @@ public class ArtifactTest {
attributeFactory.createAttributeWithDefaults(any(AttributeManager.class), any(ArtifactData.class),
eq(CoreAttributeTypes.Name))).thenReturn(attr);
when(attr.getValue()).thenReturn("test");
- artifactImpl.add(CoreAttributeTypes.Name, attr);
- artifactImpl.setName("test");
- name = artifactImpl.getName();
+ artifact.add(CoreAttributeTypes.Name, attr);
+ artifact.setName("test");
+ name = artifact.getName();
Assert.assertEquals("test", name);
}
@@ -325,11 +319,11 @@ public class ArtifactTest {
when(attributeFactory.getMaxOccurrenceLimit(CoreAttributeTypes.AccessContextId)).thenReturn(expected);
- int result = artifactImpl.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
+ int result = artifact.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(expected, result);
reset(types);
- result = artifactImpl.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
+ result = artifact.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(-1, result);
}
@@ -339,38 +333,38 @@ public class ArtifactTest {
when(attributeFactory.getMinOccurrenceLimit(CoreAttributeTypes.AccessContextId)).thenReturn(expected);
- int result = artifactImpl.getMinimumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
+ int result = artifact.getMinimumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(expected, result);
reset(types);
- result = artifactImpl.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
+ result = artifact.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(-1, result);
}
@Test
@SuppressWarnings("unchecked")
public void testGetAttributeCount() throws OseeCoreException {
- artifactImpl.add(CoreAttributeTypes.AccessContextId, notDeleted);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, deleted);
- artifactImpl.add(CoreAttributeTypes.Name, differentType);
- int result = artifactImpl.getAttributeCount(CoreAttributeTypes.AccessContextId);
+ artifact.add(CoreAttributeTypes.AccessContextId, notDeleted);
+ artifact.add(CoreAttributeTypes.AccessContextId, deleted);
+ artifact.add(CoreAttributeTypes.Name, differentType);
+ int result = artifact.getAttributeCount(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(1, result);
- result = artifactImpl.getAttributeCount(CoreAttributeTypes.Name);
+ result = artifact.getAttributeCount(CoreAttributeTypes.Name);
Assert.assertEquals(1, result);
}
@Test
@SuppressWarnings("unchecked")
public void testGetAttributes() throws OseeCoreException {
- artifactImpl.add(CoreAttributeTypes.AccessContextId, notDeleted);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, deleted);
- artifactImpl.add(CoreAttributeTypes.Name, differentType);
- List<AttributeReadable<Object>> attributes = artifactImpl.getAttributes();
+ artifact.add(CoreAttributeTypes.AccessContextId, notDeleted);
+ artifact.add(CoreAttributeTypes.AccessContextId, deleted);
+ artifact.add(CoreAttributeTypes.Name, differentType);
+ List<Attribute<Object>> attributes = artifact.getAttributes();
Assert.assertTrue(attributes.contains(notDeleted));
Assert.assertTrue(attributes.contains(differentType));
Assert.assertFalse(attributes.contains(deleted));
- attributes = artifactImpl.getAttributes(CoreAttributeTypes.AccessContextId);
+ attributes = artifact.getAttributes(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(1, attributes.size());
Assert.assertTrue(attributes.contains(notDeleted));
}
@@ -378,11 +372,11 @@ public class ArtifactTest {
@Test
@SuppressWarnings("unchecked")
public void testGetAttributeValues() throws OseeCoreException {
- artifactImpl.add(CoreAttributeTypes.AccessContextId, notDeleted);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, deleted);
+ artifact.add(CoreAttributeTypes.AccessContextId, notDeleted);
+ artifact.add(CoreAttributeTypes.AccessContextId, deleted);
when(notDeleted.getValue()).thenReturn("notDeleted");
when(deleted.getValue()).thenReturn("deleted");
- List<Object> values = artifactImpl.getAttributeValues(CoreAttributeTypes.AccessContextId);
+ List<Object> values = artifact.getAttributeValues(CoreAttributeTypes.AccessContextId);
Assert.assertEquals(1, values.size());
Assert.assertTrue(values.contains("notDeleted"));
}
@@ -391,11 +385,11 @@ public class ArtifactTest {
@SuppressWarnings("unchecked")
public void testGetSoleAttributeAsString() throws OseeCoreException {
when(notDeleted.getValue()).thenReturn(new Integer(5));
- artifactImpl.add(CoreAttributeTypes.AccessContextId, notDeleted);
- String attribute = artifactImpl.getSoleAttributeAsString(CoreAttributeTypes.AccessContextId);
+ artifact.add(CoreAttributeTypes.AccessContextId, notDeleted);
+ String attribute = artifact.getSoleAttributeAsString(CoreAttributeTypes.AccessContextId);
Assert.assertEquals("5", attribute);
- attribute = artifactImpl.getSoleAttributeAsString(CoreAttributeTypes.Category, "default");
+ attribute = artifact.getSoleAttributeAsString(CoreAttributeTypes.Category, "default");
Assert.assertEquals("default", attribute);
}
@@ -406,19 +400,19 @@ public class ArtifactTest {
Attribute two = mock(Attribute.class);
when(one.getOrcsData()).thenReturn(attributeData);
when(two.getOrcsData()).thenReturn(attributeData);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, one);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, two);
+ artifact.add(CoreAttributeTypes.AccessContextId, one);
+ artifact.add(CoreAttributeTypes.AccessContextId, two);
thrown.expect(MultipleAttributesExist.class);
- artifactImpl.getSoleAttributeAsString(CoreAttributeTypes.AccessContextId);
+ artifact.getSoleAttributeAsString(CoreAttributeTypes.AccessContextId);
}
@Test
@SuppressWarnings("unchecked")
public void testDeleteAttributesByArtifact() throws OseeCoreException {
- artifactImpl.add(CoreAttributeTypes.AccessContextId, notDeleted);
- artifactImpl.add(CoreAttributeTypes.AccessContextId, deleted);
- artifactImpl.add(CoreAttributeTypes.Active, differentType);
- artifactImpl.deleteAttributesByArtifact();
+ artifact.add(CoreAttributeTypes.AccessContextId, notDeleted);
+ artifact.add(CoreAttributeTypes.AccessContextId, deleted);
+ artifact.add(CoreAttributeTypes.Active, differentType);
+ artifact.deleteAttributesByArtifact();
verify(notDeleted).setArtifactDeleted();
verify(deleted).setArtifactDeleted();
verify(differentType).setArtifactDeleted();
@@ -429,9 +423,9 @@ public class ArtifactTest {
public void testDeleteSoleAttribute() throws OseeCoreException {
when(attributeFactory.getMinOccurrenceLimit(attributeType)).thenReturn(0);
when(notDeleted.getAttributeType()).thenReturn(attributeType);
- when(notDeleted.getContainer()).thenReturn(artifactImpl);
- artifactImpl.add(attributeType, notDeleted);
- artifactImpl.deleteSoleAttribute(attributeType);
+ when(notDeleted.getContainer()).thenReturn(artifact);
+ artifact.add(attributeType, notDeleted);
+ artifact.deleteSoleAttribute(attributeType);
verify(notDeleted).delete();
}
@@ -441,10 +435,10 @@ public class ArtifactTest {
when(attributeFactory.getMinOccurrenceLimit(attributeType)).thenReturn(1);
when(notDeleted.getAttributeType()).thenReturn(attributeType);
- artifactImpl.add(attributeType, notDeleted);
+ artifact.add(attributeType, notDeleted);
thrown.expect(OseeStateException.class);
- artifactImpl.deleteSoleAttribute(attributeType);
+ artifact.deleteSoleAttribute(attributeType);
}
@Test
@@ -459,9 +453,9 @@ public class ArtifactTest {
when(attributeFactory.getMaxOccurrenceLimit(attributeType)).thenReturn(3);
- when(attributeFactory.createAttributeWithDefaults(eq(artifactImpl), any(ArtifactData.class), eq(attributeType))).thenReturn(
+ when(attributeFactory.createAttributeWithDefaults(eq(artifact), any(ArtifactData.class), eq(attributeType))).thenReturn(
one, two, three);
- artifactImpl.setAttributesFromStrings(attributeType, "one", "two", "three");
+ artifact.setAttributesFromStrings(attributeType, "one", "two", "three");
verify(one).setFromString("one");
verify(two).setFromString("two");
verify(three).setFromString("three");
@@ -477,16 +471,16 @@ public class ArtifactTest {
when(attributeFactory.getMaxOccurrenceLimit(attributeType)).thenReturn(3);
- when(attributeFactory.createAttributeWithDefaults(eq(artifactImpl), any(ArtifactData.class), eq(attributeType))).thenReturn(
+ when(attributeFactory.createAttributeWithDefaults(eq(artifact), any(ArtifactData.class), eq(attributeType))).thenReturn(
two);
- artifactImpl.add(attributeType, one);
- artifactImpl.setAttributesFromStrings(attributeType, "1", "2");
+ artifact.add(attributeType, one);
+ artifact.setAttributesFromStrings(attributeType, "1", "2");
verify(one).setFromString("1");
verify(two).setFromString("2");
reset(one, two);
when(one.getValue()).thenReturn("1");
- artifactImpl.setAttributesFromStrings(attributeType, "1", "2");
+ artifact.setAttributesFromStrings(attributeType, "1", "2");
verify(one, never()).setFromString("1");
verify(two).setFromString("2");
}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactBuilderImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactBuilderImplTest.java
index 37676fee4e..dcc9b0e3a3 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactBuilderImplTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactBuilderImplTest.java
@@ -28,6 +28,7 @@ import org.eclipse.osee.framework.core.enums.RelationSide;
import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.ArtifactData;
import org.eclipse.osee.orcs.core.ds.AttributeData;
import org.eclipse.osee.orcs.core.ds.RelationData;
@@ -36,7 +37,7 @@ import org.eclipse.osee.orcs.core.internal.ArtifactBuilder;
import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
import org.eclipse.osee.orcs.core.internal.artifact.ArtifactFactory;
import org.eclipse.osee.orcs.core.internal.attribute.AttributeFactory;
-import org.eclipse.osee.orcs.core.internal.proxy.ArtifactProxyFactory;
+import org.eclipse.osee.orcs.core.internal.proxy.ExternalArtifactManager;
import org.eclipse.osee.orcs.core.internal.relation.RelationContainer;
import org.eclipse.osee.orcs.core.internal.relation.RelationContainerImpl;
import org.eclipse.osee.orcs.data.RelationTypes;
@@ -58,10 +59,11 @@ public class ArtifactBuilderImplTest {
// @formatter:off
@Mock private Log logger;
- @Mock private ArtifactProxyFactory proxyFactory;
+ @Mock private ExternalArtifactManager proxyFactory;
@Mock private ArtifactFactory artifactFactory;
@Mock private AttributeFactory attributeFactory;
+ @Mock private OrcsSession session;
@Mock private Artifact artifact;
@Mock private ArtifactData artifactData;
@Mock private AttributeData attributeData;
@@ -72,7 +74,8 @@ public class ArtifactBuilderImplTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- builder = new ArtifactBuilderImpl(logger, proxyFactory, artifactFactory, attributeFactory);
+ builder = new ArtifactBuilderImpl(logger, proxyFactory, artifactFactory, attributeFactory, session);
+
}
@Test
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactLoaderFactoryImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactLoaderFactoryImplTest.java
index e1e4d0c3cd..c4a8bf0533 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactLoaderFactoryImplTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/loader/ArtifactLoaderFactoryImplTest.java
@@ -122,7 +122,7 @@ public class ArtifactLoaderFactoryImplTest {
ArtifactLoader loader = factory.fromBranchAndArtifactIds(session, branch, ids);
verify(dataLoaderFactory).fromBranchAndArtifactIds(session, branch, ids);
- when(builderFactory.createArtifactBuilder()).thenReturn(builder);
+ when(builderFactory.createArtifactBuilder(session)).thenReturn(builder);
when(builder.getArtifacts()).thenReturn(artifacts);
List<ArtifactReadable> actual = loader.load(cancellation);
@@ -139,7 +139,7 @@ public class ArtifactLoaderFactoryImplTest {
ArtifactLoader loader = factory.fromBranchAndArtifactIds(session, branch, ids);
verify(dataLoaderFactory).fromBranchAndArtifactIds(session, branch, ids);
- when(builderFactory.createArtifactBuilder()).thenReturn(builder);
+ when(builderFactory.createArtifactBuilder(session)).thenReturn(builder);
when(builder.getArtifacts()).thenReturn(artifacts);
ResultSet<ArtifactReadable> result = loader.getResults(cancellation);
@@ -156,7 +156,7 @@ public class ArtifactLoaderFactoryImplTest {
ArtifactLoader loader = factory.fromQueryContext(session, queryContext);
verify(dataLoaderFactory).fromQueryContext(queryContext);
- when(builderFactory.createArtifactBuilder()).thenReturn(builder);
+ when(builderFactory.createArtifactBuilder(session)).thenReturn(builder);
when(builder.getArtifacts()).thenReturn(artifacts);
ResultSet<ArtifactReadable> result = loader.getResults(cancellation);
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ArtifactProxyFactoryTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ArtifactProxyFactoryTest.java
deleted file mode 100644
index 080060e4bf..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ArtifactProxyFactoryTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.proxy;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import java.util.Collection;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.eclipse.osee.framework.core.data.IArtifactType;
-import org.eclipse.osee.framework.core.data.IAttributeType;
-import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
-import org.eclipse.osee.framework.core.enums.CoreBranches;
-import org.eclipse.osee.framework.core.exception.OseeArgumentException;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.util.GUID;
-import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
-import org.eclipse.osee.orcs.core.internal.artifact.ArtifactFactory;
-import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.eclipse.osee.orcs.data.ArtifactWriteable;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-/**
- * Test Case for {@link ArtifactProxyFactory}
- *
- * @author Roberto E. Escobar
- */
-public class ArtifactProxyFactoryTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- // @formatter:off
- @Mock private ArtifactReadable readable;
- @Mock private ArtifactFactory artifactFactory;
- @Mock private Artifact artifact;
- @Mock private Artifact otherArtifact;
- // @formatter:on
-
- private String guid;
- private final IOseeBranch branch = CoreBranches.COMMON;
- private final IArtifactType artifactType = CoreArtifactTypes.Folder;
- private ArtifactProxyFactory factory;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
-
- guid = GUID.create();
- factory = new ArtifactProxyFactory(artifactFactory);
- }
-
- @Test
- public void testCreate() throws Throwable {
- String expectedName = "NAME";
-
- when(artifactFactory.createArtifact(branch, artifactType, guid)).thenReturn(artifact);
- when(artifactFactory.clone(artifact)).thenReturn(otherArtifact);
-
- ArtifactWriteable actual = factory.create(branch, artifactType, guid, expectedName);
-
- verify(artifactFactory).createArtifact(branch, artifactType, guid);
- verify(otherArtifact).setName(expectedName);
- verify(artifact, times(0)).setName(expectedName);
-
- assertTrue(actual instanceof ProxyWriteable);
- assertTrue(ProxyUtil.isProxy(actual));
- assertEquals(otherArtifact, factory.getProxiedObject(actual));
- assertEquals(artifact, factory.getOriginalObject(actual));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCopy() throws Throwable {
- Collection<? extends IAttributeType> types = Mockito.mock(Collection.class);
- when(artifactFactory.copyArtifact(artifact, types, branch)).thenReturn(otherArtifact);
-
- ArtifactWriteable actual = factory.copy(artifact, types, branch);
-
- verify(artifactFactory).copyArtifact(artifact, types, branch);
-
- assertTrue(actual instanceof ProxyWriteable);
- assertTrue(ProxyUtil.isProxy(actual));
- assertEquals(otherArtifact, factory.getProxiedObject(actual));
- }
-
- @Test
- public void testIntroduce() throws OseeCoreException {
- when(artifactFactory.introduceArtifact(artifact, branch)).thenReturn(otherArtifact);
-
- ArtifactWriteable actual = factory.introduce(artifact, branch);
-
- verify(artifactFactory).introduceArtifact(artifact, branch);
-
- assertTrue(actual instanceof ProxyWriteable);
- assertTrue(ProxyUtil.isProxy(actual));
- assertEquals(otherArtifact, factory.getProxiedObject(actual));
- }
-
- @Test
- public void testCreateReadable() {
- ArtifactReadable actual = factory.createReadable(artifact);
-
- assertFalse(actual instanceof ProxyWriteable);
- assertTrue(actual instanceof HasProxiedObject);
- assertTrue(ProxyUtil.isProxy(actual));
- assertEquals(artifact, factory.getProxiedObject(actual));
- }
-
- @Test
- public void testCreateWriteable() throws OseeCoreException {
- ArtifactWriteable actual = factory.createWriteable(artifact);
-
- assertTrue(actual instanceof ProxyWriteable);
- assertTrue(ProxyUtil.isProxy(actual));
- assertEquals(artifact, factory.getProxiedObject(actual));
- assertEquals(artifact, factory.getOriginalObject(actual));
- }
-
- @Test
- public void testAsProxyWriteable() throws OseeCoreException {
- ArtifactWriteable proxied = factory.createWriteable(artifact);
- ProxyWriteable<Artifact> actual = factory.asProxyWriteable(proxied);
- assertNotNull(actual);
-
- thrown.expect(OseeArgumentException.class);
- thrown.expectMessage(new RegExMatcher("Unable to convert from \\[Artifact(.*?)\\] to ProxyWriteable"));
- factory.asProxyWriteable(artifact);
- }
-
- @Test
- public void testAsWriteable() throws OseeCoreException {
- ArtifactWriteable actual = factory.asWriteable(artifact);
- assertTrue(actual != artifact);
- assertTrue(ProxyUtil.isProxy(actual));
-
- ArtifactWriteable actual2 = factory.asWriteable(actual);
- assertTrue(actual2 == actual);
-
- thrown.expect(OseeArgumentException.class);
- thrown.expectMessage(new RegExMatcher("Unable to convert from \\[ArtifactReadable(.*?)\\] to Writeable"));
- factory.asWriteable(readable);
- }
-
- @Test
- public void testAsWriteableWithNull() throws OseeCoreException {
- thrown.expect(OseeArgumentException.class);
- thrown.expectMessage("Unable to convert from [null] to Writeable");
- factory.asWriteable(null);
- }
-
- private static final class RegExMatcher extends BaseMatcher<String> {
-
- private final Matcher matcher;
-
- public RegExMatcher(String regEx) {
- this.matcher = Pattern.compile(regEx).matcher("");
- }
-
- @Override
- public void describeTo(Description description) {
- // nothing
- }
-
- @Override
- public boolean matches(Object item) {
- String value = (String) item;
- matcher.reset(value);
- return matcher.find();
- }
- };
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ProxyTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ProxyTestSuite.java
index f39a589b56..ac6a9780b7 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ProxyTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/ProxyTestSuite.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.proxy;
-import org.eclipse.osee.orcs.core.internal.proxy.handler.ProxyInvocationHandlerTestSuite;
+import org.eclipse.osee.orcs.core.internal.proxy.impl.ExternalArtifactManagerTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -18,7 +18,7 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({ProxyInvocationHandlerTestSuite.class, ArtifactProxyFactoryTest.class})
+@Suite.SuiteClasses({ExternalArtifactManagerTest.class})
public class ProxyTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ArtifactWriteableInvocationHandlerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ArtifactWriteableInvocationHandlerTest.java
deleted file mode 100644
index 217de9e7c0..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ArtifactWriteableInvocationHandlerTest.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.proxy.handler;
-
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import org.junit.Assert;
-import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.orcs.core.internal.artifact.ArtifactFactory;
-import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
-import org.eclipse.osee.orcs.core.internal.attribute.Attribute;
-import org.eclipse.osee.orcs.core.internal.proxy.AttributeProxyFactory;
-import org.eclipse.osee.orcs.core.internal.proxy.HasProxiedObject;
-import org.eclipse.osee.orcs.core.internal.proxy.ProxyUtil;
-import org.eclipse.osee.orcs.core.internal.proxy.ProxyWriteable;
-import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.eclipse.osee.orcs.data.ArtifactWriteable;
-import org.eclipse.osee.orcs.data.AttributeReadable;
-import org.eclipse.osee.orcs.data.AttributeWriteable;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-/**
- * Test Case for {@link ArtifactWriteableInvocationHandler}
- *
- * @author Roberto E. Escobar
- */
-public class ArtifactWriteableInvocationHandlerTest {
-
- //@formatter:off
- @Mock private Artifact proxiedObject;
- @Mock private Artifact copy;
- @Mock private ArtifactFactory artifactFactory;
- @Mock private AttributeProxyFactory attributeProxyFactory;
- //@formatter:on
-
- private ArtifactWriteableInvocationHandler handler;
-
- @Before
- public void setup() throws OseeCoreException {
- MockitoAnnotations.initMocks(this);
-
- handler = new ArtifactWriteableInvocationHandler(artifactFactory, attributeProxyFactory, proxiedObject);
-
- when(artifactFactory.clone(proxiedObject)).thenReturn(copy);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetProxiedObject() {
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, handler);
-
- Assert.assertNotNull(proxy);
- Assert.assertTrue(Proxy.isProxyClass(proxy.getClass()));
- Assert.assertTrue(proxy instanceof HasProxiedObject);
- ProxyWriteable<ArtifactReadable> proxied = (ProxyWriteable<ArtifactReadable>) proxy;
- Assert.assertEquals(proxiedObject, proxied.getProxiedObject());
- Assert.assertEquals(proxiedObject, proxied.getOriginalObject());
- }
-
- @Test
- public void testMethodInvocation() throws Exception {
- InvocationHandler spy = Mockito.spy(handler);
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, spy);
-
- Set<String> readMethods = new HashSet<String>();
- for (Method method : ArtifactReadable.class.getMethods()) {
- readMethods.add(method.getName());
- }
- for (Method method : Object.class.getMethods()) {
- readMethods.add(method.getName());
- }
-
- boolean copied = false;
-
- for (Method method : proxy.getClass().getMethods()) {
- Artifact object;
- if (!copied && readMethods.contains(method.getName())) {
- object = proxiedObject;
- } else {
- object = copy;
- copied = true;
- }
- ProxyTestHelper.checkNoneStaticMethodForwarding(method, proxy, object, spy);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCopyOnWrite() throws OseeCoreException {
- ArtifactWriteableInvocationHandler spy = Mockito.spy(handler);
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, spy);
-
- ProxyWriteable<Artifact> proxied = (ProxyWriteable<Artifact>) proxy;
- Assert.assertEquals(proxiedObject, proxied.getProxiedObject());
- Assert.assertEquals(proxiedObject, proxied.getOriginalObject());
-
- Assert.assertTrue(spy.isCopyRequired());
- proxy.createAttribute(null);
-
- Assert.assertFalse(spy.isCopyRequired());
- Assert.assertTrue(spy.isWriteAllowed());
-
- verify(spy).createCopyForWrite(proxiedObject);
-
- Assert.assertEquals(copy, proxied.getProxiedObject());
- Assert.assertEquals(proxiedObject, proxied.getOriginalObject());
-
- reset(spy);
-
- proxy.createAttribute(CoreAttributeTypes.Name);
- Assert.assertTrue(spy.isWriteAllowed());
- verify(spy, times(0)).createCopyForWrite(proxiedObject);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testGetAttributes() throws OseeCoreException {
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, handler);
-
- AttributeReadable<Object> r1 = Mockito.mock(AttributeReadable.class);
- AttributeReadable<Object> r2 = Mockito.mock(AttributeReadable.class);
-
- Attribute<Object> attr1 = Mockito.mock(Attribute.class);
- Attribute<Object> attr2 = Mockito.mock(Attribute.class);
-
- List<Attribute<Object>> list = new ArrayList<Attribute<Object>>();
- list.add(attr1);
- list.add(attr2);
-
- when(proxiedObject.getAttributes()).thenAnswer(new AttributesAnswer(list));
- when(attributeProxyFactory.createReadable(attr1)).thenReturn(r1);
- when(attributeProxyFactory.createReadable(attr2)).thenReturn(r2);
-
- List<AttributeReadable<Object>> proxiedList = proxy.getAttributes();
- Assert.assertEquals(list.size(), proxiedList.size());
-
- Iterator<AttributeReadable<Object>> iterator = proxiedList.iterator();
- Assert.assertEquals(r1, iterator.next());
- Assert.assertEquals(r2, iterator.next());
- }
-
- @SuppressWarnings({"unchecked"})
- @Test
- public void testGetAttributesByType() throws OseeCoreException {
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, handler);
-
- AttributeReadable<String> r1 = Mockito.mock(AttributeReadable.class);
- Attribute<String> attr1 = Mockito.mock(Attribute.class);
-
- List<Attribute<String>> list = new ArrayList<Attribute<String>>();
- list.add(attr1);
-
- when(proxiedObject.getAttributes(CoreAttributeTypes.Name)).thenAnswer(new StringAttributesAnswer(list));
- when(attributeProxyFactory.createReadable(attr1)).thenReturn(r1);
-
- List<AttributeReadable<String>> proxiedList = proxy.getAttributes(CoreAttributeTypes.Name);
- Assert.assertEquals(list.size(), proxiedList.size());
-
- Iterator<AttributeReadable<String>> iterator = proxiedList.iterator();
- Assert.assertEquals(r1, iterator.next());
- }
-
- @SuppressWarnings({"unchecked"})
- @Test
- public void testGetWriteableAttributes() throws OseeCoreException {
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, handler);
-
- AttributeWriteable<Object> r1 = Mockito.mock(AttributeWriteable.class);
- AttributeWriteable<Object> r2 = Mockito.mock(AttributeWriteable.class);
-
- Attribute<Object> attr1 = Mockito.mock(Attribute.class);
- Attribute<Object> attr2 = Mockito.mock(Attribute.class);
-
- List<Attribute<Object>> list = new ArrayList<Attribute<Object>>();
- list.add(attr1);
- list.add(attr2);
-
- when(copy.getWriteableAttributes()).thenAnswer(new AttributesAnswer(list));
- when(attributeProxyFactory.createWriteable(attr1)).thenReturn(r1);
- when(attributeProxyFactory.createWriteable(attr2)).thenReturn(r2);
-
- List<AttributeWriteable<Object>> proxiedList = proxy.getWriteableAttributes();
- Assert.assertEquals(list.size(), proxiedList.size());
-
- Iterator<AttributeWriteable<Object>> iterator = proxiedList.iterator();
- Assert.assertEquals(r1, iterator.next());
- Assert.assertEquals(r2, iterator.next());
- }
-
- @SuppressWarnings({"unchecked"})
- @Test
- public void testGetWriteableAttributesByType() throws OseeCoreException {
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, handler);
-
- AttributeWriteable<String> r1 = Mockito.mock(AttributeWriteable.class);
- Attribute<String> attr1 = Mockito.mock(Attribute.class);
-
- List<Attribute<String>> list = new ArrayList<Attribute<String>>();
- list.add(attr1);
-
- when(copy.getWriteableAttributes(CoreAttributeTypes.Name)).thenAnswer(new StringAttributesAnswer(list));
- when(attributeProxyFactory.createWriteable(attr1)).thenReturn(r1);
-
- List<AttributeWriteable<String>> proxiedList = proxy.getWriteableAttributes(CoreAttributeTypes.Name);
- Assert.assertEquals(list.size(), proxiedList.size());
-
- Iterator<AttributeWriteable<String>> iterator = proxiedList.iterator();
- Assert.assertEquals(r1, iterator.next());
- }
-
- private static final class AttributesAnswer implements Answer<List<Attribute<Object>>> {
-
- private final List<Attribute<Object>> list;
-
- public AttributesAnswer(List<Attribute<Object>> list) {
- this.list = list;
- }
-
- @Override
- public List<Attribute<Object>> answer(InvocationOnMock invocation) throws Throwable {
- return list;
- }
-
- }
-
- private static final class StringAttributesAnswer implements Answer<List<Attribute<String>>> {
-
- private final List<Attribute<String>> list;
-
- public StringAttributesAnswer(List<Attribute<String>> list) {
- this.list = list;
- }
-
- @Override
- public List<Attribute<String>> answer(InvocationOnMock invocation) throws Throwable {
- return list;
- }
-
- }
-
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyInvocationHandlerTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyInvocationHandlerTestSuite.java
deleted file mode 100644
index ddd563bdd3..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyInvocationHandlerTestSuite.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.proxy.handler;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * @author Roberto E. Escobar
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- ArtifactWriteableInvocationHandlerTest.class,
- ReadableInvocationHandlerTest.class,
- WriteableInvocationHandlerTest.class})
-public class ProxyInvocationHandlerTestSuite {
- // Test Suite
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyTestHelper.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyTestHelper.java
deleted file mode 100644
index 366f570d77..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ProxyTestHelper.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.proxy.handler;
-
-import static org.mockito.Mockito.verify;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import org.junit.Assert;
-import org.eclipse.osee.framework.jdk.core.util.Lib;
-import org.mockito.Mockito;
-
-/**
- * @author Roberto E. Escobar
- */
-public final class ProxyTestHelper {
-
- private final static Map<Class<?>, Object> defaultValues = new HashMap<Class<?>, Object>();
- private final static Collection<String> skipObjectMethods = getObjectMethods();
- static {
- defaultValues.put(String.class, "hello");
-
- defaultValues.put(Integer.class, 0);
- defaultValues.put(int.class, 0);
-
- defaultValues.put(Long.class, 0L);
- defaultValues.put(long.class, 0L);
-
- defaultValues.put(Character.class, '\0');
- defaultValues.put(char.class, '\0');
-
- defaultValues.put(Boolean.class, true);
- defaultValues.put(boolean.class, true);
-
- defaultValues.put(Float.class, 12314.02);
- defaultValues.put(float.class, 12314.02);
- }
-
- private static Collection<String> getObjectMethods() {
- Collection<String> skip = new HashSet<String>();
- for (Method method : Object.class.getMethods()) {
- skip.add(method.getName());
- }
- return skip;
- }
-
- private static Method getMethod(Object object, String name, Class<?>... paramTypes) {
- Method method = null;
- try {
- method = object.getClass().getMethod(name, paramTypes);
- } catch (Exception ex) {
- // Do Nothing;
- }
- return method;
- }
-
- public static <T> void checkNoneStaticMethodForwarding(Method method, T proxy, T proxiedObject, Object handler) {
- int modifiers = method.getModifiers();
-
- if (!Modifier.isStatic(modifiers) && !skipObjectMethods.contains(method.getName())) {
- Mockito.reset(handler);
- try {
- verifyMethodForwarding(method, proxy, proxiedObject, handler);
- } catch (Exception ex) {
- Assert.fail(String.format("Error on [%s]: [%s]\n", method.getName(), Lib.exceptionToString(ex)));
- }
- }
- }
-
- private static <T> void verifyMethodForwarding(Method method, T proxy, T proxiedObject, Object handler) throws Exception {
- Class<?>[] paramTypes = method.getParameterTypes();
- Object[] params = new Object[paramTypes.length];
- for (int index = 0; index < paramTypes.length; index++) {
- Class<?> type = paramTypes[index];
- params[index] = defaultValues.get(type);
- }
-
- method.invoke(proxy, params);
-
- Method methodOnMock = getMethod(proxiedObject, method.getName(), paramTypes);
-
- if (methodOnMock != null) {
- methodOnMock.invoke(verify(proxiedObject), params);
- } else {
- Method methodOnHandler = getMethod(handler, method.getName(), paramTypes);
- Assert.assertNotNull(methodOnHandler);
- methodOnHandler.invoke(verify(handler), params);
- }
- }
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ReadableInvocationHandlerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ReadableInvocationHandlerTest.java
deleted file mode 100644
index d700840057..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/ReadableInvocationHandlerTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.proxy.handler;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import org.junit.Assert;
-import org.eclipse.osee.orcs.core.internal.proxy.HasProxiedObject;
-import org.eclipse.osee.orcs.core.internal.proxy.ProxyUtil;
-import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-/**
- * Test Case for {@link ReadableInvocationHandler}
- *
- * @author Roberto E. Escobar
- */
-public class ReadableInvocationHandlerTest {
-
- //@formatter:off
- @Mock private ArtifactReadable proxiedObject;
- //@formatter:on
-
- private ReadableInvocationHandler<ArtifactReadable> handler;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
-
- handler = new ReadableInvocationHandler<ArtifactReadable>(proxiedObject);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetProxiedObject() {
- ArtifactReadable proxy = ProxyUtil.create(ArtifactReadable.class, handler);
-
- Assert.assertNotNull(proxy);
- Assert.assertTrue(Proxy.isProxyClass(proxy.getClass()));
- Assert.assertTrue(proxy instanceof HasProxiedObject);
- HasProxiedObject<ArtifactReadable> proxied = (HasProxiedObject<ArtifactReadable>) proxy;
- Assert.assertEquals(proxiedObject, proxied.getProxiedObject());
- }
-
- @Test
- public void testMethodInvocation() throws Exception {
- InvocationHandler spy = Mockito.spy(handler);
- ArtifactReadable proxy = ProxyUtil.create(ArtifactReadable.class, spy);
-
- for (Method method : proxy.getClass().getMethods()) {
- ProxyTestHelper.checkNoneStaticMethodForwarding(method, proxy, proxiedObject, spy);
- }
- }
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/WriteableInvocationHandlerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/WriteableInvocationHandlerTest.java
deleted file mode 100644
index a3bb6e0142..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/handler/WriteableInvocationHandlerTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.proxy.handler;
-
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import org.junit.Assert;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.orcs.core.internal.proxy.HasProxiedObject;
-import org.eclipse.osee.orcs.core.internal.proxy.ProxyUtil;
-import org.eclipse.osee.orcs.core.internal.proxy.ProxyWriteable;
-import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.eclipse.osee.orcs.data.ArtifactWriteable;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-/**
- * Test Case for {@link WriteableInvocationHandler}
- *
- * @author Roberto E. Escobar
- */
-public class WriteableInvocationHandlerTest {
-
- @Mock
- private ArtifactWriteable proxiedObject;
-
- private WriteableInvocationHandler<ArtifactWriteable> handler;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
-
- handler = new WriteableInvocationHandler<ArtifactWriteable>(proxiedObject);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testGetProxiedObject() {
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, handler);
-
- Assert.assertNotNull(proxy);
- Assert.assertTrue(Proxy.isProxyClass(proxy.getClass()));
- Assert.assertTrue(proxy instanceof HasProxiedObject);
- ProxyWriteable<ArtifactReadable> proxied = (ProxyWriteable<ArtifactReadable>) proxy;
- Assert.assertEquals(proxiedObject, proxied.getProxiedObject());
- Assert.assertEquals(proxiedObject, proxied.getOriginalObject());
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCopyOnWrite() throws OseeCoreException {
- WriteableInvocationHandler<ArtifactWriteable> spy = Mockito.spy(handler);
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, spy);
-
- ProxyWriteable<ArtifactReadable> proxied = (ProxyWriteable<ArtifactReadable>) proxy;
- Assert.assertEquals(proxiedObject, proxied.getProxiedObject());
- Assert.assertEquals(proxiedObject, proxied.getOriginalObject());
-
- Assert.assertTrue(spy.isCopyRequired());
- proxy.createAttribute(null);
-
- Assert.assertFalse(spy.isCopyRequired());
- Assert.assertTrue(spy.isWriteAllowed());
- verify(spy).createCopyForWrite(proxiedObject);
-
- reset(spy);
-
- proxy.createAttribute(null);
- Assert.assertTrue(spy.isWriteAllowed());
- verify(spy, times(0)).createCopyForWrite(proxiedObject);
- }
-
- @Test
- public void testMethodInvocation() throws Exception {
- InvocationHandler spy = Mockito.spy(handler);
- ArtifactWriteable proxy = ProxyUtil.create(ArtifactWriteable.class, spy);
-
- for (Method method : proxy.getClass().getMethods()) {
- ProxyTestHelper.checkNoneStaticMethodForwarding(method, proxy, proxiedObject, spy);
- }
- }
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ExternalArtifactManagerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ExternalArtifactManagerTest.java
new file mode 100644
index 0000000000..23f9c0f575
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ExternalArtifactManagerTest.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.proxy.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.osee.framework.core.data.ResultSet;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
+import org.eclipse.osee.orcs.core.internal.artifact.ArtifactImpl;
+import org.eclipse.osee.orcs.core.internal.proxy.ExternalArtifactManager;
+import org.eclipse.osee.orcs.core.internal.relation.RelationNode;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mock;
+
+/**
+ * @author Megumi Telles
+ */
+public class ExternalArtifactManagerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ // @formatter:off
+ @Mock private OrcsSession session;
+
+ @Mock private ArtifactReadOnlyImpl readable;
+ @Mock private ArtifactReadOnlyImpl readable1;
+ @Mock private ArtifactReadOnlyImpl readable2;
+ @Mock private ArtifactReadOnlyImpl readable3;
+
+ @Mock private ArtifactImpl artifact1;
+ @Mock private ArtifactImpl artifact2;
+ @Mock private ArtifactImpl artifact3;
+ // @formatter:on
+
+ private ExternalArtifactManager proxyManager;
+ private List<? extends Artifact> artifacts;
+ private List<? extends ArtifactReadable> readables;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+
+ artifacts = Arrays.asList(artifact1, artifact2, artifact3);
+ readables = Arrays.asList(readable1, readable2, readable3);
+
+ String sessionId = GUID.create();
+ when(session.getGuid()).thenReturn(sessionId);
+ proxyManager = new ExternalArtifactManagerImpl();
+ when(readable.getProxiedObject()).thenReturn(artifact1);
+ }
+
+ @Test
+ public void testAsArtifacts() throws OseeCoreException {
+ ResultSet<? extends RelationNode> arts1 = proxyManager.asInternalArtifacts(readables);
+ assertFalse(arts1.isEmpty());
+ assertEquals(3, arts1.size());
+ }
+
+ @Test
+ public void testAsReadables() throws OseeCoreException {
+ ResultSet<ArtifactReadable> asReadables = proxyManager.asExternalArtifacts(session, artifacts);
+ assertFalse(asReadables.isEmpty());
+ assertEquals(3, asReadables.size());
+ }
+
+ @Test
+ public void testAsWriteable() throws OseeCoreException {
+ ArtifactReadable readable = proxyManager.asExternalArtifact(session, artifact1);
+ assertNotNull(readable);
+ assertNotNull(proxyManager.asInternalArtifact(readable));
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyDataTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/CollectDirtyDataTest.java
index 3321eb8353..47bef4e7ef 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/CollectDirtyDataTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/CollectDirtyDataTest.java
@@ -8,7 +8,7 @@
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.transaction.handler;
+package org.eclipse.osee.orcs.core.internal.transaction;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionImplTest.java
deleted file mode 100644
index 591031356c..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/OrcsTransactionImplTest.java
+++ /dev/null
@@ -1,340 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.transaction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.Callable;
-import org.eclipse.osee.framework.core.data.IArtifactToken;
-import org.eclipse.osee.framework.core.data.IArtifactType;
-import org.eclipse.osee.framework.core.data.IAttributeType;
-import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.model.TransactionRecord;
-import org.eclipse.osee.framework.core.model.type.AttributeType;
-import org.eclipse.osee.framework.jdk.core.util.GUID;
-import org.eclipse.osee.logger.Log;
-import org.eclipse.osee.orcs.OrcsSession;
-import org.eclipse.osee.orcs.core.ds.ArtifactTransactionData;
-import org.eclipse.osee.orcs.core.ds.TransactionData;
-import org.eclipse.osee.orcs.core.ds.TransactionResult;
-import org.eclipse.osee.orcs.core.ds.TxDataStore;
-import org.eclipse.osee.orcs.core.internal.proxy.ArtifactProxyFactory;
-import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.eclipse.osee.orcs.data.ArtifactWriteable;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-/**
- * Test Case for {@link OrcsTransactionImpl}
- *
- * @author John Misinco
- */
-public class OrcsTransactionImplTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- // @formatter:off
- @Mock private Log logger;
- @Mock private OrcsSession session;
- @Mock private TxDataStore dataStore;
- @Mock private ArtifactProxyFactory artifactFactory;
- @Mock private TxDataManager txManager;
- @Mock private IOseeBranch branch;
- @Mock private ArtifactWriteable expected;
-
- @Mock private ArtifactReadable author;
- @Captor ArgumentCaptor<TransactionData> txData;
- // @formatter:on
-
- private OrcsTransactionImpl tx;
- private String guid;
- private final IArtifactType artType = CoreArtifactTypes.Artifact;
- private String sessionId;
-
- @Before
- public void init() {
- MockitoAnnotations.initMocks(this);
- tx = new OrcsTransactionImpl(logger, session, dataStore, artifactFactory, txManager, branch);
-
- sessionId = GUID.create();
- guid = GUID.create();
- when(expected.getGuid()).thenReturn(guid);
- when(session.getGuid()).thenReturn(sessionId);
- }
-
- @Test
- public void testSetGetAuthor() {
- tx.setAuthor(author);
- assertEquals(author, tx.getAuthor());
- }
-
- @Test
- public void testSetGetComment() {
- String comment = "This is my comment";
- tx.setComment(comment);
- assertEquals(comment, tx.getComment());
- }
-
- @Test
- public void testAsWriteable() throws OseeCoreException {
- ArtifactReadable source = mock(ArtifactReadable.class);
- when(txManager.getOrAddWrite(source)).thenReturn(expected);
-
- ArtifactWriteable actual = tx.asWriteable(source);
-
- assertEquals(actual, expected);
- verify(txManager).getOrAddWrite(source);
- }
-
- @Test
- public void testAsWriteableList() throws OseeCoreException {
- ArtifactReadable sourceA = mock(ArtifactReadable.class);
- ArtifactReadable sourceB = mock(ArtifactReadable.class);
-
- ArtifactWriteable expectedA = mock(ArtifactWriteable.class);
- ArtifactWriteable expectedB = mock(ArtifactWriteable.class);
- when(txManager.getOrAddWrite(sourceA)).thenReturn(expectedA);
- when(txManager.getOrAddWrite(sourceB)).thenReturn(expectedB);
-
- List<ArtifactReadable> readables = Arrays.asList(sourceA, sourceB);
-
- List<ArtifactWriteable> actuals = tx.asWriteable(readables);
-
- assertEquals(readables.size(), actuals.size());
- verify(txManager).getOrAddWrite(sourceA);
- verify(txManager).getOrAddWrite(sourceB);
-
- Iterator<ArtifactWriteable> iterator = actuals.iterator();
- assertEquals(expectedA, iterator.next());
- assertEquals(expectedB, iterator.next());
- }
-
- @Test
- public void testCreateArtifactFromToken() throws OseeCoreException {
- IArtifactToken token = mock(IArtifactToken.class);
- String name = "testCreateArtifactFromToken";
-
- when(token.getName()).thenReturn(name);
- when(token.getArtifactType()).thenReturn(artType);
-
- when(token.getGuid()).thenReturn(guid);
- when(artifactFactory.create(branch, artType, guid, name)).thenReturn(expected);
-
- ArtifactWriteable artifact = tx.createArtifact(token);
-
- assertNotNull(artifact);
- verify(artifactFactory).create(branch, artType, guid, name);
- verify(txManager).addWrite(artifact);
- }
-
- @Test
- public void testCreateArtifactTypeAndName() throws OseeCoreException {
- String name = "testCreateArtifact";
- when(artifactFactory.create(branch, artType, null, name)).thenReturn(expected);
-
- ArtifactWriteable artifact = tx.createArtifact(artType, name);
-
- assertNotNull(artifact);
- verify(artifactFactory).create(branch, artType, null, name);
- verify(txManager).addWrite(artifact);
- }
-
- @Test
- public void testCreateArtifactTypeNameGuid() throws OseeCoreException {
- String name = "testCreateArtifact";
- when(artifactFactory.create(branch, artType, guid, name)).thenReturn(expected);
-
- ArtifactWriteable artifact = tx.createArtifact(artType, name, guid);
-
- assertNotNull(artifact);
- verify(artifactFactory).create(branch, artType, guid, name);
- verify(txManager).addWrite(artifact);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testDuplicateArtifact() throws OseeCoreException {
- ArtifactReadable source = mock(ArtifactReadable.class);
- final Collection<AttributeType> types = mock(Collection.class);
- when(source.getGuid()).thenReturn(guid);
- when(source.getExistingAttributeTypes()).thenAnswer(new Answer<Collection<? extends IAttributeType>>() {
-
- @Override
- public Collection<? extends IAttributeType> answer(InvocationOnMock invocation) throws Throwable {
- return types;
- }
- });
- when(artifactFactory.copy(source, types, branch)).thenReturn(expected);
-
- ArtifactWriteable actual = tx.duplicateArtifact(source);
-
- assertTrue(actual != source);
- verify(artifactFactory).copy(source, types, branch);
- verify(txManager).addWrite(actual);
- }
-
- @Test
- public void testIntroduceArtifact() throws OseeCoreException {
- ArtifactReadable source = mock(ArtifactReadable.class);
- when(artifactFactory.introduce(source, branch)).thenReturn(expected);
-
- ArtifactWriteable actual = tx.introduceArtifact(source);
-
- assertTrue(actual != source);
- verify(artifactFactory).introduce(source, branch);
- verify(txManager).addWrite(actual);
- }
-
- @Test
- public void testCommitTwiceWhileInProgress() throws Exception {
- OrcsTransactionImpl spy = Mockito.spy(tx);
-
- when(spy.isCommitInProgress()).thenReturn(true);
-
- thrown.expect(OseeCoreException.class);
- thrown.expectMessage("Commit is already in progress");
- spy.commit();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCommitErrorDuringExecution() throws Exception {
- final Callable<TransactionResult> callable = mock(Callable.class);
- when(dataStore.commitTransaction(eq(session), any(TransactionData.class))).thenAnswer(
- new Answer<Callable<TransactionResult>>() {
-
- @Override
- public Callable<TransactionResult> answer(InvocationOnMock invocation) throws Throwable {
- Assert.assertTrue(tx.isCommitInProgress());
- return callable;
- }
- });
-
- OseeCoreException exception = new OseeCoreException("Execution error");
- when(callable.call()).thenThrow(exception);
-
- assertFalse(tx.isCommitInProgress());
-
- thrown.expect(OseeCoreException.class);
- thrown.expectMessage(exception.getMessage());
- tx.commit();
-
- verify(txManager).onCommitStart();
- verify(txManager).getChanges();
- verify(txManager).onCommitRollback();
- verify(txManager).onCommitEnd();
-
- assertFalse(tx.isCommitInProgress());
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCommitErrorDuringRollback() throws Exception {
- final Callable<TransactionResult> callable = mock(Callable.class);
- when(dataStore.commitTransaction(eq(session), any(TransactionData.class))).thenAnswer(
- new Answer<Callable<TransactionResult>>() {
-
- @Override
- public Callable<TransactionResult> answer(InvocationOnMock invocation) throws Throwable {
- Assert.assertTrue(tx.isCommitInProgress());
- return callable;
- }
- });
-
- OseeCoreException exception = new OseeCoreException("Execution error");
- doThrow(exception).when(txManager).onCommitRollback();
-
- assertFalse(tx.isCommitInProgress());
-
- thrown.expect(OseeCoreException.class);
- thrown.expectMessage("Exception during rollback and commit");
- tx.commit();
-
- verify(txManager).onCommitStart();
- verify(txManager).getChanges();
- verify(txManager).onCommitRollback();
- verify(txManager).onCommitEnd();
-
- assertFalse(tx.isCommitInProgress());
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCommit() throws Exception {
- final Callable<TransactionResult> callable = mock(Callable.class);
- List<ArtifactTransactionData> changes = Mockito.mock(ArrayList.class);
-
- tx.setAuthor(author);
- tx.setComment("My Comment");
-
- when(txManager.getChanges()).thenReturn(changes);
- when(dataStore.commitTransaction(eq(session), txData.capture())).thenAnswer(
- new Answer<Callable<TransactionResult>>() {
-
- @Override
- public Callable<TransactionResult> answer(InvocationOnMock invocation) throws Throwable {
- Assert.assertTrue(tx.isCommitInProgress());
- return callable;
- }
- });
- TransactionResult txResult = mock(TransactionResult.class);
- TransactionRecord newTx = mock(TransactionRecord.class);
-
- when(callable.call()).thenReturn(txResult);
- when(txResult.getTransaction()).thenReturn(newTx);
-
- Assert.assertFalse(tx.isCommitInProgress());
-
- TransactionRecord actual = tx.commit();
-
- assertEquals(newTx, actual);
-
- verify(txManager).onCommitStart();
- verify(txManager).getChanges();
- verify(txManager).onCommitSuccess(txResult);
- verify(txManager).onCommitEnd();
-
- Assert.assertFalse(tx.isCommitInProgress());
-
- TransactionData data = txData.getValue();
- assertEquals(branch, data.getBranch());
- assertEquals(author, data.getAuthor());
- assertEquals("My Comment", data.getComment());
- assertEquals(changes, data.getTxData());
-
- }
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionBuilderImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionBuilderImplTest.java
new file mode 100644
index 0000000000..081cafa4be
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionBuilderImplTest.java
@@ -0,0 +1,361 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.transaction;
+
+import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.HardwareRequirement;
+import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.SoftwareRequirement;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Active;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Annotation;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Company;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.FavoriteBranch;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Name;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.PlainTextContent;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.QualificationMethod;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.RelationOrder;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.WordTemplateContent;
+import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import org.eclipse.osee.executor.admin.CancellableCallable;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
+import org.eclipse.osee.orcs.core.internal.attribute.Attribute;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.data.AttributeReadable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+/**
+ * Test Case for {@link TransactionFactoryImpl}
+ *
+ * @author Roberto E. Escobar
+ */
+public class TransactionBuilderImplTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ // @formatter:off
+ @Mock private Log logger;
+ @Mock private OrcsSession session;
+ @Mock private TxDataManager txDataManager;
+ @Mock private TxCallableFactory txCallableFactory;
+
+
+ @Mock private ArtifactReadable expectedAuthor;
+ @Mock private ArtifactReadable node1;
+ @Mock private ArtifactReadable node2;
+ @Mock private Artifact artifact;
+ @SuppressWarnings("rawtypes")
+ @Mock private AttributeReadable attrId;
+ @SuppressWarnings("rawtypes")
+ @Mock private Attribute attribute;
+
+ @Mock private TxData txData;
+ // @formatter:on
+
+ private final IOseeBranch expectedBranch = CoreBranches.COMMON;
+ private TransactionBuilderImpl factory;
+ private String guid;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() throws OseeCoreException {
+ initMocks(this);
+ guid = GUID.create();
+ factory = new TransactionBuilderImpl(txCallableFactory, txDataManager, txData);
+
+ when(txDataManager.getForWrite(txData, expectedAuthor)).thenReturn(artifact);
+ when(artifact.getAttributeById(attrId)).thenReturn(attribute);
+ }
+
+ @Test
+ public void testGetBranch() {
+ when(factory.getBranch()).thenReturn(expectedBranch);
+
+ IOseeBranch branch = factory.getBranch();
+
+ assertEquals(expectedBranch, branch);
+ verify(txData).getBranch();
+ }
+
+ @Test
+ public void testGetAuthor() {
+ when(factory.getAuthor()).thenReturn(expectedAuthor);
+
+ ArtifactReadable author = factory.getAuthor();
+
+ assertEquals(expectedAuthor, author);
+ verify(txData).getAuthor();
+ }
+
+ @Test
+ public void testGetComment() {
+ when(factory.getComment()).thenReturn("This is a comment");
+
+ String comment = factory.getComment();
+
+ assertEquals(comment, "This is a comment");
+ verify(txData).getComment();
+ }
+
+ public void testSetAuthor() throws OseeCoreException {
+ factory.setAuthor(expectedAuthor);
+
+ verify(txDataManager).setAuthor(txData, expectedAuthor);
+ }
+
+ @Test
+ public void testCreateArtifact() throws OseeCoreException {
+ factory.createArtifact(SoftwareRequirement, "Software Requirement");
+
+ verify(txDataManager).createArtifact(txData, SoftwareRequirement, "Software Requirement", null);
+ }
+
+ @Test
+ public void testCreateArtifactWithGuid() throws OseeCoreException {
+ factory.createArtifact(HardwareRequirement, "Hardware Requirement", guid);
+
+ verify(txDataManager).createArtifact(txData, HardwareRequirement, "Hardware Requirement", guid);
+ }
+
+ @Test
+ public void testCopyArtifact() throws OseeCoreException {
+ when(expectedAuthor.getBranch()).thenReturn(expectedBranch);
+
+ factory.copyArtifact(expectedAuthor);
+
+ verify(txDataManager).copyArtifact(txData, expectedBranch, expectedAuthor);
+ }
+
+ @Test
+ public void testCopyArtifactWithList() throws OseeCoreException {
+ Collection<? extends IAttributeType> attributesToDuplicate = Arrays.asList(Name, Annotation);
+ when(expectedAuthor.getBranch()).thenReturn(expectedBranch);
+
+ factory.copyArtifact(expectedAuthor, attributesToDuplicate);
+
+ verify(txDataManager).copyArtifact(txData, expectedBranch, expectedAuthor, attributesToDuplicate);
+ }
+
+ @Test
+ public void testIntroduceArtifact() throws OseeCoreException {
+ when(expectedAuthor.getBranch()).thenReturn(expectedBranch);
+
+ factory.introduceArtifact(expectedAuthor);
+
+ verify(txDataManager).introduceArtifact(txData, expectedBranch, expectedAuthor);
+ }
+
+ @Test
+ public void testCreateAttribute() throws OseeCoreException {
+ factory.createAttribute(expectedAuthor, QualificationMethod);
+
+ verify(artifact).createAttribute(QualificationMethod);
+ }
+
+ @Test
+ public void testCreateAttributeWithValue() throws OseeCoreException {
+ factory.createAttribute(expectedAuthor, QualificationMethod, "Demonstration");
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).createAttribute(QualificationMethod, "Demonstration");
+ }
+
+ @Test
+ public void testCreateAttributeFromString() throws OseeCoreException {
+ factory.createAttributeFromString(expectedAuthor, WordTemplateContent, "This is my word template content");
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).createAttributeFromString(CoreAttributeTypes.WordTemplateContent,
+ "This is my word template content");
+ }
+
+ @Test
+ public void testSetSoleAttributeValue() throws OseeCoreException {
+ factory.setSoleAttributeValue(expectedAuthor, RelationOrder, LEXICOGRAPHICAL_DESC);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setSoleAttributeValue(RelationOrder, LEXICOGRAPHICAL_DESC);
+ }
+
+ @Test
+ public void testSetSoleAttributeFromStream() throws OseeCoreException {
+ InputStream inputStream = Mockito.mock(InputStream.class);
+
+ factory.setSoleAttributeFromStream(expectedAuthor, Company, inputStream);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setSoleAttributeFromStream(Company, inputStream);
+ }
+
+ @Test
+ public void testSetSoleAttributeFromString() throws OseeCoreException {
+ factory.setSoleAttributeFromString(expectedAuthor, Name, "Name");
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setSoleAttributeFromString(Name, "Name");
+ }
+
+ @Test
+ public void testSetAttributesFromValues() throws OseeCoreException {
+ factory.setAttributesFromValues(expectedAuthor, PlainTextContent, Arrays.asList(true, true, false));
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setAttributesFromValues(PlainTextContent, Arrays.asList(true, true, false));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testSetAttributesFromValuesList() throws OseeCoreException {
+ factory.setAttributesFromValues(expectedAuthor, CoreAttributeTypes.StaticId, Collections.EMPTY_LIST);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setAttributesFromValues(CoreAttributeTypes.StaticId, Collections.EMPTY_LIST);
+ }
+
+ @Test
+ public void testSetAttributesFromStrings() throws OseeCoreException {
+ factory.setAttributesFromStrings(expectedAuthor, PlainTextContent, Arrays.asList("one", "two", "three"));
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setAttributesFromStrings(PlainTextContent, Arrays.asList("one", "two", "three"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testSetAttributesFromStringList() throws OseeCoreException {
+ factory.setAttributesFromStrings(expectedAuthor, PlainTextContent, Collections.EMPTY_LIST);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).setAttributesFromStrings(PlainTextContent, Collections.EMPTY_LIST);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testSetAttributeByIdFromValue() throws OseeCoreException {
+ factory.setAttributeById(expectedAuthor, attrId, false);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(attribute).setValue(false);
+ }
+
+ @Test
+ public void testSetAttributeByIdFromString() throws OseeCoreException {
+ factory.setAttributeById(expectedAuthor, attrId, "value");
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(attribute).setFromString("value");
+ }
+
+ @Test
+ public void TestSetAttributeById() throws OseeCoreException {
+ InputStream inputStream = Mockito.mock(InputStream.class);
+
+ factory.setAttributeById(expectedAuthor, attrId, inputStream);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(attribute).setValueFromInputStream(inputStream);
+ }
+
+ @Test
+ public void testDeleteByAttributeId() throws OseeCoreException {
+ factory.deleteByAttributeId(expectedAuthor, attrId);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(attribute).delete();
+ }
+
+ @Test
+ public void testDeleteSoleAttribute() throws OseeCoreException {
+ factory.deleteSoleAttribute(expectedAuthor, Name);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).deleteSoleAttribute(Name);
+ }
+
+ @Test
+ public void testDeleteAttributes() throws OseeCoreException {
+ factory.deleteAttributes(expectedAuthor, FavoriteBranch);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).deleteAttributes(FavoriteBranch);
+ }
+
+ @Test
+ public void testDeleteAttributesWithValue() throws OseeCoreException {
+ factory.deleteAttributesWithValue(expectedAuthor, Active, true);
+
+ verify(txDataManager).getForWrite(txData, expectedAuthor);
+ verify(artifact).deleteAttributesWithValue(Active, true);
+ }
+
+ @Test
+ public void testDeleteArtifact() throws OseeCoreException {
+ factory.deleteArtifact(expectedAuthor);
+
+ verify(txDataManager).deleteArtifact(txData, expectedAuthor);
+ }
+
+ @Test
+ public void testIsCommitInProgress() {
+ when(factory.isCommitInProgress()).thenReturn(false);
+
+ boolean condition = factory.isCommitInProgress();
+
+ assertFalse(condition);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCommit() throws Exception {
+ CancellableCallable<TransactionRecord> callable = mock(CancellableCallable.class);
+ TransactionRecord tx = mock(TransactionRecord.class);
+
+ when(txCallableFactory.createTx(txData)).thenReturn(callable);
+ when(callable.call()).thenReturn(tx);
+
+ factory.commit();
+ verify(txCallableFactory).createTx(txData);
+ }
+
+ @Test
+ public void testCommitException() throws OseeCoreException {
+ Exception exception = new IllegalStateException("onCommit Exception");
+
+ doThrow(exception).when(txCallableFactory).createTx(txData);
+
+ thrown.expect(Exception.class);
+ factory.commit();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java
index abe6b7c4ca..6692971645 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImplTest.java
@@ -10,24 +10,23 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.transaction;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
-import org.eclipse.osee.orcs.core.ds.TxDataStore;
-import org.eclipse.osee.orcs.core.internal.proxy.ArtifactProxyFactory;
-import org.eclipse.osee.orcs.core.internal.transaction.TxDataManagerImpl.TxDataHandlerFactory;
import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.eclipse.osee.orcs.transaction.OrcsTransaction;
-import org.junit.Assert;
+import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
/**
* Test Case for {@link TransactionFactoryImpl}
@@ -42,10 +41,12 @@ public class TransactionFactoryImplTest {
// @formatter:off
@Mock private Log logger;
@Mock private OrcsSession session;
- @Mock private TxDataStore dataStore;
- @Mock private ArtifactProxyFactory artifactFactory;
- @Mock private TxDataHandlerFactory dataFactory;
+ @Mock private TxDataManager txDataManager;
+ @Mock private TxCallableFactory txCallableFactory;
+
+
@Mock private ArtifactReadable expectedAuthor;
+ @Mock private TxData txData;
// @formatter:on
private final IOseeBranch expectedBranch = CoreBranches.COMMON;
@@ -53,8 +54,9 @@ public class TransactionFactoryImplTest {
@Before
public void init() {
- MockitoAnnotations.initMocks(this);
- factory = new TransactionFactoryImpl(logger, session, dataStore, artifactFactory, dataFactory);
+ initMocks(this);
+ factory = new TransactionFactoryImpl(session, txDataManager, txCallableFactory);
+
}
@Test
@@ -89,10 +91,15 @@ public class TransactionFactoryImplTest {
public void testCreateTransaction() throws OseeCoreException {
String expectedComment = "This is my comment";
- OrcsTransaction tx = factory.createTransaction(expectedBranch, expectedAuthor, expectedComment);
- Assert.assertNotNull(tx);
- Assert.assertEquals(expectedBranch, tx.getBranch());
- Assert.assertEquals(expectedAuthor, tx.getAuthor());
- Assert.assertEquals(expectedComment, tx.getComment());
+ when(txDataManager.createTxData(session, expectedBranch)).thenReturn(txData);
+ when(txData.getAuthor()).thenReturn(expectedAuthor);
+ when(txData.getBranch()).thenReturn(expectedBranch);
+ when(txData.getComment()).thenReturn(expectedComment);
+
+ TransactionBuilder tx = factory.createTransaction(expectedBranch, expectedAuthor, expectedComment);
+ assertNotNull(tx);
+ assertEquals(expectedBranch, tx.getBranch());
+ assertEquals(expectedAuthor, tx.getAuthor());
+ assertEquals(expectedComment, tx.getComment());
}
}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionTestSuite.java
index bff3f112e2..c7b41ef9c6 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionTestSuite.java
@@ -10,16 +10,16 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.transaction;
-import org.eclipse.osee.orcs.core.internal.transaction.handler.HandlerTestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
- HandlerTestSuite.class,
- OrcsTransactionImplTest.class,
+ CollectDirtyDataTest.class,
+ TransactionBuilderImplTest.class,
TransactionFactoryImplTest.class,
- TxDataManagerImplTest.class})
+ TxCallableFactoryTest.class,
+ TxDataManagerTest.class})
public class TransactionTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxCallableFactoryTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxCallableFactoryTest.java
new file mode 100644
index 0000000000..da2aba622c
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxCallableFactoryTest.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+import org.eclipse.osee.executor.admin.CancellableCallable;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.ITransaction;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.core.ds.TransactionData;
+import org.eclipse.osee.orcs.core.ds.TransactionResult;
+import org.eclipse.osee.orcs.core.ds.TxDataStore;
+import org.eclipse.osee.orcs.core.internal.artifact.ArtifactFactory;
+import org.eclipse.osee.orcs.core.internal.proxy.ExternalArtifactManager;
+import org.eclipse.osee.orcs.core.internal.transaction.TxDataManager.TxDataLoader;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Test Case for {@link TxCallableFactory}
+ *
+ * @author Megumi Telles
+ */
+public class TxCallableFactoryTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ // @formatter:off
+ @Mock private OrcsSession session;
+ @Mock private Log logger;
+
+ @Mock private ExternalArtifactManager proxyManager;
+ @Mock private ArtifactFactory artifactFactory;
+ @Mock private TxDataLoader loader;
+
+ @Mock private IOseeBranch branch;
+ @Mock private TxDataStore txDataStore;
+
+ @Mock private ArtifactReadable userArtifact;
+ @Mock private ArtifactReadable groupArtifact;
+
+ @Captor private ArgumentCaptor<TransactionData> txData;
+
+ // @formatter:on
+
+ private TxCallableFactory txFactory;
+ private TxData data;
+ private TxDataManager txManager;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ txManager = new TxDataManager(proxyManager, artifactFactory, loader);
+ txFactory = new TxCallableFactory(logger, txDataStore, txManager);
+ data = new TxData(session, branch);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCreateUnsubscribeTx() throws Exception {
+ CancellableCallable<String> callable = mock(CancellableCallable.class);
+ when(txDataStore.createUnsubscribeTx(userArtifact, groupArtifact)).thenReturn(callable);
+
+ txFactory.createUnsubscribeTx(session, userArtifact, groupArtifact).call();
+
+ verify(txDataStore).createUnsubscribeTx(userArtifact, groupArtifact);
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ @Test
+ public void testpurgeTransactions() throws Exception {
+ Callable callable = mock(Callable.class);
+ Collection<? extends ITransaction> transactions = Collections.emptyList();
+ when(txDataStore.purgeTransactions(session, transactions)).thenReturn(callable);
+
+ txFactory.purgeTransactions(session, transactions).call();
+ verify(txDataStore).purgeTransactions(session, transactions);
+ }
+
+ @Test
+ public void testCommit() throws Exception {
+ final TransactionResult txResult = mock(TransactionResult.class);
+
+ txManager.setAuthor(data, userArtifact);
+ txManager.setComment(data, "My Comment");
+
+ when(txDataStore.commitTransaction(eq(session), txData.capture())).thenReturn(new Callable<TransactionResult>() {
+
+ @Override
+ public TransactionResult call() throws Exception {
+ assertTrue(data.isCommitInProgress());
+ return txResult;
+ }
+ });
+
+ TransactionRecord newTx = mock(TransactionRecord.class);
+
+ when(txResult.getTransaction()).thenReturn(newTx);
+
+ Assert.assertFalse(data.isCommitInProgress());
+
+ TransactionRecord actual = txFactory.createTx(data).call();
+
+ assertEquals(newTx, actual);
+ assertFalse(data.isCommitInProgress());
+
+ TransactionData data = txData.getValue();
+ assertEquals(branch, data.getBranch());
+ assertEquals(userArtifact, data.getAuthor());
+ assertEquals("My Comment", data.getComment());
+ }
+
+ @Test
+ public void testCommitErrorDuringRollback() throws Exception {
+ TxDataManager manager = mock(TxDataManager.class);
+
+ TxCallableFactory factory = new TxCallableFactory(logger, txDataStore, manager);
+
+ Exception exception = new IllegalStateException("onCommit Exception");
+
+ doThrow(exception).when(manager).txCommitSuccess(data);
+ doThrow(OseeCoreException.class).when(manager).rollbackTx(data);
+
+ thrown.expect(OseeCoreException.class);
+ thrown.expectMessage("Exception during rollback and commit");
+ factory.createTx(data).call();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerImplTest.java
deleted file mode 100644
index 48e21cd50c..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerImplTest.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.transaction;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.junit.Assert;
-import org.eclipse.osee.framework.core.exception.OseeArgumentException;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.util.GUID;
-import org.eclipse.osee.orcs.core.ds.ArtifactTransactionData;
-import org.eclipse.osee.orcs.core.ds.OrcsVisitor;
-import org.eclipse.osee.orcs.core.ds.TransactionResult;
-import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
-import org.eclipse.osee.orcs.core.internal.proxy.ArtifactProxyFactory;
-import org.eclipse.osee.orcs.core.internal.proxy.ProxyWriteable;
-import org.eclipse.osee.orcs.core.internal.transaction.TxDataManagerImpl.TxDataHandlerFactory;
-import org.eclipse.osee.orcs.data.ArtifactWriteable;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-/**
- * Test Case for {@link TxDataManagerImpl}
- *
- * @author Roberto E. Escobar
- */
-@SuppressWarnings("rawtypes")
-public class TxDataManagerImplTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- // @formatter:off
- @Mock ArtifactProxyFactory proxyFactory;
- @Mock TxDataHandlerFactory dataFactory;
- @Mock ArtifactWriteable expected;
- @Mock ProxyWriteable proxy;
- // @formatter:on
-
- private TxDataManagerImpl txManager;
- private String guid;
-
- @Before
- public void init() {
- MockitoAnnotations.initMocks(this);
-
- txManager = new TxDataManagerImpl(proxyFactory, dataFactory);
-
- guid = GUID.create();
- when(expected.getGuid()).thenReturn(guid);
- }
-
- @Test
- public void testAddAndGetOrWrite() throws OseeCoreException {
- Assert.assertEquals(0, txManager.size());
- txManager.addWrite(expected);
- Assert.assertEquals(1, txManager.size());
-
- ArtifactWriteable actual = txManager.getOrAddWrite(expected);
- Assert.assertTrue(expected == actual);
- Assert.assertEquals(1, txManager.size());
- }
-
- @Test
- public void testAddingAnotherInstanceOfWriteable() throws OseeCoreException {
- Assert.assertEquals(0, txManager.size());
- txManager.addWrite(expected);
- Assert.assertEquals(1, txManager.size());
-
- // Check no exception
- txManager.addWrite(expected);
- Assert.assertEquals(1, txManager.size());
-
- ArtifactWriteable other = mock(ArtifactWriteable.class);
- when(other.getGuid()).thenReturn(guid);
-
- thrown.expect(OseeArgumentException.class);
- thrown.expectMessage("Another instance of writeable detected - writeable tracking would be inconsistent");
- txManager.addWrite(other);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testOnStart() throws OseeCoreException {
- txManager.addWrite(expected);
- when(proxyFactory.asProxyWriteable(expected)).thenReturn(proxy);
-
- txManager.onCommitStart();
- verify(proxy).setWritesAllowed(false);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testOnRollback() throws OseeCoreException {
- txManager.addWrite(expected);
- when(proxyFactory.asProxyWriteable(expected)).thenReturn(proxy);
-
- txManager.onCommitRollback();
- verify(proxy).setWritesAllowed(true);
- }
-
- @Test
- public void testGetZeroChanges() throws OseeCoreException {
- Artifact impl = mock(Artifact.class);
-
- txManager.addWrite(expected);
- when(expected.isDirty()).thenReturn(false);
-
- txManager.getChanges();
- verify(proxyFactory, times(0)).getProxiedObject(expected);
- verify(impl, times(0)).accept(null);
- }
-
- @Test
- public void testGetOneDirty() throws OseeCoreException {
- Artifact impl = mock(Artifact.class);
-
- txManager.addWrite(expected);
- when(expected.isDirty()).thenReturn(true);
- when(proxyFactory.getProxiedObject(expected)).thenReturn(impl);
-
- List<ArtifactTransactionData> data = txManager.getChanges();
-
- verify(proxyFactory).getProxiedObject(expected);
- verify(dataFactory).createOnDirtyHandler(data);
- verify(impl).accept(null);
- }
-
- @Test
- public void testOnCommitSuccess() throws OseeCoreException {
- final List<ArtifactTransactionData> list = new ArrayList<ArtifactTransactionData>();
- Map<String, ArtifactWriteable> writeableArtifacts = new HashMap<String, ArtifactWriteable>();
- writeableArtifacts.put(expected.getGuid(), expected);
-
- TransactionResult result = mock(TransactionResult.class);
- final ArtifactTransactionData txData = mock(ArtifactTransactionData.class);
- OrcsVisitor vistor = mock(OrcsVisitor.class);
- when(dataFactory.createOnSuccessHandler(writeableArtifacts)).thenReturn(vistor);
- when(result.getData()).thenAnswer(new Answer<List<ArtifactTransactionData>>() {
-
- @Override
- public List<ArtifactTransactionData> answer(InvocationOnMock invocation) throws Throwable {
- return list;
- }
-
- });
- list.add(txData);
- txManager.addWrite(expected);
-
- txManager.onCommitSuccess(result);
-
- verify(dataFactory).createOnSuccessHandler(writeableArtifacts);
- verify(txData).accept(vistor);
- }
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerTest.java
new file mode 100644
index 0000000000..80474334fb
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/TxDataManagerTest.java
@@ -0,0 +1,367 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.transaction;
+
+import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyCollectionOf;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.ResultSet;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeStateException;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.core.ds.ArtifactData;
+import org.eclipse.osee.orcs.core.ds.OrcsData;
+import org.eclipse.osee.orcs.core.ds.TransactionData;
+import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
+import org.eclipse.osee.orcs.core.internal.artifact.ArtifactFactory;
+import org.eclipse.osee.orcs.core.internal.artifact.ArtifactImpl;
+import org.eclipse.osee.orcs.core.internal.proxy.ExternalArtifactManager;
+import org.eclipse.osee.orcs.core.internal.transaction.TxData.TxState;
+import org.eclipse.osee.orcs.core.internal.transaction.TxDataManager.TxDataLoader;
+import org.eclipse.osee.orcs.core.internal.util.ResultSetIterable;
+import org.eclipse.osee.orcs.core.internal.util.ValueProvider;
+import org.eclipse.osee.orcs.data.ArtifactId;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * Test Case for {@link TxCallableFactory}
+ *
+ * @author Megumi Telles
+ */
+public class TxDataManagerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ // @formatter:off
+ @Mock private OrcsSession session;
+ @Mock private IOseeBranch branch;
+
+ @Mock private ExternalArtifactManager proxyManager;
+ @Mock private ArtifactFactory artifactFactory;
+ @Mock private TxDataLoader loader;
+
+ @Mock private TxData txData;
+ @Mock private ArtifactReadable readable1;
+ @Mock private ArtifactReadable readable2;
+ @Mock private Artifact artifact;
+ @Mock private Artifact artifact2;
+ @Mock private Artifact child;
+ @Mock private ArtifactId artifactId;
+ @Captor private ArgumentCaptor<Collection<ArtifactId>> idCaptor;
+ // @formatter:on
+
+ private TxDataManager txDataManager;
+ private String guid;
+ private final Collection<? extends IAttributeType> types = Collections.emptyList();
+
+ @Before
+ public void init() throws OseeCoreException {
+ MockitoAnnotations.initMocks(this);
+ txDataManager = new TxDataManager(proxyManager, artifactFactory, loader);
+
+ guid = GUID.create();
+
+ when(artifact.getExistingAttributeTypes()).thenAnswer(answerValue(types));
+
+ when(proxyManager.asInternalArtifact(readable1)).thenReturn(artifact);
+ when(proxyManager.asExternalArtifact(session, artifact)).thenReturn(readable1);
+
+ when(txData.getSession()).thenReturn(session);
+ when(txData.getBranch()).thenReturn(branch);
+ }
+
+ @Test
+ public void testCreateTxData() {
+ TxData newData = txDataManager.createTxData(session, branch);
+ assertNotNull(newData);
+ }
+
+ @Test
+ public void testTxCommitSuccess() {
+ Iterable<Artifact> writeables = Arrays.asList(artifact);
+ when(txData.getAllWriteables()).thenReturn(writeables);
+
+ txDataManager.txCommitSuccess(txData);
+ verify(txData).setTxState(TxState.COMMITTED);
+ }
+
+ @Test
+ public void testRollbackTx() {
+ txDataManager.rollbackTx(txData);
+
+ verify(txData).setTxState(TxState.COMMIT_FAILED);
+ }
+
+ @Test
+ public void testStartTx() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+
+ txDataManager.startTx(txData);
+
+ verify(txData).setCommitInProgress(true);
+ verify(txData).setTxState(TxState.COMMIT_STARTED);
+ }
+
+ @Test
+ public void testStartTxCommitInProgress() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(true);
+
+ thrown.expect(OseeCoreException.class);
+ thrown.expectMessage("Commit is already in progress");
+
+ txDataManager.startTx(txData);
+ }
+
+ @Test
+ public void testEndTx() {
+ txDataManager.endTx(txData);
+
+ verify(txData).setCommitInProgress(false);
+ }
+
+ @Test
+ public void testGetForWrite() throws OseeCoreException {
+ ResultSet<Artifact> loaded = new ResultSetIterable<Artifact>(Collections.<Artifact> singleton(artifact));
+ when(loader.loadArtifacts(eq(session), eq(branch), anyCollectionOf(ArtifactId.class))).thenReturn(loaded);
+
+ Artifact actual = txDataManager.getForWrite(txData, readable1);
+
+ verify(loader).loadArtifacts(eq(session), eq(branch), idCaptor.capture());
+ assertEquals(artifact, actual);
+ }
+
+ @Test
+ public void testGetForWriteDuringWrite() throws OseeCoreException {
+ when(txData.add(artifact)).thenReturn(child);
+ when(artifactFactory.clone(artifact)).thenReturn(artifact);
+
+ thrown.expect(OseeArgumentException.class);
+ thrown.expectMessage("Another instance of writeable detected - writeable tracking would be inconsistent");
+ txDataManager.getForWrite(txData, readable1);
+ }
+
+ @Test
+ public void testSetComment() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+
+ txDataManager.setComment(txData, "this is a comment");
+ verify(txData).setComment("this is a comment");
+ }
+
+ @Test
+ public void testSetCommentChangesNotAllowed() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(true);
+
+ thrown.expect(OseeStateException.class);
+ thrown.expectMessage("Changes are not allowed - [COMMIT_IN_PROGRESS]");
+ txDataManager.setComment(txData, "trying to commit");
+ }
+
+ @Test
+ public void testSetAuthor() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+
+ txDataManager.setAuthor(txData, readable1);
+
+ verify(txData).setAuthor(readable1);
+ }
+
+ @Test
+ public void testCreateArtifact() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(artifactFactory.createArtifact(branch, CoreArtifactTypes.DirectSoftwareRequirement, guid)).thenReturn(
+ artifact);
+ when(proxyManager.asExternalArtifact(session, artifact)).thenReturn(readable1);
+
+ ArtifactReadable actual =
+ txDataManager.createArtifact(txData, CoreArtifactTypes.DirectSoftwareRequirement, "Direct SW requirement",
+ guid);
+
+ verify(artifactFactory).createArtifact(branch, CoreArtifactTypes.DirectSoftwareRequirement, guid);
+ assertEquals(readable1, actual);
+ }
+
+ @Test
+ public void testCopyExisitingArtifact() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(txData.getWriteable(readable1)).thenReturn(artifact);
+ when(artifactFactory.copyArtifact(artifact, types, branch)).thenReturn(artifact2);
+ when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2);
+
+ ArtifactReadable actual = txDataManager.copyArtifact(txData, branch, readable1);
+
+ verify(txData).getWriteable(readable1);
+ verify(artifactFactory).copyArtifact(artifact, types, branch);
+ verify(proxyManager).asExternalArtifact(session, artifact2);
+
+ assertEquals(readable2, actual);
+ }
+
+ @Test
+ public void testCopyReadableArtifact() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(readable1.getBranch()).thenReturn(branch);
+ when(txData.getWriteable(readable1)).thenReturn(null);
+ when(proxyManager.asInternalArtifact(readable1)).thenReturn(artifact);
+
+ when(artifactFactory.copyArtifact(artifact, types, branch)).thenReturn(artifact2);
+ when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2);
+
+ ArtifactReadable actual = txDataManager.copyArtifact(txData, branch, readable1);
+
+ verify(txData).getWriteable(readable1);
+ verify(proxyManager).asInternalArtifact(readable1);
+ verify(artifactFactory).copyArtifact(artifact, Collections.<IAttributeType> emptyList(), branch);
+ verify(proxyManager).asExternalArtifact(session, artifact2);
+
+ assertEquals(readable2, actual);
+ }
+
+ @Test
+ public void testCopyArtifact() throws OseeCoreException {
+ String guid = GUID.create();
+
+ ArtifactData data = Mockito.mock(ArtifactData.class);
+
+ @SuppressWarnings("unchecked")
+ ValueProvider<IOseeBranch, OrcsData> provider = Mockito.mock(ValueProvider.class);
+
+ Artifact sourceArtifact = Mockito.spy(new ArtifactImpl(null, data, null, null, provider));
+
+ when(data.getGuid()).thenReturn(guid);
+ when(provider.get()).thenReturn(branch);
+
+ List<? extends IAttributeType> copyTypes = Arrays.asList(CoreAttributeTypes.Active, CoreAttributeTypes.Name);
+ when(sourceArtifact.getExistingAttributeTypes()).thenAnswer(answerValue(copyTypes));
+
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(txData.getWriteable(sourceArtifact)).thenReturn(null);
+ when(artifactFactory.copyArtifact(sourceArtifact, copyTypes, branch)).thenReturn(artifact2);
+ when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2);
+
+ ArtifactReadable actual = txDataManager.copyArtifact(txData, branch, sourceArtifact);
+
+ verify(txData).getWriteable(sourceArtifact);
+ verify(artifactFactory).copyArtifact(sourceArtifact, copyTypes, branch);
+
+ assertEquals(readable2, actual);
+ }
+
+ @Test
+ public void testCopyArtifactId() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(txData.getWriteable(artifactId)).thenReturn(artifact);
+ when(artifact.getExistingAttributeTypes()).thenAnswer(answerValue(types));
+ when(artifactFactory.copyArtifact(artifact, types, branch)).thenReturn(artifact2);
+ when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2);
+
+ ArtifactReadable actual = txDataManager.copyArtifact(txData, branch, artifactId);
+
+ verify(txData).getWriteable(artifactId);
+ verify(artifactFactory).copyArtifact(artifact, types, branch);
+ verify(proxyManager).asExternalArtifact(session, artifact2);
+
+ assertEquals(readable2, actual);
+ }
+
+ @Test
+ public void testIntroduceArtifactExceptionSameBranch() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(txData.getBranch()).thenReturn(branch);
+
+ thrown.expect(OseeArgumentException.class);
+ thrown.expectMessage(String.format("Source branch is same branch as transaction branch[%s]", branch));
+ txDataManager.introduceArtifact(txData, branch, artifactId);
+ }
+
+ @Test
+ public void testIntroduceArtifact() throws OseeCoreException {
+ when(txData.isCommitInProgress()).thenReturn(false);
+ when(txData.getTxState()).thenReturn(TxState.NEW_TX);
+ when(txData.getBranch()).thenReturn(branch);
+
+ ResultSet<Artifact> loaded = new ResultSetIterable<Artifact>(Collections.<Artifact> singleton(artifact));
+ when(loader.loadArtifacts(eq(session), eq(COMMON), anyCollectionOf(ArtifactId.class))).thenReturn(loaded);
+ when(artifactFactory.introduceArtifact(artifact, branch)).thenReturn(artifact2);
+ when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2);
+
+ ArtifactReadable actual = txDataManager.introduceArtifact(txData, COMMON, artifactId);
+
+ verify(loader).loadArtifacts(eq(session), eq(COMMON), idCaptor.capture());
+ assertEquals(artifactId, idCaptor.getValue().iterator().next());
+ verify(artifactFactory).introduceArtifact(artifact, branch);
+ verify(proxyManager).asExternalArtifact(session, artifact2);
+ assertEquals(readable2, actual);
+ }
+
+ @Test
+ public void testDeleteArtifact() throws OseeCoreException {
+ when(artifactFactory.clone(artifact)).thenReturn(artifact2);
+
+ txDataManager.deleteArtifact(txData, artifact);
+
+ verify(artifact2).delete();
+ }
+
+ @Test
+ public void testCreateChangeData() throws OseeCoreException {
+ Iterable<Artifact> writeables = Arrays.asList(artifact);
+ when(txData.getAllWriteables()).thenReturn(writeables);
+ when(artifact.isDirty()).thenReturn(true);
+
+ TransactionData changeData = txDataManager.createChangeData(txData);
+ assertNotNull(changeData);
+ }
+
+ private <T> Answer<T> answerValue(final T value) {
+ return new Answer<T>() {
+
+ @Override
+ public T answer(InvocationOnMock invocation) throws Throwable {
+ return value;
+ }
+ };
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java
deleted file mode 100644
index 447214d63f..0000000000
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/transaction/handler/HandlerTestSuite.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.orcs.core.internal.transaction.handler;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({CollectDirtyDataTest.class})
-public class HandlerTestSuite {
- // Test Suite
-}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/ResultSetIterableTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/ResultSetIterableTest.java
new file mode 100644
index 0000000000..85f5e85a6d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/ResultSetIterableTest.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core.internal.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.ResultSet;
+import org.eclipse.osee.framework.core.exception.ItemDoesNotExist;
+import org.eclipse.osee.framework.core.exception.MultipleItemsExist;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Test Case for {@link ResultSetIterable}
+ *
+ * @author Roberto E. Escobar
+ */
+public class ResultSetIterableTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private ResultSet<String> result;
+ private Set<String> data;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ data = new LinkedHashSet<String>();
+ result = new ResultSetIterable<String>(data);
+ }
+
+ @Test
+ public void testSizeAndEmpty() {
+ data.add("a");
+ data.add("b");
+ data.add("c");
+
+ assertFalse(result.isEmpty());
+ assertEquals(3, result.size());
+
+ data.clear();
+ assertTrue(result.isEmpty());
+ assertEquals(0, result.size());
+
+ result.iterator();
+ }
+
+ @Test
+ public void testGetExactlyOneMultipleException() throws OseeCoreException {
+ data.add("a");
+ data.add("b");
+
+ thrown.expect(MultipleItemsExist.class);
+ thrown.expectMessage("Multiple items found - total [2]");
+ result.getExactlyOne();
+ }
+
+ @Test
+ public void testGetExactlyOneNoneExistException() throws OseeCoreException {
+ thrown.expect(ItemDoesNotExist.class);
+ thrown.expectMessage("No item found");
+ result.getExactlyOne();
+ }
+
+ @Test
+ public void testGetExactlyOne() throws OseeCoreException {
+ data.add("c");
+ assertEquals("c", result.getExactlyOne());
+ }
+
+ @Test
+ public void testGetOneOrNull() throws OseeCoreException {
+ Assert.assertNull(result.getOneOrNull());
+
+ data.add("a");
+ data.add("b");
+ data.add("c");
+ assertEquals("a", result.getOneOrNull());
+ }
+
+ @Test
+ public void testGetAtMostOneOrNullExceptionMoreThanOne() throws OseeCoreException {
+ assertNull(result.getAtMostOneOrNull());
+
+ data.add("a");
+ data.add("b");
+ data.add("c");
+ thrown.expect(MultipleItemsExist.class);
+ thrown.expectMessage("Multiple items found - total [3]");
+ assertEquals("a", result.getAtMostOneOrNull());
+ }
+
+ @Test
+ public void testGetAtMostOneOrNull() throws OseeCoreException {
+ assertNull(result.getAtMostOneOrNull());
+
+ data.add("a");
+ assertEquals("a", result.getAtMostOneOrNull());
+ }
+
+ @Test
+ public void testIterator() {
+ data.add("a");
+ data.add("b");
+ data.add("c");
+
+ Iterator<String> iterator = result.iterator();
+ assertEquals("a", iterator.next());
+ assertEquals("b", iterator.next());
+ assertEquals("c", iterator.next());
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/UtilTestSuite.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/UtilTestSuite.java
index dd7e6b7f82..dd07888d65 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/UtilTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/util/UtilTestSuite.java
@@ -17,7 +17,7 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({OrcsPredicatesTest.class})
+@Suite.SuiteClasses({OrcsPredicatesTest.class, ResultSetIterableTest.class})
public class UtilTestSuite {
// Test Suite
}

Back to the top