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

Created test class for WebSubHelper #669

Merged
merged 19 commits into from
Nov 24, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a23f0f8
CredentialStoreServiceImplTest update
vipuldhurve Nov 17, 2021
3a8ab45
CredentialStoreServiceImplTest update
vipuldhurve Nov 17, 2021
30d65de
Merge branch 'mosip:develop' into develop
vipuldhurve02 Nov 18, 2021
87ec560
Created Test class for HotlistServiceImpl: HotlistServiceImplTest
vipuldhurve Nov 22, 2021
899956d
Merge branch 'mosip:develop' into develop
vipuldhurve02 Nov 22, 2021
ae020a5
Created Test class for HotlistServiceImpl: HotlistServiceImplTest
vipuldhurve Nov 23, 2021
360b20a
Merge remote-tracking branch 'origin/develop' into develop
vipuldhurve Nov 23, 2021
90594bf
Created Test class for HotlistServiceImpl: HotlistServiceImplTest
vipuldhurve Nov 23, 2021
c50dcd1
Merge branch 'mosip:develop' into develop
vipuldhurve02 Nov 23, 2021
dfdd2bd
Created Test class for HotlistServiceImpl: HotlistServiceImplTest
vipuldhurve Nov 23, 2021
b9ce6f7
Merge remote-tracking branch 'origin/develop' into develop
vipuldhurve Nov 23, 2021
1db889e
Created Test class for HotlistServiceImpl: HotlistServiceImplTest
vipuldhurve Nov 23, 2021
51a82b1
Created Test class for HotlistServiceImpl: HotlistServiceImplTest
vipuldhurve Nov 23, 2021
94120f4
Merge branch 'mosip:develop' into develop
vipuldhurve02 Nov 23, 2021
5505a84
Merge branch 'mosip:develop' into develop
vipuldhurve02 Nov 24, 2021
d0b36ec
Created Test class for WebSubHelper: WebSubHelperTest
vipuldhurve Nov 24, 2021
2f13f3a
Merge remote-tracking branch 'origin/develop' into develop
vipuldhurve Nov 24, 2021
3b7b75d
Created Test class for WebSubHelper: WebSubHelperTest
vipuldhurve Nov 24, 2021
767f16f
Created Test class for WebSubHelper: WebSubHelperTest
vipuldhurve Nov 24, 2021
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,125 @@
package io.mosip.authentication.common.service.helper;

import io.mosip.authentication.common.service.websub.WebSubEventSubcriber;
import io.mosip.authentication.common.service.websub.WebSubEventTopicRegistrar;
import io.mosip.authentication.common.service.websub.dto.EventInterface;
import io.mosip.kernel.core.websub.spi.PublisherClient;
import io.mosip.kernel.core.websub.spi.SubscriptionClient;
import io.mosip.kernel.websub.api.model.SubscriptionChangeRequest;
import io.mosip.kernel.websub.api.model.SubscriptionChangeResponse;
import io.mosip.kernel.websub.api.model.UnsubscriptionRequest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.context.WebApplicationContext;

import java.io.IOException;
import java.util.function.Supplier;

@RunWith(SpringRunner.class)
@WebMvcTest
@ContextConfiguration(classes = {TestContext.class, WebApplicationContext.class})
public class WebSubHelperTest {

@InjectMocks
private WebSubHelper webSubHelper;

@Mock
private WebSubEventSubcriber subscriber;

@Mock
WebSubEventTopicRegistrar registrar;

@Mock
private SubscriptionClient<SubscriptionChangeRequest, UnsubscriptionRequest, SubscriptionChangeResponse> subscriptionClient;

@Mock
private EventInterface eventInterface;

@Mock
private PublisherClient<String, Object, HttpHeaders> publisher;

/**
* This class tests the initSubscriber method
*/
@Test
public void initSubscriberTest(){
webSubHelper.initSubscriber(subscriber);
Supplier<Boolean> enableTester = null;
webSubHelper.initSubscriber(subscriber, null);
Mockito.doThrow(ResourceAccessException.class).when(subscriber).subscribe(enableTester);
webSubHelper.initSubscriber(subscriber, enableTester);
}

/**
* This class tests the initRegistrar method
*/
@Test
public void initRegistrarTest(){
webSubHelper.initRegistrar(registrar);
Supplier<Boolean> enableTester=null;
webSubHelper.initRegistrar(registrar, enableTester);
Mockito.doThrow(ResourceAccessException.class).when(registrar).register(enableTester);
webSubHelper.initRegistrar(registrar);
}

@Test(expected = Exception.class)
public void initRegistrarExceptionTest(){
webSubHelper.initRegistrar(null);
}

@Test(expected = Exception.class)
public void initSubscriberExceptionTest(){
webSubHelper.initSubscriber(null);
}

/**
* This class tests the publishEvent method
*/
@Test
public <U> void publishEventTest(){
String eventTopic="eventTopic";
U eventModel = null;
webSubHelper.publishEvent(eventTopic, eventModel);
}

/**
* This class tests the createEventModel method
*/
@Test
public<T extends EventInterface, S> void createEventModelTest() {
String topic="topic";
webSubHelper.createEventModel(topic);
webSubHelper.createEventModel(topic, (T) eventInterface);
}

/**
* This class tests the registerTopic method
*/
@Test
public void registerTopicTest(){
String eventTopic = "eventTopic";
webSubHelper.registerTopic(eventTopic);
}

/**
* This class tests the subscribe method
*/
@Test
public void subscribeTest(){
SubscriptionChangeRequest subscriptionRequest= new SubscriptionChangeRequest();
SubscriptionChangeResponse subscriptionResponse=new SubscriptionChangeResponse();
Mockito.when(subscriptionClient.subscribe(subscriptionRequest)).thenReturn(subscriptionResponse);
webSubHelper.subscribe(subscriptionRequest);
}
}