Child: [e10b76] (diff)

Download this file

KnowledgeBaseIntegrationTest.java    217 lines (196 with data), 11.0 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
 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**
* Copyright (c) 2013/2014 Verein zur Foerderung der IT-Sicherheit in Oesterreich (SBA).
* The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium.
* TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological
* development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without
* limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR
* PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise,
* unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including
* any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this
* License or out of the use or inability to use the Work.
* See the License for the specific language governing permissions and limitation under the License.
*/
package org.sba_research.timbus.kb.timbus;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sba_research.timbus.kb.FormatMigrationOption;
import org.sba_research.timbus.kb.IntegrationTests;
import org.sbaresearch.owl.JenaQueryFacade;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;
@Category(IntegrationTests.class)
public class KnowledgeBaseIntegrationTest {
public static final String ONTOLOGY_FILE_NAME = "/toolKB_instance.owl";
@Test
public void getAlternativeTools_toolWithAlternatives_shouldReturnTools() {
List<String> expected = new ArrayList<String>() {{
add("http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#Aldus-Freehand-4");
}};
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actual = knowledgeBase.getAlternativeTools("Aldus-Freehand-3");
assertThat(actual, containsInAnyOrder(expected.toArray()));
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getAlternativeTools_unknownTool_shouldReturnEmptyList() {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
List<String> expected = new ArrayList<>();
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actual = knowledgeBase.getAlternativeTools("Aldus-Freehand-23");
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getProvidingTools_unknownAction_shouldReturnEmptyList() {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
List<String> expected = new ArrayList<>();
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actual = knowledgeBase.getProvidingTools("spawn_magic_lolcat");
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getProvidingTools_actionWithProvidingTools_shouldReturnTools() {
List<String> expected = new ArrayList<String>() {{
add("http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#Pdq-Lite");
add("http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#Adobe-Acrobat");
}};
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actual = knowledgeBase.getProvidingTools("action_read_Portable-Document-Format");
assertThat(actual, containsInAnyOrder(expected.toArray()));
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getSupportingTools_byFormatPairReadFormatOnly_shouldReturnTools() {
final String ns = "http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#";
List<String> expected = new ArrayList<String>() {{
add(ns + "OmniWeb");
add(ns + "Microsoft-Word");
add(ns + "Lynx");
add(ns + "Camino");
add(ns + "Safari");
add(ns + "Shiira");
add(ns + "Amaya");
add(ns + "Firefox");
add(ns + "Opera");
add(ns + "Web");
add(ns + "Internet-Explorer");
add(ns + "Konqueror");
add(ns + "Google-Chrome");
}};
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
Pair<String, String> formats = new ImmutablePair<>("fmt/100", null);
List<String> actual = knowledgeBase.getSupportingTools(formats);
assertThat(actual, containsInAnyOrder(expected.toArray()));
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getSupportingTools_byFormatPairWriteFormatOnly_shouldReturnTools() {
final String ns = "http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#";
List<String> expected = new ArrayList<String>() {{
add(ns + "Aptana-IDE");
add(ns + "Microsoft-Word");
add(ns + "Dreamweaver");
add(ns + "Amaya");
add(ns + "Bluefish");
}};
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
Pair<String, String> formats = new ImmutablePair<>(null, "fmt/100");
List<String> actual = knowledgeBase.getSupportingTools(formats);
assertThat(actual, containsInAnyOrder(expected.toArray()));
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getSupportingTools_byFormatPair_shouldReturnTools() {
final String ns = "http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#";
List<String> expected = new ArrayList<String>() {{
add(ns + "Microsoft-Word");
add(ns + "Word");
add(ns + "Framebuilder");
add(ns + "Wordstar");
add(ns + "Adobe-FrameMaker");
add(ns + "Wordperfect");
}};
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
Pair<String, String> formats = new ImmutablePair<>("fmt/37", "fmt/37");
List<String> actual = knowledgeBase.getSupportingTools(formats);
assertThat(actual, containsInAnyOrder(expected.toArray()));
assertThat(actual.size(), is(expected.size()));
}
@Test
public void getAllFormatIDs_validKnowledgebase_shouldReturnIDs() {
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actualIDs = knowledgeBase.getAllFormatIDs();
assertThat(actualIDs.size(), is(302));
assertThat(actualIDs.contains("fmt/100"), is(true));
}
@Test
public void getFormatName_validFormatID_shouldReturnName() {
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actual = knowledgeBase.getFormatName("fmt/100");
assertThat(actual, containsInAnyOrder(
"http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#XHTML",
"http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#HTML-File-Format"));
}
@Test
public void getReadingTools_validFormat_shouldReturnTool() {
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<String> actual = knowledgeBase.getReadingTools("fmt/50");
assertThat(actual, containsInAnyOrder("http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#TextEdit"));
}
@Test
@Ignore("this is just an example to get a list of file format alternatives")
public void getAlternativeFormats_validKnowledgebase_shouldReturnFormats() {
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
String alternatives = "";
List<String> done = new ArrayList<>();
for (String format : knowledgeBase.getAllFormatIDs()) {
@SuppressWarnings("deprecation")
List<String> actual = JenaQueryFacade.removeNamespace(knowledgeBase.getAlternativeFormats(format));
if (actual.size() >= 2) {
String formatNames = JenaQueryFacade.removeNamespace(knowledgeBase.getFormatName(format)).toString();
if (done.contains(formatNames)) continue;
alternatives += formatNames + "(" + JenaQueryFacade.removeNamespace(knowledgeBase.getReadingTools(format)) + "):\n";
alternatives += actual.toString() + "\n\n";
done.add(formatNames);
}
assertThat(actual.size(), greaterThan(0));
}
System.out.println(alternatives);
}
@Test
public void getFormatMigrationOptions_invalidFormatID_shouldReturnEmptyList() {
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
assertThat(knowledgeBase.getFormatMigrationOption("fmt/4223").size(), is(0));
}
@Test
public void getFormatMigrationOptions_validFormatID_shouldReturnFormatAndTools() {
final String ns = "http://timbus.teco.edu/ontologies/preservationIdentifier/toolKB_instance.owl#";
List<FormatMigrationOption> expected = new ArrayList<FormatMigrationOption>() {{
add(new FormatMigrationOption(ns + "Ape", ns + "Winamp"));
add(new FormatMigrationOption(ns + "Wsz", ns + "Winamp"));
add(new FormatMigrationOption(ns + "PLS", ns + "Winamp"));
add(new FormatMigrationOption(ns + "Mjf", ns + "Winamp"));
add(new FormatMigrationOption(ns + "Nsv", ns + "Winamp"));
add(new FormatMigrationOption(ns + "Wpl", ns + "Windows-Media-Player"));
add(new FormatMigrationOption(ns + "Wmp", ns + "Windows-Media-Player"));
add(new FormatMigrationOption(ns + "Wmx", ns + "Windows-Media-Player"));
}};
TimbusToolKnowledgeBase knowledgeBase = createKnowledgeBase();
List<FormatMigrationOption> actual = knowledgeBase.getFormatMigrationOption("fmt/134");
assertThat(actual, containsInAnyOrder(expected.toArray()));
}
private TimbusToolKnowledgeBase createKnowledgeBase() {
return new TimbusToolKnowledgeBase(new JenaQueryFacade(JenaQueryFacade.getModelFromPath(getClass().getResource(ONTOLOGY_FILE_NAME).getFile(), true)));
}
}