-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSymbolResolverMockV2.java
More file actions
82 lines (68 loc) · 3.21 KB
/
SymbolResolverMockV2.java
File metadata and controls
82 lines (68 loc) · 3.21 KB
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
/*
* Copyright 2022 European Union
*
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
* compliance with the Licence. You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the Licence for the specific language governing permissions and limitations under
* the Licence.
*/
package eu.europa.ted.efx.mock.sdk2;
import static java.util.Map.entry;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import eu.europa.ted.eforms.sdk.SdkSymbolResolver;
import eu.europa.ted.eforms.sdk.component.SdkComponent;
import eu.europa.ted.eforms.sdk.component.SdkComponentType;
import eu.europa.ted.eforms.sdk.entity.SdkCodelist;
import eu.europa.ted.eforms.sdk.entity.v2.SdkCodelistV2;
import eu.europa.ted.eforms.sdk.repository.SdkDataTypeRepository;
import eu.europa.ted.eforms.sdk.repository.SdkFieldRepository;
import eu.europa.ted.eforms.sdk.repository.SdkNodeRepository;
@SdkComponent(versions = {"2"}, componentType = SdkComponentType.SYMBOL_RESOLVER, qualifier = "mock")
public class SymbolResolverMockV2 extends SdkSymbolResolver {
private static final String SDK_VERSION = "eforms-sdk-2.0";
private static final Path JSON_PATH = Path.of("src", "test", "resources", "json", "sdk2-fields.json");
public SymbolResolverMockV2() throws InstantiationException {
super();
loadTestData();
}
private void loadTestData() throws InstantiationException {
// Load nodes and fields using SDK repositories
this.nodeById = new SdkNodeRepository(SDK_VERSION, JSON_PATH);
this.nodeByAlias = indexNodesByAlias();
this.fieldById = new SdkFieldRepository(SDK_VERSION, JSON_PATH, this.nodeById);
this.fieldByAlias = indexFieldsByAlias();
// Mock codelists
this.codelistById = createMockCodelists();
// Mock notice types - not needed, we override getAllNoticeSubtypeIds()
this.noticeTypesById = new HashMap<>();
this.dataTypeById = SdkDataTypeRepository.createDefault();
}
private static Entry<String, SdkCodelist> buildCodelistMock(final String codelistId,
final Optional<String> parentId) {
return entry(codelistId, new SdkCodelistV2(codelistId, "0.0.1",
Arrays.asList("code1", "code2", "code3"), parentId));
}
private Map<String, SdkCodelist> createMockCodelists() {
return new HashMap<>(Map.ofEntries(
buildCodelistMock("accessibility", Optional.empty()),
buildCodelistMock("authority-activity", Optional.of("main-activity")),
buildCodelistMock("main-activity", Optional.empty()),
buildCodelistMock("legal-basis-1", Optional.empty()),
buildCodelistMock("indicator", Optional.empty())));
}
@Override
public List<String> getAllNoticeSubtypeIds() {
return Arrays.asList("1", "2", "3", "4", "5", "E1", "E2", "X01");
}
}