|
1 | 1 | /* |
2 | 2 | * The baseCode project |
3 | | - * |
| 3 | + * |
4 | 4 | * Copyright (c) 2013 University of British Columbia |
5 | | - * |
| 5 | + * |
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
7 | 7 | * the License. You may obtain a copy of the License at |
8 | | - * |
| 8 | + * |
9 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | - * |
| 10 | + * |
11 | 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
12 | 12 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
13 | 13 | * specific language governing permissions and limitations under the License. |
14 | 14 | */ |
15 | 15 | package ubic.basecode.ontology; |
16 | 16 |
|
17 | | -import org.junit.AfterClass; |
18 | | -import org.junit.BeforeClass; |
19 | | -import ubic.basecode.util.Configuration; |
| 17 | +import org.apache.commons.io.FileUtils; |
| 18 | +import org.junit.Test; |
| 19 | +import ubic.basecode.ontology.jena.OntologyLoader; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.io.InputStream; |
| 23 | +import java.net.URL; |
| 24 | +import java.nio.file.Files; |
| 25 | +import java.nio.file.StandardCopyOption; |
| 26 | + |
| 27 | +import static org.junit.Assert.*; |
20 | 28 |
|
21 | 29 | /** |
22 | 30 | * Test loading a database-backed ontology |
23 | | - * |
| 31 | + * |
24 | 32 | * @author Paul |
25 | | - * |
26 | 33 | */ |
27 | | -public class OntologyLoaderTest { |
| 34 | +public class OntologyLoaderTest extends AbstractOntologyTest { |
28 | 35 |
|
29 | | - private static String prevDir = null; |
30 | | - private static String dataResource = "/data/nif.organism.test.owl.xml"; |
| 36 | + @Test |
| 37 | + public void testHasChanged() throws Exception { |
| 38 | + String name = "fooTEST1234"; |
31 | 39 |
|
32 | | - @BeforeClass |
33 | | - public static void setup() throws Exception { |
34 | | - prevDir = Configuration.getString( "ontology.cache.dir" ); |
35 | | - Configuration.setString( "ontology.cache.dir", System.getProperty( "java.io.tmpdir" ) ); |
36 | | - } |
| 40 | + File f = OntologyLoader.getDiskCachePath( name ); |
| 41 | + File oldFile = new File( f.getAbsolutePath() + ".old" ); |
37 | 42 |
|
38 | | - @AfterClass |
39 | | - public static void tearDown() throws Exception { |
40 | | - Configuration.setString( "ontology.cache.dir", prevDir ); |
41 | | - } |
| 43 | + assertFalse( f.exists() ); |
| 44 | + assertFalse( oldFile.exists() ); |
42 | 45 |
|
43 | | -// @Test |
44 | | -// public void testHasChanged() throws Exception { |
45 | | -// String name = "fooTEST1234"; |
46 | | -// |
47 | | -// File f = OntologyLoader.getDiskCachePath( name ); |
48 | | -// if ( f.exists() ) { |
49 | | -// f.delete(); |
50 | | -// } |
51 | | -// |
52 | | -// File oldFile = OntologyLoader.getOldDiskCachePath( name ); |
53 | | -// if ( oldFile.exists() ) { |
54 | | -// oldFile.delete(); |
55 | | -// } |
56 | | -// |
57 | | -// assertTrue( !f.exists() ); |
58 | | -// assertTrue( !oldFile.exists() ); |
59 | | -// |
60 | | -// URL resource = this.getClass().getResource( dataResource ); |
61 | | -// try (InputStream in = resource.openStream();) { |
62 | | -// Files.copy( in, f.toPath(), StandardCopyOption.REPLACE_EXISTING ); |
63 | | -// } |
64 | | -// |
65 | | -// try (InputStream in = resource.openStream();) { |
66 | | -// Files.copy( in, oldFile.toPath(), StandardCopyOption.REPLACE_EXISTING ); |
67 | | -// } |
68 | | -// |
69 | | -// assertTrue( !OntologyLoader.hasChanged( name ) ); |
70 | | -// |
71 | | -// // Now if the dataResource has changed |
72 | | -// resource = this.getClass().getResource( "/data/nif.organism.test.owl-off-by-one.xml" ); |
73 | | -// try (InputStream in = resource.openStream();) { |
74 | | -// Files.copy( in, f.toPath(), StandardCopyOption.REPLACE_EXISTING ); |
75 | | -// } |
76 | | -// assertTrue( OntologyLoader.hasChanged( name ) ); |
77 | | -// |
78 | | -// } |
| 46 | + FileUtils.forceMkdirParent( f ); |
79 | 47 |
|
| 48 | + URL resource = this.getClass().getResource( "/data/nif.organism.test.owl.xml" ); |
| 49 | + assertNotNull( resource ); |
| 50 | + try ( InputStream in = resource.openStream(); ) { |
| 51 | + Files.copy( in, f.toPath(), StandardCopyOption.REPLACE_EXISTING ); |
| 52 | + } |
| 53 | + |
| 54 | + try ( InputStream in = resource.openStream(); ) { |
| 55 | + Files.copy( in, oldFile.toPath(), StandardCopyOption.REPLACE_EXISTING ); |
| 56 | + } |
| 57 | + |
| 58 | + assertFalse( OntologyLoader.hasChanged( name ) ); |
| 59 | + |
| 60 | + // Now if the dataResource has changed |
| 61 | + resource = this.getClass().getResource( "/data/nif.organism.test.owl-off-by-one.xml" ); |
| 62 | + assertNotNull( resource ); |
| 63 | + try ( InputStream in = resource.openStream(); ) { |
| 64 | + Files.copy( in, f.toPath(), StandardCopyOption.REPLACE_EXISTING ); |
| 65 | + } |
| 66 | + assertTrue( OntologyLoader.hasChanged( name ) ); |
| 67 | + } |
80 | 68 | } |
0 commit comments