示例#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 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);
  }
示例#3
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);
  }
示例#4
0
  @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());
  }
示例#5
0
  @Test
  public void testSetComment() throws OseeCoreException {
    when(txData.isCommitInProgress()).thenReturn(false);
    when(txData.getTxState()).thenReturn(TxState.NEW_TX);

    txDataManager.setComment(txData, "this is a comment");
    verify(txData).setComment("this is a comment");
  }
示例#6
0
  @Test
  public void testSetCommentChangesNotAllowed() throws OseeCoreException {
    when(txData.isCommitInProgress()).thenReturn(true);

    thrown.expect(OseeStateException.class);
    thrown.expectMessage("Changes are not allowed - [COMMIT_IN_PROGRESS]");
    txDataManager.setComment(txData, "trying to commit");
  }
示例#7
0
  @Test
  public void testSetAuthor() throws OseeCoreException {
    when(txData.isCommitInProgress()).thenReturn(false);
    when(txData.getTxState()).thenReturn(TxState.NEW_TX);

    txDataManager.setAuthor(txData, readable1);

    verify(txData).setAuthor(readable1);
  }
示例#8
0
  @Test
  public void testStartTxCommitInProgress() throws OseeCoreException {
    when(txData.isCommitInProgress()).thenReturn(true);

    thrown.expect(OseeCoreException.class);
    thrown.expectMessage("Commit is already in progress");

    txDataManager.startTx(txData);
  }
示例#9
0
  @Test
  public void testStartTx() throws OseeCoreException {
    when(txData.isCommitInProgress()).thenReturn(false);

    txDataManager.startTx(txData);

    verify(txData).setCommitInProgress(true);
    verify(txData).setTxState(TxState.COMMIT_STARTED);
  }
示例#10
0
  @Test
  public void testUnrelateFromAll() throws OseeCoreException {
    when(txData.getWriteable(readable1)).thenReturn(artifact1);
    when(txData.getGraph()).thenReturn(graph);

    ArtifactData data = Mockito.mock(ArtifactData.class);
    when(artifact1.getOrcsData()).thenReturn(data);
    when(data.isUseBackingData()).thenReturn(false);

    txDataManager.unrelateFromAll(txData, readable1);

    verify(relationManager).unrelateFromAll(session, artifact1);
  }
示例#11
0
  @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);
  }
示例#12
0
  @Test
  public void testTxCommitSuccess() {
    Iterable<Artifact> writeables = Arrays.asList(artifact1);
    List<Relation> empty = Collections.emptyList();

    when(txData.getGraph()).thenReturn(graph);
    when(txData.getAllWriteables()).thenReturn(writeables);
    when(graph.getAdjacencies(artifact1)).thenReturn(adjacencies);
    when(adjacencies.getDirties()).thenReturn(empty);

    txDataManager.txCommitSuccess(txData);
    verify(txData).setTxState(TxState.COMMITTED);
  }
示例#13
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);
  }
示例#14
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);
  }
示例#15
0
  @Test
  public void testRelate() 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.relate(txData, readable1, DEFAULT_HIERARCHY, readable2);

    verify(relationManager).relate(session, artifact1, DEFAULT_HIERARCHY, artifact2);
  }
示例#16
0
  @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);
  }
示例#17
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);
  }
示例#18
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);
  }
示例#19
0
  @Test
  public void testGetForWriteId() throws OseeCoreException {
    when(txData.getWriteable(artifactId1)).thenReturn(null);

    ResultSet<Artifact> loaded = ResultSets.singleton(artifact1);
    when(loader.loadArtifacts(eq(session), eq(graph), anyCollectionOf(ArtifactId.class)))
        .thenReturn(loaded);

    ArtifactData data = Mockito.mock(ArtifactData.class);
    when(artifact1.getOrcsData()).thenReturn(data);
    when(data.isUseBackingData()).thenReturn(false);

    Artifact actual = txDataManager.getForWrite(txData, artifactId1);

    verify(txData).getWriteable(artifactId1);
    verify(loader).loadArtifacts(eq(session), eq(graph), idCaptor.capture());

    assertEquals(artifactId1, idCaptor.getValue().iterator().next());
    assertEquals(artifact1, actual);
  }
示例#20
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);
  }
示例#21
0
  @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);
  }
示例#22
0
  @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());
  }
示例#23
0
 @Test
 public void testCreateTxData() throws OseeCoreException {
   TxData newData = txDataManager.createTxData(session, branch);
   assertNotNull(newData);
 }
示例#24
0
  @Test
  public void testRollbackTx() {
    txDataManager.rollbackTx(txData);

    verify(txData).setTxState(TxState.COMMIT_FAILED);
  }
示例#25
0
  @Test
  public void testEndTx() {
    txDataManager.endTx(txData);

    verify(txData).setCommitInProgress(false);
  }