예제 #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);
  }
예제 #2
0
  @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);
  }
예제 #3
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);
  }
예제 #4
0
  @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);
  }
예제 #5
0
  @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);
  }
예제 #6
0
  @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);
  }
예제 #7
0
  @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);
  }
예제 #8
0
  @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);
  }