package lv.ctco.cukes.oauth;

import lv.ctco.cukes.core.internal.context.GlobalWorldFacade;

import java.util.HashMap;
import java.util.Map;

public enum GrantType {

    client_credentials,
    password(OAuthCukesConstants.USER_NAME, OAuthCukesConstants.PASSWORD);

    private static final Map<String, String> attributeNameMapping = new HashMap<>();
    static {
        attributeNameMapping.put("username", OAuthCukesConstants.USER_NAME);
        attributeNameMapping.put("password", OAuthCukesConstants.PASSWORD);
    }

    private String[] requiredAttributes;

    GrantType(String... requiredAttributes) {
        this.requiredAttributes = requiredAttributes;
    }

    public Map<String, String> getParameters(GlobalWorldFacade world) {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("grant_type", name());
        for (String attribute : requiredAttributes) {
            parameters.put(attributeNameMapping.get(attribute), world.getOrThrow(attribute));
        }
        return parameters;
    }
}

@@ -395,20 +395,8 @@
 put(
-%22username%22, 
 OAut
@@ -420,16 +420,28 @@
 SER_NAME
+, %22username%22
 );%0A     
@@ -472,20 +472,8 @@
 put(
-%22password%22, 
 OAut
@@ -496,16 +496,28 @@
 PASSWORD
+, %22password%22
 );%0A    %7D

Fix issue with "password" grant type, fix map order