increased test coverage
[controller.git] / opendaylight / config / config-persister-directory-autodetect-adapter / src / test / java / org / opendaylight / controller / config / persist / storage / directory / autodetect / AutodetectDirectoryPersisterTest.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 java.io.File;
11 import java.util.List;
12 import junit.framework.Assert;
13 import org.junit.Test;
14 import org.junit.matchers.JUnitMatchers;
15 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
16 import org.opendaylight.controller.config.persist.test.PropertiesProviderTest;
17
18 public class AutodetectDirectoryPersisterTest {
19
20     @Test
21     public void testCombined() throws Exception {
22         File resourcePath = FileTypeTest.getResourceAsFile("/combined/1controller.txt.config");
23         File parentFile = resourcePath.getParentFile();
24
25         AutodetectDirectoryStorageAdapter adapter = new AutodetectDirectoryStorageAdapter();
26
27         PropertiesProviderTest pp = new PropertiesProviderTest();
28         pp.addProperty("directoryStorage",parentFile.getPath());
29         AutodetectDirectoryPersister persister = (AutodetectDirectoryPersister) adapter.instantiate(pp);
30         List<ConfigSnapshotHolder> configs = persister.loadLastConfigs();
31
32         Assert.assertEquals(2, configs.size());
33         String snapFromTxt = configs.get(0).getConfigSnapshot();
34         org.junit.Assert.assertThat(snapFromTxt, JUnitMatchers.containsString("<config>txt</config>"));
35         org.junit.Assert.assertThat(snapFromTxt, JUnitMatchers.containsString("<service>txt</service>"));
36
37         String snapFromXml = configs.get(1).getConfigSnapshot();
38         org.junit.Assert.assertThat(snapFromXml, JUnitMatchers.containsString("<config>xml</config>"));
39
40         Assert.assertEquals(configs.get(0).getCapabilities(), configs.get(1).getCapabilities());    }
41 }