Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1c522b4df6203a97ce3d78ec3658aa3950380a4d (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
/*******************************************************************************
 * 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.db.internal.sql.join;

import java.util.List;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.junit.Assert;
import org.junit.Test;

/**
 * Test Case for {@link ArtifactJoinQuery}
 *
 * @author Roberto E. Escobar
 */
public class ArtifactJoinQueryTest {

   @Test
   public void testAdd() throws OseeCoreException {
      MockJoinAccessor joinAccessor = new MockJoinAccessor();
      Id4JoinQuery join = new Id4JoinQuery(joinAccessor, -1L, 999, 10);
      Assert.assertEquals(0, join.size());
      Assert.assertEquals(true, join.isEmpty());

      join.add(BranchId.valueOf(5678L), ArtifactId.valueOf(1234));
      Assert.assertEquals(1, join.size());
      Assert.assertEquals(false, join.isEmpty());

      join.add(BranchId.valueOf(5678L), ArtifactId.valueOf(1234));

      Assert.assertEquals(1, join.size());

      Assert.assertEquals(false, join.wasStored());
      join.store();
      Assert.assertEquals(true, join.wasStored());

      Assert.assertNull(joinAccessor.getConnection());
      Assert.assertEquals(999, joinAccessor.getQueryId());

      List<Object[]> data = joinAccessor.getDataList();
      Assert.assertEquals(1, data.size());

      Object[] entry = data.get(0);
      Assert.assertEquals(5, entry.length);
      Assert.assertEquals(999, entry[0]);
      Assert.assertEquals(ArtifactId.valueOf(1234), entry[2]);
      Assert.assertEquals(BranchId.valueOf(5678L), entry[1]);

   }

   @Test(expected = OseeCoreException.class)
   public void testStoreTwice() throws OseeCoreException {
      MockJoinAccessor joinAccessor = new MockJoinAccessor();
      Id4JoinQuery join = new Id4JoinQuery(joinAccessor, -1L, 1000, 10);

      Assert.assertEquals(false, join.wasStored());
      join.store();
      Assert.assertEquals(true, join.wasStored());

      Assert.assertNull(joinAccessor.getConnection());
      Assert.assertEquals(1000, joinAccessor.getQueryId());

      join.store();
   }

   @Test(expected = OseeCoreException.class)
   public void testMoreThanAllowed() throws OseeCoreException {
      MockJoinAccessor joinAccessor = new MockJoinAccessor();
      int maxSize = 5;
      Id4JoinQuery join = new Id4JoinQuery(joinAccessor, -1L, 1000, maxSize);

      for (int i = 0; i < maxSize + 1; i++) {
         join.add(ArtifactId.valueOf(i + 1), BranchId.valueOf(1123L));
      }

   }
}

Back to the top