diff options
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.test/src')
9 files changed, 1107 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationRule.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationRule.java new file mode 100644 index 00000000000..bd71e8e6f08 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationRule.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs; + +import org.eclipse.osee.event.EventService; +import org.eclipse.osee.executor.admin.ExecutorAdmin; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.core.services.IOseeModelFactoryService; +import org.eclipse.osee.framework.core.services.IOseeModelingService; +import org.eclipse.osee.framework.core.services.IdentityService; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.logger.Log; +import org.eclipse.osee.orcs.core.SystemPreferences; +import org.eclipse.osee.orcs.core.ds.OrcsDataStore; +import org.eclipse.osee.orcs.db.mock.OsgiRule; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.osgi.service.event.EventAdmin; + +/** + * @author Roberto E. Escobar + */ +public class OrcsIntegrationRule extends OsgiRule { + + public OrcsIntegrationRule(Object testObject) { + super(new CheckServices(), testObject); + } + + public static class CheckServices { + // @formatter:off + @OsgiService public Log log; + @OsgiService public SystemPreferences preferences; + @OsgiService public IdentityService idService; + @OsgiService public IOseeDatabaseService dbService; + @OsgiService public IOseeModelFactoryService modelFactory; + @OsgiService public IOseeModelingService modelService; + @OsgiService public EventAdmin eventAdmin; + @OsgiService public EventService eventService; + @OsgiService public ExecutorAdmin executorAdmin; + @OsgiService public IOseeCachingService cachingService; + @OsgiService public OrcsDataStore dataStore; + @OsgiService public DataStoreTypeCache typeCache; + // @formatter:on + } + +} diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java new file mode 100644 index 00000000000..4759e91adc5 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/OrcsIntegrationTestSuite.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs; + +import org.eclipse.osee.orcs.api.OrcsAttributeLoadingTest; +import org.eclipse.osee.orcs.api.OrcsAttributeSearchTest; +import org.eclipse.osee.orcs.api.OrcsBranchTest; +import org.eclipse.osee.orcs.api.OrcsQueryTest; +import org.eclipse.osee.orcs.api.OrcsRelationLoadingTest; +import org.eclipse.osee.orcs.api.OrcsTransactionTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author Roberto E. Escobar + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + OrcsAttributeLoadingTest.class, + OrcsAttributeSearchTest.class, + OrcsBranchTest.class, + OrcsQueryTest.class, + OrcsRelationLoadingTest.class, + OrcsTransactionTest.class}) +public class OrcsIntegrationTestSuite { + // Test Suite +} 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 new file mode 100644 index 00000000000..b57cbcd83a9 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeLoadingTest.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.data.ResultSet; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreBranches; +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.OrcsIntegrationRule; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.Operator; +import org.eclipse.osee.orcs.search.QueryBuilder; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.junit.Rule; + +/** + * @author Jeff C. Phillips + */ +public class OrcsAttributeLoadingTest { + + @Rule + public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this); + + @Rule + public OseeDatabase db = new OseeDatabase("osee.demo.h2"); + + @OsgiService + OrcsApi orcsApi; + + @org.junit.Test + public void testAttributeLoading() throws Exception { + ApplicationContext context = null; // TODO use real application context + + QueryFactory queryFactory = orcsApi.getQueryFactory(context); + QueryBuilder builder = queryFactory.fromBranch(CoreBranches.COMMON).andLocalIds(Arrays.asList(7, 8, 9)); + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + Assert.assertEquals(3, moreArts.size()); + Assert.assertEquals(3, builder.getCount()); + + Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + ArtifactReadable art7 = lookup.get(7); + ArtifactReadable art8 = lookup.get(8); + ArtifactReadable art9 = lookup.get(9); + + //Test loading name attributes + Assert.assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name), + "org.eclipse.osee.ats.config.demo.OseeTypes_Demo"); + Assert.assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups"); + Assert.assertEquals(art9.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone"); + + //Test boolean attributes + Assert.assertEquals(art9.getSoleAttributeAsString(CoreAttributeTypes.DefaultGroup), "true"); + + //Load WTC attributes + loadWordTemplateContentAttributes(queryFactory, orcsApi.getBranchCache()); + } + + private void loadWordTemplateContentAttributes(QueryFactory queryFactory, BranchCache branchCache) throws OseeCoreException { + QueryBuilder builder = + queryFactory.fromBranch(branchCache.getByName("SAW_Bld_1").iterator().next()).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); + } + + Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) { + Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>(); + for (ArtifactReadable artifact : arts) { + lookup.put(artifact.getLocalId(), artifact); + } + return lookup; + } +} 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 new file mode 100644 index 00000000000..6de6e092601 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsAttributeSearchTest.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.data.ResultSet; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreBranches; +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.OrcsIntegrationRule; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.CaseType; +import org.eclipse.osee.orcs.search.Operator; +import org.eclipse.osee.orcs.search.QueryBuilder; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.eclipse.osee.orcs.search.StringOperator; +import org.junit.Rule; + +/** + * @author Jeff C. Phillips + */ +public class OrcsAttributeSearchTest { + + @Rule + public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this); + + @Rule + public OseeDatabase db1 = new OseeDatabase("osee.demo.h2"); + + @OsgiService + OrcsApi orcsApi; + + @org.junit.Test + public void runGodMethod() throws OseeCoreException { + ApplicationContext context = null; // TODO use real application context + QueryFactory queryFactory = orcsApi.getQueryFactory(context); + + testNameAttributeNotEqualSearch(queryFactory); + testNameAttributeEqualSearch(queryFactory); + testBooleanAttributeSearch(queryFactory); + testWTCAttributeEqualSearch(queryFactory, orcsApi.getBranchCache()); + } + + public void testNameAttributeNotEqualSearch(QueryFactory queryFactory) throws OseeCoreException { + QueryBuilder builder = + queryFactory.fromBranch(CoreBranches.COMMON).and(CoreAttributeTypes.Name, Operator.NOT_EQUAL, "User Groups"); + + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + for (ArtifactReadable artifact : moreArts) { + Assert.assertTrue(artifact.getLocalId() != 8); + } + } + + public void testNameAttributeEqualSearch(QueryFactory queryFactory) throws OseeCoreException { + QueryBuilder builder = + queryFactory.fromBranch(CoreBranches.COMMON).and(CoreAttributeTypes.Name, Operator.EQUAL, "User Groups"); + + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + Assert.assertEquals(1, moreArts.size()); + Assert.assertEquals(1, builder.getCount()); + + Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + ArtifactReadable art8 = lookup.get(8); + + //Test loading name attributes + Assert.assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups"); + } + + public void testWTCAttributeEqualSearch(QueryFactory queryFactory, BranchCache branchCache) throws OseeCoreException { + Branch branch = branchCache.getBySoleName("SAW_Bld_1"); + QueryBuilder builder = + queryFactory.fromBranch(branch).and(CoreAttributeTypes.WordTemplateContent, + StringOperator.TOKENIZED_ANY_ORDER, CaseType.IGNORE_CASE, "commands"); + + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + Assert.assertFalse(moreArts.isEmpty()); + Assert.assertEquals(3, moreArts.size()); + Assert.assertEquals(3, builder.getCount()); + } + + public void testBooleanAttributeSearch(QueryFactory queryFactory) throws OseeCoreException { + QueryBuilder builder = + queryFactory.fromBranch(CoreBranches.COMMON).and(CoreAttributeTypes.DefaultGroup, Operator.EQUAL, "yes"); + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + Assert.assertEquals(1, moreArts.size()); + Assert.assertEquals(1, builder.getCount()); + + Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + ArtifactReadable art9 = lookup.get(9); + Assert.assertEquals(art9.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone"); + } + + Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) { + Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>(); + for (ArtifactReadable artifact : arts) { + lookup.put(artifact.getLocalId(), artifact); + } + return lookup; + } +} 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 new file mode 100644 index 00000000000..0a9fac70795 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsBranchTest.java @@ -0,0 +1,157 @@ +/* + * Created on Apr 30, 2012 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.orcs.api; + +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; +import org.eclipse.osee.orcs.OrcsBranch; +import org.eclipse.osee.orcs.OrcsIntegrationRule; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.CreateBranchData; +import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * @author David Miller + */ + +public class OrcsBranchTest { + + @Rule + public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this); + + @Rule + public OseeDatabase db = new OseeDatabase("osee.demo.h2"); + + private OrcsBranch branchInterface = null; + private final ApplicationContext context = null; // TODO use real application context + + private final static String ARTIFACT_NAME = "Joe Smith"; + + @OsgiService + OrcsApi orcsApi; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + branchInterface = orcsApi.getBranchOps(context); + } + + @Test + 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 + + // set up the query factory for the test + QueryFactory qf = orcsApi.getQueryFactory(context); + // ReadableArtifact createdBy = + // qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getExactlyOne(); + ArtifactReadable createdBy = + qf.fromBranch(CoreBranches.COMMON).andNameEquals("OSEE System").getResults().getExactlyOne(); + + 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(); + + // in the database, on the common branch, the users are all created in transaction 14 + // 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); + + // we copied the branch at transaction 13, 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); + + // finally, we copy another branch at transaction id 14, this is the transaction that added the + // 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 = + 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(); + + int postResult = qf.fromBranch(postBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size(); + Assert.assertEquals(1, postResult); + + } + + @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); + ArtifactReadable 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, ArtifactReadable 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.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java new file mode 100644 index 00000000000..eb07707baa3 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java @@ -0,0 +1,316 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import junit.framework.Assert; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.MatchLocation; +import org.eclipse.osee.orcs.ApplicationContext; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.OrcsIntegrationRule; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.AttributeReadable; +import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.CaseType; +import org.eclipse.osee.orcs.search.Match; +import org.eclipse.osee.orcs.search.Operator; +import org.eclipse.osee.orcs.search.QueryBuilder; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.eclipse.osee.orcs.search.StringOperator; +import org.eclipse.osee.orcs.utility.MatchComparator; +import org.eclipse.osee.orcs.utility.NameComparator; +import org.eclipse.osee.orcs.utility.SortOrder; +import org.junit.Rule; +import org.junit.Test; + +/** + * @author Roberto E. Escobar + */ +public class OrcsQueryTest { + + @Rule + public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this); + + @Rule + public OseeDatabase db = new OseeDatabase("osee.demo.h2"); + + private final boolean includeMatchLocationTests = false; + + @OsgiService + OrcsApi orcsApi; + + @Test + public void testQueries() throws OseeCoreException { + ApplicationContext context = null; // TODO use real application context + QueryFactory factory = orcsApi.getQueryFactory(null); + + checkQueryByIds(factory); + + checkQueryArtifactType(factory); + checkQueryArtifactTypeInheritance(factory); + checkQueryArtifactTypesNoInheritance(factory); + + checkQueryAttributeValue(factory); + checkQueryArtifactTypeAndNameValue(factory); + + checkQueryAttributeKeyword(factory); + } + + private void checkQueryByIds(QueryFactory factory) throws OseeCoreException { + QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON).andGuidsOrHrids("AEmLGXnw0WaGLxcK5qwA"); + Assert.assertEquals(1, builder.getCount()); + + ArtifactReadable artifact = builder.getResults().getExactlyOne(); + Assert.assertEquals("AEmLGXnw0WaGLxcK5qwA", artifact.getGuid()); + } + + private void checkQueryArtifactType(QueryFactory factory) throws OseeCoreException { + QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON).andIsOfType(CoreArtifactTypes.Folder); + + Assert.assertEquals(5, builder.getCount()); + + List<ArtifactReadable> artifacts = builder.getResults().getList(); + Assert.assertEquals(5, artifacts.size()); + + checkContainsTypes(artifacts, CoreArtifactTypes.Folder); + + Collections.sort(artifacts, new NameComparator(SortOrder.ASCENDING)); + + Iterator<ArtifactReadable> iterator = artifacts.iterator(); + Assert.assertEquals("Action Tracking System", iterator.next().getName()); + Assert.assertEquals("Config", iterator.next().getName()); + Assert.assertEquals("Document Templates", iterator.next().getName()); + Assert.assertEquals("User Groups", iterator.next().getName()); + Assert.assertEquals("Work Definitions", iterator.next().getName()); + + if (includeMatchLocationTests) { + List<Match<ArtifactReadable, AttributeReadable<?>>> matches = builder.getMatches().getList(); + Assert.assertEquals(5, matches.size()); + + Iterator<Match<ArtifactReadable, AttributeReadable<?>>> matchIterator = matches.iterator(); + checkMatch(matchIterator.next(), "Action Tracking System"); + checkMatch(matchIterator.next(), "Config"); + checkMatch(matchIterator.next(), "Document Templates"); + checkMatch(matchIterator.next(), "User Groups"); + checkMatch(matchIterator.next(), "Work Definitions"); + } + } + + private void checkQueryArtifactTypeInheritance(QueryFactory factory) throws OseeCoreException { + QueryBuilder builder = + factory.fromBranch(TestBranches.SAW_Bld_1).andIsOfType(CoreArtifactTypes.AbstractSoftwareRequirement);// + + builder.excludeTypeInheritance(); + Assert.assertEquals(0, builder.getCount()); + + ArtifactReadable artifact = builder.getResults().getOneOrNull(); + Assert.assertNull(artifact); + + builder.includeTypeInheritance(); + Assert.assertEquals(24, builder.getCount()); + + List<ArtifactReadable> artifacts = builder.getResults().getList(); + Assert.assertEquals(24, artifacts.size()); + + checkContainsTypes(artifacts, CoreArtifactTypes.SoftwareRequirement); + } + + private void checkQueryArtifactTypesNoInheritance(QueryFactory factory) throws OseeCoreException { + QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON); + builder.excludeTypeInheritance(); + builder.andIsOfType(CoreArtifactTypes.OseeTypeDefinition, CoreArtifactTypes.Folder); + + Assert.assertEquals(10, builder.getCount()); + + List<ArtifactReadable> artifacts = builder.getResults().getList(); + Assert.assertEquals(10, artifacts.size()); + + checkContainsTypes(artifacts, CoreArtifactTypes.OseeTypeDefinition, CoreArtifactTypes.Folder); + + Collections.sort(artifacts, new NameComparator(SortOrder.ASCENDING)); + + Iterator<ArtifactReadable> iterator = artifacts.iterator(); + Assert.assertEquals("Action Tracking System", iterator.next().getName()); + Assert.assertEquals("Config", iterator.next().getName()); + Assert.assertEquals("Document Templates", iterator.next().getName()); + Assert.assertEquals("User Groups", iterator.next().getName()); + Assert.assertEquals("Work Definitions", iterator.next().getName()); + + Assert.assertEquals("org.eclipse.osee.ats.OseeTypes_ATS", iterator.next().getName()); + Assert.assertEquals("org.eclipse.osee.ats.config.demo.OseeTypes_Demo", 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()); + } + + private void checkQueryAttributeValue(QueryFactory factory) throws OseeCoreException { + QueryBuilder builder = factory.fromBranch(CoreBranches.COMMON); + builder.and(CoreAttributeTypes.Name, Operator.EQUAL, "Action Tracking System"); + + Assert.assertEquals(1, builder.getCount()); + + ArtifactReadable artifact = builder.getResults().getExactlyOne(); + + Assert.assertEquals("Action Tracking System", artifact.getName()); + Assert.assertEquals(CoreArtifactTypes.Folder, artifact.getArtifactType()); + + if (includeMatchLocationTests) { + Match<ArtifactReadable, AttributeReadable<?>> result = builder.getMatches().getExactlyOne(); + + Assert.assertEquals(artifact, result.getItem()); + checkMatch(result, "Action Tracking System", CoreAttributeTypes.Name); + + AttributeReadable<?> attr = result.getElements().iterator().next(); + List<MatchLocation> location = result.getLocation(attr); + Assert.assertEquals(1, location.size()); + + MatchLocation loc1 = location.iterator().next(); + Assert.assertEquals(0, loc1.getStartPosition()); + Assert.assertEquals("Action Tracking System".length(), loc1.getEndPosition()); + } + } + + private void checkQueryArtifactTypeAndNameValue(QueryFactory factory) throws OseeCoreException { + ////////////////////// + QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1); + builder.and(CoreAttributeTypes.Name, Operator.EQUAL, "%Requirement%"); + + Assert.assertEquals(7, builder.getCount()); + List<ArtifactReadable> artifacts = builder.getResults().getList(); + Assert.assertEquals(7, artifacts.size()); + checkContainsTypes(artifacts, CoreArtifactTypes.Folder, CoreArtifactTypes.SubsystemRequirement, + CoreArtifactTypes.SystemRequirement); + + builder.andIsOfType(CoreArtifactTypes.Folder); + Assert.assertEquals(4, builder.getCount()); + + List<ArtifactReadable> folders = builder.getResults().getList(); + Assert.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()); + checkContainsTypes(folders, CoreArtifactTypes.Folder); + + ////////////////////// + QueryBuilder builder1 = factory.fromBranch(TestBranches.SAW_Bld_1); + builder1.and(CoreAttributeTypes.Name, Operator.EQUAL, "%Requirement%"); + builder1.andIsOfType(CoreArtifactTypes.SubsystemRequirement); + Assert.assertEquals(1, builder1.getCount()); + List<ArtifactReadable> subSystemReqs = builder1.getResults().getList(); + Assert.assertEquals(1, subSystemReqs.size()); + Assert.assertEquals("Subsystem Requirements", subSystemReqs.get(0).getName()); + checkContainsTypes(subSystemReqs, CoreArtifactTypes.SubsystemRequirement); + + ////////////////////// + QueryBuilder builder2 = factory.fromBranch(TestBranches.SAW_Bld_1); + builder2.and(CoreAttributeTypes.Name, Operator.EQUAL, "%Requirement%"); + builder2.includeTypeInheritance(); + builder2.andIsOfType(CoreArtifactTypes.Requirement); + Assert.assertEquals(3, builder2.getCount()); + + List<ArtifactReadable> requirements = builder2.getResults().getList(); + Assert.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()); + checkContainsTypes(subSystemReqs, CoreArtifactTypes.SubsystemRequirement, CoreArtifactTypes.SystemRequirement); + } + + private void checkQueryAttributeKeyword(QueryFactory factory) throws OseeCoreException { + QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1); + builder.and(CoreAttributeTypes.Name, StringOperator.TOKENIZED_ANY_ORDER, CaseType.IGNORE_CASE, "REQUIREMENTS"); + + Assert.assertEquals(7, builder.getCount()); + List<ArtifactReadable> requirements = builder.getResults().getList(); + Assert.assertEquals(7, requirements.size()); + checkContainsTypes(requirements, CoreArtifactTypes.Folder, CoreArtifactTypes.SubsystemRequirement, + CoreArtifactTypes.SystemRequirement); + 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()); + + // if (includeMatchLocationTests) { + List<Match<ArtifactReadable, AttributeReadable<?>>> matches = builder.getMatches().getList(); + Assert.assertEquals(7, matches.size()); + + Collections.sort(matches, new MatchComparator(SortOrder.ASCENDING)); + + // @formatter:off + Iterator<Match<ArtifactReadable, AttributeReadable<?>>> matchIterator = matches.iterator(); + checkMatchSingleAttribute(matchIterator.next(), "Hardware Requirements", CoreAttributeTypes.Name, "Requirements"); + checkMatchSingleAttribute(matchIterator.next(), "Performance Requirements", CoreAttributeTypes.Name, "Requirements"); + checkMatchSingleAttribute(matchIterator.next(), "Safety Requirements", CoreAttributeTypes.Name, "Requirements"); + checkMatchSingleAttribute(matchIterator.next(), "Software Requirements", CoreAttributeTypes.Name, "Requirements"); + checkMatchSingleAttribute(matchIterator.next(), "Subsystem Requirements", CoreAttributeTypes.Name, "Requirements"); + checkMatchSingleAttribute(matchIterator.next(), "Subsystem Requirements", CoreAttributeTypes.Name, "Requirements"); + checkMatchSingleAttribute(matchIterator.next(), "System Requirements", CoreAttributeTypes.Name, "Requirements"); + // @formatter:on + + QueryBuilder builder1 = factory.fromBranch(TestBranches.SAW_Bld_1); + builder1.and(CoreAttributeTypes.Name, StringOperator.TOKENIZED_ANY_ORDER, CaseType.MATCH_CASE, "REQUIREMENTS"); + Assert.assertEquals(0, builder1.getCount()); + } + + 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()), + 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()); + + AttributeReadable<?> attribute = match.getElements().iterator().next(); + Assert.assertEquals(types, attribute.getAttributeType()); + List<MatchLocation> locations = match.getLocation(attribute); + Assert.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())); + } + + private static void checkMatch(Match<ArtifactReadable, AttributeReadable<?>> match, String artName, IAttributeType... types) throws OseeCoreException { + Assert.assertEquals(artName, match.getItem().getName()); + if (types.length > 0) { + Assert.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()); + } + } + } +} 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 new file mode 100644 index 00000000000..4582a189791 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsRelationLoadingTest.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +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; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.orcs.ApplicationContext; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.OrcsIntegrationRule; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.GraphReadable; +import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiService; +import org.eclipse.osee.orcs.search.Operator; +import org.eclipse.osee.orcs.search.QueryBuilder; +import org.eclipse.osee.orcs.search.QueryFactory; +import org.junit.Assert; +import org.junit.Rule; + +/** + * Test Case for {@link OrcsApi} + * + * @author Andrew M. Finkbeiner + */ +public class OrcsRelationLoadingTest { + + @Rule + public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this); + + @Rule + public OseeDatabase db = new OseeDatabase("osee.demo.h2"); + + @OsgiService + OrcsApi orcsApi; + + @org.junit.Test + public void testSearchById() throws Exception { + ApplicationContext context = null; // TODO use real application context + + QueryFactory queryFactory = orcsApi.getQueryFactory(context); + 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(7, 8, 9)); + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + Assert.assertEquals(3, moreArts.size()); + Assert.assertEquals(3, builder.getCount()); + + Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts); + ArtifactReadable art7 = lookup.get(7); + ArtifactReadable art8 = lookup.get(8); + ArtifactReadable art9 = lookup.get(9); + + //art 7 has no relations + Assert.assertEquals(0, graph.getExistingRelationTypes(art7).size()); + //art 8 has 4 + // 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 + // 2 397 1 8 36 1 1 2 6 36 + // 3 397 8 16 37 1 1 2 6 37 + // 1 397 8 9 41 1 1 2 6 41 + // 173 397 8 121 699 1 1 2 16 + Assert.assertEquals(2, graph.getExistingRelationTypes(art8).size()); + Assert.assertEquals(3, + graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child, art8).getList().size()); + Assert.assertEquals(1, + graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, art8).getList().size()); + + //art9 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 + // 1 397 8 9 41 1 1 2 6 41 + // 21 382 9 34 326 1 1 2 14 326 + // 20 382 9 33 327 1 1 2 14 327 + // 23 382 9 36 328 1 1 2 14 328 + // 22 382 9 35 329 1 1 2 14 329 + // 28 382 9 41 334 1 1 2 14 334 + // 29 382 9 42 335 1 1 2 14 335 + // 30 382 9 43 336 1 1 2 14 336 + // 31 382 9 44 337 1 1 2 14 337 + // 24 382 9 37 338 1 1 2 14 338 + // 25 382 9 38 339 1 1 2 14 339 + // 26 382 9 39 340 1 1 2 14 340 + // 27 382 9 40 341 1 1 2 14 341 + // 36 382 9 49 342 1 1 2 14 342 + // 37 382 9 50 343 1 1 2 14 343 + // 38 382 9 51 344 1 1 2 14 344 + // 32 382 9 45 346 1 1 2 14 346 + // 33 382 9 46 347 1 1 2 14 347 + // 34 382 9 47 348 1 1 2 14 348 + // 35 382 9 48 349 1 1 2 14 349 + // 218 382 9 166 898 1 1 2 21 898 + Assert.assertEquals(2, graph.getExistingRelationTypes(art9).size()); + Assert.assertEquals(1, + graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, art9).getList().size()); + Assert.assertEquals(20, graph.getRelatedArtifacts(CoreRelationTypes.Users_User, art9).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"); + ResultSet<ArtifactReadable> resultSet = builder.getResults(); + List<ArtifactReadable> moreArts = resultSet.getList(); + + Assert.assertFalse(moreArts.isEmpty()); + ArtifactReadable artifact = moreArts.iterator().next(); + + //art 7 has no relations + + //artifact has 3 children and 1 parent + + Assert.assertEquals(2, graph.getExistingRelationTypes(artifact).size()); + Assert.assertEquals(3, + graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child, artifact).getList().size()); + Assert.assertEquals(1, + graph.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Parent, artifact).getList().size()); + } + + Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) { + Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>(); + for (ArtifactReadable artifact : arts) { + lookup.put(artifact.getLocalId(), artifact); + } + return lookup; + } +} 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 new file mode 100644 index 00000000000..8fcbc5054ff --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTransactionTest.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2012 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +import java.lang.reflect.Proxy; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.enums.SystemUser; +import org.eclipse.osee.framework.core.enums.TransactionDetailsType; +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.orcs.ApplicationContext; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.OrcsIntegrationRule; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.data.ArtifactWriteable; +import org.eclipse.osee.orcs.db.mock.OseeDatabase; +import org.eclipse.osee.orcs.db.mock.OsgiService; +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; + +/** + * @author Roberto E. Escobar + */ +public class OrcsTransactionTest { + + @Rule + public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this); + + @Rule + public OseeDatabase db = new OseeDatabase("osee.demo.h2"); + + @OsgiService + private OrcsApi orcsApi; + + private final ApplicationContext context = null; // TODO use real application context + private TransactionFactory txFactory; + private ArtifactReadable userArtifact; + + @Before + public void setUp() throws Exception { + txFactory = orcsApi.getTransactionFactory(context); + userArtifact = getSystemUser(); + } + + @Test + public void testCreateArtifact() throws OseeCoreException { + String comment = "Test Artifact Write"; + String expectedName = "Create A Folder"; + String expectedAnnotation = "Annotate It"; + + Branch branch = orcsApi.getBranchCache().get(CoreBranches.COMMON); + TransactionRecord currentTx = orcsApi.getTxsCache().getHeadTransaction(branch); + + OrcsTransaction tx = txFactory.createTransaction(branch, userArtifact, comment); + + 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()); + + String id = writeable.getGuid(); + + Assert.assertTrue(Proxy.isProxyClass(writeable.getClass())); + + TransactionRecord newTx = tx.commit(); + Assert.assertFalse(tx.isCommitInProgress()); + + TransactionRecord newHeadTx = orcsApi.getTxsCache().getHeadTransaction(branch); + + checkTransaction(currentTx, newTx, branch, comment, userArtifact); + Assert.assertEquals(newTx, newHeadTx); + + ArtifactReadable artifact = + orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andGuidsOrHrids(id).getResults().getExactlyOne(); + Assert.assertEquals(expectedName, artifact.getName()); + Assert.assertEquals(expectedAnnotation, + artifact.getAttributeValues(CoreAttributeTypes.Annotation).iterator().next()); + Assert.assertEquals(writeable, artifact); + + Assert.assertTrue(Proxy.isProxyClass(artifact.getClass())); + } + + private ArtifactReadable getSystemUser() throws OseeCoreException { + return orcsApi.getQueryFactory(context).fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne(); + } + + private void checkTransaction(TransactionRecord previousTx, TransactionRecord newTx, Branch branch, String comment, ArtifactReadable user) throws OseeCoreException { + Assert.assertEquals(previousTx.getId() + 1, 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())); + } + + // 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.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java new file mode 100644 index 00000000000..7e1f63e1ef5 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/TestBranches.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.api; + +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.TokenFactory; + +/** + * @author Roberto E. Escobar + */ +public final class TestBranches { + + private TestBranches() { + // Constants class + } + + public static final IOseeBranch SAW_Bld_1 = TokenFactory.createBranch("AyH_f2sSKy3l07fIvAAA", "SAW_Bld_1"); + public static final IOseeBranch SAW_Bld_2 = TokenFactory.createBranch("AyH_f2sSKy3l07fIvBBB", "SAW_Bld_2"); +} |