@@ -242,6 +242,7 @@ public Integer getPort() {
242242
243243 /** The Constant CONFIG_SERVER_URL. */
244244 private static final String CONFIG_SERVER_URL = "url" ;
245+ private static final String IDREPO_STATUS = "DRAFTED" ;
245246
246247 private String identityMappingjsonString ;
247248
@@ -2775,4 +2776,206 @@ public void testProcess_WithLostPacket_ShouldReturnNull() throws Exception {
27752776 assertNull (demographicIdentity .get ("packetCreatedOn" ));
27762777 }
27772778
2779+ @ Test
2780+ public void testProcessUinGenerationReprocessShouldSetReprocessStatus () throws IOException , PacketManagerException , ApisResourceAccessException , JsonProcessingException ,
2781+ IdrepoDraftReprocessableException , IdrepoDraftException {
2782+ List <ErrorDTO > errors = new ArrayList <>();
2783+ ErrorDTO errorDTO = new ErrorDTO ();
2784+ errorDTO .setErrorCode ("IDR-IDC-004" );
2785+ errorDTO .setMessage ("Unknown error occurred" );
2786+ errors .add (errorDTO );
2787+
2788+ MessageDTO messageDTO = new MessageDTO ();
2789+ messageDTO .setRid ("10031100110005020190313110030" );
2790+ messageDTO .setReg_type (RegistrationType .NEW .name ());
2791+ IdResponseDTO idResponseDTO = new IdResponseDTO ();
2792+ idResponseDTO .setErrors (errors );
2793+
2794+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .IDENTITY )).thenReturn (identityObj );
2795+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .DOCUMENT )).thenReturn (documentObj );
2796+ Mockito .when (registrationStatusMapperUtil
2797+ .getStatusCode (RegistrationExceptionTypeCode .PACKET_UIN_GENERATION_REPROCESS )).thenReturn (RegistrationTransactionStatusCode .REPROCESS .toString ());
2798+
2799+ when (packetManagerService .getFields (any (), any (), any (), any ())).thenReturn (new HashMap <>());
2800+ when (packetManagerService .getFieldByMappingJsonKey (anyString (), anyString (), any (), any ())).thenReturn ("0.1" );
2801+
2802+ when (idrepoDraftService .idrepoUpdateDraft (anyString (), any (), any ())).thenReturn (idResponseDTO );
2803+
2804+ MessageDTO result = uinGeneratorStage .process (messageDTO );
2805+ assertTrue (result .getInternalError ());
2806+ assertTrue (result .getIsValid ());
2807+ }
2808+
2809+ @ Test
2810+ public void testProcessUinGenerationFailedShouldSetFailedStatus () throws IOException , PacketManagerException , ApisResourceAccessException , JsonProcessingException ,
2811+ IdrepoDraftReprocessableException , IdrepoDraftException {
2812+
2813+ List <ErrorDTO > errors = new ArrayList <>();
2814+ ErrorDTO errorDTO = new ErrorDTO ();
2815+ errorDTO .setErrorCode ("IDR-IDC-005" );
2816+ errors .add (errorDTO );
2817+
2818+ MessageDTO messageDTO = new MessageDTO ();
2819+ messageDTO .setRid ("10031100110005020190313110030" );
2820+ messageDTO .setReg_type (RegistrationType .NEW .name ());
2821+ IdResponseDTO idResponseDTO = new IdResponseDTO ();
2822+ idResponseDTO .setErrors (errors );
2823+
2824+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .IDENTITY )).thenReturn (identityObj );
2825+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .DOCUMENT )).thenReturn (documentObj );
2826+ Mockito .when (registrationStatusMapperUtil
2827+ .getStatusCode (RegistrationExceptionTypeCode .PACKET_UIN_GENERATION_FAILED )).thenReturn (RegistrationTransactionStatusCode .FAILED .toString ());
2828+
2829+ when (packetManagerService .getFields (any (), any (), any (), any ())).thenReturn (new HashMap <>());
2830+ when (packetManagerService .getFieldByMappingJsonKey (anyString (), anyString (), any (), any ())).thenReturn ("0.1" );
2831+
2832+ when (idrepoDraftService .idrepoUpdateDraft (anyString (), any (), any ())).thenReturn (idResponseDTO );
2833+
2834+ MessageDTO result = uinGeneratorStage .process (messageDTO );
2835+ assertTrue (result .getInternalError ());
2836+ assertFalse (result .getIsValid ());
2837+ }
2838+
2839+ @ Test
2840+ public void testLostAndUpdateUinWhenIdRepoDraftReturnsNullShouldSetValidStatusFalse () throws Exception {
2841+ Map <String , String > fieldMap = new HashMap <>();
2842+ fieldMap .put ("UIN" , "123456" );
2843+ fieldMap .put ("name" , "mono" );
2844+ fieldMap .put ("email" , "mono@mono.com" );
2845+
2846+ List <String > defaultFields = new ArrayList <>();
2847+ defaultFields .add ("name" );
2848+ defaultFields .add ("dob" );
2849+ defaultFields .add ("gender" );
2850+ defaultFields .add ("UIN" );
2851+ when (idRepoService .getUinByRid (anyString (), anyString ())).thenReturn ("9403107397" );
2852+
2853+ when (utility .getUIn (any (),any (),any (ProviderStageName .class ))).thenReturn ("123456" );
2854+ when (packetManagerService .getFieldByMappingJsonKey (anyString (),anyString (),any (),any ())).thenReturn ("0.1" );
2855+ when (packetManagerService .getFields (anyString (),anyList (),anyString (),any ())).thenReturn (fieldMap );
2856+ when (idSchemaUtil .getDefaultFields (anyDouble ())).thenReturn (defaultFields );
2857+
2858+ when (idSchemaUtil .getDefaultFields (anyDouble ())).thenReturn (defaultFields );
2859+ MessageDTO messageDTO = new MessageDTO ();
2860+ messageDTO .setRid ("27847657360002520181210094052" );
2861+ messageDTO .setReg_type (RegistrationType .LOST .name ());
2862+ String str = "{\" id\" :\" mosip.id.read\" ,\" version\" :\" 1.0\" ,\" responsetime\" :\" 2019-04-05\" ,\" metadata\" :null,\" response\" :{\" uin\" :\" 2812936908\" },\" errors\" :[{\" errorCode\" :null,\" errorMessage\" :null}]}" ;
2863+ String response = "{\" timestamp\" :1553771083721,\" status\" :404,\" errors\" :[{\" errorCode\" :\" KER-UIG-004\" ,\" errorMessage\" :\" Given UIN is not in ISSUED status\" }]}" ;
2864+
2865+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .IDENTITY )).thenReturn (identityObj );
2866+ when (registrationProcessorRestClientService .putApi (any (), any (), any (), any (), any (), any (), any ()))
2867+ .thenReturn (response );
2868+
2869+ when (packetManagerService .getField (any (), any (), any (),any ())).thenReturn ("989879234" );
2870+
2871+ when (packetManagerService .getFieldByMappingJsonKey (any (), any (), any (), any ())).thenReturn ("1.0" );
2872+ when (regLostUinDetEntity .getLostUinMatchedRegIdByWorkflowId (any ())).thenReturn ("27847657360002520181210094052" );
2873+ MessageDTO result = uinGeneratorStage .process (messageDTO );
2874+ assertFalse (result .getInternalError ());
2875+ assertFalse (result .getIsValid ());
2876+ }
2877+
2878+ @ Test
2879+ public void testReactivateUinWhenStatusActivated () throws Exception {
2880+
2881+ Map <String , String > fieldMap = new HashMap <>();
2882+ fieldMap .put ("UIN" , "123456" );
2883+ fieldMap .put ("name" , "mono" );
2884+ fieldMap .put ("email" , "mono@mono.com" );
2885+
2886+ List <String > defaultFields = new ArrayList <>();
2887+ defaultFields .add ("name" );
2888+ defaultFields .add ("dob" );
2889+ defaultFields .add ("gender" );
2890+ defaultFields .add ("UIN" );
2891+
2892+ when (utility .getUIn (any (),any (),any (ProviderStageName .class ))).thenReturn ("123456" );
2893+ when (packetManagerService .getFieldByMappingJsonKey (anyString (),anyString (),any (),any ())).thenReturn ("0.1" );
2894+ when (packetManagerService .getFields (any (), any (), any (), any ())).thenReturn (fieldMap );
2895+ when (idSchemaUtil .getDefaultFields (anyDouble ())).thenReturn (defaultFields );
2896+
2897+ when (idSchemaUtil .getDefaultFields (anyDouble ())).thenReturn (defaultFields );
2898+
2899+ MessageDTO messageDTO = new MessageDTO ();
2900+ messageDTO .setRid ("27847657360002520181210094052" );
2901+ messageDTO .setReg_type (RegistrationType .valueOf ("ACTIVATED" ).name ());
2902+
2903+ IdResponseDTO idResponseDTO = new IdResponseDTO ();
2904+ ResponseDTO responseDTO = new ResponseDTO ();
2905+ idResponseDTO .setErrors (null );
2906+ idResponseDTO .setId ("mosip.id.update" );
2907+ responseDTO .setStatus (io .mosip .registration .processor .status .code .RegistrationType .ACTIVATED .toString ());
2908+ idResponseDTO .setResponse (responseDTO );
2909+ idResponseDTO .setResponsetime ("2019-01-17T06:29:01.940Z" );
2910+ idResponseDTO .setVersion ("1.0" );
2911+
2912+ IdResponseDTO idResponseDTO1 = new IdResponseDTO ();
2913+ ResponseDTO responseDTO1 = new ResponseDTO ();
2914+ idResponseDTO1 .setErrors (null );
2915+ idResponseDTO1 .setId ("mosip.id.update" );
2916+ responseDTO1 .setStatus ("DEACTIVATED" );
2917+ idResponseDTO1 .setResponse (responseDTO1 );
2918+ idResponseDTO1 .setResponsetime ("2019-01-17T06:29:01.940Z" );
2919+ idResponseDTO1 .setVersion ("1.0" );
2920+
2921+ when (registrationProcessorRestClientService .getApi (any (), any (), anyString (), any (), any ()))
2922+ .thenReturn (idResponseDTO1 );
2923+
2924+ when (idrepoDraftService .idrepoUpdateDraft (anyString (), any (), any ())).thenReturn (idResponseDTO );
2925+ when (registrationProcessorRestClientService .patchApi (any (), any (), any (), any (), any (), any ()))
2926+ .thenReturn (idResponseDTO1 );
2927+ MessageDTO result = uinGeneratorStage .process (messageDTO );
2928+ assertTrue (result .getIsValid ());
2929+ assertFalse (result .getInternalError ());
2930+ }
2931+
2932+ @ Test
2933+ public void testUinUpdateWhenIdRepoStatusDraftedShouldReturnTrue () throws ApisResourceAccessException , IOException , JsonProcessingException ,
2934+ PacketManagerException , JSONException , IdrepoDraftException , IdrepoDraftReprocessableException {
2935+ Map <String , String > fieldMap = new HashMap <>();
2936+ fieldMap .put ("UIN" , "123456" );
2937+ fieldMap .put ("name" , "mono" );
2938+ fieldMap .put ("email" , "mono@mono.com" );
2939+
2940+ List <String > defaultFields = new ArrayList <>();
2941+ defaultFields .add ("name" );
2942+ defaultFields .add ("dob" );
2943+ defaultFields .add ("gender" );
2944+ defaultFields .add ("UIN" );
2945+
2946+ when (utility .getUIn (any (),any (),any (ProviderStageName .class ))).thenReturn ("123456" );
2947+ when (packetManagerService .getFields (any (), any (), any (), any ())).thenReturn (fieldMap );
2948+
2949+ when (packetManagerService .getFieldByMappingJsonKey (anyString (),anyString (),any (),any ())).thenReturn ("0.1" );
2950+ when (packetManagerService .getFields (anyString (),anyList (),anyString (),any ())).thenReturn (fieldMap );
2951+ when (idSchemaUtil .getDefaultFields (anyDouble ())).thenReturn (defaultFields );
2952+
2953+ when (idSchemaUtil .getDefaultFields (anyDouble ())).thenReturn (defaultFields );
2954+ MessageDTO messageDTO = new MessageDTO ();
2955+ messageDTO .setRid ("10031100110005020190313110030" );
2956+ messageDTO .setReg_type (RegistrationType .valueOf ("UPDATE" ).name ());
2957+ IdResponseDTO responsedto = new IdResponseDTO ();
2958+
2959+ IdResponseDTO idResponseDTO = new IdResponseDTO ();
2960+ ResponseDTO responseDTO = new ResponseDTO ();
2961+ idResponseDTO .setErrors (null );
2962+ idResponseDTO .setId ("mosip.id.update" );
2963+ responseDTO .setStatus (IDREPO_STATUS );
2964+ idResponseDTO .setResponse (responseDTO );
2965+ idResponseDTO .setResponsetime ("2019-03-12T06:49:30.779Z" );
2966+ idResponseDTO .setVersion ("1.0" );
2967+
2968+ when (idrepoDraftService .idrepoUpdateDraft (anyString (), any (), any ())).thenReturn (idResponseDTO );
2969+ when (registrationProcessorRestClientService .getApi (any (), any (), anyString (), any (), any ()))
2970+ .thenReturn (responsedto );
2971+ when (registrationProcessorRestClientService .patchApi (any (), any (), any (), any (), any (), any ()))
2972+ .thenReturn (idResponseDTO );
2973+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .IDENTITY )).thenReturn (identityObj );
2974+ when (utilities .getRegistrationProcessorMappingJson (MappingJsonConstants .DOCUMENT )).thenReturn (documentObj );
2975+
2976+ MessageDTO result = uinGeneratorStage .process (messageDTO );
2977+ assertTrue (result .getIsValid ());
2978+ assertFalse (result .getInternalError ());
2979+ }
2980+
27782981}
0 commit comments