Test coverage in appc-dg-mdsal-bundle 02/75502/3
authorJoss Armstrong <joss.armstrong@ericsson.com>
Tue, 8 Jan 2019 22:00:43 +0000 (22:00 +0000)
committerTakamune Cho <takamune.cho@att.com>
Tue, 8 Jan 2019 22:30:05 +0000 (22:30 +0000)
Increase test coverage from 11% to 77%

Issue-ID: APPC-1308
Change-Id: I5cb45e2879bcf97a182687276fdf926f769b0e51
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/pom.xml
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/main/java/org/onap/appc/mdsal/impl/Constants.java
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/main/java/org/onap/appc/mdsal/impl/MDSALStoreImpl.java
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/main/java/org/onap/appc/mdsal/objects/BundleInfo.java
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/main/java/org/onap/appc/mdsal/operation/ConfigOperationRequestFormatter.java
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/main/java/org/onap/appc/mdsal/provider/MdsalStoreProvider.java
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/MDSALStoreTest.java
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/impl/MDSALStoreImplTest.java [new file with mode: 0644]
appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/provider/MdsalStoreProviderTest.java [new file with mode: 0644]

index 179094b..2c34c5e 100644 (file)
             <artifactId>httpcore</artifactId>
             <version>${apache.httpcomponents.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>${apache.httpcomponents.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.sli.core</groupId>
             <artifactId>sli-common</artifactId>
index 908c42c..ba88be5 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,47 +34,47 @@ public class Constants {
     /**
      * Manifest attribute for OSGI Bundle Name
      */
-    public static final String MANIFEST_ATTR_BUNDLE_NAME= "Bundle-Name";
+    public static final String MANIFEST_ATTR_BUNDLE_NAME = "Bundle-Name";
 
     /**
      * Manifest attribute for OSGI Bundle Symbolic Name
      */
-    public static final String MANIFEST_ATTR_BUNDLE_SYMBOLIC_NAME= "Bundle-SymbolicName";
+    public static final String MANIFEST_ATTR_BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName";
 
     /**
      * Manifest attribute for OSGI Bundle Description
      */
-    public static final String MANIFEST_ATTR_BUNDLE_DESCRIPTION= "Bundle-Description";
+    public static final String MANIFEST_ATTR_BUNDLE_DESCRIPTION = "Bundle-Description";
 
     /**
      * Manifest attribute for OSGI Bundle Manifest version
      */
-    public static final String MANIFEST_ATTR_BUNDLE_MANIFEST_VERSION= "Bundle-ManifestVersion";
+    public static final String MANIFEST_ATTR_BUNDLE_MANIFEST_VERSION = "Bundle-ManifestVersion";
 
     /**
      * Manifest attribute for OSGI Bundle Version
      */
-    public static final String MANIFEST_ATTR_BUNDLE_VERSION= "Bundle-Version";
+    public static final String MANIFEST_ATTR_BUNDLE_VERSION = "Bundle-Version";
 
     /**
      * Manifest attribute for OSGI Bundle Blueprint
      */
-    public static final String MANIFEST_ATTR_BUNDLE_BLUEPRINT= "Bundle-Blueprint";
+    public static final String MANIFEST_ATTR_BUNDLE_BLUEPRINT = "Bundle-Blueprint";
 
     /**
      * Manifest value for Mainfest Version
      */
-    public static final String MANIFEST_VALUE_VERSION= "1.0";
+    public static final String MANIFEST_VALUE_VERSION = "1.0";
 
     /**
      * Manifest value for OSGI Bundle Vesion
      */
-    public static final String MANIFEST_VALUE_BUNDLE_MAN_VERSION= "2";
+    public static final String MANIFEST_VALUE_BUNDLE_MAN_VERSION = "2";
 
     /**
      * Manifest value for OSGI Bundle Blueprint location
      */
-    public static final String MANIFEST_VALUE_BUNDLE_BLUEPRINT= "OSGI-INF/blueprint/blueprint.xml";
+    public static final String MANIFEST_VALUE_BUNDLE_BLUEPRINT = "OSGI-INF/blueprint/blueprint.xml";
 
     /**
      * Base URL for config actions exposed by RESTCONF API
@@ -110,12 +112,12 @@ public class Constants {
     /**
      * HTTP Header attribute for Content type - JSON
      */
-    public static final String OPERATION_APPLICATION_JSON= " application/json";
+    public static final String OPERATION_APPLICATION_JSON = " application/json";
 
     /**
      * HTTP protocol used for config operations
      */
-    public static final String OPERATION_HTTPS= "https";
+    public static final String OPERATION_HTTPS = "https";
 
     /**
      *  Constant for backslash to be used while formatting URL
index 2ef1da3..8f7bfab 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -83,7 +85,7 @@ public class MDSALStoreImpl implements MDSALStore {
         }
         if (configUrl != null) {
             try {
-                client = new RestClientInvoker(new URL(configUrl));
+                client = getRestClientInvoker(new URL(configUrl));
                 client.setAuthentication(user, password);
             } catch (MalformedURLException e) {
                 logger.error("Error initializing RestConf client: " + e.getMessage(), e);
@@ -187,7 +189,7 @@ public class MDSALStoreImpl implements MDSALStore {
                     URL configUrl = new URL(properties.getProperty(Constants.CONFIG_URL_PROPERTY, Constants.CONFIG_URL_DEFAULT));
                     String user = properties.getProperty(Constants.CONFIG_USER_PROPERTY);
                     String password = properties.getProperty(Constants.CONFIG_PASS_PROPERTY);
-                    RestClientInvoker remoteClient = new RestClientInvoker(new URL(configUrl.getProtocol(), leader, configUrl.getPort(), ""));
+                    RestClientInvoker remoteClient = getRestClientInvoker(new URL(configUrl.getProtocol(), leader, configUrl.getPort(), ""));
                     remoteClient.setAuthentication(user, password);
                     remoteClientMap.put(leader, remoteClient);
                     return remoteClient;
@@ -350,4 +352,8 @@ public class MDSALStoreImpl implements MDSALStore {
             throw new MDSALStoreException(e);
         }
     }
+
+    protected RestClientInvoker getRestClientInvoker(URL configUrl) throws MalformedURLException {
+        return new RestClientInvoker(configUrl);
+    }
 }
index 2f11b88..1399929 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,7 +38,7 @@ package org.onap.appc.mdsal.objects;
      * Creates an object of BundleInfo with version initialized to 1
      */
     public BundleInfo(){
-        version =1;
+        version = 1;
     }
 
     public String getName() {
index 5ebe58b..e565f20 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,7 +41,7 @@ public class ConfigOperationRequestFormatter {
      */
     public String buildPath(String module, String containerName , String... subModules ) {
 
-        StringBuilder path = new StringBuilder( Constants.CONFIG_PATH + Constants.URL_BACKSLASH + module + ":"+containerName + Constants.URL_BACKSLASH);
+        StringBuilder path = new StringBuilder( Constants.CONFIG_PATH + Constants.URL_BACKSLASH + module + ":" + containerName + Constants.URL_BACKSLASH);
         if(subModules.length >0){
             for(String subModule : subModules){
                 path.append(subModule);
index 18ff522..545bd32 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.appc.mdsal.provider;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.google.common.util.concurrent.Futures;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.onap.appc.Constants;
+import org.onap.appc.mdsal.MDSALStore;
+import org.onap.appc.mdsal.impl.MDSALStoreFactory;
+import org.onap.appc.mdsal.objects.BundleInfo;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
@@ -38,16 +46,9 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.response
 import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.response.StatusBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.onap.appc.Constants;
-import org.onap.appc.mdsal.MDSALStore;
-import org.onap.appc.mdsal.impl.MDSALStoreFactory;
-import org.onap.appc.mdsal.objects.BundleInfo;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.common.util.concurrent.Futures;
 
 public class MdsalStoreProvider implements MdsalStoreService ,AutoCloseable{
 
@@ -90,7 +91,8 @@ public class MdsalStoreProvider implements MdsalStoreService ,AutoCloseable{
 
     @Override
     public Future<RpcResult<StoreYangOutput>> storeYang(StoreYangInput input) {
-        Status status =null;String message=null;
+        Status status = null;
+        String message = null;
         try{
             BundleInfo bundleInfo = new BundleInfo();
             bundleInfo.setName(input.getModuleName());
index 9469df6..2229eff 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.appc.mdsal;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.http.HttpResponse;
 import org.junit.Before;
 import org.junit.Ignore;
-import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.onap.appc.mdsal.exception.MDSALStoreException;
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/impl/MDSALStoreImplTest.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/impl/MDSALStoreImplTest.java
new file mode 100644 (file)
index 0000000..fa11462
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.appc.mdsal.impl;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.nio.charset.Charset;
+import java.util.Date;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.mdsal.MDSALStore;
+import org.onap.appc.mdsal.exception.MDSALStoreException;
+import org.onap.appc.mdsal.objects.BundleInfo;
+import org.onap.appc.rest.client.RestClientInvoker;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import java.net.URL;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(FrameworkUtil.class)
+public class MDSALStoreImplTest {
+
+    private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
+    private final Bundle bundleService=Mockito.mock(Bundle.class);
+    private MDSALStoreImpl mdsalStore;
+
+    @Rule
+    public ExpectedException expectedEx = ExpectedException.none();
+
+    @Before
+    public void setup() {
+        mdsalStore = (MDSALStoreImpl) MDSALStoreFactory.createMDSALStore();
+        PowerMockito.mockStatic(FrameworkUtil.class);
+        PowerMockito.when(FrameworkUtil.getBundle(MDSALStoreImpl.class)).thenReturn(bundleService);
+        PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
+        PowerMockito.when(bundleContext.getBundle("TEST_MODULE_NAME")).thenReturn(bundleService);
+    }
+
+    @Test
+    public void testMDSALStoreImpl() {
+        Assert.assertTrue(mdsalStore.isModulePresent("TEST_MODULE_NAME", new Date()));
+    }
+
+    @Test
+    public void testStoreYangModule() throws MDSALStoreException {
+        expectedEx.expect(MDSALStoreException.class);
+        expectedEx.expectMessage("Error storing yang module:");
+        mdsalStore.storeYangModule("", new BundleInfo());
+    }
+
+    @Test
+    public void testStoreYangModuleOnLeader() throws MDSALStoreException, APPCException, IllegalStateException, IOException {
+        RestClientInvoker mockInvoker = Mockito.mock(RestClientInvoker.class);
+        Whitebox.setInternalState(mdsalStore, "client", mockInvoker);
+        HttpResponse mockResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockResponse).when(mockInvoker).doGet(Constants.GET_SHARD_LIST_PATH);
+        String httpString = "{\"value\":{\"MemberName\":\"NodeName\"}}";
+        InputStream is = new ByteArrayInputStream(httpString.getBytes(Charset.defaultCharset()));
+        HttpEntity mockEntity = Mockito.mock(HttpEntity.class);
+        Mockito.doReturn(is).when(mockEntity).getContent();
+        Mockito.doReturn(mockEntity).when(mockResponse).getEntity();
+        StatusLine mockStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(mockStatusLine).when(mockResponse).getStatusLine();
+        Mockito.doReturn(200).when(mockStatusLine).getStatusCode();
+        HttpResponse mockLeaderResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockLeaderResponse).when(mockInvoker).doGet(String.format(Constants.GET_NODE_STATUS_PATH_FORMAT, "NodeName-shard-default-config"));
+        String httpLeaderString = "{\"value\":{\"Leader\":\"NodeName-shard-default-config\"}}";
+        InputStream isLeader = new ByteArrayInputStream(httpLeaderString.getBytes(Charset.defaultCharset()));
+        HttpEntity mockLeaderEntity = Mockito.mock(HttpEntity.class);
+        Mockito.doReturn(isLeader).when(mockLeaderEntity).getContent();
+        Mockito.doReturn(mockLeaderEntity).when(mockLeaderResponse).getEntity();
+        StatusLine mockLeaderStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(mockLeaderStatusLine).when(mockLeaderResponse).getStatusLine();
+        Mockito.doReturn(200).when(mockLeaderStatusLine).getStatusCode();
+        EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+        Whitebox.setInternalState(mdsalStore, "logger", mockLogger);
+        mdsalStore.storeYangModuleOnLeader("", "");
+        Mockito.verify(mockLogger).debug("Current node is a leader.");
+    }
+    
+    @Test
+    public void testStoreYangModuleOnLeaderNotLeader() throws MDSALStoreException, APPCException, IllegalStateException, IOException {
+        RestClientInvoker mockInvoker = Mockito.mock(RestClientInvoker.class);
+        Whitebox.setInternalState(mdsalStore, "client", mockInvoker);
+        HttpResponse mockResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockResponse).when(mockInvoker).doGet(Constants.GET_SHARD_LIST_PATH);
+        String httpString = "{\"value\":{\"MemberName\":\"NodeName\"}}";
+        InputStream is = new ByteArrayInputStream(httpString.getBytes(Charset.defaultCharset()));
+        HttpEntity mockEntity = Mockito.mock(HttpEntity.class);
+        Mockito.doReturn(is).when(mockEntity).getContent();
+        Mockito.doReturn(mockEntity).when(mockResponse).getEntity();
+        StatusLine mockStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(mockStatusLine).when(mockResponse).getStatusLine();
+        Mockito.doReturn(200).when(mockStatusLine).getStatusCode();
+        HttpResponse mockLeaderResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockLeaderResponse).when(mockInvoker).doGet(String.format(Constants.GET_NODE_STATUS_PATH_FORMAT, "NodeName-shard-default-config"));
+        String httpLeaderString = "{\"value\":{\"Leader\":\"OtherShardName\",\"PeerAddresses\":\"OtherShardName@adf:a\"}}";
+        InputStream isLeader = new ByteArrayInputStream(httpLeaderString.getBytes(Charset.defaultCharset()));
+        HttpEntity mockLeaderEntity = Mockito.mock(HttpEntity.class);
+        Mockito.doReturn(isLeader).when(mockLeaderEntity).getContent();
+        Mockito.doReturn(mockLeaderEntity).when(mockLeaderResponse).getEntity();
+        StatusLine mockLeaderStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(mockLeaderStatusLine).when(mockLeaderResponse).getStatusLine();
+        Mockito.doReturn(200).when(mockLeaderStatusLine).getStatusCode();
+        MDSALStoreImpl mdsalStoreSpy = Mockito.spy((MDSALStoreImpl) MDSALStoreFactory.createMDSALStore());
+        RestClientInvoker mockRemoteInvoker = Mockito.mock(RestClientInvoker.class);
+        Mockito.doReturn(mockRemoteInvoker).when(mdsalStoreSpy).getRestClientInvoker(Mockito.any(URL.class));
+        StatusLine mockRemoteStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(200).when(mockRemoteStatusLine).getStatusCode();
+        HttpResponse mockLeaderRemoteResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockLeaderResponse).when(mockRemoteInvoker).doPost(Mockito.anyString(), Mockito.anyString());
+        Mockito.doReturn(mockRemoteStatusLine).when(mockLeaderRemoteResponse).getStatusLine();
+        EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+        Whitebox.setInternalState(mdsalStoreSpy, "logger", mockLogger);
+        mdsalStoreSpy.storeYangModuleOnLeader("", "");
+        Mockito.verify(mockLogger).debug("Yang module successfully loaded on leader. Response code: 200");
+    }
+
+    @Test
+    public void testStoreJson() throws MDSALStoreException, APPCException, IllegalStateException, IOException {
+        RestClientInvoker mockInvoker = Mockito.mock(RestClientInvoker.class);
+        Whitebox.setInternalState(mdsalStore, "client", mockInvoker);
+        HttpResponse mockResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockResponse).when(mockInvoker).doPut(Mockito.anyString(), Mockito.anyString());
+        String httpString = "{\"value\":{\"MemberName\":\"NodeName\"}}";
+        InputStream is = new ByteArrayInputStream(httpString.getBytes(Charset.defaultCharset()));
+        HttpEntity mockEntity = Mockito.mock(HttpEntity.class);
+        Mockito.doReturn(is).when(mockEntity).getContent();
+        Mockito.doReturn(mockEntity).when(mockResponse).getEntity();
+        StatusLine mockStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(mockStatusLine).when(mockResponse).getStatusLine();
+        Mockito.doReturn(200).when(mockStatusLine).getStatusCode();
+        EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+        Whitebox.setInternalState(mdsalStore, "logger", mockLogger);
+        mdsalStore.storeJson("", "", "");
+        Mockito.verify(mockLogger).debug("Configuration JSON stored to MD-SAL store successfully. Response code: 200");
+    }
+
+    @Test
+    public void testStoreJsonRestconfResponse() throws MDSALStoreException, APPCException, IllegalStateException, IOException {
+        RestClientInvoker mockInvoker = Mockito.mock(RestClientInvoker.class);
+        Whitebox.setInternalState(mdsalStore, "client", mockInvoker);
+        HttpResponse mockResponse = Mockito.mock(HttpResponse.class);
+        Mockito.doReturn(mockResponse).when(mockInvoker).doPut(Mockito.anyString(), Mockito.anyString());
+        String httpString = "{\"errors\":{\"error\":{\"error-message\":{\"error-message\":\"ERROR_MESSAGE\"}}}}";
+        InputStream is = new ByteArrayInputStream(httpString.getBytes(Charset.defaultCharset()));
+        HttpEntity mockEntity = Mockito.mock(HttpEntity.class);
+        Mockito.doReturn(is).when(mockEntity).getContent();
+        Mockito.doReturn(mockEntity).when(mockResponse).getEntity();
+        StatusLine mockStatusLine = Mockito.mock(StatusLine.class);
+        Mockito.doReturn(mockStatusLine).when(mockResponse).getStatusLine();
+        Mockito.doReturn(199).when(mockStatusLine).getStatusCode();
+        expectedEx.expect(MDSALStoreException.class);
+        expectedEx.expectMessage("Failed to load config JSON to MD SAL store. Error Message:");
+        mdsalStore.storeJson("", "", "");
+    }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/provider/MdsalStoreProviderTest.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/appc-dg-mdsal-bundle/src/test/java/org/onap/appc/mdsal/provider/MdsalStoreProviderTest.java
new file mode 100644 (file)
index 0000000..2f0e493
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.appc.mdsal.provider;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.mdsal.MDSALStore;
+import org.onap.appc.mdsal.impl.MDSALStoreFactory;
+import org.onap.appc.mdsal.impl.MDSALStoreImpl;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.MdsalStoreService;
+import org.opendaylight.yang.gen.v1.org.onap.appc.mdsal.store.rev170925.StoreYangInput;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+import org.junit.Assert;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(MDSALStoreFactory.class)
+public class MdsalStoreProviderTest {
+
+    private DataBroker dataBroker = Mockito.mock(DataBroker.class);
+    private RpcProviderRegistry rpcRegistry = Mockito.mock(RpcProviderRegistry.class);
+    private NotificationProviderService notificationService = Mockito.mock(NotificationProviderService.class);
+
+    @Test
+    public void testClose() throws Exception {
+        EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+        MdsalStoreProvider mdsalStoreProvider = new MdsalStoreProvider(dataBroker, notificationService, rpcRegistry);
+        Whitebox.setInternalState(mdsalStoreProvider, "log", mockLogger);
+        mdsalStoreProvider.close();
+        Mockito.verify(mockLogger).info("Closing provider for MdsalStoreProvider");
+        Mockito.verify(mockLogger).info("Successfully closed provider for MdsalStoreProvider");
+    }
+
+    @Test
+    public void testStoreYang() throws Exception {
+        PowerMockito.mockStatic(MDSALStoreFactory.class);
+        MDSALStore mdsalStore = Mockito.mock(MDSALStore.class);
+        PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
+        MdsalStoreProvider mdsalStoreProvider = new MdsalStoreProvider(dataBroker, notificationService, rpcRegistry);
+        StoreYangInput mockInput = Mockito.mock(StoreYangInput.class);
+        Assert.assertNotNull(mdsalStoreProvider.storeYang(mockInput));
+    }
+
+    @Test
+    public void testStoreYangExceptionFlow() throws Exception {
+        EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+        MdsalStoreProvider mdsalStoreProvider = new MdsalStoreProvider(dataBroker, notificationService, rpcRegistry);
+        Whitebox.setInternalState(mdsalStoreProvider, "log", mockLogger);
+        StoreYangInput mockInput = Mockito.mock(StoreYangInput.class);
+        mdsalStoreProvider.storeYang(mockInput);
+        Mockito.verify(mockLogger).error(Mockito.anyString(), Mockito.any(NullPointerException.class));
+    }
+}