[#23] Update proto api
Add chain functionality Add tests Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
64e275713f
commit
694bb963e4
38 changed files with 1414 additions and 299 deletions
|
@ -0,0 +1,64 @@
|
|||
package info.frostfs.sdk.mappers.chain;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostfs.ape.Types;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ChainMapperTest {
|
||||
|
||||
@Test
|
||||
void toModels_success() {
|
||||
//Given
|
||||
var chain1 = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}))
|
||||
.build();
|
||||
var chain2 = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(new byte[]{6, 7, 8, 9, 10}))
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = ChainMapper.toModels(List.of(chain1, chain2));
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result.get(0).getRaw()).containsOnly(chain1.getRaw().toByteArray());
|
||||
assertThat(result.get(1).getRaw()).containsOnly(chain2.getRaw().toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModels_null() {
|
||||
//When + Then
|
||||
assertNull(ChainMapper.toModels(null));
|
||||
assertNull(ChainMapper.toModels(Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_success() {
|
||||
//Given
|
||||
var chain = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}))
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = ChainMapper.toModel(chain);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertThat(result.getRaw()).containsOnly(chain.getRaw().toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_null() {
|
||||
//When + Then
|
||||
assertNull(ChainMapper.toModel(null));
|
||||
assertNull(ChainMapper.toModel(Types.Chain.getDefaultInstance()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package info.frostfs.sdk.mappers.chain;
|
||||
|
||||
import frostfs.ape.Types;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import info.frostfs.sdk.enums.TargetType;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class ChainTargetMapperTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = TargetType.class)
|
||||
void toGrpcMessage_success(TargetType targetType) {
|
||||
//Given
|
||||
var target = new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", targetType);
|
||||
|
||||
|
||||
//When
|
||||
var result = ChainTargetMapper.toGrpcMessage(target);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(target.getName(), result.getName());
|
||||
assertEquals(target.getType().value, result.getTypeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_null() {
|
||||
//When + Then
|
||||
assertNull(ChainTargetMapper.toGrpcMessage(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_notValidScheme() {
|
||||
//Given
|
||||
var target = new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", TargetType.UNDEFINED);
|
||||
|
||||
//When + Then
|
||||
try (MockedStatic<Types.TargetType> mockStatic = mockStatic(Types.TargetType.class)) {
|
||||
mockStatic.when(() -> Types.TargetType.forNumber(target.getType().value))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThrows(ProcessFrostFSException.class, () -> ChainTargetMapper.toGrpcMessage(target));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ public class ObjectFilterMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_notValidScheme() {
|
||||
void toGrpcMessage_notValidType() {
|
||||
//Given
|
||||
var objectFilter = new ObjectFilter.FilterByAttribute(UNSPECIFIED, "key", "value");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue