modified dbController rest api 57/100357/2
authorZhangZihao <zhangzihao@chinamobile.com>
Thu, 16 Jan 2020 03:13:55 +0000 (11:13 +0800)
committerEkko Chang <ekko.chang@qct.io>
Tue, 21 Jan 2020 07:15:17 +0000 (07:15 +0000)
Change-Id: Ie1daa567338c48a13112ef1fff02109de16e8901
Issue-ID: DCAEGEN2-1877
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java

index 49439e6..058d4ca 100644 (file)
@@ -211,17 +211,17 @@ public class DbController {
        }
 
        //Update Db
-       @PutMapping("")
+       @PutMapping("/{id}")
        @ResponseBody
        @ApiOperation(value="Update a database.")
-       public PostReturnBody<DbConfig> updateDb(@RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException {
+       public PostReturnBody<DbConfig> updateDb(@PathVariable int id, @RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException {
 
                if (result.hasErrors()) {
                        sendError(response, 400, "Error parsing DB: " + result.toString());
                        return null;
                }
 
-               Db oldDb = dbRepository.findById(dbConfig.getId()).get();
+               Db oldDb = dbRepository.findById(id).get();
                if (oldDb == null) {
                        sendError(response, 404, DB_NOT_FOUND + dbConfig.getName());
                        return null;
index c46a026..9318ee0 100644 (file)
@@ -69,6 +69,7 @@ public class DbControllerTest {
     
     public DbConfig getDbConfig() {
         DbConfig dbConfig = new DbConfig();
+        dbConfig.setId(1);
         dbConfig.setName("Elecsticsearch");
         dbConfig.setHost("localhost");
         dbConfig.setLogin("root");
@@ -112,7 +113,7 @@ public class DbControllerTest {
         DbController dbController = new DbController();
         DbConfig dbConfig = getDbConfig();
         when(mockBindingResult.hasErrors()).thenReturn(true);
-        PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig, mockBindingResult,
+        PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult,
                                                             httpServletResponse);
         assertEquals(null, db);
         //when(mockBindingResult.hasErrors()).thenReturn(false);