@Test public void testGetForWriteMultiples() throws OseeCoreException { List<? extends ArtifactId> ids = Arrays.asList(artifactId1, artifactId2, artifactId3); when(txData.getWriteable(artifactId2)).thenReturn(artifact2); List<Artifact> artifacts = Arrays.asList(artifact1, artifact3); ResultSet<Artifact> loaded = ResultSets.newResultSet(artifacts); when(loader.loadArtifacts(eq(session), eq(graph), anyCollectionOf(ArtifactId.class))) .thenReturn(loaded); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(artifact3.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); Iterable<Artifact> actual = txDataManager.getForWrite(txData, ids); verify(loader).loadArtifacts(eq(session), eq(graph), idCaptor.capture()); Iterator<ArtifactId> iterator1 = idCaptor.getValue().iterator(); assertEquals(artifactId1, iterator1.next()); assertEquals(artifactId3, iterator1.next()); Iterator<Artifact> iterator2 = actual.iterator(); assertEquals(artifact1, iterator2.next()); assertEquals(artifact2, iterator2.next()); assertEquals(artifact3, iterator2.next()); }
@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 = ResultSets.singleton(artifact1); when(loader.loadArtifacts(eq(session), eq(COMMON), anyCollectionOf(ArtifactId.class))) .thenReturn(loaded); when(artifactFactory.introduceArtifact(session, artifact1, artifact1, branch)) .thenReturn(artifact2); when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2); when(artifact1.getGraph()).thenReturn(graph); when(graph.getAdjacencies(artifact1)).thenReturn(adjacencies); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); ArtifactReadable actual = txDataManager.introduceArtifact(txData, COMMON, readable1, readable2); verify(artifactFactory).introduceArtifact(session, artifact1, artifact1, branch); verify(proxyManager).asExternalArtifact(session, artifact1); assertEquals(readable1, 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(artifact1); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); when(artifactFactory.copyArtifact(session, artifact1, 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(session, artifact1, types, branch); verify(proxyManager).asExternalArtifact(session, artifact2); assertEquals(readable2, actual); }
@Test public void testDeleteArtifact() throws OseeCoreException { when(artifactFactory.clone(session, artifact1)).thenReturn(artifact2); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); txDataManager.deleteArtifact(txData, artifact1); verify(artifact2).delete(); verify(relationManager).unrelateFromAll(session, artifact2); }
@Test public void testUnrelate() throws OseeCoreException { when(txData.getWriteable(readable1)).thenReturn(artifact1); when(txData.getWriteable(readable2)).thenReturn(artifact2); when(txData.getGraph()).thenReturn(graph); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); txDataManager.unrelate(txData, readable1, DEFAULT_HIERARCHY, readable2); verify(relationManager).unrelate(session, artifact1, DEFAULT_HIERARCHY, artifact2); }
@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); }
@Test public void testSetRationale() throws OseeCoreException { String rationale = "i have no rationale"; when(txData.getWriteable(readable1)).thenReturn(artifact1); when(txData.getWriteable(readable2)).thenReturn(artifact3); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact3.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); txDataManager.setRationale(txData, readable1, DEFAULT_HIERARCHY, readable2, rationale); verify(relationManager) .setRationale(session, artifact1, DEFAULT_HIERARCHY, artifact3, rationale); }
@Test public void testGetForWriteArtifact() throws OseeCoreException { when(txData.getWriteable(artifact1)).thenReturn(null); when(artifactFactory.clone(session, artifact1)).thenReturn(artifact2); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); Artifact actual = txDataManager.getForWrite(txData, artifact1); verify(txData).getWriteable(artifact1); verify(artifactFactory).clone(session, artifact1); assertEquals(artifact2, actual); }
@Test public void testGetForWriteReadableButIsFromDifferentBranch() throws OseeCoreException { when(readable1.getBranch()).thenReturn(CoreBranches.COMMON); when(txData.getWriteable(readable1)).thenReturn(null); when(proxyManager.asInternalArtifact(readable1)).thenReturn(artifact1); when(artifactFactory.clone(session, artifact1)).thenReturn(artifact2); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); Artifact actual = txDataManager.getForWrite(txData, readable1); verify(txData).getWriteable(readable1); verify(proxyManager).asInternalArtifact(readable1); verify(artifact1).getBranch(); assertEquals(artifact2, actual); }
@Test public void testCreateChangeData() throws OseeCoreException { Iterable<Artifact> writeables = Arrays.asList(artifact1); when(txData.getAllWriteables()).thenReturn(writeables); when(artifact1.isDirty()).thenReturn(true); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); TransactionData changeData = txDataManager.createChangeData(txData); assertNotNull(changeData); }
@Test public void testSetRelations() throws OseeCoreException { when(txData.getWriteable(readable1)).thenReturn(artifact1); when(txData.getWriteable(readable2)).thenReturn(artifact2); when(txData.getWriteable(readable3)).thenReturn(artifact3); when(txData.getGraph()).thenReturn(graph); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(artifact3.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); ResultSet<Artifact> related = ResultSets.singleton(artifact3); when(relationManager.<Artifact>getRelated(session, DEFAULT_HIERARCHY, artifact1, SIDE_A)) .thenReturn(related); when(txData.getWriteable(artifact3)).thenReturn(artifact3); txDataManager.setRelations(txData, readable1, DEFAULT_HIERARCHY, Arrays.asList(readable2)); verify(relationManager).relate(session, artifact1, DEFAULT_HIERARCHY, artifact2); verify(relationManager).unrelate(session, artifact1, DEFAULT_HIERARCHY, artifact3); }
@Test public void testAddChildren() throws OseeCoreException { List<? extends ArtifactReadable> children = Arrays.asList(readable2, readable3); when(txData.getWriteable(readable1)).thenReturn(artifact1); when(txData.getWriteable(readable2)).thenReturn(artifact2); when(txData.getWriteable(readable3)).thenReturn(artifact3); when(txData.getGraph()).thenReturn(graph); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(artifact3.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); txDataManager.addChildren(txData, readable1, children); verify(relationManager).addChildren(eq(session), eq(artifact1), nodeCaptor.capture()); Iterator<? extends RelationNode> iterator = nodeCaptor.getValue().iterator(); assertEquals(artifact2, iterator.next()); assertEquals(artifact3, iterator.next()); }
@Test public void testGetForWriteDuringWrite() throws OseeCoreException { when(txData.add(artifact1)).thenReturn(artifact3); when(artifactFactory.clone(session, artifact1)).thenReturn(artifact1); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); thrown.expect(OseeArgumentException.class); thrown.expectMessage( "Another instance of writeable detected - writeable tracking would be inconsistent"); txDataManager.getForWrite(txData, readable1); }
@Test public void testGetForWriteArtifactButIsFromDifferentBranch() throws OseeCoreException { when(artifact1.getBranch()).thenReturn(CoreBranches.COMMON); when(txData.getWriteable(readable1)).thenReturn(null); ResultSet<Artifact> loaded = ResultSets.singleton(artifact2); when(loader.loadArtifacts(eq(session), eq(graph), anyCollectionOf(ArtifactId.class))) .thenReturn(loaded); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(artifact2.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); Artifact actual = txDataManager.getForWrite(txData, artifact1); verify(txData).getWriteable(artifact1); verify(artifact1).getBranch(); verify(loader).loadArtifacts(eq(session), eq(graph), idCaptor.capture()); assertEquals(artifact1, idCaptor.getValue().iterator().next()); assertEquals(artifact2, actual); }
@Test public void testCreateArtifact() throws OseeCoreException { when(txData.isCommitInProgress()).thenReturn(false); when(txData.getTxState()).thenReturn(TxState.NEW_TX); when(artifactFactory.createArtifact(session, branch, DirectSoftwareRequirement, guid)) .thenReturn(artifact1); when(proxyManager.asExternalArtifact(session, artifact1)).thenReturn(readable1); ArtifactData data = Mockito.mock(ArtifactData.class); when(artifact1.getOrcsData()).thenReturn(data); when(data.isUseBackingData()).thenReturn(false); ArtifactReadable actual = txDataManager.createArtifact( txData, DirectSoftwareRequirement, "Direct SW requirement", guid); verify(artifactFactory).createArtifact(session, branch, DirectSoftwareRequirement, guid); assertEquals(readable1, actual); }