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
|
/********************************************************************************
* Copyright (c) 2015-2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
package org.eclipse.mdm.api.base.query;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.mdm.api.base.EntityTypeImpl;
import org.eclipse.mdm.api.base.RelationImpl;
import org.eclipse.mdm.api.base.RelationImpl.AttributeType;
import org.eclipse.mdm.api.base.model.EnumRegistry;
import org.junit.Before;
import org.junit.Test;
/**
* Test the Filter class
*
* @author Alexander Nehmer
*
*/
public class FilterTest {
static String[] values = new String[] { "1", "2", "3" };
@Before
public void init() {
EnumRegistry.getInstance();
}
/**
* Tests ids(EntityType entityType, Collection<String> ids)
*/
@Test
public void testIdsEntityType() {
Filter filter = Filter.and();
assertEquals(filter.stream().toArray().length, 0);
filter = Filter.and().ids(new EntityTypeImpl(), Arrays.asList(values));
String[] filterCondition = filter.iterator().next().getCondition().getValue().extract();
Iterator<String> valuesIterator = Arrays.asList(values).iterator();
Iterator<String> filterConditionIterator = Arrays.stream(filterCondition).iterator();
while (valuesIterator.hasNext() && filterConditionIterator.hasNext()) {
assertEquals(valuesIterator.next(), filterConditionIterator.next());
}
}
/**
* Tests ids(Relation relation, Collection<String> ids)
*/
@Test
public void testIdsRelation() {
Filter filter = Filter.and();
assertEquals(filter.stream().toArray().length, 0);
filter = Filter.and().ids(new RelationImpl(AttributeType.ID), Arrays.asList(values));
String[] filterCondition = filter.iterator().next().getCondition().getValue().extract();
Iterator<String> valuesIterator = Arrays.asList(values).iterator();
Iterator<String> filterConditionIterator = Arrays.stream(filterCondition).iterator();
while (valuesIterator.hasNext() && filterConditionIterator.hasNext()) {
assertEquals(valuesIterator.next(), filterConditionIterator.next());
}
}
/**
* Tests id(EntityType entityType, String id)
*/
@Test
public void testIdEntity() {
Filter filter = Filter.and();
assertEquals(filter.stream().toArray().length, 0);
filter = Filter.and().id(new EntityTypeImpl(), "1");
String filterCondition = filter.iterator().next().getCondition().getValue().extract();
assertEquals(filterCondition, "1");
}
/**
* Tests id(Relation relation, String id)
*/
@Test
public void testIdRelation() {
Filter filter = Filter.and();
assertEquals(filter.stream().toArray().length, 0);
filter = Filter.and().id(new RelationImpl(AttributeType.ID), "1");
String filterCondition = filter.iterator().next().getCondition().getValue().extract();
assertEquals(filterCondition, "1");
}
}
|