HONEYCOMB-130: Rename infra packages(remove vpp/v3po)
[honeycomb.git] / infra / data-impl / src / test / java / io / fd / honeycomb / data / impl / PersistingDataTreeAdapterTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.data.impl;
18
19 import static org.junit.Assert.fail;
20 import static org.mockito.Matchers.any;
21 import static org.mockito.Mockito.doThrow;
22 import static org.mockito.Mockito.times;
23 import static org.mockito.Mockito.verify;
24
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.opendaylight.controller.sal.core.api.model.SchemaService;
32 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
33 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
34 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
35
36 public class PersistingDataTreeAdapterTest {
37
38     @Mock
39     private DataTree delegatingDataTree;
40     @Mock
41     private SchemaService schemaService;
42     @Mock
43     private DataTreeSnapshot snapshot;
44
45     private Path tmpPersistFile;
46
47     private PersistingDataTreeAdapter persistingDataTreeAdapter;
48
49     @Before
50     public void setUp() throws Exception {
51         MockitoAnnotations.initMocks(this);
52         tmpPersistFile = Files.createTempFile("testing-hc-persistence", "json");
53         persistingDataTreeAdapter = new PersistingDataTreeAdapter(delegatingDataTree, schemaService, tmpPersistFile);
54     }
55
56     @Test
57     public void testNoPersistOnFailure() throws Exception {
58         doThrow(new IllegalStateException("testing errors")).when(delegatingDataTree).commit(any(DataTreeCandidate.class));
59
60         try {
61             persistingDataTreeAdapter.commit(null);
62             fail("Exception expected");
63         } catch (IllegalStateException e) {
64             verify(delegatingDataTree, times(0)).takeSnapshot();
65             verify(delegatingDataTree).commit(any(DataTreeCandidate.class));
66         }
67     }
68
69 }