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
100
101
102
103
|
/*******************************************************************************
* Copyright (c) 2012 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.transaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsBranch;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.internal.search.QueryModule;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
/**
* Test Case for {@link TransactionFactoryImpl}
*
* @author Roberto E. Escobar
*/
public class TransactionFactoryImplTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
// @formatter:off
@Mock private Log logger;
@Mock private OrcsSession session;
@Mock private TxDataManager txDataManager;
@Mock private TxCallableFactory txCallableFactory;
@Mock private QueryModule query;
@Mock private QueryFactory queryFactory;
@Mock private OrcsBranch orcsBranch;
@Mock private ArtifactReadable expectedAuthor;
@Mock private TxData txData;
// @formatter:on
private final IOseeBranch expectedBranch = CoreBranches.COMMON;
private TransactionFactoryImpl factory;
@Before
public void init() {
initMocks(this);
factory = new TransactionFactoryImpl(session, txDataManager, txCallableFactory, query, queryFactory, orcsBranch);
}
@Test
public void testNullAuthor() throws OseeCoreException {
thrown.expect(OseeArgumentException.class);
thrown.expectMessage("author cannot be null");
factory.createTransaction(expectedBranch, null, "my comment");
}
@Test
public void testNullComment() throws OseeCoreException {
thrown.expect(OseeArgumentException.class);
thrown.expectMessage("comment cannot be null");
factory.createTransaction(expectedBranch, expectedAuthor, null);
}
@Test
public void testEmptyComment() throws OseeCoreException {
thrown.expect(OseeArgumentException.class);
thrown.expectMessage("comment cannot be empty");
factory.createTransaction(expectedBranch, expectedAuthor, "");
}
@Test
public void testCreateTransaction() throws OseeCoreException {
String expectedComment = "This is my comment";
when(txDataManager.createTxData(session, expectedBranch.getUuid())).thenReturn(txData);
when(txData.getAuthor()).thenReturn(expectedAuthor);
when(txData.getBranchId()).thenReturn(expectedBranch.getUuid());
when(txData.getComment()).thenReturn(expectedComment);
TransactionBuilder tx = factory.createTransaction(expectedBranch, expectedAuthor, expectedComment);
assertNotNull(tx);
assertEquals(expectedBranch.getUuid(), tx.getBranchId());
assertEquals(expectedAuthor, tx.getAuthor());
assertEquals(expectedComment, tx.getComment());
}
}
|