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.FluentFuture;
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.mdsal.binding.api.DataBroker;
42 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
43 import org.opendaylight.mdsal.binding.api.RpcProviderService;
44 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.DaeximOffsiteBackupService;
45 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.RetrieveDataInput;
46 import org.opendaylight.yangtools.yang.binding.Augmentation;
48 public class DaeximOffsiteBackupProviderTest {
49 public DataBroker dataBroker;
50 public ReadWriteTransaction writeTransaction;
51 public FluentFuture checkedFuture;
52 public RpcProviderService rpcRegistry;
53 public DaeximOffsiteBackupProvider provider;
54 public Properties resProps;
58 resProps = new Properties();
59 resProps.put("error-code", "200");
60 resProps.put("error-message", "Success");
61 dataBroker = mock(DataBroker.class);
62 writeTransaction = mock(ReadWriteTransaction.class);
63 checkedFuture = mock(FluentFuture.class);
64 rpcRegistry = mock(RpcProviderService.class);
65 when(rpcRegistry.registerRpcImplementation(any(), any(DaeximOffsiteBackupService.class))).thenReturn(null);
67 when(checkedFuture.get()).thenReturn(null);
69 catch(InterruptedException | ExecutionException e) {
72 when(writeTransaction.commit()).thenReturn(checkedFuture);
73 when(dataBroker.newReadWriteTransaction()).thenReturn(writeTransaction);
75 provider = new DaeximOffsiteBackupProvider(dataBroker, rpcRegistry);
79 public void initializeTest() {
80 provider.initialize();
84 public void closeTest() {
94 public void onDataTreeChangedTest() {
95 provider.onDataTreeChanged(null);
96 // onDataTreeChanged is an empty stub
100 public void backupDataTest() {
102 assertNotNull(provider.backupData(null));
108 assertNotNull(provider.backupData(null));
114 assertNotNull(provider.backupData(null));
120 assertNotNull(provider.backupData(null));
126 assertNotNull(provider.backupData(null));
134 public void retrieveDataTest() {
135 RetrieveDataInput input = new RetrieveDataInput() {
137 public <E extends Augmentation<RetrieveDataInput>> @Nullable E augmentation(Class<E> augmentationType) {
142 public String getPodName() {
147 public String getTimestamp() {
148 return "Some Timestamp";
154 assertNotNull(provider.retrieveData(input));
160 assertNotNull(provider.retrieveData(input));
166 assertNotNull(provider.retrieveData(input));
172 assertNotNull(provider.retrieveData(input));
178 assertNotNull(provider.retrieveData(input));
186 public void archiveOperationsTest() {
187 List<String> files = Arrays.asList("src/test/resources/fileToZip1", "src/test/resources/fileToZip2");
188 String archive = "src/test/resources/zippedArchive.zip";
190 Method method = provider.getClass().getDeclaredMethod("createArchive", List.class, String.class);
191 method.setAccessible(true);
192 method.invoke(provider, files, archive);
195 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);