2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.northbound.daeximoffsitebackup;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.junit.Before;
26 import org.junit.Test;
28 import org.opendaylight.controller.md.sal.binding.api.*;
29 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
30 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
32 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.DaeximOffsiteBackupService;
34 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.RetrieveDataInput;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 import org.opendaylight.yangtools.yang.binding.DataContainer;
39 import com.google.common.util.concurrent.CheckedFuture;
42 import java.lang.reflect.Field;
43 import java.lang.reflect.InvocationTargetException;
44 import java.lang.reflect.Method;
45 import java.util.Arrays;
46 import java.util.List;
47 import java.util.Properties;
48 import java.util.concurrent.ExecutionException;
50 import static org.mockito.Mockito.*;
51 import static org.junit.Assert.*;
53 public class DaeximOffsiteBackupProviderTest {
54 public DataBroker dataBroker;
55 public ReadWriteTransaction writeTransaction;
56 public CheckedFuture<Void, TransactionCommitFailedException> checkedFuture;
57 public RpcProviderRegistry rpcRegistry;
58 public DaeximOffsiteBackupProvider provider;
59 public Properties resProps;
63 resProps = new Properties();
64 resProps.put("error-code", "200");
65 resProps.put("error-message", "Success");
66 dataBroker = mock(DataBroker.class);
67 writeTransaction = mock(ReadWriteTransaction.class);
68 checkedFuture = mock(CheckedFuture.class);
69 rpcRegistry = mock(RpcProviderRegistry.class);
70 when(rpcRegistry.addRoutedRpcImplementation(any(), any(DaeximOffsiteBackupService.class))).thenReturn(null);
72 when(checkedFuture.get()).thenReturn(null);
74 catch(InterruptedException | ExecutionException e) {
77 when(writeTransaction.submit()).thenReturn(checkedFuture);
78 when(dataBroker.newReadWriteTransaction()).thenReturn(writeTransaction);
80 provider = new DaeximOffsiteBackupProvider(dataBroker, rpcRegistry);
84 public void initializeTest() {
85 provider.initialize();
89 public void closeTest() {
99 public void onDataTreeChangedTest() {
100 provider.onDataTreeChanged(null);
101 // onDataTreeChanged is an empty stub
105 public void backupDataTest() {
107 assertNotNull(provider.backupData(null));
113 assertNotNull(provider.backupData(null));
119 assertNotNull(provider.backupData(null));
125 assertNotNull(provider.backupData(null));
131 assertNotNull(provider.backupData(null));
139 public void retrieveDataTest() {
140 RetrieveDataInput input = new RetrieveDataInput() {
142 public <E extends Augmentation<RetrieveDataInput>> @Nullable E augmentation(Class<E> augmentationType) {
147 public String getPodName() {
152 public String getTimestamp() {
153 return "Some Timestamp";
157 public Class<? extends DataContainer> getImplementedInterface() {
162 assertNotNull(provider.retrieveData(input));
168 assertNotNull(provider.retrieveData(input));
174 assertNotNull(provider.retrieveData(input));
180 assertNotNull(provider.retrieveData(input));
186 assertNotNull(provider.retrieveData(input));
194 public void archiveOperationsTest() {
195 List<String> files = Arrays.asList("src/test/resources/fileToZip1", "src/test/resources/fileToZip2");
196 String archive = "src/test/resources/zippedArchive.zip";
198 Method method = provider.getClass().getDeclaredMethod("createArchive", List.class, String.class);
199 method.setAccessible(true);
200 method.invoke(provider, files, archive);
203 catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
208 Field field = provider.getClass().getDeclaredField("DAEXIM_DIR");
209 field.setAccessible(true);
210 field.set(provider, "");
211 Method method = provider.getClass().getDeclaredMethod("extractArchive", String.class);
212 method.setAccessible(true);
213 method.invoke(provider, archive);
215 catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
219 File zip = new File(archive);