Parent: [8eb76c] (diff)

Download this file

PackageAlternativesBuilderTest.java    104 lines (93 with data), 6.9 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
/**
* 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 net.timbusproject.dpes.alternative.AlternativesBuilder;
import net.timbusproject.dpes.alternative.IntegrationTest;
import net.timbusproject.dpes.alternative.PreservationAlternative;
import net.timbusproject.dpes.alternative.Risk;
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sba_research.timbus.kb.PackageKnowledgeBase;
import org.sbaresearch.owl.JenaQueryFacade;
import org.sbaresearch.owl.OwlApiFacade;
import org.sbaresearch.owl.OwlElementNotFoundException;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
@Category(IntegrationTest.class)
public class PackageAlternativesBuilderTest {
public static final String KB_OWL_PATH = "http://timbus.teco.edu/ontologies/preservationIdentifier/virtualPackgeProviders-Ubuntu_12_10.owl";
public static final String BASE_URL = "http://localhost/test.owl";
public static final String MODEL_OWL_PATH = "http://timbus.teco.edu/ontologies/examples/MusicClassification/main.owl";
@Test
public void getAlternativePackages_packageWithAlternatives_shouldReturnPackages() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, OwlElementNotFoundException {
PackageKnowledgeBase knowledgeBase = createKnowledgeBase();
OwlApiFacade originalModelFacade = new OwlApiFacade(OWLManager.createOWLOntologyManager(), OWLManager.getOWLDataFactory());
originalModelFacade.load(MODEL_OWL_PATH);
String affectedResource = "oracle-java6-installer";
PreservationAlternativesBuilder builder = new PackageAlternativesBuilder(knowledgeBase, BASE_URL, originalModelFacade, affectedResource, 9999, false);
Risk risk = new Risk("riskid", "riskname", "riskdescription", affectedResource);
IRI individualAtRisk = originalModelFacade.findIndividualByFragmentAndLabel(risk.getAffectedResource());
List<PreservationAlternative> actual = builder.createAlternatives(risk, individualAtRisk);
assertThat(actual.size(), is(9));
}
@Test
@Ignore("not yet finally integrated")
public void getAlternativePackages_packageWithAlternativesUsingReasoner_shouldAddDependingPackages() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, OwlElementNotFoundException, URISyntaxException {
int limit = 1;
PackageKnowledgeBase knowledgeBase = createKnowledgeBase();
OwlApiFacade originalModelFacade = new OwlApiFacade(OWLManager.createOWLOntologyManager(), OWLManager.getOWLDataFactory());
originalModelFacade.load("file://" + getClass().getResource("/test/package_alternative_test.owl").getPath());
String affectedResource = "nano";
PreservationAlternativesBuilder builder = new PackageAlternativesBuilder(knowledgeBase, BASE_URL, originalModelFacade, affectedResource, limit, true);
Risk risk = new Risk("riskid", "riskname", "riskdescription", affectedResource);
IRI individualAtRisk = originalModelFacade.findIndividualByFragmentAndLabel(risk.getAffectedResource());
List<PreservationAlternative> actual = builder.createAlternatives(risk, individualAtRisk);
assertThat(actual.size(), is(limit));
OwlApiFacade modifiedModel = OwlApiFacade.create();
modifiedModel.load(IOUtils.toInputStream(actual.get(0).getModifiedContextModel()));
assertTrue(modifiedModel.containsIndividualByLabel("xjed:i386-common"));
}
@Test
@Ignore("not yet finally integrated")
public void getAlternativePackages_packageWithAlternativesUsingReasoner_shouldRemoveOrphanedPackages() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, OwlElementNotFoundException, URISyntaxException {
int limit = 1;
PackageKnowledgeBase knowledgeBase = createKnowledgeBase();
OwlApiFacade originalModelFacade = new OwlApiFacade(OWLManager.createOWLOntologyManager(), OWLManager.getOWLDataFactory());
originalModelFacade.load("file://" + getClass().getResource("/test/package_alternative_test2.owl").getPath());
String affectedResource = "nano";
PreservationAlternativesBuilder builder = new PackageAlternativesBuilder(knowledgeBase, BASE_URL, originalModelFacade, affectedResource, limit, true);
Risk risk = new Risk("riskid", "riskname", "riskdescription", affectedResource);
IRI individualAtRisk = originalModelFacade.findIndividualByFragmentAndLabel(risk.getAffectedResource());
List<PreservationAlternative> actual = builder.createAlternatives(risk, individualAtRisk);
assertThat(actual.size(), is(limit));
OwlApiFacade modifiedModel = OwlApiFacade.create();
modifiedModel.load(IOUtils.toInputStream(actual.get(0).getModifiedContextModel()));
assertFalse(modifiedModel.containsIndividualByLabel("nano-common"));
}
private PackageKnowledgeBase createKnowledgeBase() {
return new PackageKnowledgeBase(new JenaQueryFacade(JenaQueryFacade.getModelFromPath(KB_OWL_PATH, true)));
}
}