-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test case for VCITransactionHelper.class and AuthTransactionHel…
…per.class (#1114)
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...st/java/io/mosip/authentication/esignet/integration/helper/AuthTransactionHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.mosip.authentication.esignet.integration.helper; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.mosip.esignet.core.dto.ResponseWrapper; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.web.client.RestTemplate; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class AuthTransactionHelperTest { | ||
|
||
@Mock | ||
ObjectMapper objectMapper; | ||
|
||
@Mock | ||
RestTemplate restTemplate; | ||
|
||
@InjectMocks | ||
AuthTransactionHelper authTransactionHelper; | ||
|
||
@Test | ||
public void GetAuthTokenWithValidDetails_thenPass() throws Exception { | ||
ReflectionTestUtils.setField(authTransactionHelper, "authTokenUrl", "test"); | ||
ReflectionTestUtils.setField(authTransactionHelper, "clientId", "test"); | ||
ReflectionTestUtils.setField(authTransactionHelper,"secretKey","test"); | ||
ReflectionTestUtils.setField(authTransactionHelper,"appId","test"); String expectedAuthToken = "testAuthToken"; | ||
|
||
ResponseEntity<ResponseWrapper> responseEntity = ResponseEntity.ok() | ||
.header("authorization", expectedAuthToken) | ||
.build(); | ||
|
||
when(restTemplate.exchange(Mockito.any(RequestEntity.class), Mockito.any(ParameterizedTypeReference.class))) | ||
.thenReturn(responseEntity); | ||
|
||
String authToken = authTransactionHelper.getAuthToken(); | ||
Assert.assertEquals(expectedAuthToken, authToken); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...est/java/io/mosip/authentication/esignet/integration/helper/VCITransactionHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.mosip.authentication.esignet.integration.helper; | ||
|
||
import io.mosip.esignet.core.dto.OIDCTransaction; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.cache.Cache; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.support.NoOpCache; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class VCITransactionHelperTest { | ||
|
||
@Mock | ||
CacheManager cacheManager; | ||
|
||
@Mock | ||
Cache cache=new NoOpCache("test"); | ||
|
||
@InjectMocks | ||
VCITransactionHelper vciTransactionHelper; | ||
|
||
@Test | ||
public void getOAuthTransactionWithValidDetails_thenPass() throws Exception { | ||
ReflectionTestUtils.setField(vciTransactionHelper, "userinfoCache", "test"); | ||
OIDCTransaction oidcTransaction = new OIDCTransaction(); | ||
oidcTransaction.setTransactionId("test"); | ||
Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(cache); | ||
Mockito.when(cache.get("test",OIDCTransaction.class)).thenReturn(oidcTransaction); | ||
vciTransactionHelper.getOAuthTransaction("test"); | ||
|
||
} | ||
|
||
@Test | ||
public void getOAuthTransactionWithInValidDetails_thenFail() { | ||
try{ | ||
vciTransactionHelper.getOAuthTransaction("test"); | ||
}catch (Exception e){ | ||
assert(e.getMessage().equals("cache_missing")); | ||
} | ||
|
||
|
||
} | ||
|
||
} |