diff options
author | Angel Avila | 2013-01-11 20:37:37 +0000 |
---|---|---|
committer | Angel Avila | 2013-01-29 18:41:31 +0000 |
commit | c2e529f7f3846588314d7459391aa92cc469a07f (patch) | |
tree | ea0e79ae4d66755485cfc90686c72dc5a04e5786 /plugins/org.eclipse.osee.coverage.integration.tests | |
parent | fbf383213fa39d23689a928af8cb29f8477df274 (diff) | |
download | org.eclipse.osee-c2e529f7f3846588314d7459391aa92cc469a07f.tar.gz org.eclipse.osee-c2e529f7f3846588314d7459391aa92cc469a07f.tar.xz org.eclipse.osee-c2e529f7f3846588314d7459391aa92cc469a07f.zip |
bug[ats_73YRS]: Implement fix for TestUnitNames for Coverage
Bug: 397931
Change-Id: I012c479dfca0961ed05a79f096d0a42e7fbf4168
Diffstat (limited to 'plugins/org.eclipse.osee.coverage.integration.tests')
4 files changed, 130 insertions, 39 deletions
diff --git a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/ArtifactTestUnitStoreTest.java b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/ArtifactTestUnitStoreTest.java index b025e92a282..8bd01088cfa 100644 --- a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/ArtifactTestUnitStoreTest.java +++ b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/ArtifactTestUnitStoreTest.java @@ -11,9 +11,13 @@ package org.eclipse.osee.coverage.integration.tests.integration; import static org.eclipse.osee.coverage.demo.CoverageChoice.OSEE_COVERAGE_DEMO; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.Map.Entry; import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule; import org.eclipse.osee.client.test.framework.OseeLogMonitorRule; +import org.eclipse.osee.coverage.integration.tests.integration.util.CoverageTestUtil; import org.eclipse.osee.coverage.model.CoverageItem; import org.eclipse.osee.coverage.model.CoverageOptionManager; import org.eclipse.osee.coverage.model.CoverageOptionManagerDefault; @@ -21,6 +25,8 @@ import org.eclipse.osee.coverage.model.CoverageUnit; import org.eclipse.osee.coverage.model.CoverageUnitFactory; import org.eclipse.osee.coverage.model.ITestUnitProvider; import org.eclipse.osee.coverage.store.ArtifactTestUnitStore; +import org.eclipse.osee.coverage.store.CoverageArtifactTypes; +import org.eclipse.osee.coverage.store.CoverageAttributeTypes; import org.eclipse.osee.coverage.store.TestUnitCache; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; @@ -42,15 +48,18 @@ import org.junit.Test; */ public class ArtifactTestUnitStoreTest { + private static final String testInputDataReadOnlyList = "1|test1\n2|test2\n3|test3"; + private static final String testInputDataCoverageArtifact = "4|test4\n5|test5\n6|test6"; + private static final String coverageTestGuid = "Bs+PvSVQf4Z4EHSTcyQB"; + private static Artifact readOnlyTestUnitNames; + private Branch testTopBranch; + private Branch testWorkingBranch; + @Rule public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_COVERAGE_DEMO); - @Rule public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule(); - private static final String testInputData = "1|test1\n2|test2\n3|test3"; - private Branch testBranch; - private CoverageItem createCoverageItem(ITestUnitProvider tc) throws OseeCoreException { CoverageUnit parent = CoverageUnitFactory.createCoverageUnit(null, "Top", "C:/UserData/", null); CoverageItem ci1 = new CoverageItem(parent, CoverageOptionManager.Deactivated_Code, "1"); @@ -60,20 +69,23 @@ public class ArtifactTestUnitStoreTest { @Before public void createTestArtifact() throws OseeCoreException { - testBranch = BranchManager.createTopLevelBranch("TestBranch"); - Artifact testArtifact = - ArtifactQuery.getOrCreate(ArtifactTestUnitStore.COVERAGE_GUID, null, CoreArtifactTypes.GeneralData, testBranch); - testArtifact.setSoleAttributeFromString(CoreAttributeTypes.GeneralStringData, testInputData); + testTopBranch = BranchManager.createTopLevelBranch("Test Top Level Branch"); + testWorkingBranch = BranchManager.createWorkingBranch(CoverageTestUtil.getTestBranch(), "Test Working Branch"); + readOnlyTestUnitNames = + ArtifactQuery.getOrCreate(ArtifactTestUnitStore.READ_ONLY_GUID, null, CoreArtifactTypes.GeneralData, + testTopBranch); + readOnlyTestUnitNames.setSoleAttributeFromString(CoreAttributeTypes.GeneralStringData, testInputDataReadOnlyList); } @After public void cleanUpTestArtifact() { - BranchManager.deleteBranch(testBranch); + BranchManager.deleteBranch(testTopBranch); + BranchManager.deleteBranch(testWorkingBranch); } @Test public void testLoad() throws OseeCoreException { - ArtifactTestUnitStore store = new ArtifactTestUnitStore(testBranch); + ArtifactTestUnitStore store = new ArtifactTestUnitStore(null, readOnlyTestUnitNames); TestUnitCache tc = new TestUnitCache(store); store.load(tc); StringBuilder actual = new StringBuilder(); @@ -87,27 +99,90 @@ public class ArtifactTestUnitStoreTest { actual.append(entry.getValue()); firstTime = false; } - Assert.assertEquals(testInputData, actual.toString()); + Assert.assertEquals(testInputDataReadOnlyList, actual.toString()); } @Test public void testStore() throws OseeCoreException { - ArtifactTestUnitStore store = new ArtifactTestUnitStore(testBranch); + Artifact testArtifact = + ArtifactQuery.getOrCreate(coverageTestGuid, null, CoverageArtifactTypes.CoveragePackage, testWorkingBranch); + testArtifact.setSoleAttributeFromString(CoverageAttributeTypes.UnitTestTable, testInputDataCoverageArtifact); + + ArtifactTestUnitStore store = new ArtifactTestUnitStore(testArtifact, readOnlyTestUnitNames); TestUnitCache tc = new TestUnitCache(store); CoverageItem ci = createCoverageItem(tc); ci.addTestUnitName("test1"); - ci.addTestUnitName("test10"); - store.store(tc); + SkynetTransaction transaction = + TransactionManager.createTransaction(testWorkingBranch, getClass().getSimpleName()); + store.store(tc, transaction); - SkynetTransaction transaction = TransactionManager.createTransaction(testBranch, getClass().getSimpleName()); - Artifact testArtifact = - ArtifactQuery.getOrCreate(ArtifactTestUnitStore.COVERAGE_GUID, null, CoreArtifactTypes.GeneralData, testBranch); - String actual = testArtifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, ""); - String expected = testInputData + "\n4|test10"; + String actual = testArtifact.getSoleAttributeValueAsString(CoverageAttributeTypes.UnitTestTable, ""); + String expected = "1|test1\n" + testInputDataCoverageArtifact; Assert.assertEquals(expected, actual); testArtifact.persist(transaction); transaction.execute(); } + + @Test + public void testCoveragePackageEmptyTestUnitTableAttr() throws OseeCoreException { + // Test when CoveragePackageArtifact has an empty UnitTestTable the ArtifactStore gets testUnits from the readOnly Artifact + Artifact testCoverageArtifact = + ArtifactQuery.getOrCreate(coverageTestGuid, null, CoverageArtifactTypes.CoveragePackage, testWorkingBranch); + testCoverageArtifact.setSoleAttributeFromString(CoverageAttributeTypes.UnitTestTable, ""); + + ArtifactTestUnitStore store = new ArtifactTestUnitStore(testCoverageArtifact, readOnlyTestUnitNames); + TestUnitCache tc = new TestUnitCache(store); + + Collection<Entry<Integer, String>> allCachedTestUnitNames = tc.getAllCachedTestUnitEntries(); + Map<Integer, String> testUnitNamesList = new HashMap<Integer, String>(); + for (Entry<Integer, String> entry : allCachedTestUnitNames) { + testUnitNamesList.put(entry.getKey(), entry.getValue()); + } + + String actual = testUnitNamesList.get(1); + String expected = "test1"; + Assert.assertEquals(expected, actual); + + actual = testUnitNamesList.get(2); + expected = "test2"; + Assert.assertEquals(expected, actual); + + actual = testUnitNamesList.get(3); + expected = "test3"; + Assert.assertEquals(expected, actual); + + } + + @Test + public void testCoveragePackageTestUnitTableAttr() throws OseeCoreException { + + Artifact testCoverageArtifact = + ArtifactQuery.getOrCreate(coverageTestGuid, null, CoverageArtifactTypes.CoveragePackage, testWorkingBranch); + testCoverageArtifact.setSoleAttributeFromString(CoverageAttributeTypes.UnitTestTable, + testInputDataCoverageArtifact); + + ArtifactTestUnitStore store = new ArtifactTestUnitStore(testCoverageArtifact, readOnlyTestUnitNames); + TestUnitCache tc = new TestUnitCache(store); + + Collection<Entry<Integer, String>> allCachedTestUnitNames = tc.getAllCachedTestUnitEntries(); + Map<Integer, String> testUnitNamesList = new HashMap<Integer, String>(); + for (Entry<Integer, String> entry : allCachedTestUnitNames) { + testUnitNamesList.put(entry.getKey(), entry.getValue()); + } + + String actual = testUnitNamesList.get(4); + String expected = "test4"; + Assert.assertEquals(expected, actual); + + actual = testUnitNamesList.get(5); + expected = "test5"; + Assert.assertEquals(expected, actual); + + actual = testUnitNamesList.get(6); + expected = "test6"; + Assert.assertEquals(expected, actual); + + } } diff --git a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageItemPersistTest.java b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageItemPersistTest.java index dcba0a5c8c9..e71f677be9e 100644 --- a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageItemPersistTest.java +++ b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageItemPersistTest.java @@ -10,8 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.coverage.integration.tests.integration; -import static org.eclipse.osee.coverage.demo.CoverageChoice.*; -import static org.mockito.Mockito.*; +import static org.eclipse.osee.coverage.demo.CoverageChoice.OSEE_COVERAGE_DEMO; import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule; import org.eclipse.osee.client.test.framework.OseeLogMonitorRule; import org.eclipse.osee.coverage.event.CoverageEventType; @@ -22,10 +21,12 @@ import org.eclipse.osee.coverage.model.CoverageOptionManager; import org.eclipse.osee.coverage.model.CoverageOptionManagerDefault; import org.eclipse.osee.coverage.model.CoverageUnit; import org.eclipse.osee.coverage.model.CoverageUnitFactory; -import org.eclipse.osee.coverage.store.ITestUnitStore; +import org.eclipse.osee.coverage.store.ArtifactTestUnitStore; import org.eclipse.osee.coverage.store.OseeCoverageUnitStore; import org.eclipse.osee.coverage.store.TestUnitCache; import org.eclipse.osee.coverage.util.CoverageUtil; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.exception.ArtifactDoesNotExist; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.GUID; @@ -44,19 +45,19 @@ import org.junit.Test; */ public class CoverageItemPersistTest { - @Rule - public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_COVERAGE_DEMO); - - @Rule - public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule(); - public static CoverageUnit parentCu = null; + public static Artifact readOnlyTestUnitNames = null; public static CoverageItem ci = null; public static String parentGuid = null; public static String guid = null; public static TestUnitCache testUnitCache; public static boolean initOnce = false; + @Rule + public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_COVERAGE_DEMO); + @Rule + public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule(); + @AfterClass public static void testCleanup() throws OseeCoreException { CoverageTestUtil.cleanupCoverageTests(); @@ -71,9 +72,14 @@ public class CoverageItemPersistTest { // If this fails, cleanup didn't happen. Must DbInit Assert.assertEquals(0, CoverageTestUtil.getAllCoverageArtifacts().size()); + readOnlyTestUnitNames = + ArtifactQuery.getOrCreate(ArtifactTestUnitStore.READ_ONLY_GUID, null, CoreArtifactTypes.GeneralData, + CoverageTestUtil.getTestBranch()); + readOnlyTestUnitNames.setSoleAttributeFromString(CoreAttributeTypes.GeneralStringData, ""); parentCu = CoverageUnitFactory.createCoverageUnit(null, "Top", "C:/UserData/", null); parentGuid = parentCu.getGuid(); - ITestUnitStore testUnitStore = mock(ITestUnitStore.class); + ArtifactTestUnitStore testUnitStore = new ArtifactTestUnitStore(null, readOnlyTestUnitNames); + testUnitCache = new TestUnitCache(testUnitStore); ci = new CoverageItem(parentCu, CoverageOptionManager.Deactivated_Code, "1"); ci.setTestUnitProvider(testUnitCache); @@ -98,9 +104,11 @@ public class CoverageItemPersistTest { // do nothing } - Artifact artifact = new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).getArtifact(false); + Artifact artifact = + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).getArtifact(false); Assert.assertNull("Artifact should not have been created", artifact); - artifact = new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).getArtifact(true); + artifact = + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).getArtifact(true); CoverageTestUtil.registerAsTestArtifact(artifact); artifact.persist(getClass().getSimpleName()); Assert.assertNotNull("Artifact should have been created", artifact); @@ -115,7 +123,8 @@ public class CoverageItemPersistTest { // Since test units are stored through provider, ensure they are same before and after save Assert.assertEquals(10, ci.getTestUnits().size()); - Artifact artifact = new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).getArtifact(true); + Artifact artifact = + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).getArtifact(true); Assert.assertNotNull(artifact); SkynetTransaction transaction = TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Save CoverageItem"); @@ -123,8 +132,8 @@ public class CoverageItemPersistTest { String coverageName = "Test CP"; CoveragePackageEvent coverageEvent = new CoveragePackageEvent(coverageName, coverageGuid, CoverageEventType.Modified, GUID.create()); - new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).save(transaction, coverageEvent, - CoverageOptionManagerDefault.instance()); + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).save(transaction, + coverageEvent, CoverageOptionManagerDefault.instance()); artifact.persist(transaction); transaction.execute(); @@ -165,15 +174,18 @@ public class CoverageItemPersistTest { */ @Test public void testDelete() throws OseeCoreException { - Artifact artifact = new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).getArtifact(false); + Artifact artifact = + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).getArtifact(false); Assert.assertNotNull(artifact); SkynetTransaction transaction = TransactionManager.createTransaction(CoverageTestUtil.getTestBranch(), "Save CoverageItem"); CoveragePackageEvent coverageEvent = new CoveragePackageEvent("Test CP", GUID.create(), CoverageEventType.Deleted, GUID.create()); - new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).delete(transaction, coverageEvent, false); + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).delete(transaction, + coverageEvent, false); transaction.execute(); - artifact = new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch()).getArtifact(false); + artifact = + new OseeCoverageUnitStore(parentCu, CoverageTestUtil.getTestBranch(), readOnlyTestUnitNames).getArtifact(false); Assert.assertNull(artifact); Assert.assertEquals(0, CoverageTestUtil.getAllCoverageArtifacts().size()); Assert.assertEquals(1, coverageEvent.getCoverages().size()); diff --git a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageManagerTest.java b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageManagerTest.java index 84941ea5ba9..46fd86098cf 100644 --- a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageManagerTest.java +++ b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/CoverageManagerTest.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.coverage.integration.tests.integration; -import static org.eclipse.osee.coverage.demo.CoverageChoice.*; +import static org.eclipse.osee.coverage.demo.CoverageChoice.OSEE_COVERAGE_DEMO; import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule; import org.eclipse.osee.client.test.framework.OseeHousekeepingRule; import org.eclipse.osee.client.test.framework.OseeLogMonitorRule; diff --git a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/util/CoverageTestUtil.java b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/util/CoverageTestUtil.java index f1fd8026083..087ae4d2164 100644 --- a/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/util/CoverageTestUtil.java +++ b/plugins/org.eclipse.osee.coverage.integration.tests/src/org/eclipse/osee/coverage/integration/tests/integration/util/CoverageTestUtil.java @@ -27,6 +27,7 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.operation.IOperation; import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache; import org.eclipse.osee.framework.skynet.core.artifact.PurgeArtifacts; import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; @@ -38,6 +39,9 @@ public class CoverageTestUtil { public static void cleanupCoverageTests() throws OseeCoreException { try { + for (Artifact art : ArtifactCache.getDirtyArtifacts()) { + ArtifactCache.deCache(art); + } Collection<? extends Artifact> allCoverageArtifacts = getAllCoverageArtifacts(); IOperation op = new PurgeArtifacts(allCoverageArtifacts); Operations.executeWorkAndCheckStatus(op); @@ -118,7 +122,7 @@ public class CoverageTestUtil { } public static IOseeBranch getTestBranch() { - return CoverageBranches.SAW_Bld_1; + return CoverageBranches.COVERAGE_TEST_BRANCH; } } |