hazelcast-master/hazelcast/src/test/java/com/hazelcast/aws/RegionValidatorTest.java
/*
 * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.aws;

import com.hazelcast.config.InvalidConfigurationException;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;

import static com.hazelcast.test.HazelcastTestSupport.assertThrows;
import static org.junit.Assert.assertEquals;

public class RegionValidatorTest {
    @Test
    public void validateValidRegion() {
        RegionValidator.validateRegion("us-west-1");
        RegionValidator.validateRegion("us-gov-east-1");
    }

    @Test
    public void validateInvalidRegion() {
        // given
        String region = "us-wrong-1";
        String expectedMessage = String.format("The provided region %s is not a valid AWS region.", region);

        //when
        ThrowingRunnable validateRegion = () -> RegionValidator.validateRegion(region);

        //then
        InvalidConfigurationException thrownEx = assertThrows(InvalidConfigurationException.class, validateRegion);
        assertEquals(expectedMessage, thrownEx.getMessage());
    }

    @Test
    public void validateInvalidGovRegion() {
        // given
        String region = "us-gov-wrong-1";
        String expectedMessage = String.format("The provided region %s is not a valid AWS region.", region);

        // when
        ThrowingRunnable validateRegion = () -> RegionValidator.validateRegion(region);

        //then
        InvalidConfigurationException thrownEx = assertThrows(InvalidConfigurationException.class, validateRegion);
        assertEquals(expectedMessage, thrownEx.getMessage());
    }

    @Test
    public void validateNullRegion() {
        // given
        String expectedMessage = "The provided region is null.";

        // when
        ThrowingRunnable validateRegion = () -> RegionValidator.validateRegion(null);

        //then
        InvalidConfigurationException thrownEx = assertThrows(InvalidConfigurationException.class, validateRegion);
        assertEquals(expectedMessage, thrownEx.getMessage());
    }
}
