Skip to content

Commit

Permalink
feat(irs-api):[#199] added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-psosnowski committed Mar 13, 2024
1 parent 4975d01 commit eba7540
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,35 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

import io.minio.GetObjectResponse;
import io.minio.MinioClient;
import io.minio.Result;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidResponseException;
import io.minio.errors.ServerException;
import io.minio.errors.XmlParserException;
import io.minio.messages.Contents;
import io.minio.messages.ErrorResponse;
import io.minio.messages.Item;
import lombok.AllArgsConstructor;
import okhttp3.Headers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -217,4 +233,36 @@ void shouldNotFindBlobByPrefix() throws Exception {
assertThat(blobsByPrefix).isEmpty();
}

@Test
void test() throws BlobPersistenceException, ServerException, InsufficientDataException, ErrorResponseException,
IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException,
InternalException {
final String name = "test-name";
when(client.listObjects(any())).thenReturn(List.of(new Result<>(new TestItem(name))));

final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeUTF("");
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInputStream outputStream = new ObjectInputStream(inputStream);

when(client.getObject(any())).thenReturn(new GetObjectResponse(null, null, null, null, outputStream));

// act
final Map<String, byte[]> allBlobs = testee.getAllBlobs();

// assert
assertThat(allBlobs.get(name)).isNotNull();
}

@AllArgsConstructor
static class TestItem extends Item {

private final String name;

@Override
public String objectName() {
return name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistence;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceException;
import org.eclipse.tractusx.irs.common.persistence.BlobPersistenceRuntimeException;
import org.eclipse.tractusx.irs.edc.client.policy.Policy;
import org.eclipse.tractusx.irs.policystore.exceptions.PolicyStoreException;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -139,7 +138,7 @@ public Map<String, List<Policy>> readAll() {
throw new PolicyStoreException("Could not read the policies from the store", e);
}
}).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
} catch (BlobPersistenceException | BlobPersistenceRuntimeException e) {
} catch (BlobPersistenceException e) {
throw new PolicyStoreException("Could not read the policies from the store", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ void deletePolicy() {
verify(persistence).delete(BPN, "testId");
}

@Test
void shouldThrowException() {

}

@Test
void deletePolicyShouldThrowResponseStatusException() {
// act
Expand Down

0 comments on commit eba7540

Please sign in to comment.