You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@linkis.apache.org by GitBox <gi...@apache.org> on 2022/05/19 02:28:54 UTC

[GitHub] [incubator-linkis] casionone commented on a diff in pull request #2028: Dev [1.1.2] add junit test to linkis-variable

casionone commented on code in PR #2028:
URL: https://github.com/apache/incubator-linkis/pull/2028#discussion_r876529282


##########
linkis-public-enhancements/linkis-publicservice/linkis-variable/src/test/java/org/apache/linkis/variable/dao/VarMapperTest.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.linkis.variable.dao;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import org.apache.linkis.variable.entity.VarKey;
+import org.apache.linkis.variable.entity.VarKeyUser;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.h2.tools.Server;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class VarMapperTest extends BaseDaoTest {
+    @Autowired private VarMapper varMapper;
+
+    private VarKey insertVarKey() {
+        VarKey varKey = new VarKey();
+        varKey.setKey("myWork6");
+        varKey.setApplicationID(-1L);
+        return varKey;
+    }
+
+    private VarKeyUser InsertVarKeyUser() {
+        VarKeyUser varKeyUser = new VarKeyUser();
+        varKeyUser.setApplicationID(-1L);
+        varKeyUser.setUserName("tom6");
+        varKeyUser.setValue("sing");
+        varKeyUser.setKeyID(6L);
+        varMapper.insertValue(varKeyUser);
+        return varKeyUser;
+    }
+
+    @BeforeAll
+    @DisplayName("Each unit test method is executed once before execution")
+    protected static void beforeAll() throws Exception {
+        // Start the console of h2 to facilitate viewing of h2 data
+        Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082").start();
+    }
+
+    @AfterAll
+    @DisplayName("Each unit test method is executed once before execution")
+    protected static void afterAll() throws Exception {}
+
+    @Test
+    void testListGlobalVariable() {
+        // h2数据库执行生成的sql语句报错,在mysql数据库中可以正常运行
+        //        List<VarKeyValueVO> varKeyValueVOList = varMapper.listGlobalVariable("tom1");
+        //        assertEquals(1,varKeyValueVOList.size());
+    }
+
+    @Test
+    void testGetValueByKeyID() {
+        VarKeyUser varKeyUser = varMapper.getValueByKeyID(3L);
+        assertEquals("tom3", varKeyUser.getUserName());
+    }
+
+    @Test
+    void testRemoveKey() {
+        varMapper.removeKey(1L);
+    }
+
+    @Test
+    void testRemoveValue() {
+        varMapper.removeValue(1L);
+        assertEquals(null, varMapper.getValueByKeyID(1L));
+    }
+
+    @Test
+    void testInsertKey() {
+        VarKey varKey = insertVarKey();
+        assertEquals("myWork6", varKey.getKey());

Review Comment:
   Whether the database is inserted successfully should be judged by the return value



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org