Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,50 @@
<target>11</target>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Used for unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>@{surefireArgLine}</argLine>
<forkCount>1</forkCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -131,6 +175,34 @@
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.data.jpa}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<properties>
Expand All @@ -151,6 +223,8 @@
<jclouds.version>2.5.0</jclouds.version>
<commons.io.version>2.6</commons.io.version>
<apache.http.client.version>4.5.13</apache.http.client.version>
<jupiter.version>5.8.1</jupiter.version>
<mockito.version>4.6.1</mockito.version>
</properties>

</project>
6 changes: 6 additions & 0 deletions services/resource-service/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<artifactId>grpc-services</artifactId>
<version>1.25.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId>
<version>1.25.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.airavata.mft.resource.server.handler;


import io.grpc.internal.testing.StreamRecorder;
import org.apache.airavata.mft.resource.server.backend.ResourceBackend;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3Storage;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3StorageListRequest;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3StorageListResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;

@RunWith( MockitoJUnitRunner.class )
class S3ServiceHandlerTest
{

@InjectMocks
private S3ServiceHandler s3ServiceHandler;

@Mock
private ResourceBackend backend;


@BeforeEach
void setUp()
{
s3ServiceHandler = new S3ServiceHandler();
MockitoAnnotations.openMocks( this );
}

@Test
void listS3Storage() throws Exception
{

S3StorageListRequest request1 = S3StorageListRequest.newBuilder().setOffset( 0 ).setLimit( 10 ).build();
when( backend.listS3Storage( request1 ) ).thenReturn( S3StorageListResponse.newBuilder().addStorages( 0,
S3Storage.newBuilder().setStorageId( "1" ).setBucketName( "testBkt" ).setName( "testJCV" )
.setRegion( "usa-east" ) ).build() );

S3StorageListRequest request = S3StorageListRequest.newBuilder().setOffset( 0 ).setLimit( 10 ).build();
StreamRecorder<S3StorageListResponse> responseOb = StreamRecorder.create();
s3ServiceHandler.listS3Storage( request, responseOb );
if ( !responseOb.awaitCompletion( 5, TimeUnit.SECONDS ) )
{
System.out.println( "Time out !" );
fail();
}
List<S3StorageListResponse> results = responseOb.getValues();
assertEquals( 1, results.size() );
S3StorageListResponse response = results.get( 0 );
assertEquals( S3StorageListResponse.newBuilder().addStorages( 0,
S3Storage.newBuilder().setStorageId( "1" ).setBucketName( "testBkt" ).setName( "testJCV" )
.setRegion( "usa-east" ) ).build(), response );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.apache.airavata.mft.resource.server.backend.sql;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.apache.airavata.mft.resource.server.backend.sql.entity.S3StorageEntity;
import org.apache.airavata.mft.resource.server.backend.sql.repository.S3StorageRepository;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3Storage;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3StorageGetRequest;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3StorageListRequest;
import org.apache.airavata.mft.resource.stubs.s3.storage.S3StorageListResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.PageRequest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

@RunWith( MockitoJUnitRunner.class )
class SQLResourceBackendTest
{
@InjectMocks
private SQLResourceBackend sqlResourceBackend;
@Mock
private S3StorageRepository s3StorageRepository;

@BeforeEach
void setUp()
{
MockitoAnnotations.openMocks( this );
}

@Test
void listS3Storage() throws Exception
{
List<S3StorageEntity> storageList = new ArrayList<>();
S3StorageEntity storage = new S3StorageEntity();
storage.setStorageId( String.valueOf( 1 ) );
storage.setBucketName( "testBucket" );
storage.setName( "Bucket" );
storage.setRegion( "usa-east" );
storage.setEndpoint( "aws.com" );
storage.setUseTLS( true );
storageList.add( storage );
when( s3StorageRepository.findAll( PageRequest.of( 1, 5 ) ) ).thenReturn( storageList );
S3StorageListRequest request = S3StorageListRequest.newBuilder().setLimit( 5 ).setOffset( 1 ).build();
S3StorageListResponse response = sqlResourceBackend.listS3Storage( request );
assertTrue( response.getStoragesList().size() > 0 );
}

@Test
void getS3Storage() throws Exception
{
S3StorageEntity storage = new S3StorageEntity();
storage.setStorageId( String.valueOf( 1 ) );
storage.setBucketName( "testBucket" );
storage.setName( "Bucket" );
storage.setRegion( "usa-east" );
storage.setEndpoint( "aws.com" );
storage.setUseTLS( true );
when( s3StorageRepository.findById( "1" ) ).thenReturn( Optional.of( storage ) );
S3StorageGetRequest request = S3StorageGetRequest.newBuilder().setStorageId( "1" ).build();
Optional<S3Storage> response = sqlResourceBackend.getS3Storage( request );
assertTrue( response.isPresent() );
assertEquals( "1", ( (S3Storage) response.get() ).getStorageId() );
}

}