There is a security vulnerability in SSH key-generation using GitKraken < v8.0.1. If you used this tool to create SSH keys, please update GitKraken and regenerate. If you need help with this, contact forum-support@opengroup.org

Commit 0bca494e authored by Abhishek Kumar's avatar Abhishek Kumar Committed by Abhishek Kumar
Browse files

Test case enhancements and adding vendor stub

parent 5fcf4fcc
package org.opengroup.osdu.schema.provider.aws.impl.messagebus;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.provider.interfaces.messagebus.IMessageBus;
import org.springframework.stereotype.Component;
@Component
public class MessageBusImpl implements IMessageBus{
@Inject
private JaxRsDpsLog logger;
@Override
public void publishMessage(DpsHeaders headers, String schemaId, String eventType) {
// TODO Auto-generated method stub
logger.warning("publish message not implemented ye");
}
}
......@@ -6,18 +6,30 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class EventGridConfig {
public boolean isPublishingToEventGridEnabled() {
return publishToEventGridEnabled;
}
public String getCustomTopicName() {
return eventGridCustomTopic;
}
@Value("#{new Boolean('${azure.publishToEventGrid:false}')}")
private boolean publishToEventGridEnabled;
@Value("#{new String('${azure.eventGridTopic:schema-change-alert}')}")
private String eventGridCustomTopic;
}
\ No newline at end of file
public boolean isPublishToEventGridEnabled() {
return publishToEventGridEnabled;
}
public String getCustomTopicName() {
return eventGridCustomTopic;
}
private boolean publishToEventGridEnabled;
private String eventGridCustomTopic;
public EventGridConfig(@Value("#{new Boolean('${azure.publishToEventGrid:false}')}") boolean publish,
@Value("#{new String('${azure.eventGridTopic:schema-change-alert}')}") String topicName) {
if (publish) {
if ((topicName.isEmpty())) {
throw new RuntimeException("Missing EventGrid Configuration");
}
}
this.publishToEventGridEnabled = publish;
this.eventGridCustomTopic = topicName;
}
}
......@@ -15,21 +15,12 @@ import org.opengroup.osdu.schema.azure.di.EventGridConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.logging.AuditLogger;
import org.opengroup.osdu.schema.provider.interfaces.messagebus.IMessageBus;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.ISchemaInfoStore;
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.opengroup.osdu.schema.service.IAuthorityService;
import org.opengroup.osdu.schema.service.IEntityTypeService;
import org.opengroup.osdu.schema.service.ISourceService;
import org.opengroup.osdu.schema.util.SchemaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.microsoft.azure.eventgrid.models.EventGridEvent;
import lombok.RequiredArgsConstructor;
@Component
@RequiredArgsConstructor
public class MessageBusImpl implements IMessageBus {
@Autowired
......@@ -41,16 +32,18 @@ public class MessageBusImpl implements IMessageBus {
@Autowired
private EventGridConfig eventGridConfig;
private final AuditLogger auditLogger;
@Autowired
private AuditLogger auditLogger;
final JaxRsDpsLog log;
@Autowired
private JaxRsDpsLog log;
private final static String EVENT_DATA_VERSION = "1.0";
@Override
public void publishMessage(DpsHeaders headers, String schemaId, String eventType) {
if (eventGridConfig.isPublishingToEventGridEnabled()) {
if (eventGridConfig.isPublishToEventGridEnabled()) {
logger.info("Generating event of type {}",eventType);
try {
publishToEventGrid(headers, schemaId, eventType);
......
package org.opengroup.osdu.schema.azure.impl.messagebus;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.eventgrid.EventGridTopicStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.di.EventGridConfig;
import org.opengroup.osdu.schema.logging.AuditLogger;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
@ExtendWith(MockitoExtension.class)
public class MessageBusImplTest {
private static final String DATA_PARTITION_WITH_FALLBACK_ACCOUNT_ID = "data-partition-account-id";
private static final String CORRELATION_ID = "correlation-id";
private static final String PARTITION_ID = "partition-id";
@Mock
private EventGridTopicStore eventGridTopicStore;
@Mock
private EventGridConfig eventGridConfig;
@Mock
private DpsHeaders dpsHeaders;
@Mock
private JaxRsDpsLog logger;
@Mock
private AuditLogger auditLogger;
@InjectMocks
private MessageBusImpl messageBusImpl;
@Before
public void init() throws ServiceBusException, InterruptedException {
initMocks(this);
doReturn(DATA_PARTITION_WITH_FALLBACK_ACCOUNT_ID).when(dpsHeaders).getPartitionIdWithFallbackToAccountId();
doReturn(PARTITION_ID).when(dpsHeaders).getPartitionId();
doReturn(CORRELATION_ID).when(dpsHeaders).getCorrelationId();
}
@Test
public void should_publishToEventGrid_WhenFlagIsFalse() {
//The schema-notification is turned off
when(this.eventGridConfig.isPublishToEventGridEnabled()).thenReturn(false);
//Call publish Message
messageBusImpl.publishMessage(dpsHeaders, "dummy", "dummy");
//Assert that eventGridTopicStore is not called even once
verify(this.eventGridTopicStore, times(0)).publishToEventGridTopic(any(), any(), anyList());
}
@Test
public void should_publishToEventGrid_WhenFlagIsTrue() {
//The schema-notification is turned off
when(this.eventGridConfig.isPublishToEventGridEnabled()).thenReturn(true);
//The schema-notification is turned off
doNothing().when(this.eventGridTopicStore).publishToEventGridTopic(anyString(), anyString(), anyList());;
//Call publish Message
messageBusImpl.publishMessage(dpsHeaders, "dummy", "dummy");
//Assert that eventGridTopicStore is not called even once
verify(this.eventGridTopicStore, times(1)).publishToEventGridTopic(any(), any(), anyList());
}
}
package org.opengroup.osdu.schema.provider.azure.di;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.schema.azure.di.EventGridConfig;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(MockitoExtension.class)
public class EventGridConfigTest {
private static String VALID_TOPIC_NAME = "topicname";
private static String INVALID_TOPIC_NAME = "";
@Test
public void configurationValidationTests() {
// Positive Case
EventGridConfig eventGridConfig = new EventGridConfig(true, VALID_TOPIC_NAME);
assertEquals(VALID_TOPIC_NAME, eventGridConfig.getCustomTopicName());
// Negative Cases
RuntimeException runtimeException = Assertions.assertThrows(RuntimeException.class,
() -> new EventGridConfig(true, INVALID_TOPIC_NAME));
assertEquals("Missing EventGrid Configuration", runtimeException.getMessage());
}
}
\ No newline at end of file
package org.opengroup.osdu.schema.impl.messagebus;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.provider.interfaces.messagebus.IMessageBus;
import org.springframework.stereotype.Component;
@Component
public class MessageBusImpl implements IMessageBus{
@Inject
private JaxRsDpsLog logger;
@Override
public void publishMessage(DpsHeaders headers, String schemaId, String eventType) {
// TODO Auto-generated method stub
logger.warning("publish message not implemented ye");
}
}
\ No newline at end of file
package org.opengroup.osdu.schema.provider.ibm;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.provider.interfaces.messagebus.IMessageBus;
import org.springframework.stereotype.Component;
@Component
public class MessageBusImpl implements IMessageBus{
@Inject
private JaxRsDpsLog logger;
@Override
public void publishMessage(DpsHeaders headers, String schemaId, String eventType) {
// TODO Auto-generated method stub
logger.warning("publish message not implemented ye");
}
}
\ No newline at end of file
......@@ -4,12 +4,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import static org.mockito.Mockito.*;
import org.json.JSONException;
import org.junit.Assert;
import org.junit.Before;
......@@ -174,8 +172,10 @@ public class SchemaServiceTest {
Mockito.when(schemaResolver.resolveSchema(Mockito.anyString())).thenReturn("{}");
Mockito.when(schemaStore.createSchema(Mockito.anyString(), Mockito.anyString())).thenReturn("{}");
Mockito.when(schemaInfoStore.createSchemaInfo(schReqPubInt)).thenReturn(schInfo);
assertEquals(SchemaStatus.PUBLISHED,
schemaService.createSchema(schReqPubInt).getStatus());
verify(messageBus, times(1)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -205,6 +205,7 @@ public class SchemaServiceTest {
Mockito.when(schemaInfoStore.createSchemaInfo(schReq))
.thenReturn(schInfo);
assertEquals(schInfo, schemaService.createSchema(schReq));
verify(messageBus, times(1)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -233,6 +234,7 @@ public class SchemaServiceTest {
Mockito.when(schemaStore.createSchema(Mockito.anyString(), Mockito.anyString()))
.thenThrow(ApplicationException.class);
schemaService.createSchema(schReq);
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -261,8 +263,8 @@ public class SchemaServiceTest {
Mockito.when(schemaResolver.resolveSchema(Mockito.anyString())).thenReturn("{}");
Mockito.when(schemaStore.createSchema(Mockito.anyString(), Mockito.anyString())).thenReturn("{}");
Mockito.when(schemaInfoStore.createSchemaInfo(schReqPub)).thenReturn(schInfoPub);
assertEquals(SchemaStatus.PUBLISHED, schemaService.createSchema(schReqPub).getStatus());
verify(messageBus, times(1)).publishMessage(any(), anyString(), anyString());
}
......@@ -284,6 +286,7 @@ public class SchemaServiceTest {
.thenReturn(true);
Mockito.when(schemaInfoStore.isUnique(schemaId, tenantId)).thenReturn(false);
schemaService.createSchema(getMockSchemaObject_published());
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -301,6 +304,7 @@ public class SchemaServiceTest {
Mockito.when(schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo_Published_InternalScope()))
.thenReturn(latestSchema);
schemaService.createSchema(schReqBreakingChange);
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -335,8 +339,7 @@ public class SchemaServiceTest {
Mockito.when(schemaInfoStore.createSchemaInfo(mockSchReqPubInt))
.thenReturn(mockSchInfoPubInt);
assertEquals(mockSchInfoPubInt, schemaService.createSchema(mockSchReqPubInt));
schemaService.createSchema(schReqBreakingChange);
verify(messageBus, times(1)).publishMessage(any(DpsHeaders.class), anyString(), anyString());
}
@Test
......@@ -358,6 +361,7 @@ public class SchemaServiceTest {
Mockito.when(entityTypeService.checkAndRegisterEntityTypeIfNotPresent(
schReqPub.getSchemaInfo().getSchemaIdentity().getEntityType())).thenReturn(false);
schemaService.createSchema(schReqPub);
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -378,6 +382,7 @@ public class SchemaServiceTest {
Mockito.when(entityTypeService.checkAndRegisterEntityTypeIfNotPresent(
schReqPub.getSchemaInfo().getSchemaIdentity().getEntityType())).thenReturn(true);
schemaService.createSchema(schReqPub);
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -397,8 +402,8 @@ public class SchemaServiceTest {
schReqPub.getSchemaInfo().getSchemaIdentity().getSource())).thenReturn(false);
Mockito.when(entityTypeService.checkAndRegisterEntityTypeIfNotPresent(
schReqPub.getSchemaInfo().getSchemaIdentity().getEntityType())).thenReturn(true);
schemaService.createSchema(schReqPub);
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -412,6 +417,7 @@ public class SchemaServiceTest {
when(schemaInfoStore.isUnique(schemaId, "common")).thenReturn(false);
when(schemaInfoStore.isUnique(schemaId, "tenant")).thenReturn(false);
schemaService.createSchema(getMockSchemaObject_published());
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
}
@Test
......@@ -433,6 +439,7 @@ public class SchemaServiceTest {
fail("Should not succeed");
} catch (BadRequestException e) {
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
assertEquals(SchemaConstants.SCHEMA_UPDATE_EXCEPTION, e.getMessage());
} catch (Exception e) {
fail("Should not get different exception");
......@@ -457,6 +464,7 @@ public class SchemaServiceTest {
fail("Should not succeed");
} catch (BadRequestException e) {
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
assertEquals(SchemaConstants.SCHEMA_PUT_CREATE_EXCEPTION, e.getMessage());
} catch (Exception e) {
fail("Should not get different exception");
......@@ -481,6 +489,7 @@ public class SchemaServiceTest {
fail("Should not succeed");
} catch (NoSchemaFoundException e) {
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
assertEquals(SchemaConstants.INVALID_SCHEMA_UPDATE, e.getMessage());
} catch (Exception e) {
fail("Should not get different exception");
......@@ -507,6 +516,7 @@ public class SchemaServiceTest {
fail("Should not succeed");
} catch (BadRequestException e) {
verify(messageBus, times(0)).publishMessage(any(), anyString(), anyString());
assertEquals(SchemaConstants.SCHEMA_PUT_CREATE_EXCEPTION, e.getMessage());
} catch (Exception e) {
fail("Should not get different exception");
......@@ -522,6 +532,7 @@ public class SchemaServiceTest {
Mockito.when(schemaInfoStore.updateSchemaInfo(getMockSchemaObject_Development()))
.thenReturn(getMockSchemaInfo_development_status());
assertNotNull(schemaService.updateSchema(getMockSchemaObject_Development()));
verify(messageBus, times(1)).publishMessage(any(), anyString(), anyString());
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment