diff options
author | Roberto E. Escobar | 2013-08-13 19:59:28 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-08-21 20:29:46 +0000 |
commit | 88ce034a1fa133ebb880b13ee6427ecfc524b216 (patch) | |
tree | cd1436bf5fa150eb932bdeeb69a37265ea3c5c07 | |
parent | 6b7b7d0e67c7e3f7059a041704167fcb38ce0834 (diff) | |
download | org.eclipse.osee-88ce034a1fa133ebb880b13ee6427ecfc524b216.tar.gz org.eclipse.osee-88ce034a1fa133ebb880b13ee6427ecfc524b216.tar.xz org.eclipse.osee-88ce034a1fa133ebb880b13ee6427ecfc524b216.zip |
refactor: ORCS test clean-up
Change-Id: Ib72b13dd097ce2b5d340919442c10aa741aa040d
8 files changed, 259 insertions, 294 deletions
diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeLoadingTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeLoadingTest.java index 5529b4eb072..204218f9f1b 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeLoadingTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeLoadingTest.java @@ -11,6 +11,9 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -20,15 +23,15 @@ import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.core.enums.Operator; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.model.cache.BranchCache; import org.eclipse.osee.orcs.ApplicationContext; import org.eclipse.osee.orcs.OrcsApi; import org.eclipse.osee.orcs.data.ArtifactReadable; import org.eclipse.osee.orcs.db.mock.OsgiService; import org.eclipse.osee.orcs.search.QueryBuilder; import org.eclipse.osee.orcs.search.QueryFactory; -import org.junit.Assert; +import org.junit.Before; import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TestRule; /** @@ -42,52 +45,54 @@ public class OrcsAttributeLoadingTest { @OsgiService private OrcsApi orcsApi; - @org.junit.Test - public void testAttributeLoading() throws Exception { + private QueryFactory query; + + @Before + public void setUp() throws Exception { ApplicationContext context = null; // TODO use real application context + query = orcsApi.getQueryFactory(context); + } - QueryFactory queryFactory = orcsApi.getQueryFactory(context); - QueryBuilder builder = queryFactory.fromBranch(CoreBranches.COMMON).andLocalIds(Arrays.asList(6, 7, 8)); + @Test + public void testAttributeLoading() throws Exception { + QueryBuilder builder = query.fromBranch(CoreBranches.COMMON).andLocalIds(Arrays.asList(6, 7, 8)); ResultSet<ArtifactReadable> resultSet = builder.getResults(); List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertEquals(3, moreArts.size()); - Assert.assertEquals(3, builder.getCount()); + assertEquals(3, moreArts.size()); + assertEquals(3, builder.getCount()); - Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + Map<Integer, ArtifactReadable> lookup = createLookup(moreArts); ArtifactReadable art6 = lookup.get(6); ArtifactReadable art7 = lookup.get(7); ArtifactReadable art8 = lookup.get(8); //Test loading name attributes - Assert.assertEquals(art6.getSoleAttributeAsString(CoreAttributeTypes.Name), + assertEquals(art6.getSoleAttributeAsString(CoreAttributeTypes.Name), "org.eclipse.osee.coverage.OseeTypes_Coverage"); - Assert.assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups"); - Assert.assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone"); + assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups"); + assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone"); //Test boolean attributes - Assert.assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.DefaultGroup), "true"); - - //Load WTC attributes - loadWordTemplateContentAttributes(queryFactory, orcsApi.getBranchCache()); + assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.DefaultGroup), "true"); } - private void loadWordTemplateContentAttributes(QueryFactory queryFactory, BranchCache branchCache) throws OseeCoreException { + @Test + public void testLoadWordTemplateContentAttributes() throws OseeCoreException { QueryBuilder builder = - queryFactory.fromBranch(branchCache.getByName("SAW_Bld_1").iterator().next()).and(CoreAttributeTypes.Name, - Operator.EQUAL, "Haptic Constraints"); + query.fromBranch(TestBranches.SAW_Bld_1).and(CoreAttributeTypes.Name, Operator.EQUAL, "Haptic Constraints"); ResultSet<ArtifactReadable> resultSet = builder.getResults(); List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertFalse(moreArts.isEmpty()); - Assert.assertTrue(builder.getCount() > 0); - ArtifactReadable artifact = moreArts.iterator().next(); - Assert.assertTrue(artifact.getSoleAttributeAsString(CoreAttributeTypes.WordTemplateContent).length() > 2); + assertTrue(artifact.getSoleAttributeAsString(CoreAttributeTypes.WordTemplateContent).length() > 2); + + assertFalse(moreArts.isEmpty()); + assertEquals(moreArts.size(), builder.getCount()); } - Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) { + private Map<Integer, ArtifactReadable> createLookup(List<ArtifactReadable> arts) { Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>(); for (ArtifactReadable artifact : arts) { lookup.put(artifact.getLocalId(), artifact); diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeSearchTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeSearchTest.java index 11d8fac35ce..4e7ae099a49 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeSearchTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeSearchTest.java @@ -11,6 +11,9 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,15 +26,12 @@ import org.eclipse.osee.framework.core.enums.Operator; import org.eclipse.osee.framework.core.enums.TokenDelimiterMatch; import org.eclipse.osee.framework.core.enums.TokenOrderType; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.model.Branch; -import org.eclipse.osee.framework.core.model.cache.BranchCache; import org.eclipse.osee.orcs.ApplicationContext; import org.eclipse.osee.orcs.OrcsApi; import org.eclipse.osee.orcs.data.ArtifactReadable; import org.eclipse.osee.orcs.db.mock.OsgiService; import org.eclipse.osee.orcs.search.QueryBuilder; import org.eclipse.osee.orcs.search.QueryFactory; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -65,7 +65,7 @@ public class OrcsAttributeSearchTest { List<ArtifactReadable> moreArts = resultSet.getList(); for (ArtifactReadable artifact : moreArts) { - Assert.assertTrue(artifact.getLocalId() != 7); + assertTrue(artifact.getLocalId() != 7); } } @@ -77,31 +77,30 @@ public class OrcsAttributeSearchTest { ResultSet<ArtifactReadable> resultSet = builder.getResults(); List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertEquals(1, moreArts.size()); - Assert.assertEquals(1, builder.getCount()); + assertEquals(1, moreArts.size()); + assertEquals(1, builder.getCount()); - Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + Map<Integer, ArtifactReadable> lookup = createLookup(moreArts); ArtifactReadable art7 = lookup.get(7); //Test loading name attributes - Assert.assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups"); + assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups"); } @Test public void testWTCAttributeEqualSearch() throws OseeCoreException { - BranchCache branchCache = orcsApi.getBranchCache(); - Branch branch = branchCache.getBySoleName("SAW_Bld_1"); QueryBuilder builder = - queryFactory.fromBranch(branch).and(CoreAttributeTypes.WordTemplateContent, "commands", + queryFactory.fromBranch(TestBranches.SAW_Bld_1).and(CoreAttributeTypes.WordTemplateContent, "commands", TokenDelimiterMatch.ANY, TokenOrderType.MATCH_ORDER, CaseType.IGNORE_CASE, MatchTokenCountType.IGNORE_TOKEN_COUNT); + assertEquals(3, builder.getCount()); + ResultSet<ArtifactReadable> resultSet = builder.getResults(); List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertFalse(moreArts.isEmpty()); - Assert.assertEquals(3, moreArts.size()); - Assert.assertEquals(3, builder.getCount()); + assertFalse(moreArts.isEmpty()); + assertEquals(3, moreArts.size()); } @Test @@ -111,15 +110,15 @@ public class OrcsAttributeSearchTest { ResultSet<ArtifactReadable> resultSet = builder.getResults(); List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertEquals(1, moreArts.size()); - Assert.assertEquals(1, builder.getCount()); + assertEquals(1, moreArts.size()); + assertEquals(1, builder.getCount()); - Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + Map<Integer, ArtifactReadable> lookup = createLookup(moreArts); ArtifactReadable art8 = lookup.get(8); - Assert.assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone"); + assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone"); } - private Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) { + private Map<Integer, ArtifactReadable> createLookup(List<ArtifactReadable> arts) { Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>(); for (ArtifactReadable artifact : arts) { lookup.put(artifact.getLocalId(), artifact); diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchTest.java index 830d83b5ada..22135eedee8 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchTest.java @@ -11,6 +11,9 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; @@ -34,7 +37,7 @@ import org.eclipse.osee.orcs.data.ArtifactWriteable; import org.eclipse.osee.orcs.db.mock.OsgiService; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.transaction.OrcsTransaction; -import org.junit.Assert; +import org.eclipse.osee.orcs.transaction.TransactionFactory; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -45,20 +48,24 @@ import org.junit.rules.TestRule; */ public class OrcsBranchTest { + private static final String ARTIFACT_NAME = "Joe Smith"; + @Rule public TestRule osgi = integrationRule(this, "osee.demo.hsql"); - private OrcsBranch branchInterface = null; - private final ApplicationContext context = null; // TODO use real application context - - private final static String ARTIFACT_NAME = "Joe Smith"; - @OsgiService private OrcsApi orcsApi; + private OrcsBranch branchInterface; + private QueryFactory query; + private TransactionFactory txFactory; + @Before public void setUp() throws Exception { + ApplicationContext context = null; branchInterface = orcsApi.getBranchOps(context); + query = orcsApi.getQueryFactory(context); + txFactory = orcsApi.getTransactionFactory(context); } @Test @@ -66,9 +73,6 @@ public class OrcsBranchTest { int SOURCE_TX_ID = 7; // Chosen starting transaction on Common Branch int CHANGED_TX_ID = 8; // Transaction containing tested change - // set up the query factory for the test - QueryFactory qf = orcsApi.getQueryFactory(context); - // set up the initial branch IOseeBranch branch = TokenFactory.createBranch(GUID.create(), "PriorBranch"); @@ -77,20 +81,20 @@ public class OrcsBranchTest { ITransaction tx = TokenFactory.createTransaction(SOURCE_TX_ID); Callable<ReadableBranch> callable = branchInterface.createCopyTxBranch(branch, author, tx, null); - Assert.assertNotNull(callable); + assertNotNull(callable); ReadableBranch priorBranch = callable.call(); // in the database, on the common branch, the users are all created in transaction 8 // the common branch will have one user named Joe Smith - int coreResult = qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); - Assert.assertEquals(1, coreResult); + int coreResult = query.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); + assertEquals(1, coreResult); // we copied the branch at transaction 7, so, on the copied branch there will not be any // user Joe Smith - int priorResult = qf.fromBranch(priorBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); - Assert.assertEquals(0, priorResult); + int priorResult = query.fromBranch(priorBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); + assertEquals(0, priorResult); // finally, we copy another branch at transaction id 8, this is the transaction that added the // user Joe Smith, so if the code is correct, and the copy includes the final @@ -101,12 +105,11 @@ public class OrcsBranchTest { ITransaction tx1 = TokenFactory.createTransaction(CHANGED_TX_ID); Callable<ReadableBranch> postCallable = branchInterface.createCopyTxBranch(postbranch, author, tx1, null); - Assert.assertNotNull(postCallable); + assertNotNull(postCallable); ReadableBranch postBranch = postCallable.call(); - int postResult = qf.fromBranch(postBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); - Assert.assertEquals(1, postResult); - + int postResult = query.fromBranch(postBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); + assertEquals(1, postResult); } @Test @@ -140,17 +143,15 @@ public class OrcsBranchTest { @Test public void testCommitBranchMissingArtifactsOnDestination() throws Exception { - - QueryFactory qf = orcsApi.getQueryFactory(context); ArtifactReadable author = - qf.fromBranch(CoreBranches.COMMON).andNameEquals("OSEE System").getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andNameEquals("OSEE System").getResults().getExactlyOne(); // set up the initial branch IOseeBranch branch = TokenFactory.createBranch(GUID.create(), "BaseBranch"); Callable<ReadableBranch> callableBranch = branchInterface.createTopLevelBranch(branch, author); ReadableBranch base = callableBranch.call(); // put some changes on the base branch - OrcsTransaction tx = orcsApi.getTransactionFactory(context).createTransaction(base, author, "add some changes"); + OrcsTransaction tx = txFactory.createTransaction(base, author, "add some changes"); ArtifactWriteable folder = tx.createArtifact(CoreArtifactTypes.Folder, "BaseFolder"); tx.commit(); @@ -162,10 +163,9 @@ public class OrcsBranchTest { ReadableBranch childBranch = callableChildBranch.call(); - OrcsTransaction tx2 = - orcsApi.getTransactionFactory(context).createTransaction(childBranch, author, "modify and make new arts"); + OrcsTransaction tx2 = txFactory.createTransaction(childBranch, author, "modify and make new arts"); ArtifactReadable readableFolder = - qf.fromBranch(childBranch).andGuidsOrHrids(folder.getGuid()).getResults().getExactlyOne(); + query.fromBranch(childBranch).andGuidsOrHrids(folder.getGuid()).getResults().getExactlyOne(); // modifying this artifact should cause it to get introduced ArtifactWriteable writeableFolder = tx2.asWriteable(readableFolder); @@ -202,7 +202,7 @@ public class OrcsBranchTest { break; } } - Assert.assertTrue(contains); + assertTrue(contains); } } } @@ -210,11 +210,11 @@ public class OrcsBranchTest { private void compareBranchChanges(List<ChangeItem> priorItems, List<ChangeItem> newItems) { Collections.sort(priorItems); Collections.sort(newItems); - Assert.assertEquals(priorItems, newItems); + assertEquals(priorItems, newItems); } private ArtifactReadable getSystemUser() throws OseeCoreException { - return orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne(); + return query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne(); } } diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsPortingTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsPortingTest.java index 30ae920f34f..f43dcef38eb 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsPortingTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsPortingTest.java @@ -11,7 +11,9 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.data.ResultSet; import org.eclipse.osee.framework.core.data.TokenFactory; @@ -31,7 +33,6 @@ import org.eclipse.osee.orcs.db.mock.OsgiService; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.transaction.OrcsTransaction; import org.eclipse.osee.orcs.transaction.TransactionFactory; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -50,7 +51,7 @@ public class OrcsPortingTest { public TestRule osgi = integrationRule(this, "osee.demo.hsql"); @OsgiService - private OrcsApi orcsApi; + private OrcsApi orcsApi; private OrcsBranch branchApi; private QueryFactory query; @@ -72,7 +73,6 @@ public class OrcsPortingTest { @Test public void testCreateBranch() throws Exception { - String artifactGuid = GUID.create(); String assocArtifactGuid = GUID.create(); @@ -92,43 +92,43 @@ public class OrcsPortingTest { query.fromBranch(finalTx.getBranch()).andTypeEquals(CoreArtifactTypes.Artifact).getResults(); for (ArtifactReadable art : artifacts) { if (art.isOfType(CoreArtifactTypes.SoftwareRequirement)) { - Assert.assertEquals(2, art.getAttributes().size()); + assertEquals(2, art.getAttributes().size()); - Assert.assertEquals(artifactGuid, art.getGuid()); - Assert.assertEquals("SecondRequirement", art.getName()); + assertEquals(artifactGuid, art.getGuid()); + assertEquals("SecondRequirement", art.getName()); String actual = art.getSoleAttributeAsString(CoreAttributeTypes.Subsystem); - Assert.assertEquals("test changed", actual); + assertEquals("test changed", actual); // if there is a requirement with an attribute other than "test changed" then the above should fail } else if (art.isOfType(CoreArtifactTypes.Folder)) { - Assert.assertEquals("childBranch folder", art.getName()); + assertEquals("childBranch folder", art.getName()); // if there is any other folder like "folder after transaction" then the above should fail } else { - Assert.fail("incorrect artifact found on branch"); + fail("incorrect artifact found on branch"); } } } - + @Test public void testForMultiplePortBranches() throws Exception { - String artifactGuid = GUID.create(); - String differentGuid = GUID.create(); - - String assocArtifactGuid = GUID.create(); - setupAssociatedArtifact(assocArtifactGuid); - - TransactionRecord mainBranchTx = createBaselineBranchAndArtifacts(artifactGuid); - TransactionRecord differentBranchTx = createBaselineBranchAndArtifacts(differentGuid); - - IOseeBranch copyTxBranch = createCopyFromTransactionBranch(mainBranchTx, assocArtifactGuid); - Assert.assertNotNull(copyTxBranch); - - // There should only be one Port Branch per associated artifact. Expecting an exception - thrown.expect(OseeStateException.class); - thrown.expectMessage(String.format("Existing port branch creation detected for [%s]", branchString)); - IOseeBranch failedBranch = createCopyFromTransactionBranch(differentBranchTx, assocArtifactGuid); - Assert.fail(); // should never get here due to thrown exception + String artifactGuid = GUID.create(); + String differentGuid = GUID.create(); + + String assocArtifactGuid = GUID.create(); + setupAssociatedArtifact(assocArtifactGuid); + + TransactionRecord mainBranchTx = createBaselineBranchAndArtifacts(artifactGuid); + TransactionRecord differentBranchTx = createBaselineBranchAndArtifacts(differentGuid); + + IOseeBranch copyTxBranch = createCopyFromTransactionBranch(mainBranchTx, assocArtifactGuid); + assertNotNull(copyTxBranch); + + // There should only be one Port Branch per associated artifact. Expecting an exception + thrown.expect(OseeStateException.class); + thrown.expectMessage(String.format("Existing port branch creation detected for [%s]", branchString)); + createCopyFromTransactionBranch(differentBranchTx, assocArtifactGuid); + fail(); // should never get here due to thrown exception } private TransactionRecord createBaselineBranchAndArtifacts(String artifactGuid) throws Exception { @@ -142,16 +142,12 @@ public class OrcsPortingTest { ArtifactWriteable baseReq = tx.createArtifact(CoreArtifactTypes.SoftwareRequirement, "BaseRequirement"); baseReq.setSoleAttributeFromString(CoreAttributeTypes.Subsystem, "Test"); - - OrcsTransaction tx2 = txFactory.createTransaction(branch, author, "add another requirement"); ArtifactWriteable nextReq = tx2.createArtifact(CoreArtifactTypes.SoftwareRequirement, "SecondRequirement", artifactGuid); nextReq.setSoleAttributeFromString(CoreAttributeTypes.Subsystem, "Test2"); - TransactionRecord commitTx = tx2.commit(); - - return commitTx; + return tx2.commit(); } private void setupAssociatedArtifact(String associatedArtifactGuid) throws Exception { @@ -207,7 +203,7 @@ public class OrcsPortingTest { ArtifactReadable readableReq = query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(assocArtifactGuid).getResults().getExactlyOne(); - Assert.assertNotNull(readableReq); + assertNotNull(readableReq); // the new branch will contain two transactions - return branchApi.createPortBranch(branch, author, transactionToCopy, readableReq).call(); } diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java index 0e088782914..31f82c2b3fd 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java @@ -11,6 +11,9 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -39,7 +42,6 @@ import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.utility.MatchComparator; import org.eclipse.osee.orcs.utility.NameComparator; import org.eclipse.osee.orcs.utility.SortOrder; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -69,40 +71,40 @@ public class OrcsQueryTest { @Test public void testAllArtifactsFromBranch() throws OseeCoreException { QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON); - Assert.assertEquals(26, builder.getCount()); + assertEquals(26, builder.getCount()); - Assert.assertEquals(26, builder.getResults().getList().size()); + assertEquals(26, builder.getResults().getList().size()); } @Test public void testQueryByIds() throws OseeCoreException { QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON).andGuidsOrHrids("AkA2AmNuEDDL4VolM9AA"); - Assert.assertEquals(1, builder.getCount()); + assertEquals(1, builder.getCount()); ArtifactReadable artifact = builder.getResults().getExactlyOne(); - Assert.assertEquals("AkA2AmNuEDDL4VolM9AA", artifact.getGuid()); + assertEquals("AkA2AmNuEDDL4VolM9AA", artifact.getGuid()); } @Test public void testQueryArtifactType() throws OseeCoreException { QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON).andIsOfType(CoreArtifactTypes.Folder); - Assert.assertEquals(2, builder.getCount()); + assertEquals(2, builder.getCount()); List<ArtifactReadable> artifacts = builder.getResults().getList(); - Assert.assertEquals(2, artifacts.size()); + assertEquals(2, artifacts.size()); checkContainsTypes(artifacts, CoreArtifactTypes.Folder); Collections.sort(artifacts, new NameComparator(SortOrder.ASCENDING)); Iterator<ArtifactReadable> iterator = artifacts.iterator(); - Assert.assertEquals("Document Templates", iterator.next().getName()); - Assert.assertEquals("User Groups", iterator.next().getName()); + assertEquals("Document Templates", iterator.next().getName()); + assertEquals("User Groups", iterator.next().getName()); if (includeMatchLocationTests) { List<Match<ArtifactReadable, AttributeReadable<?>>> matches = builder.getMatches().getList(); - Assert.assertEquals(2, matches.size()); + assertEquals(2, matches.size()); Iterator<Match<ArtifactReadable, AttributeReadable<?>>> matchIterator = matches.iterator(); checkMatch(matchIterator.next(), "Document Templates"); @@ -115,17 +117,17 @@ public class OrcsQueryTest { QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1).andTypeEquals(CoreArtifactTypes.AbstractSoftwareRequirement); - Assert.assertEquals(0, builder.getCount()); + assertEquals(0, builder.getCount()); ArtifactReadable artifact = builder.getResults().getOneOrNull(); - Assert.assertNull(artifact); + assertNull(artifact); builder = factory.fromBranch(TestBranches.SAW_Bld_1).andIsOfType(CoreArtifactTypes.AbstractSoftwareRequirement); - Assert.assertEquals(24, builder.getCount()); + assertEquals(24, builder.getCount()); List<ArtifactReadable> artifacts = builder.getResults().getList(); - Assert.assertEquals(24, artifacts.size()); + assertEquals(24, artifacts.size()); checkContainsTypes(artifacts, CoreArtifactTypes.SoftwareRequirement); } @@ -135,23 +137,23 @@ public class OrcsQueryTest { QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON); builder.andTypeEquals(CoreArtifactTypes.OseeTypeDefinition, CoreArtifactTypes.Folder); - Assert.assertEquals(6, builder.getCount()); + assertEquals(6, builder.getCount()); List<ArtifactReadable> artifacts = builder.getResults().getList(); - Assert.assertEquals(6, artifacts.size()); + assertEquals(6, artifacts.size()); checkContainsTypes(artifacts, CoreArtifactTypes.OseeTypeDefinition, CoreArtifactTypes.Folder); Collections.sort(artifacts, new NameComparator(SortOrder.ASCENDING)); Iterator<ArtifactReadable> iterator = artifacts.iterator(); - Assert.assertEquals("Document Templates", iterator.next().getName()); - Assert.assertEquals("User Groups", iterator.next().getName()); + assertEquals("Document Templates", iterator.next().getName()); + assertEquals("User Groups", iterator.next().getName()); - Assert.assertEquals("org.eclipse.osee.client.demo.OseeTypes_ClientDemo", iterator.next().getName()); - Assert.assertEquals("org.eclipse.osee.coverage.OseeTypes_Coverage", iterator.next().getName()); - Assert.assertEquals("org.eclipse.osee.framework.skynet.core.OseeTypes_Framework", iterator.next().getName()); - Assert.assertEquals("org.eclipse.osee.ote.define.OseeTypesOTE", iterator.next().getName()); + assertEquals("org.eclipse.osee.client.demo.OseeTypes_ClientDemo", iterator.next().getName()); + assertEquals("org.eclipse.osee.coverage.OseeTypes_Coverage", iterator.next().getName()); + assertEquals("org.eclipse.osee.framework.skynet.core.OseeTypes_Framework", iterator.next().getName()); + assertEquals("org.eclipse.osee.ote.define.OseeTypesOTE", iterator.next().getName()); } @Test @@ -159,26 +161,26 @@ public class OrcsQueryTest { QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON); builder.and(CoreAttributeTypes.Name, Operator.EQUAL, "User Groups"); - Assert.assertEquals(1, builder.getCount()); + assertEquals(1, builder.getCount()); ArtifactReadable artifact = builder.getResults().getExactlyOne(); - Assert.assertEquals("User Groups", artifact.getName()); - Assert.assertEquals(CoreArtifactTypes.Folder, artifact.getArtifactType()); + assertEquals("User Groups", artifact.getName()); + assertEquals(CoreArtifactTypes.Folder, artifact.getArtifactType()); if (includeMatchLocationTests) { Match<ArtifactReadable, AttributeReadable<?>> result = builder.getMatches().getExactlyOne(); - Assert.assertEquals(artifact, result.getItem()); + assertEquals(artifact, result.getItem()); checkMatch(result, "User Groups", CoreAttributeTypes.Name); AttributeReadable<?> attr = result.getElements().iterator().next(); List<MatchLocation> location = result.getLocation(attr); - Assert.assertEquals(1, location.size()); + assertEquals(1, location.size()); MatchLocation loc1 = location.iterator().next(); - Assert.assertEquals(0, loc1.getStartPosition()); - Assert.assertEquals("User Groups".length(), loc1.getEndPosition()); + assertEquals(0, loc1.getStartPosition()); + assertEquals("User Groups".length(), loc1.getEndPosition()); } } @@ -187,48 +189,48 @@ public class OrcsQueryTest { QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1); builder.and(CoreAttributeTypes.Name, "Requirements", MatchTokenCountType.IGNORE_TOKEN_COUNT); - Assert.assertEquals(7, builder.getCount()); + assertEquals(7, builder.getCount()); List<ArtifactReadable> artifacts = builder.getResults().getList(); - Assert.assertEquals(7, artifacts.size()); + assertEquals(7, artifacts.size()); checkContainsTypes(artifacts, CoreArtifactTypes.Folder, CoreArtifactTypes.SubsystemRequirementMSWord, CoreArtifactTypes.SystemRequirementMSWord); builder.andIsOfType(CoreArtifactTypes.Folder); - Assert.assertEquals(4, builder.getCount()); + assertEquals(4, builder.getCount()); List<ArtifactReadable> folders = builder.getResults().getList(); - Assert.assertEquals(4, folders.size()); + assertEquals(4, folders.size()); Collections.sort(folders, new NameComparator(SortOrder.ASCENDING)); Iterator<ArtifactReadable> folderIterator = folders.iterator(); - Assert.assertEquals("Hardware Requirements", folderIterator.next().getName()); - Assert.assertEquals("Software Requirements", folderIterator.next().getName()); - Assert.assertEquals("Subsystem Requirements", folderIterator.next().getName()); - Assert.assertEquals("System Requirements", folderIterator.next().getName()); + assertEquals("Hardware Requirements", folderIterator.next().getName()); + assertEquals("Software Requirements", folderIterator.next().getName()); + assertEquals("Subsystem Requirements", folderIterator.next().getName()); + assertEquals("System Requirements", folderIterator.next().getName()); checkContainsTypes(folders, CoreArtifactTypes.Folder); ////////////////////// QueryBuilder builder1 = factory.fromBranch(TestBranches.SAW_Bld_1); builder1.and(CoreAttributeTypes.Name, "Requirements", MatchTokenCountType.IGNORE_TOKEN_COUNT); builder1.andTypeEquals(CoreArtifactTypes.SubsystemRequirementMSWord); - Assert.assertEquals(1, builder1.getCount()); + assertEquals(1, builder1.getCount()); List<ArtifactReadable> subSystemReqs = builder1.getResults().getList(); - Assert.assertEquals(1, subSystemReqs.size()); - Assert.assertEquals("Subsystem Requirements", subSystemReqs.get(0).getName()); + assertEquals(1, subSystemReqs.size()); + assertEquals("Subsystem Requirements", subSystemReqs.get(0).getName()); checkContainsTypes(subSystemReqs, CoreArtifactTypes.SubsystemRequirementMSWord); ////////////////////// QueryBuilder builder2 = factory.fromBranch(TestBranches.SAW_Bld_1); builder2.and(CoreAttributeTypes.Name, "Requirements", MatchTokenCountType.IGNORE_TOKEN_COUNT); builder2.andIsOfType(CoreArtifactTypes.Requirement); - Assert.assertEquals(3, builder2.getCount()); + assertEquals(3, builder2.getCount()); List<ArtifactReadable> requirements = builder2.getResults().getList(); - Assert.assertEquals(3, requirements.size()); + assertEquals(3, requirements.size()); Collections.sort(requirements, new NameComparator(SortOrder.ASCENDING)); Iterator<ArtifactReadable> reqIterator = requirements.iterator(); - Assert.assertEquals("Performance Requirements", reqIterator.next().getName()); - Assert.assertEquals("Safety Requirements", reqIterator.next().getName()); - Assert.assertEquals("Subsystem Requirements", reqIterator.next().getName()); + assertEquals("Performance Requirements", reqIterator.next().getName()); + assertEquals("Safety Requirements", reqIterator.next().getName()); + assertEquals("Subsystem Requirements", reqIterator.next().getName()); checkContainsTypes(subSystemReqs, CoreArtifactTypes.SubsystemRequirementMSWord, CoreArtifactTypes.SystemRequirementMSWord); } @@ -238,24 +240,24 @@ public class OrcsQueryTest { QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1); builder.and(CoreAttributeTypes.Name, "REQUIREMENTS", TokenDelimiterMatch.ANY); - Assert.assertEquals(7, builder.getCount()); + assertEquals(7, builder.getCount()); List<ArtifactReadable> requirements = builder.getResults().getList(); - Assert.assertEquals(7, requirements.size()); + assertEquals(7, requirements.size()); checkContainsTypes(requirements, CoreArtifactTypes.Folder, CoreArtifactTypes.SubsystemRequirementMSWord, CoreArtifactTypes.SystemRequirementMSWord); Collections.sort(requirements, new NameComparator(SortOrder.ASCENDING)); Iterator<ArtifactReadable> reqIterator = requirements.iterator(); - Assert.assertEquals("Hardware Requirements", reqIterator.next().getName()); - Assert.assertEquals("Performance Requirements", reqIterator.next().getName()); - Assert.assertEquals("Safety Requirements", reqIterator.next().getName()); - Assert.assertEquals("Software Requirements", reqIterator.next().getName()); - Assert.assertEquals("Subsystem Requirements", reqIterator.next().getName()); - Assert.assertEquals("Subsystem Requirements", reqIterator.next().getName()); - Assert.assertEquals("System Requirements", reqIterator.next().getName()); + assertEquals("Hardware Requirements", reqIterator.next().getName()); + assertEquals("Performance Requirements", reqIterator.next().getName()); + assertEquals("Safety Requirements", reqIterator.next().getName()); + assertEquals("Software Requirements", reqIterator.next().getName()); + assertEquals("Subsystem Requirements", reqIterator.next().getName()); + assertEquals("Subsystem Requirements", reqIterator.next().getName()); + assertEquals("System Requirements", reqIterator.next().getName()); // if (includeMatchLocationTests) { List<Match<ArtifactReadable, AttributeReadable<?>>> matches = builder.getMatches().getList(); - Assert.assertEquals(7, matches.size()); + assertEquals(7, matches.size()); Collections.sort(matches, new MatchComparator(SortOrder.ASCENDING)); @@ -272,53 +274,53 @@ public class OrcsQueryTest { QueryBuilder builder1 = factory.fromBranch(TestBranches.SAW_Bld_1); builder1.and(CoreAttributeTypes.Name, "REQUIREMENTS", TokenDelimiterMatch.ANY, CaseType.MATCH_CASE); - Assert.assertEquals(0, builder1.getCount()); + assertEquals(0, builder1.getCount()); } @Test public void testRelatedToTest() throws OseeCoreException { QueryBuilder builder1 = factory.fromBranch(TestBranches.SAW_Bld_1); builder1.and(CoreAttributeTypes.Name, Operator.EQUAL, "Frame Synchronization"); - Assert.assertEquals("Frame Synchronization", builder1.getResults().getExactlyOne().getName()); + assertEquals("Frame Synchronization", builder1.getResults().getExactlyOne().getName()); QueryBuilder builder2 = factory.fromBranch(TestBranches.SAW_Bld_1); builder2.andRelatedTo(CoreRelationTypes.Default_Hierarchical__Child, builder1.getResults().getExactlyOne()); - Assert.assertEquals("Video processing", builder2.getResults().getExactlyOne().getName()); + assertEquals("Video processing", builder2.getResults().getExactlyOne().getName()); QueryBuilder builder3 = factory.fromBranch(TestBranches.SAW_Bld_1); builder3.andRelatedTo(CoreRelationTypes.Default_Hierarchical__Child, builder2.getResults().getExactlyOne()); - Assert.assertEquals("Subsystem Requirements", builder3.getResults().getExactlyOne().getName()); + assertEquals("Subsystem Requirements", builder3.getResults().getExactlyOne().getName()); } private static void checkContainsTypes(Collection<ArtifactReadable> arts, IArtifactType... types) throws OseeCoreException { List<IArtifactType> expected = Arrays.asList(types); for (ArtifactReadable art : arts) { - Assert.assertTrue(String.format("artifact type [%s] not found", art.getArtifactType()), + assertTrue(String.format("artifact type [%s] not found", art.getArtifactType()), expected.contains(art.getArtifactType())); } } private static void checkMatchSingleAttribute(Match<ArtifactReadable, AttributeReadable<?>> match, String artName, IAttributeType types, String matched) throws OseeCoreException { - Assert.assertEquals(artName, match.getItem().getName()); + assertEquals(artName, match.getItem().getName()); AttributeReadable<?> attribute = match.getElements().iterator().next(); - Assert.assertEquals(types, attribute.getAttributeType()); + assertEquals(types, attribute.getAttributeType()); List<MatchLocation> locations = match.getLocation(attribute); - Assert.assertEquals(1, locations.size()); + assertEquals(1, locations.size()); MatchLocation location = locations.get(0); String value = String.valueOf(attribute.getValue()); - Assert.assertEquals(matched, value.substring(location.getStartPosition() - 1, location.getEndPosition())); + assertEquals(matched, value.substring(location.getStartPosition() - 1, location.getEndPosition())); } private static void checkMatch(Match<ArtifactReadable, AttributeReadable<?>> match, String artName, IAttributeType... types) throws OseeCoreException { - Assert.assertEquals(artName, match.getItem().getName()); + assertEquals(artName, match.getItem().getName()); if (types.length > 0) { - Assert.assertEquals(types.length, match.getElements().size()); + assertEquals(types.length, match.getElements().size()); Iterator<AttributeReadable<?>> iterator = match.getElements().iterator(); for (int index = 0; index < types.length; index++) { - Assert.assertEquals(types[index], iterator.next().getAttributeType()); + assertEquals(types[index], iterator.next().getAttributeType()); } } } diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsRelationLoadingTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsRelationLoadingTest.java index d909c865f90..59dabf8cdce 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsRelationLoadingTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsRelationLoadingTest.java @@ -11,9 +11,10 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.osee.framework.core.data.ResultSet; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; @@ -28,8 +29,8 @@ import org.eclipse.osee.orcs.data.GraphReadable; import org.eclipse.osee.orcs.db.mock.OsgiService; import org.eclipse.osee.orcs.search.QueryBuilder; import org.eclipse.osee.orcs.search.QueryFactory; -import org.junit.Assert; import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TestRule; /** @@ -45,7 +46,7 @@ public class OrcsRelationLoadingTest { @OsgiService private OrcsApi orcsApi; - @org.junit.Test + @Test public void testSearchById() throws Exception { ApplicationContext context = null; // TODO use real application context @@ -53,34 +54,30 @@ public class OrcsRelationLoadingTest { GraphReadable graph = orcsApi.getGraph(context); checkRelationsForCommonBranch(orcsApi, queryFactory, graph, context); checkRelationsForSawBranch(orcsApi, queryFactory, graph, context); - } private void checkRelationsForCommonBranch(OrcsApi oseeApi, QueryFactory queryFactory, GraphReadable graph, ApplicationContext context) throws OseeCoreException { QueryBuilder builder = queryFactory.fromBranch(CoreBranches.COMMON).andLocalIds(Arrays.asList(6, 7, 8)); ResultSet<ArtifactReadable> resultSet = builder.getResults(); - List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertEquals(3, moreArts.size()); - Assert.assertEquals(3, builder.getCount()); + assertEquals(3, resultSet.getList().size()); + assertEquals(3, builder.getCount()); - Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + Map<Integer, ArtifactReadable> lookup = createLookup(resultSet); ArtifactReadable art6 = lookup.get(6); ArtifactReadable art7 = lookup.get(7); ArtifactReadable art8 = lookup.get(8); //art 6 has no relations - Assert.assertEquals(0, graph.getExistingRelationTypes(art6).size()); + assertEquals(0, graph.getExistingRelationTypes(art6).size()); //art 7 has 3 // REL_LINK_ID REL_LINK_TYPE_ID A_ART_ID B_ART_ID RATIONALE GAMMA_ID TX_CURRENT MOD_TYPE BRANCH_ID TRANSACTION_ID GAMMA_ID // 1 219 7 8 53 // 3 219 7 15 54 // 2 219 1 7 52 - Assert.assertEquals(2, graph.getExistingRelationTypes(art7).size()); - Assert.assertEquals(2, - graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child, art7).getList().size()); - Assert.assertEquals(1, - graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, art7).getList().size()); + assertEquals(2, graph.getExistingRelationTypes(art7).size()); + assertEquals(2, graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child, art7).getList().size()); + assertEquals(1, graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, art7).getList().size()); //art8 has // REL_LINK_ID REL_LINK_TYPE_ID A_ART_ID B_ART_ID RATIONALE GAMMA_ID TX_CURRENT MOD_TYPE BRANCH_ID TRANSACTION_ID GAMMA_ID @@ -90,35 +87,34 @@ public class OrcsRelationLoadingTest { // 6 233 8 19 76 // 5 233 8 18 78 // 1 219 7 8 53 - Assert.assertEquals(2, graph.getExistingRelationTypes(art8).size()); - Assert.assertEquals(1, - graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, art8).getList().size()); - Assert.assertEquals(5, graph.getRelatedArtifacts(CoreRelationTypes.Users_User, art8).getList().size()); + assertEquals(2, graph.getExistingRelationTypes(art8).size()); + assertEquals(1, graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, art8).getList().size()); + assertEquals(5, graph.getRelatedArtifacts(CoreRelationTypes.Users_User, art8).getList().size()); } private void checkRelationsForSawBranch(OrcsApi oseeApi, QueryFactory queryFactory, GraphReadable graph, ApplicationContext context) throws OseeCoreException { QueryBuilder builder = - queryFactory.fromBranch(oseeApi.getBranchCache().getByName("SAW_Bld_1").iterator().next()).and( - CoreAttributeTypes.Name, Operator.EQUAL, "Design Constraints"); + queryFactory.fromBranch(TestBranches.SAW_Bld_1).and(CoreAttributeTypes.Name, Operator.EQUAL, + "Design Constraints"); ResultSet<ArtifactReadable> resultSet = builder.getResults(); - List<ArtifactReadable> moreArts = resultSet.getList(); - Assert.assertFalse(moreArts.isEmpty()); - ArtifactReadable artifact = moreArts.iterator().next(); + assertEquals(1, resultSet.getList().size()); + + ArtifactReadable artifact = resultSet.getAtMostOneOrNull(); + assertNotNull(artifact); //art 7 has no relations //artifact has 3 children and 1 parent - - Assert.assertEquals(2, graph.getExistingRelationTypes(artifact).size()); - Assert.assertEquals(3, + assertEquals(2, graph.getExistingRelationTypes(artifact).size()); + assertEquals(3, graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child, artifact).getList().size()); - Assert.assertEquals(1, + assertEquals(1, graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, artifact).getList().size()); } - Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) { + private Map<Integer, ArtifactReadable> createLookup(Iterable<ArtifactReadable> arts) { Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>(); for (ArtifactReadable artifact : arts) { lookup.put(artifact.getLocalId(), artifact); diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java index c077372d69b..29d01a4dbd5 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java @@ -11,6 +11,11 @@ package org.eclipse.osee.orcs.api; import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; import java.lang.reflect.Proxy; import java.util.concurrent.Callable; import org.eclipse.osee.framework.core.data.IOseeBranch; @@ -34,9 +39,9 @@ import org.eclipse.osee.orcs.OrcsBranch; import org.eclipse.osee.orcs.data.ArtifactReadable; import org.eclipse.osee.orcs.data.ArtifactWriteable; import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.transaction.OrcsTransaction; import org.eclipse.osee.orcs.transaction.TransactionFactory; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -65,11 +70,13 @@ public class OrcsTransactionTest { private TransactionFactory txFactory; private ArtifactReadable userArtifact; private OrcsBranch orcsBranch; + private QueryFactory query; @Before public void setUp() throws Exception { txFactory = orcsApi.getTransactionFactory(context); orcsBranch = orcsApi.getBranchOps(context); + query = orcsApi.getQueryFactory(context); userArtifact = getSystemUser(); } @@ -87,40 +94,37 @@ public class OrcsTransactionTest { ArtifactWriteable writeable = tx.createArtifact(CoreArtifactTypes.Folder, expectedName); writeable.setAttributesFromStrings(CoreAttributeTypes.Annotation, expectedAnnotation); - Assert.assertEquals(expectedName, writeable.getName()); - Assert.assertEquals(expectedAnnotation, - writeable.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next()); + assertEquals(expectedName, writeable.getName()); + assertEquals(expectedAnnotation, writeable.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next()); String id = writeable.getGuid(); - Assert.assertTrue(Proxy.isProxyClass(writeable.getClass())); + assertTrue(Proxy.isProxyClass(writeable.getClass())); TransactionRecord newTx = tx.commit(); - Assert.assertFalse(tx.isCommitInProgress()); + assertFalse(tx.isCommitInProgress()); TransactionRecord newHeadTx = orcsApi.getTxsCache().getHeadTransaction(branch); - Assert.assertEquals(newTx, newHeadTx); + assertEquals(newTx, newHeadTx); checkTransaction(previousTx, newTx, branch, comment, userArtifact); - ResultSet<ArtifactReadable> result = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(id).getResults(); + ResultSet<ArtifactReadable> result = query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(id).getResults(); ArtifactReadable artifact = result.getExactlyOne(); - Assert.assertEquals(expectedName, artifact.getName()); - Assert.assertEquals(expectedAnnotation, - artifact.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next()); - Assert.assertEquals(writeable.getLocalId(), artifact.getLocalId()); + assertEquals(expectedName, artifact.getName()); + assertEquals(expectedAnnotation, artifact.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next()); + assertEquals(writeable.getLocalId(), artifact.getLocalId()); - Assert.assertTrue(Proxy.isProxyClass(artifact.getClass())); + assertTrue(Proxy.isProxyClass(artifact.getClass())); } @Test public void testDuplicateAritfact() throws Exception { ArtifactReadable guestUser = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); // duplicate on same branch OrcsTransaction transaction1 = @@ -128,10 +132,10 @@ public class OrcsTransactionTest { ArtifactWriteable duplicate = transaction1.duplicateArtifact(guestUser); transaction1.commit(); ArtifactReadable guestUserDup = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(duplicate.getGuid()).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(duplicate.getGuid()).getResults().getExactlyOne(); - Assert.assertNotSame(SystemUser.Guest.getGuid(), guestUserDup.getGuid()); - Assert.assertEquals(SystemUser.Guest.getName(), guestUserDup.getName()); + assertNotSame(SystemUser.Guest.getGuid(), guestUserDup.getGuid()); + assertEquals(SystemUser.Guest.getName(), guestUserDup.getName()); // duplicate on different branch IOseeBranch branchToken = TokenFactory.createBranch(GUID.create(), "DuplicateArtifact tests"); @@ -143,17 +147,16 @@ public class OrcsTransactionTest { txFactory.createTransaction(topLevelBranch, userArtifact, "testDuplicateArtifactDifferentBranch"); duplicate = transaction2.duplicateArtifact(guestUser); transaction2.commit(); - guestUserDup = - orcsApi.getQueryFactory(context).fromBranch(topLevelBranch).andGuidsOrHrids(duplicate.getGuid()).getResults().getExactlyOne(); + guestUserDup = query.fromBranch(topLevelBranch).andGuidsOrHrids(duplicate.getGuid()).getResults().getExactlyOne(); - Assert.assertNotSame(SystemUser.Guest.getGuid(), guestUserDup.getGuid()); - Assert.assertEquals(SystemUser.Guest.getName(), guestUserDup.getName()); + assertNotSame(SystemUser.Guest.getGuid(), guestUserDup.getGuid()); + assertEquals(SystemUser.Guest.getName(), guestUserDup.getName()); } @Test public void testIntroduceArtifact() throws Exception { ArtifactReadable guestUser = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); IOseeBranch branchToken = TokenFactory.createBranch(GUID.create(), "IntroduceArtifact tests"); Callable<ReadableBranch> callableBranch = orcsBranch.createTopLevelBranch(branchToken, userArtifact); @@ -164,14 +167,14 @@ public class OrcsTransactionTest { transaction.commit(); ArtifactReadable introduced = - orcsApi.getQueryFactory(context).fromBranch(topLevelBranch).andGuidsOrHrids(SystemUser.Guest.getGuid()).getResults().getExactlyOne(); - Assert.assertEquals(guestUser.getLocalId(), introduced.getLocalId()); + query.fromBranch(topLevelBranch).andGuidsOrHrids(SystemUser.Guest.getGuid()).getResults().getExactlyOne(); + assertEquals(guestUser.getLocalId(), introduced.getLocalId()); } @Test public void testIntroduceOnSameBranch() throws OseeCoreException { ArtifactReadable guestUser = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); OrcsTransaction transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, "testIntroduceOnSameBranch"); @@ -183,30 +186,29 @@ public class OrcsTransactionTest { @Test public void testAsWritable() throws OseeCoreException { ArtifactReadable guestUser = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); OrcsTransaction transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName()); ArtifactWriteable writeable = transaction.asWriteable(guestUser); writeable.setName("Test"); // make sure readables have not been updated - Assert.assertEquals("Guest", guestUser.getName()); + assertEquals("Guest", guestUser.getName()); transaction.commit(); // make sure readables have not been updated - Assert.assertEquals("Guest", guestUser.getName()); + assertEquals("Guest", guestUser.getName()); - guestUser = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); + guestUser = query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); - Assert.assertEquals("Test", guestUser.getName()); + assertEquals("Test", guestUser.getName()); } @Test public void testAsWritableException() throws OseeCoreException { ArtifactReadable guestUser = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.Guest).getResults().getExactlyOne(); OrcsTransaction transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName()); ArtifactWriteable writeable = transaction.asWriteable(guestUser); @@ -227,16 +229,15 @@ public class OrcsTransactionTest { transaction = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName()); ArtifactReadable toDelete = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(artifact.getGuid()).getResults().getExactlyOne(); + query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(artifact.getGuid()).getResults().getExactlyOne(); ArtifactWriteable writeable = transaction.asWriteable(toDelete); writeable.delete(); transaction.commit(); toDelete = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(writeable.getGuid()).includeDeleted().getResults().getOneOrNull(); - Assert.assertNotNull(toDelete); - Assert.assertTrue(toDelete.isDeleted()); - + query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(writeable.getGuid()).includeDeleted().getResults().getOneOrNull(); + assertNotNull(toDelete); + assertTrue(toDelete.isDeleted()); } @Test @@ -248,8 +249,8 @@ public class OrcsTransactionTest { int startingTx = transaction.commit().getId(); ArtifactReadable artifact = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(guid).getResults().getExactlyOne(); - Assert.assertEquals(startingTx, artifact.getTransaction()); + query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(guid).getResults().getExactlyOne(); + assertEquals(startingTx, artifact.getTransaction()); OrcsTransaction transaction2 = txFactory.createTransaction(CoreBranches.COMMON, userArtifact, testName.getMethodName()); @@ -257,58 +258,24 @@ public class OrcsTransactionTest { transaction2.asWriteable(artifact).setName("Modified - component"); int lastTx = transaction2.commit().getId(); - Assert.assertTrue(startingTx != lastTx); + assertTrue(startingTx != lastTx); ArtifactReadable currentArtifact = - orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(guid).getResults().getExactlyOne(); - Assert.assertEquals(lastTx, currentArtifact.getTransaction()); + query.fromBranch(CoreBranches.COMMON).andGuidsOrHrids(guid).getResults().getExactlyOne(); + assertEquals(lastTx, currentArtifact.getTransaction()); } private ArtifactReadable getSystemUser() throws OseeCoreException { - return orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne(); + return query.fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne(); } private void checkTransaction(TransactionRecord previousTx, TransactionRecord newTx, Branch branch, String comment, ArtifactReadable user) throws OseeCoreException { - Assert.assertTrue(previousTx.getId() < newTx.getId()); - Assert.assertEquals(comment, newTx.getComment()); - Assert.assertEquals(branch, newTx.getBranch()); - Assert.assertEquals(TransactionDetailsType.NonBaselined, newTx.getTxType()); - Assert.assertEquals(user.getLocalId(), newTx.getAuthor()); - Assert.assertEquals(-1, newTx.getCommit()); - Assert.assertTrue(previousTx.getTimeStamp().before(newTx.getTimeStamp())); + assertTrue(previousTx.getId() < newTx.getId()); + assertEquals(comment, newTx.getComment()); + assertEquals(branch, newTx.getBranch()); + assertEquals(TransactionDetailsType.NonBaselined, newTx.getTxType()); + assertEquals(user.getLocalId(), newTx.getAuthor()); + assertEquals(-1, newTx.getCommit()); + assertTrue(previousTx.getTimeStamp().before(newTx.getTimeStamp())); } - - // public static void main(String[] args) throws Exception { - // Tester x = new Tester(); - // - // ArtifactReadable artifact1 = null; - // ArtifactReadable artifact2 = null; - // - // x.modifyOneArtifact(artifact1); - // - // GraphReadable readableGraph = x.getApi().getGraph(null); - // - // OrcsTransaction tx = x.getTransaction(); // branch and user and comment - // - // GraphWriteable wGraph = tx.asWriteableGraph(readableGraph); - // - // ArtifactWriteable wArt1 = tx.asWritable(artifact1); - // ArtifactWriteable wArt2 = tx.asWritable(artifact2); - // - // for (ArtifactWriteable child : wGraph.getWriteableChildren(wArt1)) { - // child.setName("George"); - // } - // - // List<AttributeWriteable<String>> attributes = wArt1.getWriteableAttributes(); - // for (AttributeWriteable<String> attribute : attributes) { - // attribute.setValue("Hello"); - // } - // - // wArt1.setName("Name"); - // wArt1.setSoleAttributeValue(CoreAttributeTypes.Annotation, "hello"); - // - // wArt2.setName("Shawn"); - // - // tx.commit(); - // } } diff --git a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/OseeClientQueryTest.java b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/OseeClientQueryTest.java index 72e6da1606c..1324a8b4c92 100644 --- a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/OseeClientQueryTest.java +++ b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/OseeClientQueryTest.java @@ -92,21 +92,21 @@ public class OseeClientQueryTest { } @Test - public void SearchForArtifactByGuid() throws OseeCoreException { + public void searchForArtifactByGuid() throws OseeCoreException { final int EXPECTED_RESULTS = 1; SearchResult results = createClient.createQueryBuilder(COMMON).andGuidsOrHrids(GUID1).getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); } @Test - public void SearchForArtifactByGuids() throws OseeCoreException { + public void searchForArtifactByGuids() throws OseeCoreException { final int EXPECTED_RESULTS = 2; SearchResult results = createClient.createQueryBuilder(COMMON).andGuidsOrHrids(GUID1, GUID2).getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); } @Test - public void SearchForArtifactByGuidsExcludeCache() throws OseeCoreException { + public void searchForArtifactByGuidsExcludeCache() throws OseeCoreException { final int EXPECTED_RESULTS = 2; SearchResult results = createClient.createQueryBuilder(COMMON).andGuidsOrHrids(GUID1, GUID2).excludeCache().getSearchResult(); @@ -114,7 +114,7 @@ public class OseeClientQueryTest { } @Test - public void SearchForArtifactByGuidsIncludeCache() throws OseeCoreException { + public void searchForArtifactByGuidsIncludeCache() throws OseeCoreException { final int EXPECTED_RESULTS = 2; SearchResult results = createClient.createQueryBuilder(COMMON).andGuidsOrHrids(GUID1, GUID2).includeCache().getSearchResult(); @@ -122,35 +122,35 @@ public class OseeClientQueryTest { } @Test - public void SearchForArtifactByHrid() throws OseeCoreException { + public void searchForArtifactByHrid() throws OseeCoreException { final int EXPECTED_RESULTS = 1; SearchResult results = createClient.createQueryBuilder(COMMON).andGuidsOrHrids(HRID1).getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); } @Test - public void SearchForArtifactByHrids() throws OseeCoreException { + public void searchForArtifactByHrids() throws OseeCoreException { final int EXPECTED_RESULTS = 2; SearchResult results = createClient.createQueryBuilder(COMMON).andGuidsOrHrids(HRID1, HRID2).getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); } @Test - public void SearchForArtifactByLocalId() throws OseeCoreException { + public void searchForArtifactByLocalId() throws OseeCoreException { final int EXPECTED_RESULTS = 1; SearchResult results = createClient.createQueryBuilder(COMMON).andLocalId(9).getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); } @Test - public void SearchForArtifactByLocalIds() throws OseeCoreException { + public void searchForArtifactByLocalIds() throws OseeCoreException { final int EXPECTED_RESULTS = 2; SearchResult results = createClient.createQueryBuilder(COMMON).andLocalId(19, 9).getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); } @Test - public void SearchForArtifactByName() throws OseeCoreException { + public void searchForArtifactByName() throws OseeCoreException { final int EXPECTED_RESULTS = 1; SearchResult results = createClient.createQueryBuilder(COMMON).andNameEquals("Joe Smith").getSearchResult(); assertEquals(EXPECTED_RESULTS, results.getTotal()); |