2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.data.impl;
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;
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;
36 public class PersistingDataTreeAdapterTest {
39 private DataTree delegatingDataTree;
41 private SchemaService schemaService;
43 private DataTreeSnapshot snapshot;
45 private Path tmpPersistFile;
47 private PersistingDataTreeAdapter persistingDataTreeAdapter;
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);
57 public void testNoPersistOnFailure() throws Exception {
58 doThrow(new IllegalStateException("testing errors")).when(delegatingDataTree).commit(any(DataTreeCandidate.class));
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));