You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2021/07/29 09:45:48 UTC

[incubator-eventmesh] branch develop updated: [ISSUE #374] add unit test for header class. (#472)

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 9e172e8  [ISSUE #374] add unit test for header class. (#472)
9e172e8 is described below

commit 9e172e86ce6f17c01dc69b7799f332bcb3b246f3
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Thu Jul 29 17:45:44 2021 +0800

    [ISSUE #374] add unit test for header class. (#472)
    
    * [ISSUE #374] add unit test for PushMessageRequestHeader class.
    
    * [ISSUE #374] add unit test for PushMessageResponseHeader class.
    
    * [ISSUE #374] add unit test for ReplyMessageRequestHeader class.
    
    * [ISSUE #374] add unit test for ReplyMessageResponseHeader class.
    
    close #374
---
 .../message/PushMessageRequestHeaderTest.java      | 59 ++++++++++++++++++++
 .../message/PushMessageResponseHeaderTest.java     | 48 ++++++++++++++++
 .../message/ReplyMessageRequestHeaderTest.java     | 65 ++++++++++++++++++++++
 .../message/ReplyMessageResponseHeaderTest.java    | 38 +++++++++++++
 4 files changed, 210 insertions(+)

diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java
new file mode 100644
index 0000000..4f4d96e
--- /dev/null
+++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.protocol.http.header.message;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
+import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class PushMessageRequestHeaderTest {
+
+    private PushMessageRequestHeader header;
+
+    @Before
+    public void before() {
+        Map<String, Object> headerParam = new HashMap<>();
+        headerParam.put(ProtocolKey.REQUEST_CODE, 200);
+        headerParam.put(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA);
+        headerParam.put(ProtocolKey.VERSION, "1.0");
+        headerParam.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, "default cluster");
+        headerParam.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, "127.0.0.1");
+        headerParam.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, "DEV");
+        headerParam.put(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, "IDC");
+        header = PushMessageRequestHeader.buildHeader(headerParam);
+    }
+
+    @Test
+    public void testToMap() {
+        Assert.assertThat(header.toMap().get(ProtocolKey.REQUEST_CODE), is(200));
+        Assert.assertThat(header.toMap().get(ProtocolKey.LANGUAGE), is(Constants.LANGUAGE_JAVA));
+        Assert.assertThat(header.toMap().get(ProtocolKey.VERSION), is(ProtocolVersion.V1));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER), is("default cluster"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP), is("127.0.0.1"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV), is("DEV"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC), is("IDC"));
+    }
+}
diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java
new file mode 100644
index 0000000..728a5a4
--- /dev/null
+++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.protocol.http.header.message;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
+import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class PushMessageResponseHeaderTest {
+
+    @Test
+    public void testToMap() {
+        PushMessageResponseHeader header = PushMessageResponseHeader.buildHeader(100, "DEV",
+                "IDC", "SYSID", "PID", "127.0.0.1");
+        Assert.assertThat(header.toMap().get(ProtocolKey.REQUEST_CODE), is(100));
+        Assert.assertThat(header.toMap().get(ProtocolKey.LANGUAGE), is(Constants.LANGUAGE_JAVA));
+        Assert.assertThat(header.toMap().get(ProtocolKey.VERSION), is(ProtocolVersion.V1));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.ENV), is("DEV"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.IDC), is("IDC"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.SYS), is("SYSID"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PID), is("PID"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.IP), is("127.0.0.1"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.USERNAME), is("username"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PASSWD), is("user@123"));
+    }
+}
diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java
new file mode 100644
index 0000000..e54b641
--- /dev/null
+++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.protocol.http.header.message;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
+import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class ReplyMessageRequestHeaderTest {
+
+    private ReplyMessageRequestHeader header;
+
+    @Before
+    public void before() {
+        Map<String, Object> headerParam = new HashMap<>();
+        headerParam.put(ProtocolKey.REQUEST_CODE, "200");
+        headerParam.put(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA);
+        headerParam.put(ProtocolKey.VERSION, "1.0");
+        headerParam.put(ProtocolKey.ClientInstanceKey.ENV, "DEV");
+        headerParam.put(ProtocolKey.ClientInstanceKey.IDC, "IDC");
+        headerParam.put(ProtocolKey.ClientInstanceKey.SYS, "SYS");
+        headerParam.put(ProtocolKey.ClientInstanceKey.PID, "PID");
+        headerParam.put(ProtocolKey.ClientInstanceKey.IP, "127.0.0.1");
+        headerParam.put(ProtocolKey.ClientInstanceKey.USERNAME, "username");
+        headerParam.put(ProtocolKey.ClientInstanceKey.PASSWD, "user@123");
+        header = ReplyMessageRequestHeader.buildHeader(headerParam);
+    }
+
+    @Test
+    public void testToMap() {
+        Assert.assertThat(header.toMap().get(ProtocolKey.REQUEST_CODE), is("200"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.LANGUAGE), is(Constants.LANGUAGE_JAVA));
+        Assert.assertThat(header.toMap().get(ProtocolKey.VERSION), is(ProtocolVersion.V1));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.ENV), is("DEV"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.IDC), is("IDC"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.SYS), is("SYS"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PID), is("PID"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.IP), is("127.0.0.1"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.USERNAME), is("username"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PASSWD), is("user@123"));
+    }
+}
diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java
new file mode 100644
index 0000000..a3b90da
--- /dev/null
+++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.protocol.http.header.message;
+
+import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+
+public class ReplyMessageResponseHeaderTest {
+
+    @Test
+    public void testToMap() {
+        ReplyMessageResponseHeader header = ReplyMessageResponseHeader.buildHeader(100,
+                "Cluster", "127.0.0.1", "DEV", "IDC");
+        Assert.assertThat(header.toMap().get(ProtocolKey.REQUEST_CODE), is(100));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER), is("Cluster"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP), is("127.0.0.1"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV), is("DEV"));
+        Assert.assertThat(header.toMap().get(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC), is("IDC"));
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org