|
| 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 | + |
| 33 | + private final HeaderStub headerStub = new HeaderStub(); |
| 34 | + private final ProtocolKey mockedProtocolKey = new ProtocolKey(); |
| 35 | + private final EventMeshInstanceKey mockedEventMeshProtocolKey = new EventMeshInstanceKey(); |
| 36 | + |
| 37 | + @Test |
| 38 | + void httpMapConverts() { |
| 39 | + Map<String, Object> httpMapConverts = new HttpConvertsUtils().httpMapConverts(headerStub, mockedProtocolKey); |
| 40 | + Assertions.assertEquals(httpMapConverts.get(headerStub.code), headerStub.code); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void testHttpMapConverts() { |
| 45 | + Map<String, Object> httpMapConverts = new HttpConvertsUtils().httpMapConverts(headerStub, mockedProtocolKey, mockedEventMeshProtocolKey); |
| 46 | + Assertions.assertEquals(httpMapConverts.get(headerStub.code), headerStub.code); |
| 47 | + Assertions.assertEquals(httpMapConverts.get(headerStub.eventmeshenv), headerStub.eventmeshenv); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void httpHeaderConverts() { |
| 52 | + HashMap<String, Object> headerParams = new HashMap<>(); |
| 53 | + String code = "test"; |
| 54 | + headerParams.put("code", code); |
| 55 | + Header header = new HttpConvertsUtils().httpHeaderConverts(headerStub, headerParams); |
| 56 | + Assertions.assertEquals(code, header.toMap().get("code")); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void testHttpHeaderConverts() { |
| 61 | + HashMap<String, Object> headerParams = new HashMap<>(); |
| 62 | + String env = "test"; |
| 63 | + headerParams.put("eventmeshenv", env); |
| 64 | + Header header = new HttpConvertsUtils().httpHeaderConverts(headerStub, headerParams, mockedEventMeshProtocolKey); |
| 65 | + Assertions.assertEquals(env, header.toMap().get("eventmeshenv")); |
| 66 | + } |
| 67 | +} |
0 commit comments