package org.wso2.carbon.identity.application.authentication.framework.handler.request.impl;

import org.testng.annotations.Test;
import org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping;
import org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertEquals;


public class PostAuthnMissingClaimHandlerTest extends PostAuthnMissingClaimHandler {

    @Test(description = "This test case tests the related display names for mandatory missing claims are derived ")
    public void testCorrectDisplayNamesDeriveForMissingClaims() throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {

        List<AttributeMapping> mappedAttributes = new ArrayList<>();

        Map<String, String> localClaimProperties = new HashMap<>();
        localClaimProperties.put("Description", "Local");
        localClaimProperties.put("DisplayName", "Local");

        Map<String, String> localityClaimProperties = new HashMap<>();
        localityClaimProperties.put("Description", "Locality");
        localityClaimProperties.put("DisplayName", "Locality");

        Map<String, String> SecretKeyClaimProperties = new HashMap<>();
        SecretKeyClaimProperties.put("Description", "Claim to store the secret key");
        SecretKeyClaimProperties.put("DisplayName", "Secret Key");

        Map<String, String> countryClaimProperties = new HashMap<>();
        countryClaimProperties.put("Description", "Country");
        countryClaimProperties.put("DisplayName", "Country");

        Map<String, String> verifyEmailClaimProperties = new HashMap<>();
        verifyEmailClaimProperties.put("Description", "Temporary claim to invoke email verified feature");
        verifyEmailClaimProperties.put("DisplayName", "Verify Email");

        List<LocalClaim> localClaims = new ArrayList<>();
        LocalClaim localClaim = new LocalClaim("http://wso2.org/claims/local", mappedAttributes, localClaimProperties);
        LocalClaim localClaim2 = new LocalClaim("http://wso2.org/claims/locality", mappedAttributes, localityClaimProperties);
        LocalClaim localClaim3 = new LocalClaim("http://wso2.org/claims/identity/secretkey", mappedAttributes, SecretKeyClaimProperties);
        LocalClaim localClaim4 = new LocalClaim("http://wso2.org/claims/country", mappedAttributes, countryClaimProperties);
        LocalClaim localClaim5 = new LocalClaim("http://wso2.org/claims/identity/verifyEmail", mappedAttributes, verifyEmailClaimProperties);
        localClaims.add(localClaim);
        localClaims.add(localClaim2);
        localClaims.add(localClaim3);
        localClaims.add(localClaim4);
        localClaims.add(localClaim5);

        Map<String, String> missingClaimMap = new HashMap<>();
        missingClaimMap.put("http://wso2.org/claims/local", "http://wso2.org/claims/local");
        missingClaimMap.put("http://wso2.org/claims/country", "http://wso2.org/claims/country");
        missingClaimMap.put("http://wso2.org/claims/locality", "http://wso2.org/claims/locality");

        String relatedDisplayNames = "http://wso2.org/claims/local|Local,http://wso2.org/claims/country|Country,http://wso2.org/claims/locality|Locality";

        Class<PostAuthnMissingClaimHandler> claimDisplay = PostAuthnMissingClaimHandler.class;
        Object obj = claimDisplay.newInstance();
        Method displayName = claimDisplay.
                getDeclaredMethod("getMissingClaimsDisplayNames", Map.class, List.class);
        displayName.setAccessible(true);
        String returnedDisplayNames = (String) displayName.invoke(obj, missingClaimMap, localClaims);
        assertEquals(returnedDisplayNames, relatedDisplayNames);

    }

}
@@ -1,8 +1,649 @@
+/*%0A * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A */%0A%0A
 package 
@@ -1140,17 +1140,90 @@
 quals;%0A%0A
+/**%0A * This is a test class for %7B@link PostAuthnMissingClaimHandler%7D.%0A */
 %0A
-
 public c
@@ -1296,24 +1296,78 @@
 mHandler %7B%0A%0A
+    @SuppressWarnings(%22checkstyle:LocalVariableName%22)%0A
     @Test(de
@@ -1466,17 +1466,16 @@
  derived
- 
 %22)%0A    p
@@ -1532,16 +1532,28 @@
 Claims()
+%0A           
  throws 
@@ -2135,17 +2135,17 @@
 String%3E 
-S
+s
 ecretKey
@@ -2179,33 +2179,33 @@
 ap%3C%3E();%0A        
-S
+s
 ecretKeyClaimPro
@@ -2273,17 +2273,17 @@
         
-S
+s
 ecretKey
@@ -2991,24 +2991,40 @@
 Claim2 = new
+%0A               
  LocalClaim(
@@ -3134,24 +3134,40 @@
 Claim3 = new
+%0A               
  LocalClaim(
@@ -3229,17 +3229,17 @@
 ibutes, 
-S
+s
 ecretKey
@@ -3288,24 +3288,40 @@
 Claim4 = new
+%0A               
  LocalClaim(
@@ -3429,24 +3429,40 @@
 Claim5 = new
+%0A               
  LocalClaim(
@@ -4210,16 +4210,37 @@
 Country,
+%22 +%0A                %22
 http://w
@@ -4764,13 +4764,12 @@
 s);%0A
-%0A
     %7D%0A
-%0A
 %7D
+%0A

Resolve checkstyle errors