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 static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.fail;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29 import com.google.common.util.concurrent.CheckedFuture;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.InvocationTargetException;
33 import java.lang.reflect.Method;
34 import java.util.Arrays;
35 import java.util.List;
36 import java.util.Properties;
37 import java.util.concurrent.ExecutionException;
38 import org.eclipse.jdt.annotation.Nullable;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
42 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
43 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
44 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
45 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.DaeximOffsiteBackupService;
46 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.RetrieveDataInput;
47 import org.opendaylight.yangtools.yang.binding.Augmentation;
49 public class DaeximOffsiteBackupProviderTest {
50 public DataBroker dataBroker;
51 public ReadWriteTransaction writeTransaction;
52 public CheckedFuture<Void, TransactionCommitFailedException> checkedFuture;
53 public RpcProviderRegistry rpcRegistry;
54 public DaeximOffsiteBackupProvider provider;
55 public Properties resProps;
59 resProps = new Properties();
60 resProps.put("error-code", "200");
61 resProps.put("error-message", "Success");
62 dataBroker = mock(DataBroker.class);
63 writeTransaction = mock(ReadWriteTransaction.class);
64 checkedFuture = mock(CheckedFuture.class);
65 rpcRegistry = mock(RpcProviderRegistry.class);
66 when(rpcRegistry.addRoutedRpcImplementation(any(), any(DaeximOffsiteBackupService.class))).thenReturn(null);
68 when(checkedFuture.get()).thenReturn(null);
70 catch(InterruptedException | ExecutionException e) {
73 when(writeTransaction.submit()).thenReturn(checkedFuture);
74 when(dataBroker.newReadWriteTransaction()).thenReturn(writeTransaction);
76 provider = new DaeximOffsiteBackupProvider(dataBroker, rpcRegistry);
80 public void initializeTest() {
81 provider.initialize();
85 public void closeTest() {
95 public void onDataTreeChangedTest() {
96 provider.onDataTreeChanged(null);
97 // onDataTreeChanged is an empty stub
101 public void backupDataTest() {
103 assertNotNull(provider.backupData(null));
109 assertNotNull(provider.backupData(null));
115 assertNotNull(provider.backupData(null));
121 assertNotNull(provider.backupData(null));
127 assertNotNull(provider.backupData(null));
135 public void retrieveDataTest() {
136 RetrieveDataInput input = new RetrieveDataInput() {
138 public <E extends Augmentation<RetrieveDataInput>> @Nullable E augmentation(Class<E> augmentationType) {
143 public String getPodName() {
148 public String getTimestamp() {
149 return "Some Timestamp";
155 assertNotNull(provider.retrieveData(input));
161 assertNotNull(provider.retrieveData(input));
167 assertNotNull(provider.retrieveData(input));
173 assertNotNull(provider.retrieveData(input));
179 assertNotNull(provider.retrieveData(input));
187 public void archiveOperationsTest() {
188 List<String> files = Arrays.asList("src/test/resources/fileToZip1", "src/test/resources/fileToZip2");
189 String archive = "src/test/resources/zippedArchive.zip";
191 Method method = provider.getClass().getDeclaredMethod("createArchive", List.class, String.class);
192 method.setAccessible(true);
193 method.invoke(provider, files, archive);
196 catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
201 Field field = provider.getClass().getDeclaredField("DAEXIM_DIR");
202 field.setAccessible(true);
203 field.set(provider, "");
204 Method method = provider.getClass().getDeclaredMethod("extractArchive", String.class);
205 method.setAccessible(true);
206 method.invoke(provider, archive);
208 catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
212 File zip = new File(archive);