Skip to content
Snippets Groups Projects
Commit 35f5ee0c authored by Guillaume Caillet's avatar Guillaume Caillet
Browse files

Merge branch 'aws-sync-dev-to-master' into 'master'

AWS Merge Dev Into Master

See merge request !539
parents e95b7bf1 8102e2ca
No related branches found
No related tags found
1 merge request!539AWS Merge Dev Into Master
Pipeline #205295 failed
Showing
with 336 additions and 178 deletions
......@@ -73,8 +73,8 @@ phases:
- echo "Building primary service assemblies..."
- mvn --no-transfer-progress install -N # required for this service to install the parent pom so that the integration tests will find it
- mvn --no-transfer-progress -B test install -pl .,schema-core,provider/schema-aws -Ddeployment.environment=prod -Dsonar.login=${SONAR_USERNAME} -Dsonar.password=${SONAR_PASSWORD} -Dsonar.branch.name=${BRANCH_NAME}
- mvn -ntp -B test install -pl .,schema-core,provider/schema-aws -Ddeployment.environment=prod
- mvn sonar:sonar -pl .,provider/schema-aws -Dsonar.login=${SONAR_USERNAME} -Dsonar.password=${SONAR_PASSWORD} -Dsonar.branch.name=${BRANCH_NAME}
- echo "Building integration testing assemblies and gathering artifacts..."
#Needed to add this for Windows
- chmod +x ./testing/schema-test-aws/build-aws/prepare-dist.sh
......
......@@ -215,6 +215,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
......@@ -29,7 +29,6 @@ public class MessageBusImpl implements IMessageBus{
public void publishMessage(String schemaId, String eventType) {
// TODO Auto-generated method stub
logger.warning("publish message not implemented yet");
}
@Override
......
......@@ -193,7 +193,7 @@ public class MongoDBSchemaInfoStore implements ISchemaInfoStore {
schemaInfoDto = mongoDBMultiClusterFactory.getHelper(dataPartitionId).getById(schemaId, SchemaInfoDto.class, getCollection(dataPartitionId));
} catch (Exception ex) {
log.error("Unable to delete schema info", ex);
log.error("Unable to read schema info", ex);
throw new ApplicationException(SchemaConstants.INTERNAL_SERVER_ERROR);
}
if (schemaInfoDto == null) {
......
package org.opengroup.osdu.schema.provider.aws.impl.messagebus;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
@RunWith(MockitoJUnitRunner.class)
public class MessageBusImplTest {
@InjectMocks
private MessageBusImpl messageBusImpl;
@Mock
private JaxRsDpsLog logger;
@Test
public void publishMessage_Success() {
String schemaId = "schemaId";
String eventType = "eventType";
assertDoesNotThrow(() -> {
messageBusImpl.publishMessage(schemaId, eventType);
});
}
@Test
public void publishMessageForSystemSchema_Success() {
String schemaId = "schemaId";
String eventType = "eventType";
assertDoesNotThrow(() -> {
messageBusImpl.publishMessageForSystemSchema(schemaId, eventType);
});
}
}
......@@ -13,6 +13,8 @@
// limitations under the License.
package org.opengroup.osdu.schema.provider.aws.impl.schemainfostore;
import static org.junit.Assert.assertEquals;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -34,87 +36,103 @@ import org.opengroup.osdu.schema.model.Authority;
import org.opengroup.osdu.schema.provider.aws.models.AuthorityDoc;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.assertEquals;
@RunWith(MockitoJUnitRunner.class)
public class AwsAuthorityStoreTest {
@InjectMocks
private AwsAuthorityStore authorityStore;
@Mock
private DpsHeaders headers;
@Mock
private DynamoDBQueryHelperV2 queryHelper;
@Mock
private DynamoDBQueryHelperFactory queryHelperFactory;
@Mock
private JaxRsDpsLog logger;
private static final String COMMON_TENANT_ID = "common";
@Before
public void setUp() throws Exception {
Mockito.when(queryHelperFactory.getQueryHelperForPartition(Mockito.any(DpsHeaders.class), Mockito.any()))
.thenReturn(queryHelper);
ReflectionTestUtils.setField(authorityStore, "sharedTenant", COMMON_TENANT_ID);
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void get() throws NotFoundException, ApplicationException {
String authorityId = "source";
String partitionId = "partitionId";
Authority expected = new Authority();
AuthorityDoc authorityDoc = new AuthorityDoc("id", partitionId, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(authorityDoc);
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
Authority actual = authorityStore.get(authorityId);
Assert.assertEquals(expected, actual);
}
@Test
public void get_SystemSchemas() throws NotFoundException, ApplicationException {
String authorityId = "source";
Authority expected = new Authority();
AuthorityDoc authorityDoc = new AuthorityDoc("id", COMMON_TENANT_ID, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(authorityDoc);
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
Authority actual = authorityStore.getSystemAuthority(authorityId);
Assert.assertEquals(expected, actual);
}
@Test
public void create() throws BadRequestException, ApplicationException {
String partitionId = "partitionId";
Authority expected = new Authority();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
Authority actual = authorityStore.create(expected);
assertEquals(expected, actual);
}
@Test
public void create_SystemSchemas() throws BadRequestException, ApplicationException {
Authority expected = new Authority();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
Authority actual = authorityStore.createSystemAuthority(expected);
assertEquals(expected, actual);
}
@InjectMocks
private AwsAuthorityStore authorityStore;
@Mock
private DpsHeaders headers;
@Mock
private DynamoDBQueryHelperV2 queryHelper;
@Mock
private DynamoDBQueryHelperFactory queryHelperFactory;
@Mock
private JaxRsDpsLog logger;
private static final String COMMON_TENANT_ID = "common";
@Before
public void setUp() throws Exception {
Mockito.when(queryHelperFactory.getQueryHelperForPartition(Mockito.any(DpsHeaders.class), Mockito.any()))
.thenReturn(queryHelper);
ReflectionTestUtils.setField(authorityStore, "sharedTenant", COMMON_TENANT_ID);
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void get() throws NotFoundException, ApplicationException {
String authorityId = "source";
String partitionId = "partitionId";
Authority expected = new Authority();
AuthorityDoc authorityDoc = new AuthorityDoc("id", partitionId, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(authorityDoc);
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
Authority actual = authorityStore.get(authorityId);
Assert.assertEquals(expected, actual);
}
@Test(expected = NotFoundException.class)
public void getThrowsNotFoundException() throws NotFoundException, ApplicationException {
String authorityId = "source";
authorityStore.get(authorityId);
}
@Test
public void get_SystemSchemas() throws NotFoundException, ApplicationException {
String authorityId = "source";
Authority expected = new Authority();
AuthorityDoc authorityDoc = new AuthorityDoc("id", COMMON_TENANT_ID, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(authorityDoc);
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
Authority actual = authorityStore.getSystemAuthority(authorityId);
Assert.assertEquals(expected, actual);
}
@Test
public void create() throws BadRequestException, ApplicationException {
String partitionId = "partitionId";
Authority expected = new Authority();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
Authority actual = authorityStore.create(expected);
assertEquals(expected, actual);
}
@Test()
public void createHandleskeyExistsInTable() throws BadRequestException, ApplicationException {
String partitionId = "partitionId";
Authority expected = new Authority();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(true);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
Authority actual = authorityStore.create(expected);
assertEquals(expected, actual);
}
@Test
public void create_SystemSchemas() throws BadRequestException, ApplicationException {
Authority expected = new Authority();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
Authority actual = authorityStore.createSystemAuthority(expected);
assertEquals(expected, actual);
}
}
\ No newline at end of file
......@@ -39,12 +39,11 @@ import static org.junit.Assert.assertEquals;
@RunWith(MockitoJUnitRunner.class)
public class AwsEntityTypeStoreTest {
@InjectMocks
private AwsEntityTypeStore entityTypeStore;
@InjectMocks
private AwsEntityTypeStore entityTypeStore;
@Mock
private DpsHeaders headers;
@Mock
private DpsHeaders headers;
@Mock
private DynamoDBQueryHelperFactory queryHelperFactory;
......@@ -52,70 +51,91 @@ public class AwsEntityTypeStoreTest {
@Mock
private DynamoDBQueryHelperV2 queryHelper;
@Mock
private JaxRsDpsLog logger;
private static final String COMMON_TENANT_ID = "common";
@Before
public void setUp() throws Exception {
Mockito.when(queryHelperFactory.getQueryHelperForPartition(Mockito.any(DpsHeaders.class), Mockito.any()))
.thenReturn(queryHelper);
ReflectionTestUtils.setField(entityTypeStore, "sharedTenant", COMMON_TENANT_ID);
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void get() throws NotFoundException, ApplicationException {
String entityTypeId = "id";
String partitionId = "partitionId";
EntityType expected = new EntityType();
EntityTypeDoc entityTypeDoc = new EntityTypeDoc("id", partitionId, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(entityTypeDoc);
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
EntityType actual = entityTypeStore.get(entityTypeId);
Assert.assertEquals(expected, actual);
}
@Test
public void get_SystemSchemas() throws NotFoundException, ApplicationException {
String entityTypeId = "id";
EntityType expected = new EntityType();
EntityTypeDoc entityTypeDoc = new EntityTypeDoc("id", COMMON_TENANT_ID, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(entityTypeDoc);
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
EntityType actual = entityTypeStore.get(entityTypeId);
Assert.assertEquals(expected, actual);
}
@Test
public void create() throws BadRequestException, ApplicationException {
String partitionId = "partitionId";
EntityType expected = new EntityType();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
EntityType actual = entityTypeStore.create(expected);
assertEquals(expected, actual);
}
@Test
public void create_SystemSchemas() throws BadRequestException, ApplicationException {
EntityType expected = new EntityType();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
EntityType actual = entityTypeStore.create(expected);
assertEquals(expected, actual);
}
@Mock
private JaxRsDpsLog logger;
private static final String COMMON_TENANT_ID = "common";
@Before
public void setUp() throws Exception {
Mockito.when(queryHelperFactory.getQueryHelperForPartition(Mockito.any(DpsHeaders.class), Mockito.any()))
.thenReturn(queryHelper);
ReflectionTestUtils.setField(entityTypeStore, "sharedTenant", COMMON_TENANT_ID);
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void get() throws NotFoundException, ApplicationException {
String entityTypeId = "id";
String partitionId = "partitionId";
EntityType expected = new EntityType();
EntityTypeDoc entityTypeDoc = new EntityTypeDoc("id", partitionId, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(entityTypeDoc);
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
EntityType actual = entityTypeStore.get(entityTypeId);
Assert.assertEquals(expected, actual);
}
@Test(expected = NotFoundException.class)
public void getThrowsNotFoundException() throws NotFoundException, ApplicationException {
String entityTypeId = "id";
String partitionId = "partitionId";
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(null);
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
entityTypeStore.get(entityTypeId);
}
@Test
public void get_SystemSchemas() throws NotFoundException, ApplicationException {
String entityTypeId = "id";
EntityType expected = new EntityType();
EntityTypeDoc entityTypeDoc = new EntityTypeDoc("id", COMMON_TENANT_ID, expected);
Mockito.when(queryHelper.loadByPrimaryKey(Mockito.any(), Mockito.any())).thenReturn(entityTypeDoc);
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
EntityType actual = entityTypeStore.get(entityTypeId);
Assert.assertEquals(expected, actual);
}
@Test
public void create() throws BadRequestException, ApplicationException {
String partitionId = "partitionId";
EntityType expected = new EntityType();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
EntityType actual = entityTypeStore.create(expected);
assertEquals(expected, actual);
}
@Test(expected = BadRequestException.class)
public void createHandleskeyExistsInTable() throws BadRequestException, ApplicationException {
String partitionId = "partitionId";
EntityType expected = new EntityType();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(true);
Mockito.when(headers.getPartitionId()).thenReturn(partitionId);
entityTypeStore.create(expected);
}
@Test
public void create_SystemSchemas() throws BadRequestException, ApplicationException {
EntityType expected = new EntityType();
Mockito.when(queryHelper.keyExistsInTable(Mockito.any(), Mockito.any())).thenReturn(false);
Mockito.doNothing().when(queryHelper).save(Mockito.any());
Mockito.when(headers.getPartitionId()).thenReturn(COMMON_TENANT_ID);
EntityType actual = entityTypeStore.create(expected);
assertEquals(expected, actual);
}
}
\ No newline at end of file
......@@ -13,22 +13,39 @@
// limitations under the License.
package org.opengroup.osdu.schema.provider.aws.models;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.opengroup.osdu.schema.model.EntityType;
import static org.junit.Assert.assertEquals;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class EntityTypeDocTest {
@Test
public void entityTypeUNConverter_Success() {
EntityTypeDoc.EntityTypeConverter converter = new EntityTypeDoc.EntityTypeConverter();
EntityType obj = new EntityType();
obj.setEntityTypeId("id");
obj.setDescription("description");
obj.setIcon("icon");
obj.setStatus("status");
EntityType actual = converter.unconvert(converter.convert(obj));
assertEquals(obj, actual);
}
@Test
public void entityTypeConverter_Success() throws JsonProcessingException {
EntityTypeDoc.EntityTypeConverter converter = new EntityTypeDoc.EntityTypeConverter();
EntityType obj = new EntityType();
obj.setEntityTypeId("id");
obj.setDescription("description");
obj.setIcon("icon");
obj.setStatus("status");
String expected = new ObjectMapper().writeValueAsString(obj);
String actual = converter.convert(obj);
assertEquals(expected, actual);
}
@Test
public void entityTypeConverter_Success() {
EntityTypeDoc.EntityTypeConverter converter = new EntityTypeDoc.EntityTypeConverter();
EntityType obj = new EntityType();
obj.setEntityTypeId("id");
obj.setDescription("description");
obj.setIcon("icon");
obj.setStatus("status");
EntityType actual = converter.unconvert(converter.convert(obj));
assertEquals(obj, actual);
}
}
\ No newline at end of file
......@@ -16,16 +16,30 @@ package org.opengroup.osdu.schema.provider.aws.models;
import org.junit.Test;
import org.opengroup.osdu.schema.model.Source;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import static org.junit.Assert.*;
public class SourceDocTest {
@Test
public void sourceConverter_Success() {
SourceDoc.SourceConverter converter = new SourceDoc.SourceConverter();
Source obj = new Source();
obj.setSourceId("id");
Source actual = converter.unconvert(converter.convert(obj));
assertEquals(obj, actual);
}
@Test
public void UnConverter_Success() {
SourceDoc.SourceConverter converter = new SourceDoc.SourceConverter();
Source obj = new Source();
obj.setSourceId("id");
Source actual = converter.unconvert(converter.convert(obj));
assertEquals(obj, actual);
}
@Test
public void Converter_Success() throws JsonProcessingException {
SourceDoc.SourceConverter converter = new SourceDoc.SourceConverter();
Source obj = new Source();
obj.setSourceId("id");
String expected = new ObjectMapper().writeValueAsString(obj);
String actual = converter.convert(obj);
assertEquals(expected, actual);
}
}
\ No newline at end of file
......@@ -73,7 +73,7 @@ public class MongoDBSchemaInfoStoreTest extends ParentUtil {
}
@Test(expected = BadRequestException.class)
public void updateSchemaInfoNodFound() throws ApplicationException, BadRequestException {
public void updateSchemaInfoNotFound() throws ApplicationException, BadRequestException {
//given
SchemaRequest schemaRequest = createSchemaRequest();
......@@ -185,6 +185,15 @@ public class MongoDBSchemaInfoStoreTest extends ParentUtil {
//when
schemaInfoStore.getSchemaInfo(id);
}
@Test(expected = ApplicationException.class)
public void getSchemaInfoThrowsApplicationException() throws ApplicationException, NotFoundException {
//given
String id = null;
//when
schemaInfoStore.getSchemaInfo(id);
}
@Test
public void getSystemSchemaInfo() throws ApplicationException, NotFoundException {
......@@ -219,14 +228,27 @@ public class MongoDBSchemaInfoStoreTest extends ParentUtil {
Mockito.when(awsSchemaStore.getSchema(anyString(), anyString())).thenReturn("content:minor:minor:minor:5555.1000.10000");
mongoTemplateHelper.insert(getSchemas("other", 10), SCHEMA_INFO_PREFIX + DATA_PARTITION);
//when
String latestMinorVerSchema = schemaInfoStore.getLatestMinorVerSchema(schemas.stream().findAny().get().getData());
//then
assertEquals(contentPrefix + schemas.get(9).getId(), latestMinorVerSchema);
}
@Test
public void getLatestMinorVerSchemaHandlesNotFoundException() throws ApplicationException, NotFoundException {
//given
List<SchemaInfoDto> schemas = getSchemas("minor", 10);
mongoTemplateHelper.insert(schemas, SCHEMA_INFO_PREFIX + DATA_PARTITION);
Mockito.when(awsSchemaStore.getSchema(anyString(), anyString())).thenReturn(null);
//when
String latestMinorVerSchema = schemaInfoStore.getLatestMinorVerSchema(schemas.stream().findAny().get().getData());
//then
assertEquals(null, latestMinorVerSchema);
}
@Test
public void getSchemaInfoList() throws ApplicationException {
......@@ -370,6 +392,15 @@ public class MongoDBSchemaInfoStoreTest extends ParentUtil {
assertTrue(before);
assertFalse(after);
}
@Test(expected = ApplicationException.class)
public void isUniqueThrowsApplicationException() throws ApplicationException {
//given
SchemaInfoDto schemaInfDto = createSchemaInfDto("test", 1);
//when
schemaInfoStore.isUnique(schemaInfDto.getId(), null);
}
@Test
public void isUniqueSystemSchema() throws ApplicationException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment