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
diff --git a/opendaylight/config/config-persister-directory-autodetect-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/FileTypeTest.java b/opendaylight/config/config-persister-directory-autodetect-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/FileTypeTest.java
new file mode 100644 (file)
index 0000000..bbc272d
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.directory.autodetect;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.matchers.JUnitMatchers;
+
+import java.io.File;
+
+public class FileTypeTest {
+
+    @Test
+    public void testPlaintext() throws Exception {
+        File file = getResourceAsFile("/test.txt.config");
+
+        FileType type = FileType.getFileType(file);
+        Assert.assertEquals(FileType.plaintext, type);
+
+    }
+
+    @Test
+    public void testXml() throws Exception {
+        File file = getResourceAsFile("/test.xml.config");
+
+        FileType type = FileType.getFileType(file);
+        Assert.assertEquals(FileType.xml, type);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testUnknown() throws Exception {
+        File file = getResourceAsFile("/unknown.config");
+
+        try {
+            FileType.getFileType(file);
+        } catch (IllegalArgumentException e) {
+            org.junit.Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("File " + file + " is not of permitted storage type"));
+            throw e;
+        }
+    }
+
+    static File getResourceAsFile(String resource) {
+        String f = FileTypeTest.class.getResource(resource).getFile();
+        return new File(f);
+    }
+
+}