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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/*******************************************************************************
* 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.rest.internal.search.predicate;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyCollectionOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IRelationType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.enums.QueryOption;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.orcs.rest.internal.search.artifact.predicate.ExistsTypePredicateHandler;
import org.eclipse.osee.orcs.rest.model.search.artifact.Predicate;
import org.eclipse.osee.orcs.rest.model.search.artifact.SearchMethod;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* @author John R. Misinco
*/
public class ExistsTypePredicateHandlerTest {
@Mock
private QueryBuilder builder;
@Captor
private ArgumentCaptor<IRelationType> relationTypeCaptor;
@Captor
private ArgumentCaptor<Collection<IAttributeType>> attrTypeSideCaptor;
@Before
public void initialize() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testHandleRelationTypeSideA() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
List<String> typeParameters = Collections.singletonList("relType");
//for relation type sides, first char must be A or B denoting side, followed by relation type uuid
String relationValue = "12345";
List<String> values = Collections.singletonList(relationValue);
Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values);
handler.handle(builder, testPredicate);
verify(builder).andExists(relationTypeCaptor.capture());
Assert.assertEquals(1, relationTypeCaptor.getAllValues().size());
Assert.assertTrue(12345L == relationTypeCaptor.getValue().getGuid());
}
@Test
public void testHandleRelationTypeSideB() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
List<String> typeParameters = Collections.singletonList("relType");
//no flags for exists type
String relationValue = "12345";
List<String> values = Collections.singletonList(relationValue);
Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values);
handler.handle(builder, testPredicate);
verify(builder).andExists(relationTypeCaptor.capture());
Assert.assertEquals(1, relationTypeCaptor.getAllValues().size());
Assert.assertTrue(12345L == relationTypeCaptor.getValue().getGuid());
}
@Test
public void testHandleRelationTypeSideMultiples() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
List<String> typeParameters = Collections.singletonList("relType");
//test multiples
String relationValue1 = "12345";
String relationValue2 = "34567";
List<String> values = Arrays.asList(relationValue1, relationValue2);
Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values);
handler.handle(builder, testPredicate);
verify(builder, times(2)).andExists(relationTypeCaptor.capture());
Assert.assertEquals(2, relationTypeCaptor.getAllValues().size());
IRelationType type = relationTypeCaptor.getAllValues().get(0);
Assert.assertTrue(12345L == type.getGuid());
type = relationTypeCaptor.getAllValues().get(1);
Assert.assertTrue(34567L == type.getGuid());
}
@Test
public void testHandleAttrTypeSingle() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
List<String> typeParameters = Collections.singletonList("attrType");
//for relation type sides, first char must be A or B denoting side, followed by relation type uuid
String attrUuid = "12345";
List<String> values = Collections.singletonList(attrUuid);
Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values);
handler.handle(builder, testPredicate);
verify(builder).andExists(attrTypeSideCaptor.capture());
Assert.assertEquals(1, attrTypeSideCaptor.getAllValues().size());
List<IAttributeType> attrTypes = new ArrayList<IAttributeType>(attrTypeSideCaptor.getValue());
Assert.assertTrue(12345L == attrTypes.get(0).getGuid());
}
@Test
public void testHandleAttrTypeMultiple() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
List<String> typeParameters = Collections.singletonList("attrType");
String attrType1 = "12345";
String attrType2 = "34567";
List<String> values = Arrays.asList(attrType1, attrType2);
Predicate testPredicate =
new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values, QueryOption.TOKEN_DELIMITER__ANY);
handler.handle(builder, testPredicate);
verify(builder).andExists(attrTypeSideCaptor.capture());
Assert.assertEquals(1, attrTypeSideCaptor.getAllValues().size());
Iterator<IAttributeType> iterator = attrTypeSideCaptor.getValue().iterator();
Assert.assertEquals(Long.valueOf(12345L), iterator.next().getGuid());
Assert.assertEquals(Long.valueOf(34567L), iterator.next().getGuid());
}
@Test
public void testHandleBadValues() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
List<String> typeParameters = Collections.singletonList("attrType");
String value = "12A4G";
List<String> values = Collections.singletonList(value);
Predicate testPredicate =
new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values, QueryOption.TOKEN_DELIMITER__ANY);
handler.handle(builder, testPredicate);
verify(builder, never()).andExists(anyCollectionOf(IAttributeType.class));
value = "12A4G";
typeParameters = Collections.singletonList("relType");
values = Collections.singletonList(value);
testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, values, QueryOption.TOKEN_DELIMITER__ANY);
handler.handle(builder, testPredicate);
verify(builder, never()).andExists(any(IRelationTypeSide.class));
}
@Test(expected = OseeCoreException.class)
public void testBadValuesThrowException() throws OseeCoreException {
ExistsTypePredicateHandler handler = new ExistsTypePredicateHandler();
Predicate testPredicate =
new Predicate(SearchMethod.ATTRIBUTE_TYPE, Collections.singletonList("relType"),
Collections.singletonList("A12A4G"), QueryOption.TOKEN_DELIMITER__ANY);
handler.handle(builder, testPredicate);
}
}
|