diff options
author | David W. Miller | 2012-05-23 17:55:37 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2012-05-23 17:55:37 +0000 |
commit | f6fefbd78479fd2685cc9544578f490b80c79e53 (patch) | |
tree | 919958ba43d3b855b6fa0229709895ff3abe8837 | |
parent | ad438e8b6fc798b0e21c4a770d3c46257739676a (diff) | |
download | org.eclipse.osee-f6fefbd78479fd2685cc9544578f490b80c79e53.tar.gz org.eclipse.osee-f6fefbd78479fd2685cc9544578f490b80c79e53.tar.xz org.eclipse.osee-f6fefbd78479fd2685cc9544578f490b80c79e53.zip |
feature[ats_MCQKT]: Add integration test for branch copy with transaction
12 files changed, 150 insertions, 34 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java index ce2fd7d3ac3..24b852e230d 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java @@ -77,4 +77,9 @@ public class MockOseeTransactionDataAccessor implements ITransactionDataAccessor return null; } + @Override + public TransactionRecord getHeadTransaction(TransactionCache cache, Branch branch) throws OseeCoreException { + return null; + } + } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java index a4be2eb8c13..91bb72a88ae 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java @@ -44,4 +44,6 @@ public interface ITransactionDataAccessor { public TransactionRecord getOrLoadPriorTransaction(TransactionCache cache, int transactionNumber, int branchId) throws OseeCoreException; + public TransactionRecord getHeadTransaction(TransactionCache cache, Branch branch) throws OseeCoreException; + }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java index b0f41fa280f..03990a9b9bb 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java @@ -163,6 +163,10 @@ public class TransactionCache implements IOseeCache<String, TransactionRecord> { return toReturn; } + public TransactionRecord getHeadTransaction(Branch branch) throws OseeCoreException { + return accessor.getHeadTransaction(this, branch); + } + public Collection<TransactionRecord> getTransactions(Branch branch) { return Collections.emptyList(); } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItem.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItem.java index 30c8e4574d8..f176e4f5ffe 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItem.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItem.java @@ -15,7 +15,7 @@ import org.eclipse.osee.framework.core.enums.ModificationType; /** * @author Roberto E. Escobar */ -public abstract class ChangeItem { +public abstract class ChangeItem implements Comparable<ChangeItem> { private final int artId; private final int itemId; private final int itemTypeId; @@ -90,4 +90,45 @@ public abstract class ChangeItem { itemId, getArtId(), getItemTypeId(), getBaselineVersion(), getFirstNonCurrentChange(), getCurrentVersion(), getDestinationVersion(), getNetChange(), isSynthetic()); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof ChangeItem)) { + return false; + } + + ChangeItem other = (ChangeItem) obj; + + if (itemId != other.itemId) { + return false; + } + if (artId != other.artId) { + return false; + } + if (currentEntry == null) { + if (other.currentEntry != null) { + return false; + } + } + if (!currentEntry.equals(other.currentEntry)) { + return false; + } + if (itemTypeId != other.itemTypeId) { + return false; + } + return true; + } + + @Override + public int compareTo(ChangeItem obj) { + return itemId - obj.itemId; + } + + @Override + public int hashCode() { + return itemId; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java index eb3a2b632d0..214c7afcd20 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java @@ -36,7 +36,8 @@ public class ClientTransactionAccessor implements ITransactionDataAccessor { private static final String GET_PRIOR_TRANSACTION = "select transaction_id FROM osee_tx_details where branch_id = ? and transaction_id < ? order by transaction_id desc"; - + private static final String TX_GET_MAX_AS_LARGEST_TX = + "SELECT max(transaction_id) as largest_transaction_id FROM osee_tx_details WHERE branch_id = ?"; private final TransactionRecordFactory txFactory; private final BranchCache branchCache; @@ -85,4 +86,9 @@ public class ClientTransactionAccessor implements ITransactionDataAccessor { transactionNumber); return cache.getOrLoad(priorTransactionId); } + + @Override + public TransactionRecord getHeadTransaction(TransactionCache cache, Branch branch) throws OseeCoreException { + return cache.getOrLoad(ConnectionHandler.runPreparedQueryFetchInt(-1, TX_GET_MAX_AS_LARGEST_TX, branch.getId())); + } } diff --git a/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java b/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java index 770b05476ff..975dbbeae5b 100644 --- a/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java +++ b/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java @@ -5,11 +5,14 @@ */ package org.eclipse.osee.orcs.core.internal; +import java.util.Collections; +import java.util.List; import java.util.concurrent.Callable; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.core.model.ReadableBranch; +import org.eclipse.osee.framework.core.model.change.ChangeItem; import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.orcs.ApplicationContext; import org.eclipse.osee.orcs.OrcsApi; @@ -54,27 +57,16 @@ public class OrcsBranchTest { public void testCreateBranch() throws Exception { int SOURCE_TX_ID = 13; // Chosen starting transaction on Common Branch int CHANGED_TX_ID = 14; // Transaction containing tested change - int MERGE_DESTINATION_BRANCH_ID = -1; // only used on merge branches - int MERGE_ADDRESSING_QUERY_ID = -1; // only used on merge branches // set up the query factory for the test QueryFactory qf = orcsApi.getQueryFactory(context); - - CreateBranchData createData = new CreateBranchData(); - createData.setGuid(GUID.create()); - createData.setName("Prior Branch"); - createData.setBranchType(BranchType.WORKING); - createData.setCreationComment("Creation of initial working branch for test"); - createData.setFromTransaction(TokenFactory.createTransaction(SOURCE_TX_ID)); - + // ReadableArtifact createdBy = + // qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getExactlyOne(); ReadableArtifact createdBy = - qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getExactlyOne(); - createData.setUserArtifact(createdBy); - - createData.setAssociatedArtifact(createdBy); - createData.setMergeDestinationBranchId(MERGE_DESTINATION_BRANCH_ID); + qf.fromBranch(CoreBranches.COMMON).andNameEquals("OSEE System").getResults().getExactlyOne(); - createData.setMergeAddressingQueryId(MERGE_ADDRESSING_QUERY_ID); + CreateBranchData createData = + makeBranchData(qf, "PriorBranch", "Creation of initial working branch for test", SOURCE_TX_ID, createdBy, true); Callable<ReadableBranch> callable = branchInterface.createBranch(createData); Assert.assertNotNull(callable); ReadableBranch priorBranch = callable.call(); @@ -95,21 +87,9 @@ public class OrcsBranchTest { // user Joe Smith, so if the code is correct, and the copy includes the final // transaction, then this will produce the same result as the query of the common branch - CreateBranchData createDataNew = new CreateBranchData(); - createDataNew.setGuid(GUID.create()); - createDataNew.setName("PostBranch"); - createDataNew.setBranchType(BranchType.WORKING); - createDataNew.setCreationComment("Creation of branch with transaction ID equal to the change test"); - createDataNew.setFromTransaction(TokenFactory.createTransaction(CHANGED_TX_ID)); - - ReadableArtifact createdByNew = - qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getExactlyOne(); - createData.setUserArtifact(createdByNew); - - createData.setAssociatedArtifact(createdByNew); - createData.setMergeDestinationBranchId(MERGE_DESTINATION_BRANCH_ID); - - createData.setMergeAddressingQueryId(MERGE_ADDRESSING_QUERY_ID); + CreateBranchData createDataNew = + makeBranchData(qf, "PostBranch", "Creation of branch with transaction ID equal to the change test", + CHANGED_TX_ID, createdBy, true); Callable<ReadableBranch> postCallable = branchInterface.createBranch(createDataNew); Assert.assertNotNull(postCallable); ReadableBranch postBranch = postCallable.call(); @@ -119,4 +99,56 @@ public class OrcsBranchTest { } + @Test + public void testCreateBranchCopyFromTx() throws Exception { + // this test shows that the change report for a transaction for the newly copied branch is + // the same as the change report on the branch the transaction is copied from + int PRIOR_TX_ID = 15; + int SOURCE_TX_ID = 16; + + // get the list of changes from the original branch + Callable<List<ChangeItem>> callable = + branchInterface.compareBranch(TokenFactory.createTransaction(PRIOR_TX_ID), + TokenFactory.createTransaction(SOURCE_TX_ID)); + List<ChangeItem> priorItems = callable.call(); + + // create the branch with the copied transaction + QueryFactory qf = orcsApi.getQueryFactory(context); + ReadableArtifact createdBy = + qf.fromBranch(CoreBranches.COMMON).andNameEquals("OSEE System").getResults().getExactlyOne(); + + CreateBranchData createData = + makeBranchData(qf, "CopiedBranch", "Creation of branch with copied tx for test", SOURCE_TX_ID, createdBy, true); + Callable<ReadableBranch> callableBranch = branchInterface.createBranch(createData); + + // the new branch will contain two transactions - these should have the same change report as the original branch + ReadableBranch postBranch = callableBranch.call(); + + callable = branchInterface.compareBranch(postBranch); + List<ChangeItem> newItems = callable.call(); + compareBranchChanges(priorItems, newItems); + } + + private CreateBranchData makeBranchData(QueryFactory qf, String name, String creationComment, int fromTransaction, ReadableArtifact userArtifact, boolean copyTx) { + int MERGE_DESTINATION_BRANCH_ID = -1; // only used on merge branches + int MERGE_ADDRESSING_QUERY_ID = -1; // only used on merge branches + CreateBranchData createData = new CreateBranchData(); + createData.setGuid(GUID.create()); + createData.setName(name); + createData.setBranchType(BranchType.WORKING); + createData.setCreationComment(creationComment); + createData.setFromTransaction(TokenFactory.createTransaction(fromTransaction)); + createData.setUserArtifact(userArtifact); + createData.setAssociatedArtifact(userArtifact); + createData.setMergeDestinationBranchId(MERGE_DESTINATION_BRANCH_ID); + createData.setMergeAddressingQueryId(MERGE_ADDRESSING_QUERY_ID); + createData.setTxCopyBranchType(copyTx); + return createData; + } + + private void compareBranchChanges(List<ChangeItem> priorItems, List<ChangeItem> newItems) { + Collections.sort(priorItems); + Collections.sort(newItems); + Assert.assertEquals(priorItems, newItems); + } } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java index 6342029bb1f..0428339f303 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.concurrent.Callable; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.core.model.change.ChangeItem; @@ -37,6 +38,8 @@ public interface BranchDataStore { Callable<List<ChangeItem>> compareBranch(String sessionId, TransactionRecord sourceTx, TransactionRecord destinationTx); + Callable<List<ChangeItem>> compareBranch(String sessionId, Branch branch) throws OseeCoreException; + Callable<URI> exportBranch(List<IOseeBranch> branches, PropertyStore options, String exportName); Callable<URI> importBranch(URI fileToImport, List<IOseeBranch> branches, PropertyStore options); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java index 958026ec5c3..f92f311cb26 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java @@ -90,6 +90,11 @@ public class OrcsBranchImpl implements OrcsBranch { } @Override + public Callable<List<ChangeItem>> compareBranch(IOseeBranch branch) throws OseeCoreException { + return branchStore.compareBranch(sessionContext.toString(), branchCache.get(branch)); + } + + @Override public Callable<ReadableBranch> changeBranchState(IOseeBranch branch, BranchState newState) { return new ChangeBranchStateCallable(logger, sessionContext, branchStore, branchCache, branch, newState); } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseTransactionRecordAccessor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseTransactionRecordAccessor.java index de5a5402e43..ab5fea49dd1 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseTransactionRecordAccessor.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseTransactionRecordAccessor.java @@ -27,6 +27,7 @@ import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.framework.database.core.IdJoinQuery; import org.eclipse.osee.framework.database.core.JoinUtility; import org.eclipse.osee.framework.jdk.core.type.MutableInteger; +import org.eclipse.osee.orcs.db.internal.sql.OseeSql; /** * @author Roberto E. Escobar @@ -175,4 +176,10 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess oseeDatabaseService.runPreparedQueryFetchObject(-1, GET_PRIOR_TRANSACTION, branchId, transactionNumber); return cache.getOrLoad(priorTransactionId); } + + @Override + public TransactionRecord getHeadTransaction(TransactionCache cache, Branch branch) throws OseeCoreException { + return cache.getOrLoad(oseeDatabaseService.runPreparedQueryFetchObject(-1, + OseeSql.TX_GET_MAX_AS_LARGEST_TX.getSql(), branch.getId())); + } } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java index a0b9533353a..f6baab6cf7a 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java @@ -16,8 +16,10 @@ import java.util.concurrent.Callable; import org.eclipse.osee.executor.admin.ExecutorAdmin; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.TransactionRecord; +import org.eclipse.osee.framework.core.model.cache.TransactionCache; import org.eclipse.osee.framework.core.model.change.ChangeItem; import org.eclipse.osee.framework.core.services.IOseeCachingService; import org.eclipse.osee.framework.core.services.IOseeModelFactoryService; @@ -126,6 +128,13 @@ public class BranchDataStoreImpl implements BranchDataStore { } @Override + public Callable<List<ChangeItem>> compareBranch(String sessionId, Branch branch) throws OseeCoreException { + TransactionCache txCache = cachingService.getTransactionCache(); + return new CompareDatabaseCallable(logger, dbService, cachingService.getBranchCache(), txCache, + branch.getBaseTransaction(), txCache.getHeadTransaction(branch)); + } + + @Override public Callable<URI> exportBranch(List<IOseeBranch> branches, PropertyStore options, String exportName) { ExportItemFactory factory = new ExportItemFactory(logger, dbService, cachingService, typeModelService, resourceManager); diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/OseeSql.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/OseeSql.java index e7a345cb23b..9583b1d22ae 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/OseeSql.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/OseeSql.java @@ -85,7 +85,7 @@ public enum OseeSql { this.isDynamicHint = isDynamicHint; } - protected String getSql() { + public String getSql() { return sql; } diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java index 99adb29ac65..3944013adc5 100644 --- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java @@ -43,6 +43,8 @@ public interface OrcsBranch { Callable<List<ChangeItem>> compareBranch(ITransaction sourceTx, ITransaction destinationTx); + Callable<List<ChangeItem>> compareBranch(IOseeBranch branch) throws OseeCoreException; + Callable<ReadableBranch> changeBranchState(IOseeBranch branch, BranchState newState); Callable<ReadableBranch> changeBranchType(IOseeBranch branch, BranchType branchType); |