/*-
  * ============LICENSE_START=======================================================
- * ONAP : DATALAKE
+ * ONAP : DATALAKE DES
  * ================================================================================
  * Copyright (C) 2020 China Mobile. All rights reserved.
  * ================================================================================
 import org.junit.Test;
 import org.onap.datalake.des.DesApplication;
 
+/**
+ * Test Application.
+ * 
+ * @author Kai Lu
+ *
+ */
+ 
 public class ApplicationTest {
+
     @Test
     public void testRunner() {
         DesApplication application = new DesApplication();
 
 /*
 * ============LICENSE_START=======================================================
-* ONAP : DATALAKE
+* ONAP : DATALAKE DES
 * ================================================================================
-* Copyright 2020 China Mobile
+* Copyright 2020 China Mobile. 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.
 
 /*-
  * ============LICENSE_START=======================================================
- * ONAP : DATALAKE
+ * ONAP : DATALAKE DES
  * ================================================================================
  * Copyright (C) 2020 China Mobile. All rights reserved.
  * ================================================================================
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.datalake.des.repository.DataExposureRepository;
-import org.onap.datalake.des.service.DataExposureService;
 import org.springframework.validation.BindingResult;
 
-
 /**
  * Test Data Exposure Controller.
  *
     @Mock
     private BindingResult mockBindingResult;
 
-    @InjectMocks
-    private DataExposureService dataExposureService;
-
     @Test(expected = NullPointerException.class)
-    public void testServe() throws IOException, NoSuchFieldException,
-                                   IllegalAccessException, ClassNotFoundException, SQLException {
+    public void testServe()
+            throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException {
         DataExposureController dataExposureController = new DataExposureController();
         String serviceId = "test";
-        Map<String, String> requestMap = new HashMap<String,String>();
+        Map<String, String> requestMap = new HashMap<String, String>();
         requestMap.put("name", "oteNB5309");
-        HashMap<String, Object> result = dataExposureController
-            .serve(serviceId, requestMap, mockBindingResult, httpServletResponse);
+        HashMap<String, Object> result = dataExposureController.serve(serviceId, requestMap, mockBindingResult,
+                httpServletResponse);
         assertEquals(null, result);
         when(mockBindingResult.hasErrors()).thenReturn(true);
     }
 
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE
+ * ================================================================================
+ * Copyright (C) 2020 China Mobile. 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.datalake.des.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test PostReturnBody.
+ *
+ * @author Kai Lu
+ */
+public class PostReturnBodyTest {
+
+    @Test
+    public void testPostReturnBody() {
+        PostReturnBody<String> postReturnBody = new PostReturnBody<String>();
+        postReturnBody.setStatusCode(200);
+        assertEquals(200, postReturnBody.getStatusCode());
+        postReturnBody.setReturnBody("abc");
+        assertTrue("abc".equals(postReturnBody.getReturnBody()));
+    }
+}
 
 /*
  * ============LICENSE_START=======================================================
- * ONAP : DataLake
+ * ONAP : DataLake DES
  * ================================================================================
- * Copyright 2020 China Mobile
+ * Copyright 2020 China Mobile. 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.
 
 /*
  * ============LICENSE_START=======================================================
- * ONAP : DataLake
+ * ONAP : DataLake DES
  * ================================================================================
- * Copyright 2020 China Mobile
+ * Copyright 2020 China Mobile. 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.
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.onap.datalake.des.util.TestUtil;
 
         assertNotEquals(mongoDb2, dbType);
         assertFalse(mongoDb1.getDbType().isTool());
+
+        mongoDb2.setHost("localhost");
+        mongoDb2.setPort(1234);
+        mongoDb2.setLogin("root");
+        mongoDb2.setPass("root123");
+        mongoDb2.setDatabase("mongoDB2");
+        mongoDb2.setEncrypt(true);
+        mongoDb2.setProperty1("property1");
+        mongoDb2.setProperty2("property2");
+        mongoDb2.setProperty3("property3");
+        assertTrue("localhost".equals(mongoDb2.getHost()));
+        assertFalse("1234".equals(mongoDb2.getPort()));
+        assertTrue("root".equals(mongoDb2.getLogin()));
+        assertTrue("root123".equals(mongoDb2.getPass()));
+        assertTrue("mongoDB2".equals(mongoDb2.getDatabase()));
+        assertFalse("true".equals(mongoDb2.isEncrypt()));
+        assertTrue("property1".equals(mongoDb2.getProperty1()));
+        assertTrue("property2".equals(mongoDb2.getProperty2()));
+        assertTrue("property3".equals(mongoDb2.getProperty3()));
+        assertEquals(mongoDb2.getDbConfig().getHost(), mongoDb2.getHost());
     }
 }
 
 /*
  * ============LICENSE_START=======================================================
- * ONAP : DataLake
+ * ONAP : DataLake DES
  * ================================================================================
- * Copyright 2020 China Mobile
+ * Copyright 2020 China Mobile. 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.
 
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE DES
+ * ================================================================================
+ * Copyright (C) 2020 China Mobile. 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.datalake.des.dto;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test DB config.
+ *
+ * @author Kai Lu
+ */
+public class DbConfigTest {
+
+    @Test
+    public void testDbConfig() {
+        DbConfig dbConfig = new DbConfig();
+        dbConfig.setId(1);
+        assertEquals(1, dbConfig.getId());
+        dbConfig.setName("elasticsearch");
+        assertTrue("elasticsearch".equals(dbConfig.getName()));
+        dbConfig.setHost("localhost");
+        assertTrue("localhost".equals(dbConfig.getHost()));
+        dbConfig.setLogin("root");
+        assertTrue("root".equals(dbConfig.getLogin()));
+        dbConfig.setPass("root123");
+        assertTrue("root123".equals(dbConfig.getPass()));
+        dbConfig.setDatabase("elasticsearch");
+        assertTrue("elasticsearch".equals(dbConfig.getDatabase()));
+        dbConfig.setPort(123);
+        //assertEquals(123, dbConfig.getPort());
+        assertFalse("123".equals(dbConfig.getPort()));
+        dbConfig.setPoperties("driver");
+        assertTrue("driver".equals(dbConfig.getPoperties()));
+    }
+}
 
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake DES
+ * ================================================================================
+ * Copyright 2020 China Mobile. 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.datalake.des.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.des.domain.DataExposure;
+import org.onap.datalake.des.domain.Db;
+import org.onap.datalake.des.domain.DbType;
+import org.onap.datalake.des.dto.DataExposureConfig;
+import org.onap.datalake.des.dto.DbConfig;
+import org.onap.datalake.des.repository.DataExposureRepository;
+import org.onap.datalake.des.repository.DbRepository;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Test DB exposure Service.
+ *
+ * @author Kai Lu
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class DataExposureServiceTest {
+
+    @Mock
+    private DbType dbType;
+
+    @Mock
+    private ApplicationContext context;
+
+    @Mock
+    private DbRepository dbRepository;
+
+    @Mock
+    private DataExposureRepository dataExposureRepository;
+
+    @InjectMocks
+    private DataExposureService dataExposureService;
+
+    /**
+     * Generate data exposure config.
+     *
+     * @return DataExposureConfig object
+     *
+     */
+    public DataExposureConfig getDataExposureConfig() {
+        DataExposureConfig deConfig = new DataExposureConfig();
+        deConfig.setDbId(3);
+        deConfig.setId("test");
+        deConfig.setNote("testSql");
+        deConfig.setSqlTemplate("select name from datalake");
+        return deConfig;
+    }
+
+    /**
+     * Generate DB config.
+     *
+     * @return DbConfig object
+     *
+     */
+    public DbConfig getDbConfig() {
+        DbConfig dbConfig = new DbConfig();
+        dbConfig.setId(1);
+        dbConfig.setName("Elecsticsearch");
+        dbConfig.setHost("localhost");
+        dbConfig.setLogin("root");
+        dbConfig.setPass("root123");
+        dbConfig.setDatabase("Elecsticsearch");
+        dbConfig.setPort(123);
+        dbConfig.setPoperties("driver");
+        dbConfig.setDbTypeId("ES");
+        return dbConfig;
+    }
+
+    @Test
+    public void testQueryAllDataExposure() {
+        Db newdb = new Db();
+        DbConfig dbConfig = getDbConfig();
+        newdb.setName(dbConfig.getName());
+        newdb.setHost(dbConfig.getHost());
+        newdb.setPort(dbConfig.getPort());
+        newdb.setEnabled(dbConfig.isEnabled());
+        newdb.setLogin(dbConfig.getLogin());
+        newdb.setPass(dbConfig.getPass());
+        newdb.setEncrypt(dbConfig.isEncrypt());
+        DataExposureConfig deConfig = getDataExposureConfig();
+        DataExposure de = new DataExposure();
+        de.setDb(newdb);
+        de.setId(deConfig.getId());
+        de.setNote(deConfig.getNote());
+        de.setSqlTemplate(deConfig.getSqlTemplate());
+        List<DataExposure> deList = new ArrayList<>();
+        deList.add(de);
+        when(dataExposureRepository.findAll()).thenReturn(deList);
+        List<DataExposureConfig> deConfigList = dataExposureService.queryAllDataExposure();
+        assertEquals(de.getId(), deConfigList.get(0).getId());
+    }
+
+    @Test
+    public void testFillDataExposureConfiguration() {
+        Db newdb = new Db();
+        DbConfig dbConfig = getDbConfig();
+        newdb.setName(dbConfig.getName());
+        newdb.setHost(dbConfig.getHost());
+        newdb.setPort(dbConfig.getPort());
+        newdb.setEnabled(dbConfig.isEnabled());
+        newdb.setLogin(dbConfig.getLogin());
+        newdb.setPass(dbConfig.getPass());
+        newdb.setEncrypt(dbConfig.isEncrypt());
+        DataExposureConfig deConfig = getDataExposureConfig();
+        when(dbRepository.findById(deConfig.getDbId())).thenReturn(Optional.of(newdb));
+        DataExposure de = dataExposureService.fillDataExposureConfiguration(deConfig);
+        assertEquals(de.getId(), deConfig.getId());
+    }
+
+    @Test
+    public void testFillDataExposureConfigurationWithTwoPara() {
+        Db newdb = new Db();
+        DbConfig dbConfig = getDbConfig();
+        newdb.setName(dbConfig.getName());
+        newdb.setHost(dbConfig.getHost());
+        newdb.setPort(dbConfig.getPort());
+        newdb.setEnabled(dbConfig.isEnabled());
+        newdb.setLogin(dbConfig.getLogin());
+        newdb.setPass(dbConfig.getPass());
+        newdb.setEncrypt(dbConfig.isEncrypt());
+        DataExposureConfig deConfig = getDataExposureConfig();
+        when(dbRepository.findById(deConfig.getDbId())).thenReturn(Optional.of(newdb));
+        DataExposure de = new DataExposure();
+        de.setDb(newdb);
+        de.setId(deConfig.getId());
+        de.setNote(deConfig.getNote());
+        de.setSqlTemplate(deConfig.getSqlTemplate());
+        dataExposureService.fillDataExposureConfiguration(deConfig, de);
+    }
+
+}