| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2025 the original author or authors.  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + *      https://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + * See the License for the specific language governing permissions and  | 
 | 14 | + * limitations under the License.  | 
 | 15 | + */  | 
 | 16 | +package org.springframework.vault.repository.core;  | 
 | 17 | + | 
 | 18 | +import org.junit.jupiter.api.Test;  | 
 | 19 | +import org.junit.jupiter.api.extension.ExtendWith;  | 
 | 20 | + | 
 | 21 | +import org.springframework.beans.factory.annotation.Autowired;  | 
 | 22 | +import org.springframework.test.context.ContextConfiguration;  | 
 | 23 | +import org.springframework.test.context.junit.jupiter.SpringExtension;  | 
 | 24 | +import org.springframework.vault.VaultException;  | 
 | 25 | +import org.springframework.vault.core.VaultIntegrationTestConfiguration;  | 
 | 26 | +import org.springframework.vault.core.VaultTemplate;  | 
 | 27 | +import org.springframework.vault.core.util.KeyValueDelegate;  | 
 | 28 | +import org.springframework.vault.domain.Person;  | 
 | 29 | +import org.springframework.vault.util.IntegrationTestSupport;  | 
 | 30 | + | 
 | 31 | +import static org.assertj.core.api.Assertions.*;  | 
 | 32 | + | 
 | 33 | +/**  | 
 | 34 | + * Integration tests for {@link VaultKeyValueAdapter}.  | 
 | 35 | + *  | 
 | 36 | + * @author Mark Paluch  | 
 | 37 | + */  | 
 | 38 | +@ExtendWith(SpringExtension.class)  | 
 | 39 | +@ContextConfiguration(classes = VaultIntegrationTestConfiguration.class)  | 
 | 40 | +class VaultKeyValueAdapterIntegrationTests extends IntegrationTestSupport {  | 
 | 41 | + | 
 | 42 | +	@Autowired  | 
 | 43 | +	VaultTemplate template;  | 
 | 44 | + | 
 | 45 | +	@Test  | 
 | 46 | +	void shouldFailOnAbsentKeyspace() {  | 
 | 47 | + | 
 | 48 | +		VaultKeyValueAdapter adapter = new VaultKeyValueAdapter(template);  | 
 | 49 | + | 
 | 50 | +		assertThatExceptionOfType(VaultException.class).isThrownBy(() -> adapter.get("some-id", "absent", Person.class))  | 
 | 51 | +			.withMessageContaining("Cannot determine MountInfo");  | 
 | 52 | +	}  | 
 | 53 | + | 
 | 54 | +	@Test  | 
 | 55 | +	void shouldReturnVersionedMountInfo() {  | 
 | 56 | + | 
 | 57 | +		KeyValueDelegate delegate = new KeyValueDelegate(template);  | 
 | 58 | + | 
 | 59 | +		KeyValueDelegate.MountInfo mountInfo = delegate.getMountInfo("versioned/nothing/here");  | 
 | 60 | + | 
 | 61 | +		assertThat(mountInfo.isAvailable()).isTrue();  | 
 | 62 | +		assertThat(mountInfo.getOptions()).containsEntry("version", "2");  | 
 | 63 | +	}  | 
 | 64 | + | 
 | 65 | +	@Test  | 
 | 66 | +	void shouldReturnUnversionedMountInfo() {  | 
 | 67 | + | 
 | 68 | +		KeyValueDelegate delegate = new KeyValueDelegate(template);  | 
 | 69 | + | 
 | 70 | +		KeyValueDelegate.MountInfo mountInfo = delegate.getMountInfo("secret/nothing/here");  | 
 | 71 | + | 
 | 72 | +		assertThat(mountInfo.isAvailable()).isTrue();  | 
 | 73 | +		assertThat(mountInfo.getOptions()).doesNotContainEntry("version", "2");  | 
 | 74 | +	}  | 
 | 75 | + | 
 | 76 | +}  | 
0 commit comments