X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-directory-autodetect-adapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fstorage%2Fdirectory%2Fautodetect%2FAutodetectDirectoryPersisterTest.java;fp=opendaylight%2Fconfig%2Fconfig-persister-directory-autodetect-adapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fstorage%2Fdirectory%2Fautodetect%2FAutodetectDirectoryPersisterTest.java;h=bcade93352670fcae086cf75f776242d0886276e;hb=257c03617a708ca997c0e004e1fcde45949c3435;hp=f8334607669103203f03f5c273dbaa7cf75a4977;hpb=0c327766c89e6e31c2c6e7581ac79722d01e3bf6;p=controller.git diff --git a/opendaylight/config/config-persister-directory-autodetect-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/AutodetectDirectoryPersisterTest.java b/opendaylight/config/config-persister-directory-autodetect-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/AutodetectDirectoryPersisterTest.java index f833460766..bcade93352 100644 --- a/opendaylight/config/config-persister-directory-autodetect-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/AutodetectDirectoryPersisterTest.java +++ b/opendaylight/config/config-persister-directory-autodetect-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/AutodetectDirectoryPersisterTest.java @@ -8,12 +8,15 @@ package org.opendaylight.controller.config.persist.storage.directory.autodetect; import java.io.File; +import java.io.IOException; import java.util.List; import junit.framework.Assert; import org.junit.Test; import org.junit.matchers.JUnitMatchers; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.config.persist.test.PropertiesProviderTest; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; public class AutodetectDirectoryPersisterTest { @@ -37,5 +40,52 @@ public class AutodetectDirectoryPersisterTest { String snapFromXml = configs.get(1).getConfigSnapshot(); org.junit.Assert.assertThat(snapFromXml, JUnitMatchers.containsString("xml")); - Assert.assertEquals(configs.get(0).getCapabilities(), configs.get(1).getCapabilities()); } + Assert.assertEquals(configs.get(0).getCapabilities(), configs.get(1).getCapabilities()); + } + + @Test + public void testInvalidXml() throws Exception { + File resourcePath = FileTypeTest.getResourceAsFile("/bad_controller.xml.config"); + File parentFile = resourcePath.getParentFile(); + + AutodetectDirectoryStorageAdapter adapter = new AutodetectDirectoryStorageAdapter(); + + PropertiesProviderTest pp = new PropertiesProviderTest(); + pp.addProperty("directoryStorage",parentFile.getPath()); + AutodetectDirectoryPersister persister = (AutodetectDirectoryPersister) adapter.instantiate(pp); + try { + List configs = persister.loadLastConfigs(); + fail("An exception of type " + IllegalStateException.class + " was expected"); + } catch (IllegalStateException ise){ + String message = ise.getMessage(); + assertThat(message, JUnitMatchers.containsString("Unable to restore configuration snapshot from ")); + } + + } + + @Test + public void testPersistConfig() throws Exception { + File resourcePath = FileTypeTest.getResourceAsFile("/combined/1controller.txt.config"); + File parentFile = resourcePath.getParentFile(); + + AutodetectDirectoryStorageAdapter adapter = new AutodetectDirectoryStorageAdapter(); + + PropertiesProviderTest pp = new PropertiesProviderTest(); + pp.addProperty("directoryStorage",parentFile.getPath()); + AutodetectDirectoryPersister persister = (AutodetectDirectoryPersister) adapter.instantiate(pp); + List configs = null; + try { + configs = persister.loadLastConfigs(); + } catch (IOException e) { + fail("An exception of type " + UnsupportedOperationException.class + " was expected"); + } + Assert.assertEquals(2, configs.size()); + try { + persister.persistConfig(configs.get(0)); + } catch (UnsupportedOperationException uoe){ + String message = uoe.getMessage(); + assertThat(message,JUnitMatchers.containsString("This adapter is read only. Please set readonly=true on class")); + } + } + }