Skip to main content
summaryrefslogtreecommitdiffstats
blob: c009739fd6301fbf19dcf8f1445c1a413c8ff4b0 (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
/*******************************************************************************
 * 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.orcs.core.internal.relation.impl;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.LoadLevel;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.DataLoader;
import org.eclipse.osee.orcs.core.ds.DataLoaderFactory;
import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
import org.eclipse.osee.orcs.core.internal.graph.GraphBuilder;
import org.eclipse.osee.orcs.core.internal.graph.GraphBuilderFactory;
import org.eclipse.osee.orcs.core.internal.graph.GraphData;
import org.eclipse.osee.orcs.core.internal.relation.RelationNode;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;

/**
 * @author Megumi Telles
 */
public class RelationNodeLoaderImplTest {

   @Rule
   public ExpectedException thrown = ExpectedException.none();

   // @formatter:off
   @Mock private DataLoaderFactory dataLoaderFactory;
   @Mock private GraphBuilderFactory graphBuilderFactory;
   
   @Mock private OrcsSession session;
   @Mock private GraphData graph;
   @Mock private GraphBuilder builder;
   @Mock private DataLoader loader;
   
   @Mock private Artifact artifact;
   // @formatter:on

   private static final IOseeBranch BRANCH = CoreBranches.COMMON;
   private static final int TRANSACTION_ID = 231214214;
   private static final Collection<Integer> ids = Arrays.asList(4, 5, 6, 7);

   private RelationNodeLoaderImpl relationNode;

   @Before
   public void setUp() throws Exception {
      initMocks(this);

      relationNode = new RelationNodeLoaderImpl(dataLoaderFactory, graphBuilderFactory);

      when(graph.getBranch()).thenReturn(BRANCH);
      when(graph.getTransaction()).thenReturn(TRANSACTION_ID);
   }

   @Test
   public void testLoadNodes() throws OseeCoreException {
      Iterable<Artifact> artifacts = Arrays.asList(artifact);

      when(dataLoaderFactory.fromBranchAndArtifactIds(session, BRANCH, ids)).thenReturn(loader);
      when(graphBuilderFactory.createBuilderForGraph(graph)).thenReturn(builder);
      when(builder.getArtifacts()).thenReturn(artifacts);

      Iterable<RelationNode> actual = relationNode.loadNodes(session, graph, ids, LoadLevel.FULL);

      verify(dataLoaderFactory).fromBranchAndArtifactIds(session, BRANCH, ids);
      verify(graphBuilderFactory).createBuilderForGraph(graph);

      verify(loader).setLoadLevel(LoadLevel.FULL);
      verify(loader).fromTransaction(TRANSACTION_ID);
      verify(loader).load(null, builder);
      verify(builder).getArtifacts();

      assertEquals(artifacts, actual);
   }
}

Back to the top