Beispiel #1
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);
  }
Beispiel #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);
  }
Beispiel #3
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());
  }
Beispiel #4
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);
  }
Beispiel #5
0
 @Override
 public ArtifactData introduce(IOseeBranch destination, ArtifactData source)
     throws OseeCoreException {
   ArtifactData newVersion = objectFactory.createCopy(source);
   newVersion.setUseBackingData(true);
   updateDataForIntroduce(destination, newVersion);
   return newVersion;
 }
Beispiel #6
0
 @Override
 public ArtifactData copy(IOseeBranch destination, ArtifactData source) throws OseeCoreException {
   ArtifactData copy = objectFactory.createCopy(source);
   updateDataForCopy(destination, copy);
   copy.setGuid(idFactory.getUniqueGuid(null));
   copy.setLocalId(idFactory.getNextArtifactId());
   return copy;
 }
Beispiel #7
0
 @Override
 public AttributeData create(ArtifactData parent, IAttributeType attributeType)
     throws OseeCoreException {
   VersionData version = objectFactory.createDefaultVersionData();
   version.setBranchId(parent.getVersion().getBranchId());
   ModificationType modType = RelationalConstants.DEFAULT_MODIFICATION_TYPE;
   Integer attributeid = RelationalConstants.DEFAULT_ITEM_ID;
   return objectFactory.createAttributeData(
       version, attributeid, attributeType, modType, parent.getLocalId());
 }
Beispiel #8
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);
  }
Beispiel #9
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);
  }
Beispiel #10
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);
  }
Beispiel #11
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);
  }
Beispiel #12
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);
  }
Beispiel #13
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);
  }
Beispiel #14
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);
  }
Beispiel #15
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);
  }
Beispiel #16
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);
  }
Beispiel #17
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);
  }
Beispiel #18
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);
  }
Beispiel #19
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());
  }
 @Override
 public void visit(ArtifactData data) throws OseeCoreException {
   if (!isNewAndDeleted(data)) {
     if (!data.getVersion().isInStorage()
         || data.getLoadedTypeUuid() != data.getTypeUuid()
         || data.getModType() != data.getLoadedModType()
         || data.getModType() == ModificationType.REPLACED_WITH_VERSION) {
       boolean isRowAllowed = isGammaCreationAllowed(data);
       updateTxValues(data);
       if (isRowAllowed) {
         updateGamma(data);
         int localTypeId = getLocalTypeId(data.getTypeUuid());
         addRow(
             SqlOrderEnum.ARTIFACTS,
             data.getLocalId(),
             localTypeId,
             data.getVersion().getGammaId(),
             data.getGuid(),
             data.getHumanReadableId());
       }
       addTxs(SqlOrderEnum.ARTIFACTS, data);
     }
   }
 }