/******************************************************************************* * Copyright 2019 Graz University of Technology * MOA ZS has been developed in a cooperation between EGIZ * and Graz University of Technology. * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ package at.gv.egiz.moazs; import at.gv.egiz.moazs.preprocess.ConfigUtil; import at.gv.zustellung.app2mzs.xsd.ConfigType; import org.junit.Before; import org.junit.Test; import java.util.List; import java.util.Map; import static at.gv.zustellung.app2mzs.xsd.ClientType.clientTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; import static org.assertj.core.api.Assertions.assertThat; /** * @author Christof Rabensteiner * */ public class ConfigUtilTest { private ConfigUtil configUtil; @Before public void setup() { configUtil = new ConfigUtil(); } @Test public void convertTNVZClientsCustomHttpHeaders() { var prefix = ConfigUtil.TNVZ_CLIENT_KEY + "." + ConfigUtil.CUSTOM_HTTP_HEADERS_KEY + "."; var map = Map.of( prefix + "X-PVP-VERSION", "2.1", prefix + "X-PVP-BINDING", "http", prefix + "X-PVP-PARTICIPANT_ID", "AT:L9:MA2412" ); ConfigType config = configUtil.convert(map); var customHeaderMap = configUtil.convertHeadersToMap(config.getTNVZClient().getCustomHTTPHeader()); assertThat(customHeaderMap).containsEntry("X-PVP-VERSION", List.of("2.1")); assertThat(customHeaderMap).containsEntry("X-PVP-BINDING", List.of("http")); assertThat(customHeaderMap).containsEntry("X-PVP-PARTICIPANT_ID", List.of("AT:L9:MA2412")); assertThat(customHeaderMap).hasSize(3); } @Test public void overrideCustomHeaders() { var fallbackConfig = createConfig(Map.of( "X-header-1", "fallback-value-a", "X-header-2", "fallback-value-b" )); var primaryConfig = createConfig(Map.of( "X-header-2", "primary-value-c", "X-header-3", "primary-value-d" )); ConfigType mergedConfig = configUtil.merge(primaryConfig, fallbackConfig); var mergedHeaderMap = configUtil.convertHeadersToMap(mergedConfig.getTNVZClient().getCustomHTTPHeader()); assertThat(mergedHeaderMap).containsEntry("X-header-1", List.of("fallback-value-a")); assertThat(mergedHeaderMap).containsEntry("X-header-2", List.of("primary-value-c")); assertThat(mergedHeaderMap).containsEntry("X-header-3", List.of("primary-value-d")); assertThat(mergedHeaderMap).hasSize(3); } @Test public void convertBooleanToTrue() { var prefix = ConfigUtil.TNVZ_REQUEST_KEY; var map = Map.of(prefix, "true"); ConfigType config = configUtil.convert(map); assertThat(config.isPerformQueryPersonRequest()).isTrue(); } @Test public void convertBooleanToFalse() { var prefix = ConfigUtil.TNVZ_REQUEST_KEY; var map = Map.of(prefix, "false"); ConfigType config = configUtil.convert(map); assertThat(config.isPerformQueryPersonRequest()).isFalse(); } private ConfigType createConfig(Map headerMap) { var headers = configUtil.convertMapToHeaders(headerMap); var client = clientTypeBuilder() .withCustomHTTPHeader(headers) .build(); return configTypeBuilder() .withTNVZClient(client) .build(); } }