Skip to content

Commit cac190c

Browse files
committed
test: adds unit tests for HttpConvertsUtils.java
1 parent a3ac7f1 commit cac190c

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.apache.eventmesh.common.stubs;
2+
3+
import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
4+
import org.apache.eventmesh.common.protocol.http.header.Header;
5+
import org.apache.eventmesh.common.utils.HttpConvertsUtils;
6+
7+
import java.util.Map;
8+
9+
public class HeaderStub extends Header {
10+
11+
public String code;
12+
public String eventmeshenv;
13+
14+
@Override
15+
public Map<String, Object> toMap() {
16+
return new HttpConvertsUtils().httpMapConverts(this, new ProtocolKey(), new ProtocolKey.EventMeshInstanceKey());
17+
}
18+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.eventmesh.common.utils;
19+
20+
import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
21+
import org.apache.eventmesh.common.protocol.http.common.ProtocolKey.EventMeshInstanceKey;
22+
import org.apache.eventmesh.common.protocol.http.header.Header;
23+
import org.apache.eventmesh.common.stubs.HeaderStub;
24+
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
28+
import org.junit.jupiter.api.Assertions;
29+
import org.junit.jupiter.api.Test;
30+
31+
class HttpConvertsUtilsTest {
32+
private final HeaderStub headerStub = new HeaderStub();
33+
private final ProtocolKey mockedProtocolKey = new ProtocolKey();
34+
private final EventMeshInstanceKey mockedEventMeshProtocolKey = new EventMeshInstanceKey();
35+
36+
@Test
37+
void httpMapConverts() {
38+
Map<String, Object> httpMapConverts = new HttpConvertsUtils().httpMapConverts(headerStub, mockedProtocolKey);
39+
Assertions.assertEquals(httpMapConverts.get(headerStub.code), headerStub.code);
40+
}
41+
42+
@Test
43+
void testHttpMapConverts() {
44+
Map<String, Object> httpMapConverts = new HttpConvertsUtils().httpMapConverts(headerStub, mockedProtocolKey, mockedEventMeshProtocolKey);
45+
Assertions.assertEquals(httpMapConverts.get(headerStub.code), headerStub.code);
46+
Assertions.assertEquals(httpMapConverts.get(headerStub.eventmeshenv), headerStub.eventmeshenv);
47+
}
48+
49+
@Test
50+
void httpHeaderConverts() {
51+
HashMap<String, Object> headerParams = new HashMap<>();
52+
String code = "test";
53+
headerParams.put("code", code);
54+
55+
Header header = new HttpConvertsUtils().httpHeaderConverts(headerStub, headerParams);
56+
57+
Assertions.assertEquals(code, header.toMap().get("code"));
58+
}
59+
60+
@Test
61+
void testHttpHeaderConverts() {
62+
HashMap<String, Object> headerParams = new HashMap<>();
63+
String env = "test";
64+
headerParams.put("eventmeshenv", env);
65+
66+
Header header = new HttpConvertsUtils().httpHeaderConverts(headerStub, headerParams, mockedEventMeshProtocolKey);
67+
68+
Assertions.assertEquals(env, header.toMap().get("eventmeshenv"));
69+
}
70+
}
71+

0 commit comments

Comments
 (0)