This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch 1.3.0
in repository https://gitbox.apache.org/repos/asf/eventmesh.git

commit 47a20bf54f0409d77707222f394f32bdaa107d33
Author: Zonglei Dong <[email protected]>
AuthorDate: Tue Jul 6 11:19:31 2021 +0800

    [ISSUE-#374] Add unit test class. (#414)
    
    * [ISSUE #374] add unit test for CommonConfiguration class.
    
    * [ISSUE #374] add unit test for ConfigurationWraper class.
    
    * [ISSUE #374] add unit test for Weight class.
    
    * [ISSUE #374] add unit test for CommonConfiguration class.
---
 .../common/config/CommonConfigurationTest.java     | 42 +++++++++++++++++++++
 .../common/config/ConfigurationWraperTest.java     | 39 +++++++++++++++++++
 .../eventmesh/common/loadbalance/WeightTest.java   | 44 ++++++++++++++++++++++
 .../src/test/resources/configuration.properties    | 23 +++++++++++
 4 files changed, 148 insertions(+)

diff --git 
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java
 
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java
new file mode 100644
index 000000000..7880cddb0
--- /dev/null
+++ 
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package org.apache.eventmesh.common.config;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CommonConfigurationTest {
+
+    private CommonConfiguration configuration;
+
+    @Before
+    public void before() {
+        String file = 
ConfigurationWraperTest.class.getResource("/configuration.properties").getFile();
+        ConfigurationWraper wraper = new ConfigurationWraper(file, false);
+        configuration = new CommonConfiguration(wraper);
+    }
+
+    @Test
+    public void testInit() {
+        configuration.init();
+        Assert.assertEquals("value1", configuration.eventMeshEnv);
+        Assert.assertEquals("value2", configuration.eventMeshIDC);
+        Assert.assertEquals("3", configuration.sysID);
+    }
+}
diff --git 
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/ConfigurationWraperTest.java
 
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/ConfigurationWraperTest.java
new file mode 100644
index 000000000..7a89efa6a
--- /dev/null
+++ 
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/ConfigurationWraperTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package org.apache.eventmesh.common.config;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConfigurationWraperTest {
+
+    private ConfigurationWraper wraper;
+
+    @Before
+    public void before() {
+        String file = 
ConfigurationWraperTest.class.getResource("/configuration.properties").getFile();
+        wraper = new ConfigurationWraper(file, false);
+    }
+
+    @Test
+    public void testGetProp() {
+        Assert.assertEquals("value1", wraper.getProp("eventMesh.server.env"));
+        Assert.assertEquals("value2", wraper.getProp("eventMesh.server.idc"));
+    }
+}
diff --git 
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightTest.java
 
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightTest.java
new file mode 100644
index 000000000..bdf7a845f
--- /dev/null
+++ 
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package org.apache.eventmesh.common.loadbalance;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class WeightTest {
+
+    @Test
+    public void testDecreaseTotal() {
+        Weight weight = new Weight(null, 0);
+        weight.decreaseTotal(1);
+        Assert.assertEquals(-1, weight.getCurrentWeight().get());
+    }
+
+    @Test
+    public void testIncreaseCurrentWeight() {
+        Weight weight = new Weight(null, 10);
+        weight.increaseCurrentWeight();
+        Assert.assertEquals(10, weight.getCurrentWeight().get());
+    }
+
+    @Test
+    public void testGetCurrentWeight() {
+        Weight weight = new Weight(null, 0);
+        Assert.assertEquals(0, weight.getCurrentWeight().get());
+    }
+}
diff --git a/eventmesh-common/src/test/resources/configuration.properties 
b/eventmesh-common/src/test/resources/configuration.properties
new file mode 100644
index 000000000..d7c50968b
--- /dev/null
+++ b/eventmesh-common/src/test/resources/configuration.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+eventMesh.server.env=value1
+eventMesh.server.idc=value2
+eventMesh.sysid=3
+eventMesh.server.cluster=value4
+eventMesh.server.name=value5
+eventMesh.server.hostIp=value6


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to