Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1230

Closed
wants to merge 5 commits into from
Closed

Develop #1230

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package TestNotificationServiceTest;
import org.mockito.Mockito;
import org.openelisglobal.notification.dao.AnalysisNotificationConfigDAO;
import org.openelisglobal.notification.dao.NotificationPayloadTemplateDAO;
import org.openelisglobal.notification.service.AnalysisNotificationConfigService;
import org.openelisglobal.notification.service.AnalysisNotificationConfigServiceImpl;
import org.openelisglobal.notification.service.NotificationPayloadTemplateService;
import org.openelisglobal.notification.service.NotificationPayloadTemplateServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class TestNotificationServiceConfig {
@Bean
public AnalysisNotificationConfigService analysisNotificationConfigService() {
return Mockito.mock(AnalysisNotificationConfigServiceImpl.class);
}

@Bean
public AnalysisNotificationConfigDAO analysisNotificationConfigDAO() {
return Mockito.mock(AnalysisNotificationConfigDAO.class);
}

@Bean
public NotificationPayloadTemplateService notificationPayloadTemplateService() {
return Mockito.mock(NotificationPayloadTemplateServiceImpl.class);
}

@Bean
public NotificationPayloadTemplateDAO notificationPayloadTemplateDAO() {
return Mockito.mock(NotificationPayloadTemplateDAO.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package TestNotificationServiceTest;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openelisglobal.BaseTestConfig;
import org.openelisglobal.notification.service.TestNotificationService;
import org.openelisglobal.notification.valueholder.TestNotificationConfig;
import org.openelisglobal.result.valueholder.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.mockito.Mockito.when;
import org.openelisglobal.notification.valueholder.notificationature;
import org.openelisglobal.notification.valueholder.NotificationConfigOption;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { BaseTestConfig.class, TestNotificationService.class })
@TestPropertySource("classpath:common.properties")
@ActiveProfiles("test")

public class TestNotificationServiceImplIntegrationTest {
@Autowired
private
TestNotificationService TestNotificationService;

@Before
public void init() throws Exception {
}

@Test
public void testCreateAndSendNotificationsToConfiguredSources() {
// Create a sample Result object
Result result = new Result();
result.setAnalysisId("sampleAnalysisId"); // Set analysis ID
result.setTestId("sampleTestId"); // Set test ID
result.setResultValue = new TestResult();
// Set properties of the Result object as needed for the test

// Mock the behavior of testNotificationConfigService to return a predefined TestNotificationConfig
TestNotificationConfig testNotificationConfig = new TestNotificationConfig();
// Set properties of the TestNotificationConfig object as needed for the test
when(TestNotificationServiceConfig.getTestNotificationConfigForTestId("yourTestId"))
.thenReturn(Optional.of(testNotificationConfig));

// Call the method being tested
TestNotificationService.createAndSendNotificationsToConfiguredSources(NotificationConfigOption.NotificationNature.RESULT_VALIDATION, result);
// Perform assertions as needed
Notification notification = // Retrieve the notification from somewhere (e.g., database, service)
Assert.assertTrue(notification.isSent());

}

public org.openelisglobal.notification.service.TestNotificationService getTestNotificationService() {
return TestNotificationService;
}

public void setTestNotificationService(org.openelisglobal.notification.service.TestNotificationService testNotificationService) {
TestNotificationService = testNotificationService;
}

// You can add more integration test methods for other functionalities
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.openelisglobal.TestNotificationServiceTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openelisglobal.BaseTestConfig;
import org.openelisglobal.BaseWebContextSensitiveTest;
import org.openelisglobal.analysis.valueholder.Analysis;
import org.openelisglobal.notification.service.TestNotificationServiceImpl;
import org.openelisglobal.result.valueholder.Result;
import org.openelisglobal.notification.valueholder.NotificationConfigOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { BaseTestConfig.class })
@TestPropertySource("classpath:common.properties")
@ActiveProfiles("test")
public class NotificationServiceTest extends BaseWebContextSensitiveTest {

@Autowired
private TestNotificationServiceImpl testNotificationService;

@Before
public void init() throws Exception {
super.setUp();
}

@Test
public void testCreateAndSendNotificationsToConfiguredSources() {
Result result = new Result();
result.setId("sampleResultId");
result.setValue("sampleValue");

Analysis analysis = new Analysis();
analysis.setId("sampleAnalysisId");
result.setAnalysis(analysis);

result.setResultType("sampleResultType");
result.setSortOrder("1");

testNotificationService.createAndSendNotificationsToConfiguredSources(
NotificationConfigOption.NotificationNature.RESULT_VALIDATION, result);

// Add more assertions as needed
}
}
Loading