Switch initial config files format to xml and add autodetect adapter for config persi...
[controller.git] / opendaylight / config / config-persister-directory-autodetect-adapter / src / test / java / org / opendaylight / controller / config / persist / storage / directory / autodetect / FileTypeTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.persist.storage.directory.autodetect;
9
10 import junit.framework.Assert;
11 import org.junit.Test;
12 import org.junit.matchers.JUnitMatchers;
13
14 import java.io.File;
15
16 public class FileTypeTest {
17
18     @Test
19     public void testPlaintext() throws Exception {
20         File file = getResourceAsFile("/test.txt.config");
21
22         FileType type = FileType.getFileType(file);
23         Assert.assertEquals(FileType.plaintext, type);
24
25     }
26
27     @Test
28     public void testXml() throws Exception {
29         File file = getResourceAsFile("/test.xml.config");
30
31         FileType type = FileType.getFileType(file);
32         Assert.assertEquals(FileType.xml, type);
33     }
34
35     @Test(expected = IllegalArgumentException.class)
36     public void testUnknown() throws Exception {
37         File file = getResourceAsFile("/unknown.config");
38
39         try {
40             FileType.getFileType(file);
41         } catch (IllegalArgumentException e) {
42             org.junit.Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("File " + file + " is not of permitted storage type"));
43             throw e;
44         }
45     }
46
47     static File getResourceAsFile(String resource) {
48         String f = FileTypeTest.class.getResource(resource).getFile();
49         return new File(f);
50     }
51
52 }