@Test public void testCopyArtifact() throws OseeCoreException { String guid = GUID.create(); ArtifactData data = Mockito.mock(ArtifactData.class); VersionData version = Mockito.mock(VersionData.class); when(data.getVersion()).thenReturn(version); when(version.getBranchId()).thenReturn(111L); Artifact sourceArtifact = Mockito.spy(new ArtifactImpl(null, data, null, provider)); when(data.getGuid()).thenReturn(guid); List<? extends IAttributeType> copyTypes = Arrays.asList(CoreAttributeTypes.Active, CoreAttributeTypes.Name); when(sourceArtifact.getExistingAttributeTypes()).thenAnswer(answerValue(copyTypes)); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); when(txData.isCommitInProgress()).thenReturn(false); when(txData.getTxState()).thenReturn(TxState.NEW_TX); when(txData.getWriteable(sourceArtifact)).thenReturn(null); when(artifactFactory.copyArtifact(session, 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(session, sourceArtifact, copyTypes, branch); assertEquals(readable2, actual); }
@Before public void init() throws OseeCoreException { MockitoAnnotations.initMocks(this); txDataManager = new TxDataManager(proxyManager, artifactFactory, relationManager, loader); guid = GUID.create(); when(artifact1.getExistingAttributeTypes()).thenAnswer(answerValue(types)); when(proxyManager.asInternalArtifact(readable1)).thenReturn(artifact1); when(proxyManager.asExternalArtifact(session, artifact1)).thenReturn(readable1); when(branch.getUuid()).thenReturn(111L); when(provider.getBranch(111L)).thenReturn(branch); when(txData.getSession()).thenReturn(session); when(txData.getBranch()).thenReturn(branch); when(txData.getGraph()).thenReturn(graph); r1Guid = GUID.create(); r2Guid = GUID.create(); r3Guid = GUID.create(); when(artifactId1.getGuid()).thenReturn(r1Guid); when(artifactId2.getGuid()).thenReturn(r2Guid); when(artifactId3.getGuid()).thenReturn(r3Guid); when(readable1.getGuid()).thenReturn(r1Guid); when(readable2.getGuid()).thenReturn(r2Guid); when(readable3.getGuid()).thenReturn(r3Guid); when(readable1.getBranch()).thenReturn(branch); when(readable2.getBranch()).thenReturn(branch); when(readable3.getBranch()).thenReturn(branch); when(artifact1.getGuid()).thenReturn(r1Guid); when(artifact2.getGuid()).thenReturn(r2Guid); when(artifact3.getGuid()).thenReturn(r3Guid); when(artifact1.getBranch()).thenReturn(branch); when(artifact2.getBranch()).thenReturn(branch); when(artifact3.getBranch()).thenReturn(branch); }
@Test public void testCopyArtifactId() throws OseeCoreException { when(txData.isCommitInProgress()).thenReturn(false); when(txData.getTxState()).thenReturn(TxState.NEW_TX); when(txData.getWriteable(artifactId1)).thenReturn(artifact1); when(artifact1.getExistingAttributeTypes()).thenAnswer(answerValue(types)); when(artifactFactory.copyArtifact(session, artifact1, types, branch)).thenReturn(artifact2); when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); ArtifactReadable actual = txDataManager.copyArtifact(txData, branch, artifactId1); verify(txData).getWriteable(artifactId1); verify(artifactFactory).copyArtifact(session, artifact1, types, branch); verify(proxyManager).asExternalArtifact(session, artifact2); assertEquals(readable2, actual); }