Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
  @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);
  }