diff options
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee')
7 files changed, 143 insertions, 94 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactFactoryTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactFactoryTest.java index 969cb79115e..612160390fd 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactFactoryTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactFactoryTest.java @@ -10,21 +10,24 @@ *******************************************************************************/ package org.eclipse.osee.orcs.core.internal.artifact; -import static org.junit.Assert.*; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +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.Collections; import java.util.List; +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.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.Branch; -import org.eclipse.osee.framework.core.model.cache.ArtifactTypeCache; import org.eclipse.osee.framework.core.model.cache.BranchCache; -import org.eclipse.osee.framework.core.model.type.ArtifactType; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.ArtifactDataFactory; @@ -34,6 +37,7 @@ import org.eclipse.osee.orcs.core.internal.attribute.Attribute; import org.eclipse.osee.orcs.core.internal.attribute.AttributeFactory; import org.eclipse.osee.orcs.core.internal.relation.RelationContainer; import org.eclipse.osee.orcs.core.internal.relation.RelationFactory; +import org.eclipse.osee.orcs.data.ArtifactTypes; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -57,7 +61,7 @@ public class ArtifactFactoryTest { // @formatter:off @Mock private Branch branch; - @Mock private ArtifactType artifactType; + @Mock private IArtifactType artifactType; @Mock private ArtifactData artifactData; @Mock private RelationContainer relationContainer; @Mock private VersionData artifactVersion; @@ -65,7 +69,7 @@ public class ArtifactFactoryTest { @Mock private ArtifactDataFactory dataFactory; @Mock private AttributeFactory attributeFactory; @Mock private RelationFactory relationFactory; - @Mock private ArtifactTypeCache artifactTypeCache; + @Mock private ArtifactTypes artifactTypeCache; @Mock private BranchCache branchCache; @Mock private Attribute<Object> attribute; @@ -84,7 +88,7 @@ public class ArtifactFactoryTest { MockitoAnnotations.initMocks(this); artifactFactory = - new ArtifactFactory(dataFactory, attributeFactory, relationFactory, artifactTypeCache, branchCache); + new ArtifactFactory(dataFactory, attributeFactory, relationFactory, branchCache, artifactTypeCache); guid = GUID.create(); @@ -109,8 +113,9 @@ public class ArtifactFactoryTest { when(otherArtifactData.getVersion()).thenReturn(artifactVersion); when(relationFactory.createRelationContainer(45)).thenReturn(relationContainer); - when(artifactTypeCache.getByGuid(65L)).thenReturn(artifactType); when(branchCache.getById(23)).thenReturn(branch); + + when(artifactTypeCache.getByUuid(65L)).thenReturn(artifactType); } @Test @@ -127,7 +132,6 @@ public class ArtifactFactoryTest { @Test public void testCreateArtifactFromArtifactData() throws OseeCoreException { when(relationFactory.createRelationContainer(45)).thenReturn(relationContainer); - when(artifactTypeCache.getByGuid(65L)).thenReturn(artifactType); when(branchCache.getById(23)).thenReturn(branch); ArtifactImpl artifact = artifactFactory.createArtifact(artifactData); @@ -143,7 +147,7 @@ public class ArtifactFactoryTest { when(source.getAttributes(CoreAttributeTypes.Annotation)).thenAnswer(new ReturnAttribute(attribute)); when(attribute.getOrcsData()).thenReturn(attributeData); - when(artifactType.isValidAttributeType(CoreAttributeTypes.Annotation, branch)).thenReturn(true); + when(artifactTypeCache.isValidAttributeType(artifactType, branch, CoreAttributeTypes.Annotation)).thenReturn(true); ArgumentCaptor<ArtifactImpl> implCapture = ArgumentCaptor.forClass(ArtifactImpl.class); @@ -153,6 +157,7 @@ public class ArtifactFactoryTest { verify(source, times(0)).getAttributes(CoreAttributeTypes.City); verify(source, times(1)).getAttributes(CoreAttributeTypes.Annotation); verify(attributeFactory).copyAttribute(eq(attributeData), eq(branch), implCapture.capture()); + Assert.assertTrue(implCapture.getValue().isLoaded()); Assert.assertTrue(actual == implCapture.getValue()); } @@ -178,7 +183,7 @@ public class ArtifactFactoryTest { when(source.getExistingAttributeTypes()).thenAnswer(new ReturnExistingTypes(types)); when(source.getAttributes(CoreAttributeTypes.Annotation)).thenAnswer(new ReturnAttribute(attribute)); when(attribute.getOrcsData()).thenReturn(attributeData); - when(artifactType.isValidAttributeType(CoreAttributeTypes.Annotation, branch)).thenReturn(true); + when(artifactTypeCache.isValidAttributeType(artifactType, branch, CoreAttributeTypes.Annotation)).thenReturn(true); ArgumentCaptor<ArtifactImpl> implCapture = ArgumentCaptor.forClass(ArtifactImpl.class); @@ -202,7 +207,7 @@ public class ArtifactFactoryTest { when(source.getExistingAttributeTypes()).thenAnswer(new ReturnExistingTypes(types)); when(source.getAttributes(CoreAttributeTypes.Annotation)).thenAnswer(new ReturnAttribute(attribute)); when(attribute.getOrcsData()).thenReturn(attributeData); - when(artifactType.isValidAttributeType(CoreAttributeTypes.Annotation, branch)).thenReturn(true); + when(artifactTypeCache.isValidAttributeType(artifactType, branch, CoreAttributeTypes.Annotation)).thenReturn(true); ArgumentCaptor<ArtifactImpl> implCapture = ArgumentCaptor.forClass(ArtifactImpl.class); diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactImplTest.java index f04403a0547..37fa8d71e03 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactImplTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactImplTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.List; import org.junit.Assert; +import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; @@ -27,8 +28,6 @@ import org.eclipse.osee.framework.core.exception.MultipleAttributesExist; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.exception.OseeStateException; import org.eclipse.osee.framework.core.model.Branch; -import org.eclipse.osee.framework.core.model.type.ArtifactType; -import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.AttributeData; @@ -37,6 +36,7 @@ import org.eclipse.osee.orcs.core.internal.artifact.ArtifactImpl; import org.eclipse.osee.orcs.core.internal.artifact.AttributeManager; import org.eclipse.osee.orcs.core.internal.artifact.ValueProvider; import org.eclipse.osee.orcs.core.internal.relation.RelationContainer; +import org.eclipse.osee.orcs.data.ArtifactTypes; import org.eclipse.osee.orcs.data.AttributeReadable; import org.junit.Before; import org.junit.Rule; @@ -59,9 +59,8 @@ public class ArtifactImplTest { @Mock private AttributeFactory attributeFactory; @Mock private RelationContainer relationContainer; @Mock private ValueProvider<Branch, ArtifactData> branchProvider; - @Mock private ValueProvider<ArtifactType, ArtifactData> artifactTypeProvider; - @Mock private ArtifactType artifactType; - @Mock private AttributeType attributeType; + @Mock private ArtifactTypes types; + @Mock private VersionData version; @Mock private AttributeData attributeData; @Mock private Branch branch; @@ -77,15 +76,17 @@ public class ArtifactImplTest { // @formatter:on private final String guid = GUID.create(); + private final IAttributeType attributeType = CoreAttributeTypes.Annotation; + private final IArtifactType artifactType = CoreArtifactTypes.GeneralData; @SuppressWarnings("unchecked") @Before public void init() throws OseeCoreException { MockitoAnnotations.initMocks(this); - artifactImpl = - new ArtifactImpl(artifactData, attributeFactory, relationContainer, branchProvider, artifactTypeProvider); - when(artifactTypeProvider.get()).thenReturn(artifactType); - when(artifactType.isValidAttributeType(any(IAttributeType.class), any(Branch.class))).thenReturn(true); + artifactImpl = new ArtifactImpl(types, artifactData, attributeFactory, relationContainer, branchProvider); + + when(types.isValidAttributeType(any(IArtifactType.class), any(Branch.class), any(IAttributeType.class))).thenReturn( + true); when(attributeFactory.getMaxOccurrenceLimit(any(IAttributeType.class))).thenReturn(1); when(attributeFactory.createAttribute(any(AttributeManager.class), any(AttributeData.class))).thenReturn( @@ -97,11 +98,16 @@ public class ArtifactImplTest { when(artifactData.getGuid()).thenReturn(guid); when(artifactData.getVersion()).thenReturn(version); + when(artifactData.getTypeUuid()).thenReturn(artifactType.getGuid()); when(branchProvider.get()).thenReturn(branch); + when(deleted.isDeleted()).thenReturn(true); when(notDeleted.getOrcsData()).thenReturn(attributeData); when(deleted.getOrcsData()).thenReturn(attributeData); when(differentType.getOrcsData()).thenReturn(attributeData); + + when(types.getByUuid(CoreArtifactTypes.GeneralData.getGuid())).thenReturn(CoreArtifactTypes.GeneralData); + when(types.getByUuid(CoreArtifactTypes.CodeUnit.getGuid())).thenReturn(CoreArtifactTypes.CodeUnit); } @Test @@ -122,7 +128,8 @@ public class ArtifactImplTest { Attribute two = mock(Attribute.class); when(one.getOrcsData()).thenReturn(attributeData); when(two.getOrcsData()).thenReturn(attributeData); - when(attributeType.getMaxOccurrences()).thenReturn(1); + + when(attributeFactory.getMaxOccurrenceLimit(attributeType)).thenReturn(1); artifactImpl.add(attributeType, one); artifactImpl.add(attributeType, two); Assert.assertEquals(2, artifactImpl.getAttributes(attributeType).size()); @@ -150,7 +157,6 @@ public class ArtifactImplTest { ArtifactData newOrcsData = mock(ArtifactData.class); artifactImpl.setOrcsData(newOrcsData); verify(branchProvider).setOrcsData(newOrcsData); - verify(artifactTypeProvider).setOrcsData(newOrcsData); } @Test @@ -192,7 +198,7 @@ public class ArtifactImplTest { @Test public void testArtifactType() throws OseeCoreException { artifactImpl.getArtifactType(); - verify(artifactTypeProvider).get(); + verify(types).getByUuid(artifactData.getTypeUuid()); } @Test @@ -210,13 +216,20 @@ public class ArtifactImplTest { @Test public void testSetArtifactType() throws OseeCoreException { when(version.isInStorage()).thenReturn(true); + artifactImpl.setArtifactType(CoreArtifactTypes.CodeUnit); + verify(artifactData).setTypeUuid(CoreArtifactTypes.CodeUnit.getGuid()); verify(artifactData).setModType(ModificationType.MODIFIED); reset(version); reset(artifactData); + + when(artifactData.getVersion()).thenReturn(version); + when(artifactData.getGuid()).thenReturn(guid); when(artifactData.getVersion()).thenReturn(version); + when(artifactData.getTypeUuid()).thenReturn(artifactType.getGuid()); + artifactImpl.setArtifactType(CoreArtifactTypes.CodeUnit); verify(artifactData, never()).setModType(ModificationType.MODIFIED); } @@ -224,7 +237,8 @@ public class ArtifactImplTest { @Test public void testIsOfType() throws OseeCoreException { artifactImpl.isOfType(CoreArtifactTypes.CodeUnit); - verify(artifactType).inheritsFrom(CoreArtifactTypes.CodeUnit); + + verify(types).inheritsFrom(CoreArtifactTypes.GeneralData, CoreArtifactTypes.CodeUnit); } @Test @@ -264,13 +278,13 @@ public class ArtifactImplTest { @Test public void testIsAttributeTypeValid() throws OseeCoreException { artifactImpl.isAttributeTypeValid(CoreAttributeTypes.Afha); - verify(artifactType).isValidAttributeType(CoreAttributeTypes.Afha, branch); + verify(types).isValidAttributeType(artifactType, branch, CoreAttributeTypes.Afha); } @Test public void testGetValidAttributeTypes() throws OseeCoreException { artifactImpl.getValidAttributeTypes(); - verify(artifactType).getAttributeTypes(branch); + verify(types).getAttributeTypes(artifactType, branch); } @Test @@ -314,7 +328,7 @@ public class ArtifactImplTest { int result = artifactImpl.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId); Assert.assertEquals(expected, result); - reset(artifactType); + reset(types); result = artifactImpl.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId); Assert.assertEquals(-1, result); } @@ -328,7 +342,7 @@ public class ArtifactImplTest { int result = artifactImpl.getMinimumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId); Assert.assertEquals(expected, result); - reset(artifactType); + reset(types); result = artifactImpl.getMaximumAttributeTypeAllowed(CoreAttributeTypes.AccessContextId); Assert.assertEquals(-1, result); } @@ -413,7 +427,7 @@ public class ArtifactImplTest { @Test @SuppressWarnings("unchecked") public void testDeleteSoleAttribute() throws OseeCoreException { - when(attributeType.getMinOccurrences()).thenReturn(0); + when(attributeFactory.getMinOccurrenceLimit(attributeType)).thenReturn(0); when(notDeleted.getAttributeType()).thenReturn(attributeType); when(notDeleted.getContainer()).thenReturn(artifactImpl); artifactImpl.add(attributeType, notDeleted); diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeClassResolverTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeClassResolverTest.java index f65a14ac93a..373be3c9bb8 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeClassResolverTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeClassResolverTest.java @@ -10,13 +10,14 @@ *******************************************************************************/ package org.eclipse.osee.orcs.core.internal.attribute; +import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import org.junit.Assert; +import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.orcs.core.AttributeClassProvider; import org.eclipse.osee.orcs.core.internal.attribute.primitives.BooleanAttribute; import org.eclipse.osee.orcs.core.internal.attribute.primitives.CompressedContentAttribute; @@ -27,11 +28,14 @@ import org.eclipse.osee.orcs.core.internal.attribute.primitives.IntegerAttribute import org.eclipse.osee.orcs.core.internal.attribute.primitives.JavaObjectAttribute; import org.eclipse.osee.orcs.core.internal.attribute.primitives.PrimitiveAttributeClassProvider; import org.eclipse.osee.orcs.core.internal.attribute.primitives.StringAttribute; +import org.eclipse.osee.orcs.data.AttributeTypes; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; /** * Test Case for {@link AttributeClassResolver} @@ -41,9 +45,15 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class AttributeClassResolverTest { + //@formatter:off + @Mock private AttributeTypes cache; + @Mock private IAttributeType type; + //@formatter:on + private final String alias; private final Class<? extends Attribute<?>> expected; private AttributeClassResolver resolver; + private AttributeClassRegistry registry; public AttributeClassResolverTest(String alias, Class<? extends Attribute<?>> expected) { this.alias = alias; @@ -52,9 +62,13 @@ public class AttributeClassResolverTest { @Before public void setup() { - resolver = new AttributeClassResolver(); + MockitoAnnotations.initMocks(this); + + registry = new AttributeClassRegistry(); + resolver = new AttributeClassResolver(registry, cache); + PrimitiveAttributeClassProvider provider = new PrimitiveAttributeClassProvider(); - resolver.addProvider(provider); + registry.addProvider(provider); } @Test @@ -64,24 +78,25 @@ public class AttributeClassResolverTest { } @Test - public void testGetBaseClazzByType() { - AttributeType type = createType(alias); + public void testGetBaseClazzByType() throws OseeCoreException { + when(cache.getBaseAttributeTypeId(type)).thenReturn(alias); + Class<? extends Attribute<?>> actual = resolver.getBaseClazz(type); Assert.assertEquals(expected, actual); } @Test - public void testRemoveProvider() { + public void testRemoveProvider() throws OseeCoreException { Class<? extends Attribute<?>> actual1 = resolver.getBaseClazz(alias); Assert.assertNotNull(actual1); - AttributeType type = createType(alias); + when(cache.getBaseAttributeTypeId(type)).thenReturn(alias); Class<? extends Attribute<?>> actual2 = resolver.getBaseClazz(type); Assert.assertNotNull(actual2); Assert.assertEquals(actual1, actual2); - resolver.removeProvider(new AttributeClassProvider() { + registry.removeProvider(new AttributeClassProvider() { @Override public List<Class<? extends Attribute<?>>> getClasses() { @@ -98,7 +113,8 @@ public class AttributeClassResolverTest { @Test(expected = OseeCoreException.class) public void testIsBaseCompatibleException1() throws OseeCoreException { - AttributeType type = createType(alias); + when(cache.getBaseAttributeTypeId(type)).thenReturn(alias); + resolver.isBaseTypeCompatible(null, type); } @@ -109,24 +125,23 @@ public class AttributeClassResolverTest { @Test(expected = OseeCoreException.class) public void testIsBaseCompatibleException3() throws OseeCoreException { - AttributeType type2 = createType(alias + "1"); - resolver.isBaseTypeCompatible(expected, type2); + when(cache.getBaseAttributeTypeId(type)).thenReturn(alias + "1"); + + resolver.isBaseTypeCompatible(expected, type); } @Test public void testIsBaseCompatible() throws OseeCoreException { - AttributeType type1 = createType(alias); - boolean result1 = resolver.isBaseTypeCompatible(expected, type1); + when(cache.getBaseAttributeTypeId(type)).thenReturn(alias); + + boolean result1 = resolver.isBaseTypeCompatible(expected, type); Assert.assertTrue(result1); String other = !alias.equals("BooleanAttribute") ? "BooleanAttribute" : "StringAttribute"; - AttributeType type2 = createType(other); - boolean result2 = resolver.isBaseTypeCompatible(expected, type2); - Assert.assertFalse(result2); - } + when(cache.getBaseAttributeTypeId(type)).thenReturn(other); - private static AttributeType createType(String baseType) { - return new AttributeType(1L, "dummy", baseType, "", "", "", 1, 1, "", "", ""); + boolean result2 = resolver.isBaseTypeCompatible(expected, type); + Assert.assertFalse(result2); } @Parameters diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactoryTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactoryTest.java index 8505184ab0e..b487931b896 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactoryTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/AttributeFactoryTest.java @@ -25,7 +25,6 @@ import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; 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.core.model.cache.AttributeTypeCache; import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.orcs.core.ds.ArtifactData; import org.eclipse.osee.orcs.core.ds.AttributeData; @@ -34,6 +33,7 @@ import org.eclipse.osee.orcs.core.ds.DataProxy; import org.eclipse.osee.orcs.core.ds.ResourceNameResolver; import org.eclipse.osee.orcs.core.ds.VersionData; import org.eclipse.osee.orcs.core.internal.artifact.AttributeManager; +import org.eclipse.osee.orcs.data.AttributeTypes; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -54,13 +54,13 @@ public class AttributeFactoryTest { // @formatter:off @Mock private AttributeClassResolver classResolver; - @Mock private AttributeTypeCache cache; + @Mock private AttributeTypes cache; @Mock private AttributeDataFactory dataFactory; @Mock private AttributeData attributeData; @Mock private VersionData attrVersionData; - @Mock private AttributeType attributeType; + @Mock private IAttributeType attributeType; @Mock private Attribute<Object> attribute; @Mock private AttributeManager container; @@ -75,19 +75,19 @@ public class AttributeFactoryTest { public void init() throws OseeCoreException { MockitoAnnotations.initMocks(this); - factory = new AttributeFactory(classResolver, cache, dataFactory); + factory = new AttributeFactory(classResolver, dataFactory, cache); expectedGuid = CoreAttributeTypes.Name.getGuid(); when(attributeData.getTypeUuid()).thenReturn(expectedGuid); - when(cache.getByGuid(expectedGuid)).thenReturn(attributeType); + when(cache.getByUuid(expectedGuid)).thenReturn(attributeType); when(classResolver.createAttribute(attributeType)).thenReturn(attribute); when(attributeData.getDataProxy()).thenReturn(proxy); } @Test public void testCreateAttributeNullType() throws OseeCoreException { - when(cache.getByGuid(expectedGuid)).thenReturn(null); + when(cache.getByUuid(expectedGuid)).thenReturn(null); thrown.expect(OseeArgumentException.class); thrown.expectMessage("attributeType cannot be null - Cannot find attribute type with uuid[" + expectedGuid + "]"); @@ -202,27 +202,25 @@ public class AttributeFactoryTest { public void testGetMaxOccurrenceLimit() throws OseeCoreException { IAttributeType token = mock(IAttributeType.class); - when(cache.get(token)).thenReturn(attributeType); - when(attributeType.getMaxOccurrences()).thenReturn(56); + when(cache.getMaxOccurrences(token)).thenReturn(56); int actual = factory.getMaxOccurrenceLimit(token); assertEquals(56, actual); - verify(attributeType).getMaxOccurrences(); + verify(cache).getMaxOccurrences(token); } @Test public void testGetMinOccurrenceLimit() throws OseeCoreException { IAttributeType token = mock(IAttributeType.class); - when(cache.get(token)).thenReturn(attributeType); - when(attributeType.getMinOccurrences()).thenReturn(99); + when(cache.getMinOccurrences(token)).thenReturn(99); int actual = factory.getMinOccurrenceLimit(token); assertEquals(99, actual); - verify(attributeType).getMinOccurrences(); + verify(cache).getMinOccurrences(token); } } diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationLoadingTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationLoadingTest.java index 484112ef051..8b3f670a4ff 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationLoadingTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationLoadingTest.java @@ -10,23 +10,26 @@ *******************************************************************************/ package org.eclipse.osee.orcs.core.internal.relation; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.eclipse.osee.framework.core.data.IRelationType; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.ModificationType; 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.framework.core.model.cache.RelationTypeCache; -import org.eclipse.osee.framework.core.model.mocks.MockOseeDataAccessor; -import org.eclipse.osee.framework.core.model.type.RelationType; import org.eclipse.osee.orcs.core.ds.RelationData; import org.eclipse.osee.orcs.core.ds.VersionData; +import org.eclipse.osee.orcs.data.RelationTypes; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -39,7 +42,7 @@ public class RelationLoadingTest { @Test public void testRelationCountMatches() throws OseeCoreException, IOException { - RelationTypeCache cache = createAndPopulate(); + RelationTypes cache = createAndPopulate(); Map<Integer, RelationContainer> providersThatWillBeLoaded = getRelationProviderList(cache, 22); RelationRowMapper relationRowMapper = new RelationRowMapper(providersThatWillBeLoaded); @@ -57,7 +60,7 @@ public class RelationLoadingTest { @Ignore @Test public void testRelatedArtifactsMatch() throws OseeCoreException, IOException { - RelationTypeCache cache = createAndPopulate(); + RelationTypes cache = createAndPopulate(); Map<Integer, RelationContainer> providersThatWillBeLoaded = getRelationProviderList(cache, 22); RelationRowMapper relationRowMapper = new RelationRowMapper(providersThatWillBeLoaded); @@ -72,15 +75,29 @@ public class RelationLoadingTest { } //@formatter:on - public RelationTypeCache createAndPopulate() throws OseeCoreException { - RelationTypeCache cache = new RelationTypeCache(new MockOseeDataAccessor<Long, RelationType>()); - cache.cache(new RelationType(1l, "test", "sideAName", "sideBName", CoreArtifactTypes.Artifact, - CoreArtifactTypes.Artifact, RelationTypeMultiplicity.MANY_TO_MANY, "")); + public RelationTypes createAndPopulate() throws OseeCoreException { + IRelationType type = mock(IRelationType.class); + RelationTypes cache = mock(RelationTypes.class); + + when(type.getGuid()).thenReturn(1L); + when(type.getName()).thenReturn("test"); + + when(cache.getByUuid(1L)).thenReturn(type); + when(cache.getSideAName(type)).thenReturn("sideAName"); + when(cache.getSideBName(type)).thenReturn("sideBName"); + when(cache.getArtifactTypeSideA(type)).thenReturn(CoreArtifactTypes.Artifact); + when(cache.getArtifactTypeSideB(type)).thenReturn(CoreArtifactTypes.Artifact); + when(cache.getMultiplicity(type)).thenReturn(RelationTypeMultiplicity.MANY_TO_MANY); + when(cache.getDefaultOrderTypeGuid(type)).thenReturn(""); + + when(cache.getSideName(type, RelationSide.SIDE_A)).thenReturn("sideAName"); + when(cache.getSideName(type, RelationSide.SIDE_B)).thenReturn("sideBName"); + + when(cache.getArtifactType(eq(type), any(RelationSide.class))).thenReturn(CoreArtifactTypes.Artifact); return cache; } private void checkRelationCount(RelationContainer relationContainer, RelationSide side, int size) { - // int count = relationContainer.getRelationCount(1, side); int count = relationContainer.getRelationCount(TokenFactory.createRelationTypeSide(side, 1, "blah")); Assert.assertEquals( String.format("We did not get the expected number of relations back [%d != %d]", size, count), size, count); @@ -96,7 +113,7 @@ public class RelationLoadingTest { } } - private Map<Integer, RelationContainer> getRelationProviderList(RelationTypeCache relationTypeCache, int size) { + private Map<Integer, RelationContainer> getRelationProviderList(RelationTypes relationTypeCache, int size) { Map<Integer, RelationContainer> providersThatWillBeLoaded = new HashMap<Integer, RelationContainer>(); for (int i = 1; i <= size; i++) { providersThatWillBeLoaded.put(i, createRelationContainer(relationTypeCache, i)); @@ -104,7 +121,7 @@ public class RelationLoadingTest { return providersThatWillBeLoaded; } - private RelationContainer createRelationContainer(RelationTypeCache relationTypeCache, final int parentId) { + private RelationContainer createRelationContainer(RelationTypes relationTypeCache, final int parentId) { return new RelationContainerImpl(parentId, relationTypeCache); } diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/SearchCriteriaTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/SearchCriteriaTest.java index c67d2f3bc7a..4fdbccf90d0 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/SearchCriteriaTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/SearchCriteriaTest.java @@ -18,9 +18,8 @@ import org.eclipse.osee.framework.core.data.IAttributeType; 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.model.cache.AttributeTypeCache; -import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeKeywords; +import org.eclipse.osee.orcs.data.AttributeTypes; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -34,23 +33,21 @@ import org.mockito.MockitoAnnotations; public class SearchCriteriaTest { @Mock - private AttributeTypeCache cache; - @Mock - private AttributeType type; - private final ArrayList<IAttributeType> types = new ArrayList<IAttributeType>(); + private AttributeTypes cache; @Before - public void setup() { + public void setup() throws OseeCoreException { MockitoAnnotations.initMocks(this); - types.add(CoreAttributeTypes.Active); - types.add(CoreAttributeTypes.FavoriteBranch); + + when(cache.getByUuid(CoreAttributeTypes.Name.getGuid())).thenReturn(CoreAttributeTypes.Name); + when(cache.getByUuid(CoreAttributeTypes.Active.getGuid())).thenReturn(CoreAttributeTypes.Active); + when(cache.getByUuid(CoreAttributeTypes.FavoriteBranch.getGuid())).thenReturn(CoreAttributeTypes.FavoriteBranch); } @Test public void isTagged() throws OseeCoreException { - when(cache.get(CoreAttributeTypes.Name)).thenReturn(type); - when(type.getName()).thenReturn("Name"); - when(type.isTaggable()).thenReturn(true); + when(cache.isTaggable(CoreAttributeTypes.Name)).thenReturn(true); + CriteriaAttributeKeywords keyword = new CriteriaAttributeKeywords(false, Collections.singletonList(CoreAttributeTypes.Name), cache, ""); keyword.checkNotTaggable(); @@ -59,9 +56,9 @@ public class SearchCriteriaTest { @Test(expected = OseeArgumentException.class) public void notTagged() throws OseeCoreException { - when(cache.get(CoreAttributeTypes.Active)).thenReturn(type); - when(type.getName()).thenReturn("Active"); - when(type.isTaggable()).thenReturn(false); + + when(cache.isTaggable(CoreAttributeTypes.Active)).thenReturn(false); + CriteriaAttributeKeywords keyword = new CriteriaAttributeKeywords(false, Collections.singletonList(CoreAttributeTypes.Active), cache, ""); keyword.checkNotTaggable(); @@ -71,11 +68,13 @@ public class SearchCriteriaTest { @Test(expected = OseeArgumentException.class) public void notTaggedList() throws OseeCoreException { - when(cache.get(CoreAttributeTypes.Active)).thenReturn(type); - when(type.getName()).thenReturn("Active"); - when(cache.get(CoreAttributeTypes.FavoriteBranch)).thenReturn(type); - when(type.getName()).thenReturn("Favorite Branch"); - when(type.isTaggable()).thenReturn(false); + + when(cache.isTaggable(CoreAttributeTypes.FavoriteBranch)).thenReturn(false); + + ArrayList<IAttributeType> types = new ArrayList<IAttributeType>(); + types.add(CoreAttributeTypes.Active); + types.add(CoreAttributeTypes.FavoriteBranch); + CriteriaAttributeKeywords keyword = new CriteriaAttributeKeywords(false, types, cache, ""); keyword.checkNotTaggable(); diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java index b9dd0ff46ee..2742f03354e 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java @@ -39,6 +39,7 @@ import org.eclipse.osee.framework.core.exception.OseeExceptions; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.resource.management.IResource; import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.OrcsTypes; import org.eclipse.osee.orcs.core.ds.OrcsTypesDataStore; import org.eclipse.osee.orcs.core.internal.SessionContext; import org.eclipse.osee.orcs.core.internal.types.impl.OrcsTypesImpl; |