a b/src/test/java/org/sbaresearch/owl/RenamerTest.java
1
/**
2
 * Copyright (c) 2013/2014 Verein zur Foerderung der IT-Sicherheit in Oesterreich (SBA).
3
 * The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium.
4
 * TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological
5
 * development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940.
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
8
 * the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
9
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without
11
 * limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR
12
 * PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise,
13
 * unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including
14
 * any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this
15
 * License or out of the use or inability to use the Work.
16
 * See the License for the specific language governing permissions and limitation under the License.
17
 */
18
package org.sbaresearch.owl;
19
20
import junitparams.JUnitParamsRunner;
21
import org.junit.Test;
22
import org.junit.runner.RunWith;
23
import org.semanticweb.owlapi.model.OWLOntology;
24
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
25
26
import java.net.URISyntaxException;
27
import java.util.HashMap;
28
29
import static junit.framework.Assert.assertTrue;
30
import static org.hamcrest.CoreMatchers.equalTo;
31
import static org.hamcrest.CoreMatchers.is;
32
import static org.junit.Assert.assertThat;
33
34
@RunWith(JUnitParamsRunner.class)
35
public class RenamerTest {
36
37
    private final String newURI = "http;//localhost/new/";
38
39
    @Test
40
    public void testRenameIndividual_directIndividual_shouldRenameIndividual() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
41
        OwlApiFacade facade = TestUtils.createDefaultOwlApiFacade();
42
        facade.load(TestUtils.getUri("/test_ab1.owl"));
43
        Renamer renamer = new Renamer(facade.getOntology(), newURI);
44
        renamer.renameIndividual(facade.getIndividual("http://localhost/test_ab1.owl#IndivA"), "xIndivA");
45
        assertThat(facade.containsIndividual("http://localhost/test_ab1.owl#xIndivA"), is(true));
46
    }
47
48
    @Test
49
    public void testRenameIndividual_importedIndividual_shouldRenameIndividual() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
50
        OwlApiFacade facade = createDefaultOwlApiFacade();
51
        Renamer renamer = new Renamer(facade.getOntology(), newURI);
52
        renamer.renameIndividual(facade.getIndividualByUnqualifiedName("IndivA", true), "xIndivA");
53
        assertTrue(new OwlApiFacade(renamer.getOntology()).containsIndividual(newURI + "test_ab1.owl#xIndivA"));
54
    }
55
56
    @Test
57
    public void testRenameIndividual_importedIndividual_shouldCloneImportedOntology() throws URISyntaxException, OWLOntologyCreationException, OwlElementNotFoundException {
58
        OwlApiFacade facade = createDefaultOwlApiFacade();
59
        Renamer renamer = new Renamer(facade.getOntology(), newURI);
60
61
        renamer.renameIndividual(facade.getIndividualByUnqualifiedName("IndivA", true), "xIndivA");
62
63
        assertThat(renamer.getChangedOntologies().size(), is(1));
64
        OWLOntology actualImported = renamer.getChangedOntologies().get(0);
65
        assertThat(actualImported.getOntologyID().getOntologyIRI().toString(), equalTo(newURI + "test_ab1.owl"));
66
67
        OwlApiFacade sourceImported = TestUtils.createDefaultOwlApiFacade();
68
        sourceImported.load(TestUtils.getUri("/test_ab1.owl"));
69
        assertThat(actualImported.getIndividualsInSignature().size(), equalTo(sourceImported.getOntology().getIndividualsInSignature().size()));
70
    }
71
72
    private OwlApiFacade createDefaultOwlApiFacade() throws URISyntaxException, OWLOntologyCreationException {
73
        OwlApiFacade model = TestUtils.createDefaultOwlApiFacade();
74
        model.load(TestUtils.getUri("/test_ab3.owl"), new HashMap<String, String>() {{
75
            put("http://localhost/test_ab1.owl", TestUtils.getUri("/test_ab1.owl"));
76
            put("http://localhost/test_ab2.owl", TestUtils.getUri("/test_ab2.owl"));
77
        }});
78
        return model;
79
    }
80
81
}