Skip to main content
summaryrefslogtreecommitdiffstats
blob: 562439d1e3110bf051dcd71c9956ba1a9f846a3b (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
/*******************************************************************************
 * Copyright (c) 2013 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.ats.client.integration.tests.ats.navigate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
import org.eclipse.osee.ats.client.demo.DemoArtifactToken;
import org.eclipse.osee.ats.client.demo.DemoUsers;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
import org.eclipse.osee.ats.navigate.SubscribeUtility;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Test case for {@link SubscribeUtility}
 * 
 * @author Donald G. Dunne
 */
public class SubscribeUtilityTest {

   @BeforeClass
   @AfterClass
   public static void cleanup() throws OseeCoreException {
      Artifact userArt = getAlexUserArtifact();
      userArt.deleteRelations(CoreRelationTypes.Users_Artifact);
      userArt.persist(SubscribeUtilityTest.class.getSimpleName() + " - cleanup");
   }

   @Test
   public void test() throws OseeCoreException {
      Artifact alexUserArt = getAlexUserArtifact();
      Assert.assertEquals("Should be nothing subscribed by alex", 0,
         alexUserArt.getRelatedArtifactsCount(CoreRelationTypes.Users_Artifact));

      // Subscribe to 2 team definitions
      Artifact cisCodeTeam = ArtifactQuery.getArtifactFromToken(DemoArtifactToken.CIS_Code, AtsUtilCore.getAtsBranch());
      Artifact cisSwTeam = ArtifactQuery.getArtifactFromToken(DemoArtifactToken.CIS_SW, AtsUtilCore.getAtsBranch());

      SubscribeUtility.setSubcriptionsAndPersist(alexUserArt, CoreRelationTypes.Users_Artifact,
         Arrays.asList(cisCodeTeam, cisSwTeam), AtsArtifactTypes.TeamDefinition, getClass().getSimpleName());
      List<Artifact> subscribed = alexUserArt.getRelatedArtifacts(CoreRelationTypes.Users_Artifact);
      Assert.assertTrue("CIS Code should be subscribed", subscribed.contains(cisCodeTeam));
      Assert.assertTrue("CIS SW should be subscribed", subscribed.contains(cisSwTeam));
      Assert.assertFalse("User artifact changes should be persisted", alexUserArt.isDirty());

      // Remove one, add another
      Artifact cisTestTeam = ArtifactQuery.getArtifactFromToken(DemoArtifactToken.CIS_Test, AtsUtilCore.getAtsBranch());

      SubscribeUtility.setSubcriptionsAndPersist(alexUserArt, CoreRelationTypes.Users_Artifact,
         Arrays.asList(cisCodeTeam, cisTestTeam), AtsArtifactTypes.TeamDefinition, getClass().getSimpleName());
      subscribed = alexUserArt.getRelatedArtifacts(CoreRelationTypes.Users_Artifact);
      Assert.assertTrue("CIS Code should be subscribed", subscribed.contains(cisCodeTeam));
      Assert.assertFalse("CIS SW should NOT be subscribed", subscribed.contains(cisSwTeam));
      Assert.assertTrue("CIS Test should be subscribed", subscribed.contains(cisTestTeam));
      Assert.assertFalse("User artifact changes should be persisted", alexUserArt.isDirty());

      // Un-subscribe all
      SubscribeUtility.setSubcriptionsAndPersist(alexUserArt, CoreRelationTypes.Users_Artifact,
         new ArrayList<Artifact>(), AtsArtifactTypes.TeamDefinition, getClass().getSimpleName());
      subscribed = alexUserArt.getRelatedArtifacts(CoreRelationTypes.Users_Artifact);
      Assert.assertTrue("No subscriptions remain", subscribed.isEmpty());
      Assert.assertFalse("User artifact changes should be persisted", alexUserArt.isDirty());
   }

   private static Artifact getAlexUserArtifact() throws OseeCoreException {
      return ArtifactQuery.getArtifactFromToken(DemoUsers.Alex_Kay, AtsUtilCore.getAtsBranch());
   }

}

Back to the top