Skip to main content
summaryrefslogtreecommitdiffstats
blob: f11afe70262796d11cea10c909efa497fbe7b712 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
 * Copyright (c) 2011 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.coverage.test.store;

import java.util.Map.Entry;
import org.eclipse.osee.coverage.model.CoverageItem;
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.store.ArtifactTestUnitStore;
import org.eclipse.osee.coverage.store.TestUnitCache;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.support.test.util.TestUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author John Misinco
 */
public class ArtifactTestUnitStoreTest {

   private static final String testInputData = "1|test1\n2|test2\n3|test3";
   Branch testBranch;
   private static final String testArtifactGuid = "AEas7qndRl+k+g6YpkwA";

   private CoverageItem createCoverageItem(TestUnitCache tc) throws OseeCoreException {
      CoverageUnit parent = new CoverageUnit(null, "Top", "C:/UserData/", null);
      CoverageItem ci1 = new CoverageItem(parent, CoverageOptionManager.Deactivated_Code, "1");
      ci1.setName("this is text");
      return CoverageItem.createCoverageItem(parent, ci1.toXml(), CoverageOptionManagerDefault.instance(), tc);
   }

   @Before
   public void createTestArtifact() throws OseeCoreException {
      Assert.assertTrue(TestUtil.isTestDb());
      testBranch = BranchManager.createTopLevelBranch("TestBranch");
      Artifact testArtifact =
         ArtifactQuery.getOrCreate(testArtifactGuid, null, CoreArtifactTypes.GeneralData, testBranch);
      testArtifact.setSoleAttributeFromString(CoreAttributeTypes.GeneralStringData, testInputData);
   }

   @After
   public void cleanUpTestArtifact() {
      BranchManager.deleteBranch(testBranch);
   }

   @Test
   public void testLoad() throws OseeCoreException {
      ArtifactTestUnitStore store = new ArtifactTestUnitStore(testBranch);
      TestUnitCache tc = new TestUnitCache(store);
      store.load(tc);
      StringBuilder actual = new StringBuilder();
      boolean firstTime = true;
      for (Entry<Integer, String> entry : tc.getAllCachedTestUnitEntries()) {
         if (!firstTime) {
            actual.append("\n");
         }
         actual.append(Integer.toString(entry.getKey()));
         actual.append("|");
         actual.append(entry.getValue());
         firstTime = false;
      }
      Assert.assertEquals(testInputData, actual.toString());
   }

   @Test
   public void testStore() throws OseeCoreException {
      ArtifactTestUnitStore store = new ArtifactTestUnitStore(testBranch);
      TestUnitCache tc = new TestUnitCache(store);
      CoverageItem ci = createCoverageItem(tc);
      ci.addTestUnitName("test1");
      ci.addTestUnitName("test10");

      store.store(tc);
      Artifact testArtifact =
         ArtifactQuery.getOrCreate(testArtifactGuid, null, CoreArtifactTypes.GeneralData, testBranch);
      String actual = testArtifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, "");
      String expected = testInputData + "\n4|test10";
      Assert.assertEquals(expected, actual);

   }

}

Back to the top