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
53
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.tenant;
import com.yahoo.config.model.api.ApplicationClusterEndpoint;
import com.yahoo.config.model.api.ContainerEndpoint;
import com.yahoo.slime.Slime;
import org.junit.Test;
import java.util.List;
import java.util.OptionalInt;
import static org.junit.Assert.assertEquals;
/**
* @author ogronnesby
*/
public class ContainerEndpointSerializerTest {
@Test
public void readSingleEndpoint() {
final var slime = new Slime();
final var entry = slime.setObject();
entry.setString("clusterId", "foobar");
entry.setString("scope", "application");
final var entryNames = entry.setArray("names");
entryNames.addString("a");
entryNames.addString("b");
final var endpoint = ContainerEndpointSerializer.endpointFromSlime(slime.get());
assertEquals("foobar", endpoint.clusterId());
assertEquals(ApplicationClusterEndpoint.Scope.application, endpoint.scope());
assertEquals(List.of("a", "b"), endpoint.names());
}
@Test
public void writeReadSingleEndpoint() {
final var endpoint = new ContainerEndpoint("foo", ApplicationClusterEndpoint.Scope.global, List.of("a", "b"), OptionalInt.of(1));
final var serialized = new Slime();
ContainerEndpointSerializer.endpointToSlime(serialized.setObject(), endpoint);
final var deserialized = ContainerEndpointSerializer.endpointFromSlime(serialized.get());
assertEquals(endpoint, deserialized);
}
@Test
public void writeReadEndpoints() {
List<ContainerEndpoint> endpoints = List.of(new ContainerEndpoint("foo", ApplicationClusterEndpoint.Scope.global, List.of("a", "b"), OptionalInt.of(3),
ApplicationClusterEndpoint.RoutingMethod.shared, ApplicationClusterEndpoint.AuthMethod.token));
assertEquals(endpoints, ContainerEndpointSerializer.endpointListFromSlime(ContainerEndpointSerializer.endpointListToSlime(endpoints)));
}
}
|