|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY |
| 3 | + * All Rights Reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +package org.testcontainers.containers.tarantool.config; |
| 7 | + |
| 8 | +import java.util.Collections; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.stream.Stream; |
| 12 | + |
| 13 | +import org.junit.jupiter.api.Assertions; |
| 14 | +import org.junit.jupiter.params.ParameterizedTest; |
| 15 | +import org.junit.jupiter.params.provider.Arguments; |
| 16 | +import org.junit.jupiter.params.provider.MethodSource; |
| 17 | + |
| 18 | +import io.tarantool.autogen.Tarantool3Configuration; |
| 19 | +import io.tarantool.autogen.credentials.Credentials; |
| 20 | +import io.tarantool.autogen.credentials.users.Users; |
| 21 | +import io.tarantool.autogen.credentials.users.usersProperty.UsersProperty; |
| 22 | + |
| 23 | +class ConfigurationUtilsTest { |
| 24 | + |
| 25 | + public static Stream<Arguments> dataForTestAddUsersMethod() { |
| 26 | + |
| 27 | + /* |
| 28 | + /********************************************************** |
| 29 | + /* Additional user properties |
| 30 | + /********************************************************** |
| 31 | + */ |
| 32 | + final String userPwd = "user-pwd"; |
| 33 | + final String userName = "user-name"; |
| 34 | + final UsersProperty usersProperty = UsersProperty.builder().withPassword(userPwd).build(); |
| 35 | + Map<String, UsersProperty> users = |
| 36 | + new HashMap<>() { |
| 37 | + { |
| 38 | + put(userName, usersProperty); |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + /* |
| 43 | + /********************************************************** |
| 44 | + /* Without credentials section |
| 45 | + /********************************************************** |
| 46 | + */ |
| 47 | + final Tarantool3Configuration oldConfigWithoutCredSection = new Tarantool3Configuration(); |
| 48 | + final Tarantool3Configuration expectedConfigWithoutCredSection = |
| 49 | + Tarantool3Configuration.builder() |
| 50 | + .withCredentials( |
| 51 | + Credentials.builder() |
| 52 | + .withUsers( |
| 53 | + Users.builder().withAdditionalProperty(userName, usersProperty).build()) |
| 54 | + .build()) |
| 55 | + .build(); |
| 56 | + |
| 57 | + /* |
| 58 | + /********************************************************** |
| 59 | + /* With credentials section without users |
| 60 | + /********************************************************** |
| 61 | + */ |
| 62 | + final Tarantool3Configuration oldConfigWithCredWithoutUsersSection = |
| 63 | + Tarantool3Configuration.builder().withCredentials(new Credentials()).build(); |
| 64 | + final Tarantool3Configuration expectedConfigWithCredWithoutUsersSection = |
| 65 | + Tarantool3Configuration.builder() |
| 66 | + .withCredentials( |
| 67 | + Credentials.builder() |
| 68 | + .withUsers( |
| 69 | + Users.builder().withAdditionalProperty(userName, usersProperty).build()) |
| 70 | + .build()) |
| 71 | + .build(); |
| 72 | + |
| 73 | + /* |
| 74 | + /********************************************************** |
| 75 | + /* With credentials and users sections |
| 76 | + /********************************************************** |
| 77 | + */ |
| 78 | + final Tarantool3Configuration oldConfigWithCredWithUsersSection = |
| 79 | + Tarantool3Configuration.builder() |
| 80 | + .withCredentials(Credentials.builder().withUsers(new Users()).build()) |
| 81 | + .build(); |
| 82 | + final Tarantool3Configuration expectedConfigWithCredWithUsersSection = |
| 83 | + Tarantool3Configuration.builder() |
| 84 | + .withCredentials( |
| 85 | + Credentials.builder() |
| 86 | + .withUsers( |
| 87 | + Users.builder().withAdditionalProperty(userName, usersProperty).build()) |
| 88 | + .build()) |
| 89 | + .build(); |
| 90 | + |
| 91 | + /* |
| 92 | + /********************************************************** |
| 93 | + /* Override users with same name |
| 94 | + /********************************************************** |
| 95 | + */ |
| 96 | + final Tarantool3Configuration oldConfigWithUser = |
| 97 | + Tarantool3Configuration.builder() |
| 98 | + .withCredentials( |
| 99 | + Credentials.builder() |
| 100 | + .withUsers( |
| 101 | + Users.builder() |
| 102 | + .withAdditionalProperty(userName, new UsersProperty()) |
| 103 | + .build()) |
| 104 | + .build()) |
| 105 | + .build(); |
| 106 | + final Tarantool3Configuration expectedConfigWithUser = |
| 107 | + Tarantool3Configuration.builder() |
| 108 | + .withCredentials( |
| 109 | + Credentials.builder() |
| 110 | + .withUsers( |
| 111 | + Users.builder().withAdditionalProperty(userName, usersProperty).build()) |
| 112 | + .build()) |
| 113 | + .build(); |
| 114 | + Assertions.assertNotEquals(oldConfigWithUser, expectedConfigWithUser); |
| 115 | + |
| 116 | + return Stream.of( |
| 117 | + // old config null |
| 118 | + Arguments.of(null, Collections.emptyMap(), null), |
| 119 | + |
| 120 | + // without credentials |
| 121 | + Arguments.of(oldConfigWithoutCredSection, users, expectedConfigWithoutCredSection), |
| 122 | + |
| 123 | + // with credentials and without users |
| 124 | + Arguments.of( |
| 125 | + oldConfigWithCredWithoutUsersSection, users, expectedConfigWithCredWithoutUsersSection), |
| 126 | + |
| 127 | + // with credentials and with users |
| 128 | + Arguments.of( |
| 129 | + oldConfigWithCredWithUsersSection, users, expectedConfigWithCredWithUsersSection), |
| 130 | + |
| 131 | + // override user with same name |
| 132 | + Arguments.of(oldConfigWithUser, users, expectedConfigWithUser)); |
| 133 | + } |
| 134 | + |
| 135 | + @ParameterizedTest |
| 136 | + @MethodSource("dataForTestAddUsersMethod") |
| 137 | + void testAddUsersMethod( |
| 138 | + Tarantool3Configuration oldConfig, |
| 139 | + Map<String, UsersProperty> additionalUsers, |
| 140 | + Tarantool3Configuration expected) { |
| 141 | + Assertions.assertEquals(expected, ConfigurationUtils.addUsers(oldConfig, additionalUsers)); |
| 142 | + } |
| 143 | +} |
0 commit comments