aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/component/BindingPatternTest.java
blob: 2cf38e4bc7ed293085496e36daf34f6f87c12454 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.component;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
 * @author bjorncs
 */
public class BindingPatternTest {

    @Test
    void parses_valid_bindings_correctly() {
        assertBindingParses("http://host:1234/path");
        assertBindingParses("http://host/path");
        assertBindingParses("http://host/");
        assertBindingParses("*://*:*/*");
        assertBindingParses("http://*/*");
        assertBindingParses("https://*/my/path");
        assertBindingParses("https://*/path/*");
        assertBindingParses("https://host:*/path/*");
        assertBindingParses("https://host:1234/*");
    }

    @Test
    void getters_returns_correct_components() {
        {
            BindingPattern pattern = SystemBindingPattern.fromPattern("http://host:1234/path/*");
            assertEquals("http", pattern.scheme());
            assertEquals("host", pattern.host());
            assertEquals("1234", pattern.port().get());
            assertEquals("/path/*", pattern.path());
        }
        {
            BindingPattern pattern = SystemBindingPattern.fromPattern("https://*/path/v1/");
            assertEquals("https", pattern.scheme());
            assertEquals("*", pattern.host());
            assertFalse(pattern.port().isPresent());
            assertEquals("/path/v1/", pattern.path());
        }
    }

    private static void assertBindingParses(String binding) {
        BindingPattern pattern = SystemBindingPattern.fromPattern(binding);
        String stringRepresentation = pattern.patternString();
        assertEquals(
                binding, stringRepresentation, "Expected string representation of parsed binding to match original binding string");
    }

}