From 50bd4a0f591d9d00335b008a9e66f1906d40bc20 Mon Sep 17 00:00:00 2001 From: "Haddox, Anthony" Date: Wed, 16 Jan 2019 08:08:35 -0800 Subject: [CCSDK-953]Create Daexim Offsite Backup Inital commit of ODL feature Issue-ID: CCSDK-953 Change-Id: I7eb64fc9f414083db424700f2c901ba0a66cb0c4 Signed-off-by: Haddox, Anthony --- .../DaeximOffsiteBackupProviderTest.java | 223 +++++++++++++++++++++ .../DaeximOffsiteBackupUtilTest.java | 40 ++++ .../resources/daexim-offsite-backup.properties | 4 + .../provider/src/test/resources/fileToZip1 | 1 + .../provider/src/test/resources/fileToZip2 | 1 + 5 files changed, 269 insertions(+) create mode 100644 daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java create mode 100644 daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupUtilTest.java create mode 100755 daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties create mode 100644 daexim-offsite-backup/provider/src/test/resources/fileToZip1 create mode 100644 daexim-offsite-backup/provider/src/test/resources/fileToZip2 (limited to 'daexim-offsite-backup/provider/src/test') diff --git a/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java b/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java new file mode 100644 index 000000000..65d0dcaf2 --- /dev/null +++ b/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java @@ -0,0 +1,223 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.northbound.daeximoffsitebackup; + +import org.eclipse.jdt.annotation.Nullable; +import org.junit.Before; +import org.junit.Test; + +import org.opendaylight.controller.md.sal.binding.api.*; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; + +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.DaeximOffsiteBackupService; + +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.RetrieveDataInput; + +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.DataContainer; + +import com.google.common.util.concurrent.CheckedFuture; + +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +public class DaeximOffsiteBackupProviderTest { + public DataBroker dataBroker; + public ReadWriteTransaction writeTransaction; + public CheckedFuture checkedFuture; + public RpcProviderRegistry rpcRegistry; + public DaeximOffsiteBackupProvider provider; + public Properties resProps; + + @Before + public void setup() { + resProps = new Properties(); + resProps.put("error-code", "200"); + resProps.put("error-message", "Success"); + dataBroker = mock(DataBroker.class); + writeTransaction = mock(ReadWriteTransaction.class); + checkedFuture = mock(CheckedFuture.class); + rpcRegistry = mock(RpcProviderRegistry.class); + when(rpcRegistry.addRoutedRpcImplementation(any(), any(DaeximOffsiteBackupService.class))).thenReturn(null); + try { + when(checkedFuture.get()).thenReturn(null); + } + catch(InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + when(writeTransaction.submit()).thenReturn(checkedFuture); + when(dataBroker.newReadWriteTransaction()).thenReturn(writeTransaction); + + provider = new DaeximOffsiteBackupProvider(dataBroker, rpcRegistry); + } + + @Test + public void initializeTest() { + provider.initialize(); + } + + @Test + public void closeTest() { + try { + provider.close(); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void onDataTreeChangedTest() { + provider.onDataTreeChanged(null); + // onDataTreeChanged is an empty stub + } + + @Test + public void backupDataTest() { + try { + assertNotNull(provider.backupData(null)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.backupData(null)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.backupData(null)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.backupData(null)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.backupData(null)); + } + catch(Exception e) { + fail(); + } + } + + @Test + public void retrieveDataTest() { + RetrieveDataInput input = new RetrieveDataInput() { + @Override + public > @Nullable E augmentation(Class augmentationType) { + return null; + } + + @Override + public String getPodName() { + return "Some Pod"; + } + + @Override + public String getTimestamp() { + return "Some Timestamp"; + } + + @Override + public Class getImplementedInterface() { + return null; + } + }; + try { + assertNotNull(provider.retrieveData(input)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.retrieveData(input)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.retrieveData(input)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.retrieveData(input)); + } + catch(Exception e) { + fail(); + } + try { + assertNotNull(provider.retrieveData(input)); + } + catch(Exception e) { + fail(); + } + } + + @Test + public void archiveOperationsTest() { + List files = Arrays.asList("src/test/resources/fileToZip1", "src/test/resources/fileToZip2"); + String archive = "src/test/resources/zippedArchive.zip"; + try { + Method method = provider.getClass().getDeclaredMethod("createArchive", List.class, String.class); + method.setAccessible(true); + method.invoke(provider, files, archive); + + } + catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + fail(); + } + + try { + Field field = provider.getClass().getDeclaredField("DAEXIM_DIR"); + field.setAccessible(true); + field.set(provider, ""); + Method method = provider.getClass().getDeclaredMethod("extractArchive", String.class); + method.setAccessible(true); + method.invoke(provider, archive); + } + catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) { + fail(); + } + finally { + File zip = new File(archive); + zip.delete(); + } + } +} diff --git a/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupUtilTest.java b/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupUtilTest.java new file mode 100644 index 000000000..16ce68198 --- /dev/null +++ b/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupUtilTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.northbound.daeximoffsitebackup; + +import org.junit.Test; + +import java.lang.reflect.Field; + +public class DaeximOffsiteBackupUtilTest { + @Test + public void loadProperties() { + try { + Field field = DaeximOffsiteBackupUtil.class.getDeclaredField("PROPERTIES_FILE"); + field.setAccessible(true); + field.set(new DaeximOffsiteBackupUtil(), "src/test/resources/daexim-offsite-backup.properties"); + DaeximOffsiteBackupUtil.loadProperties(); + } catch(Exception e) { + // Files don't exist on build server + } + } +} diff --git a/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties b/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties new file mode 100755 index 000000000..49dd133bc --- /dev/null +++ b/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties @@ -0,0 +1,4 @@ +daeximDirectory=/opt/opendaylight/current/daexim/ +credentials=admin:admin123 +nexusUrl=http://localhost:8081/nexus/content/repositories/ +podName=UNKNOWN_ODL \ No newline at end of file diff --git a/daexim-offsite-backup/provider/src/test/resources/fileToZip1 b/daexim-offsite-backup/provider/src/test/resources/fileToZip1 new file mode 100644 index 000000000..c7ef4260e --- /dev/null +++ b/daexim-offsite-backup/provider/src/test/resources/fileToZip1 @@ -0,0 +1 @@ +Lorem ipsum. \ No newline at end of file diff --git a/daexim-offsite-backup/provider/src/test/resources/fileToZip2 b/daexim-offsite-backup/provider/src/test/resources/fileToZip2 new file mode 100644 index 000000000..c7ef4260e --- /dev/null +++ b/daexim-offsite-backup/provider/src/test/resources/fileToZip2 @@ -0,0 +1 @@ +Lorem ipsum. \ No newline at end of file -- cgit 1.2.3-korg From 81fd4cee0d7ca6a014eb33d5ffba63f731249141 Mon Sep 17 00:00:00 2001 From: "Haddox, Anthony" Date: Fri, 25 Jan 2019 08:57:39 -0800 Subject: [CCSDK-1008]Generalize offsite backup Revised the provider to use file names designated in the properties file. This is for those who use vendor provided distributions of OpenDaylight Change-Id: Ib120452fa989fff371a832416a34d95745fead1b Issue-ID: CCSDK-1008 Signed-off-by: Haddox, Anthony --- daexim-offsite-backup/README.md | 5 +++++ .../DaeximOffsiteBackupProvider.java | 16 ++++++++++++--- .../resources/daexim-offsite-backup.properties | 24 +++++++++++++++++++++- .../resources/daexim-offsite-backup.properties | 24 +++++++++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) (limited to 'daexim-offsite-backup/provider/src/test') diff --git a/daexim-offsite-backup/README.md b/daexim-offsite-backup/README.md index 26d8a7ede..e3f13aee9 100755 --- a/daexim-offsite-backup/README.md +++ b/daexim-offsite-backup/README.md @@ -78,5 +78,10 @@ Before each RPC execution this module pulls information from a user supplied pro - credentials - nexusUrl - podName +- file.operational +- file.models +- file.config + +> Refer to the example properties file If the module cannot find the properties file it will default to generic values and attempt to move forward. diff --git a/daexim-offsite-backup/provider/src/main/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProvider.java b/daexim-offsite-backup/provider/src/main/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProvider.java index cc16bf70d..09c8f92f4 100755 --- a/daexim-offsite-backup/provider/src/main/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProvider.java +++ b/daexim-offsite-backup/provider/src/main/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProvider.java @@ -75,11 +75,11 @@ public class DaeximOffsiteBackupProvider implements AutoCloseable, DaeximOffsite private static String CREDENTIALS; private static String NEXUS_URL; private static String POD_NAME; + private static String OPERATIONAL_JSON; + private static String MODELS_JSON; + private static String CONFIG_JSON; private static String PROPERTIES_FILE = System.getenv("SDNC_CONFIG_DIR") + "/daexim-offsite-backup.properties"; - private static final String OPERATIONAL_JSON = "odl_backup_operational.json"; - private static final String MODELS_JSON = "odl_backup_models.json"; - private static final String CONFIG_JSON = "odl_backup_config.json"; private static final String BACKUP_ARCHIVE = "odl_backup.zip"; private static final String appName = "daexim-offsite-backup"; @@ -122,6 +122,9 @@ public class DaeximOffsiteBackupProvider implements AutoCloseable, DaeximOffsite properties.put("credentials", "admin:enc:YWRtaW4xMjM="); properties.put("nexusUrl", "http://localhost:8081/nexus/content/repositories/"); properties.put("podName", "UNKNOWN_ODL"); + properties.put("file.operational", "odl_backup_operational.json"); + properties.put("file.models", "odl_backup_models.json"); + properties.put("file.config", "odl_backup_config.json"); return; } FileInputStream fileInputStream; @@ -133,6 +136,9 @@ public class DaeximOffsiteBackupProvider implements AutoCloseable, DaeximOffsite LOG.info("daeximDirectory: " + properties.getProperty("daeximDirectory")); LOG.info("nexusUrl: " + properties.getProperty("nexusUrl")); LOG.info("podName: " + properties.getProperty("podName")); + LOG.info("file.operational: " + properties.getProperty("file.operational")); + LOG.info("file.models: " + properties.getProperty("file.models")); + LOG.info("file.config: " + properties.getProperty("file.config")); } catch(IOException e) { LOG.error("Error loading properties.", e); } @@ -147,6 +153,10 @@ public class DaeximOffsiteBackupProvider implements AutoCloseable, DaeximOffsite DAEXIM_DIR = properties.getProperty("daeximDirectory"); NEXUS_URL = properties.getProperty("nexusUrl"); + OPERATIONAL_JSON = properties.getProperty("file.operational"); + MODELS_JSON = properties.getProperty("file.models"); + CONFIG_JSON = properties.getProperty("file.config"); + if(!properties.getProperty("credentials").contains(":")) { //Entire thing is encoded CREDENTIALS = new String(Base64.getDecoder().decode(properties.getProperty("credentials"))); } diff --git a/daexim-offsite-backup/provider/src/main/resources/daexim-offsite-backup.properties b/daexim-offsite-backup/provider/src/main/resources/daexim-offsite-backup.properties index bdfa8155a..51efc1f1e 100755 --- a/daexim-offsite-backup/provider/src/main/resources/daexim-offsite-backup.properties +++ b/daexim-offsite-backup/provider/src/main/resources/daexim-offsite-backup.properties @@ -1,6 +1,28 @@ +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2019 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= + # Example properties file daeximDirectory=/opt/opendaylight/current/daexim/ credentials=admin:enc:YWRtaW4xMjM= nexusUrl=http://localhost:8081/nexus/content/repositories/ -podName=UNKNOWN_ODL \ No newline at end of file +podName=UNKNOWN_ODL +file.operational=odl_backup_operational.json +file.models=odl_backup_models.json +file.config=odl_backup_config.json \ No newline at end of file diff --git a/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties b/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties index 49dd133bc..b69027906 100755 --- a/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties +++ b/daexim-offsite-backup/provider/src/test/resources/daexim-offsite-backup.properties @@ -1,4 +1,26 @@ +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2019 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= + daeximDirectory=/opt/opendaylight/current/daexim/ credentials=admin:admin123 nexusUrl=http://localhost:8081/nexus/content/repositories/ -podName=UNKNOWN_ODL \ No newline at end of file +podName=UNKNOWN_ODL +file.operational=odl_backup_operational.json +file.models=odl_backup_models.json +file.config=odl_backup_config.json \ No newline at end of file -- cgit 1.2.3-korg From 73bf30dec7bbda557752ae7024f3d8e329409635 Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Fri, 10 Jul 2020 05:07:17 +0200 Subject: upgrade northbound to sodium MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed unit test due changes in sodium Issue-ID: CCSDK-2544 Signed-off-by: Michael Dürre Change-Id: I69af992f1db267e282a0ed66b4e4bed72d4f2bd4 --- daexim-offsite-backup/provider/pom.xml | 4 +++ .../DaeximOffsiteBackupProviderTest.java | 39 +++++++++------------- 2 files changed, 20 insertions(+), 23 deletions(-) (limited to 'daexim-offsite-backup/provider/src/test') diff --git a/daexim-offsite-backup/provider/pom.xml b/daexim-offsite-backup/provider/pom.xml index 94ffc4411..a9f72b1ce 100755 --- a/daexim-offsite-backup/provider/pom.xml +++ b/daexim-offsite-backup/provider/pom.xml @@ -61,6 +61,10 @@ sli-provider ${sdnctl.sli.version} + + com.google.code.findbugs + annotations + junit junit diff --git a/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java b/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java index 65d0dcaf2..d070c30e2 100644 --- a/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java +++ b/daexim-offsite-backup/provider/src/test/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProviderTest.java @@ -21,23 +21,12 @@ package org.onap.ccsdk.sli.northbound.daeximoffsitebackup; -import org.eclipse.jdt.annotation.Nullable; -import org.junit.Before; -import org.junit.Test; - -import org.opendaylight.controller.md.sal.binding.api.*; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; - -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.DaeximOffsiteBackupService; - -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.RetrieveDataInput; - -import org.opendaylight.yangtools.yang.binding.Augmentation; -import org.opendaylight.yangtools.yang.binding.DataContainer; - +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.CheckedFuture; - import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -46,9 +35,16 @@ import java.util.Arrays; import java.util.List; import java.util.Properties; import java.util.concurrent.ExecutionException; - -import static org.mockito.Mockito.*; -import static org.junit.Assert.*; +import org.eclipse.jdt.annotation.Nullable; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.DaeximOffsiteBackupService; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.daeximoffsitebackup.rev180926.RetrieveDataInput; +import org.opendaylight.yangtools.yang.binding.Augmentation; public class DaeximOffsiteBackupProviderTest { public DataBroker dataBroker; @@ -153,10 +149,7 @@ public class DaeximOffsiteBackupProviderTest { return "Some Timestamp"; } - @Override - public Class getImplementedInterface() { - return null; - } + }; try { assertNotNull(provider.retrieveData(input)); -- cgit 1.2.3-korg