|
@@ -0,0 +1,215 @@
|
|
|
+
|
|
|
+ * 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:
|
|
|
+ *
|
|
|
+ * 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.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.apache.dolphinscheduler.alert.utils;
|
|
|
+
|
|
|
+import org.apache.dolphinscheduler.common.enums.ZKNodeType;
|
|
|
+import org.junit.Test;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import static org.junit.Assert.*;
|
|
|
+
|
|
|
+
|
|
|
+ * Test PropertyUtils
|
|
|
+ * and the resource path is src/test/resources/alert.properties.
|
|
|
+ */
|
|
|
+public class PropertyUtilsTest {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(PropertyUtilsTest.class);
|
|
|
+
|
|
|
+
|
|
|
+ * Test getString
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetString() {
|
|
|
+
|
|
|
+
|
|
|
+ String result = PropertyUtils.getString("alert.type");
|
|
|
+ logger.info(result);
|
|
|
+ assertEquals(result, "EMAIL");
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getString("mail.server.host");
|
|
|
+ assertEquals(result, "xxx.xxx.test");
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getString("abc");
|
|
|
+ assertNull(result);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getString(null);
|
|
|
+ assertNull(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * Test getBoolean
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetBoolean() {
|
|
|
+
|
|
|
+
|
|
|
+ Boolean result = PropertyUtils.getBoolean("mail.smtp.starttls.enable");
|
|
|
+ assertTrue(result);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getBoolean("mail.smtp.ssl.enable");
|
|
|
+ assertFalse(result);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getBoolean("abc");
|
|
|
+ assertFalse(result);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getBoolean(null);
|
|
|
+ assertFalse(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Test getLong
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetLong() {
|
|
|
+
|
|
|
+
|
|
|
+ long result = PropertyUtils.getLong("mail.server.port");
|
|
|
+ assertSame(result, 25L);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getLong(null);
|
|
|
+ assertSame(result, -1L);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getLong("abc");
|
|
|
+ assertSame(result, -1L);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getLong("abc", 200);
|
|
|
+ assertEquals(result, 200L);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getLong("test.server.testnumber");
|
|
|
+ assertSame(result, -1L);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Test getDouble
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetDouble() {
|
|
|
+
|
|
|
+
|
|
|
+ double result = PropertyUtils.getDouble("test.server.factor");
|
|
|
+ assertEquals(result, 3.0, 0);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getDouble(null);
|
|
|
+ assertEquals(result, -1.0, 0);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getDouble("abc");
|
|
|
+ assertEquals(result, -1.0, 0);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getDouble("abc", 5.0);
|
|
|
+ assertEquals(result, 5.0, 0);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getDouble("test.server.testnumber");
|
|
|
+ assertEquals(result, -1.0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Test getArray
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetArray() {
|
|
|
+
|
|
|
+
|
|
|
+ String[] result = PropertyUtils.getArray("test.server.list", ",");
|
|
|
+ assertEquals(result.length, 3);
|
|
|
+
|
|
|
+
|
|
|
+ assertEquals(result[0], "xxx.xxx.test1");
|
|
|
+ assertEquals(result[1], "xxx.xxx.test2");
|
|
|
+ assertEquals(result[2], "xxx.xxx.test3");
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getArray(null, ",");
|
|
|
+ assertNull(result);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getArray("abc", ",");
|
|
|
+ assertNull(result);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getArray("test.server.list", null);
|
|
|
+ assertNull(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * test getInt
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetInt() {
|
|
|
+
|
|
|
+
|
|
|
+ int result = PropertyUtils.getInt("mail.server.port");
|
|
|
+ assertSame(result, 25);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getInt(null);
|
|
|
+ assertSame(result, -1);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getInt("abc");
|
|
|
+ assertSame(result, -1);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getInt("abc", 300);
|
|
|
+ assertEquals(result, 300);
|
|
|
+
|
|
|
+
|
|
|
+ result = PropertyUtils.getInt("test.server.testnumber");
|
|
|
+ assertSame(result, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Test getEnum
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetEnum() {
|
|
|
+
|
|
|
+
|
|
|
+ ZKNodeType zkNodeType = PropertyUtils.getEnum("test.server.enum1", ZKNodeType.class,ZKNodeType.WORKER);
|
|
|
+ assertEquals(zkNodeType, ZKNodeType.MASTER);
|
|
|
+
|
|
|
+
|
|
|
+ zkNodeType = PropertyUtils.getEnum("test.server.enum2", ZKNodeType.class,ZKNodeType.WORKER);
|
|
|
+ assertEquals(zkNodeType, ZKNodeType.DEAD_SERVER);
|
|
|
+
|
|
|
+
|
|
|
+ zkNodeType = PropertyUtils.getEnum(null, ZKNodeType.class,ZKNodeType.WORKER);
|
|
|
+ assertEquals(zkNodeType, ZKNodeType.WORKER);
|
|
|
+
|
|
|
+
|
|
|
+ zkNodeType = PropertyUtils.getEnum("test.server.enum3", ZKNodeType.class,ZKNodeType.WORKER);
|
|
|
+ assertEquals(zkNodeType, ZKNodeType.WORKER);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|