// Path: src/main/java/com/amazon/dtasdk/serializer/SerializationException.java
// public class SerializationException extends Exception {
//     private static final long serialVersionUID = -3095196341869438153L;
// 
//     public SerializationException(String message) {
//         super(message);
//     }
// 
//     public SerializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public SerializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/signature/Request.java
// public enum Method {
//     POST,
//     GET
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessOperationValue.java
// public enum InstantAccessOperationValue {
//     PURCHASE("Purchase"),
//     REVOKE("Revoke"),
//     GETUSERID("GetUserId"),
//     SUBSCRIPTIONGET("SubscriptionGet"),
//     SUBSCRIPTIONACTIVATE("SubscriptionActivate"),
//     SUBSCRIPTIONDEACTIVATE("SubscriptionDeactivate"),
//     SUBSCRIPTIONUPDATE("SubscriptionUpdate");
// 
//     private String apiName;
// 
//     /**
//      * @param apiName
//      *            The string representation of the operation according to the API
//      */
//     InstantAccessOperationValue(String apiName) {
//         this.apiName = apiName;
//     }
// 
//     @JsonValue
//     public String toJson() {
//         return apiName;
//     }
// 
//     @JsonCreator
//     public static InstantAccessOperationValue fromJson(String text) {
//         // ignore the case when deserializing
//         return valueOf(text.toUpperCase());
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessResponse.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
// public abstract class InstantAccessResponse<R extends Serializable> {
//     protected R response;
// 
//     public R getResponse() {
//         return response;
//     }
// 
//     public void setResponse(R response) {
//         this.response = response;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((response == null) ? 0 : response.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         }
//         if (obj == null) {
//             return false;
//         }
//         if (getClass() != obj.getClass()) {
//             return false;
//         }
//         InstantAccessResponse other = (InstantAccessResponse) obj;
//         if (response == null) {
//             if (other.response != null) {
//                 return false;
//             }
//         } else if (!response.equals(other.response)) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("response", response).toString();
//     }
// }


import java.util.Vector;
import com.amazon.dtasdk.serializer.SerializationException;
import com.amazon.dtasdk.signature.*;
import com.amazon.dtasdk.signature.Request.Method;
import com.amazon.dtasdk.base.InstantAccessOperationValue;
import com.amazon.dtasdk.base.InstantAccessResponse;
import junit.framework.Assert;
import org.easymock.EasyMock;
import org.junit.Test;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/*
 * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.amazon.dtasdk.v3.servlets;



/**
 * Test class for InstantAccessServlet.
 */

public class InstantAccessServletTest {

    private static final String RESPONSE = "OK";

    private class InstantAccessServletImpl extends InstantAccessServlet {

        private final CredentialStore store;

        public InstantAccessServletImpl(CredentialStore store) {
            this.store = store;
        }

        @Override
        public CredentialStore getCredentialStore() {
            return store;
        }

        @Override
        public InstantAccessResponse<?> processOperation(InstantAccessOperationValue instantAccessOperationValue,
                String requestBody) throws SerializationException {
            return new InstantAccessResponse<String>() {
                {
                    setResponse(RESPONSE);
                }
            };
        }
    }

    @Test
    public void testDoPost() throws SigningException, IOException {
        HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
        HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);

        CredentialStore store = new CredentialStore();
        Credential credential = new Credential("SECRETKEY", "KEYID");
        store.add(credential);

// Path: src/main/java/com/amazon/dtasdk/serializer/SerializationException.java
// public class SerializationException extends Exception {
//     private static final long serialVersionUID = -3095196341869438153L;
// 
//     public SerializationException(String message) {
//         super(message);
//     }
// 
//     public SerializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public SerializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/signature/Request.java
// public enum Method {
//     POST,
//     GET
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessOperationValue.java
// public enum InstantAccessOperationValue {
//     PURCHASE("Purchase"),
//     REVOKE("Revoke"),
//     GETUSERID("GetUserId"),
//     SUBSCRIPTIONGET("SubscriptionGet"),
//     SUBSCRIPTIONACTIVATE("SubscriptionActivate"),
//     SUBSCRIPTIONDEACTIVATE("SubscriptionDeactivate"),
//     SUBSCRIPTIONUPDATE("SubscriptionUpdate");
// 
//     private String apiName;
// 
//     /**
//      * @param apiName
//      *            The string representation of the operation according to the API
//      */
//     InstantAccessOperationValue(String apiName) {
//         this.apiName = apiName;
//     }
// 
//     @JsonValue
//     public String toJson() {
//         return apiName;
//     }
// 
//     @JsonCreator
//     public static InstantAccessOperationValue fromJson(String text) {
//         // ignore the case when deserializing
//         return valueOf(text.toUpperCase());
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessResponse.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
// public abstract class InstantAccessResponse<R extends Serializable> {
//     protected R response;
// 
//     public R getResponse() {
//         return response;
//     }
// 
//     public void setResponse(R response) {
//         this.response = response;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((response == null) ? 0 : response.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         }
//         if (obj == null) {
//             return false;
//         }
//         if (getClass() != obj.getClass()) {
//             return false;
//         }
//         InstantAccessResponse other = (InstantAccessResponse) obj;
//         if (response == null) {
//             if (other.response != null) {
//                 return false;
//             }
//         } else if (!response.equals(other.response)) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("response", response).toString();
//     }
// }


// Path: src/test/java/com/amazon/dtasdk/v3/servlets/InstantAccessServletTest.java
import java.util.Vector;
import com.amazon.dtasdk.serializer.SerializationException;
import com.amazon.dtasdk.signature.*;
import com.amazon.dtasdk.signature.Request.Method;
import com.amazon.dtasdk.base.InstantAccessOperationValue;
import com.amazon.dtasdk.base.InstantAccessResponse;
import junit.framework.Assert;
import org.easymock.EasyMock;
import org.junit.Test;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/*
 * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.amazon.dtasdk.v3.servlets;



/**
 * Test class for InstantAccessServlet.
 */

public class InstantAccessServletTest {

    private static final String RESPONSE = "OK";

    private class InstantAccessServletImpl extends InstantAccessServlet {

        private final CredentialStore store;

        public InstantAccessServletImpl(CredentialStore store) {
            this.store = store;
        }

        @Override
        public CredentialStore getCredentialStore() {
            return store;
        }

        @Override
        public InstantAccessResponse<?> processOperation(InstantAccessOperationValue instantAccessOperationValue,
                String requestBody) throws SerializationException {
            return new InstantAccessResponse<String>() {
                {
                    setResponse(RESPONSE);
                }
            };
        }
    }

    @Test
    public void testDoPost() throws SigningException, IOException {
        HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
        HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);

        CredentialStore store = new CredentialStore();
        Credential credential = new Credential("SECRETKEY", "KEYID");
        store.add(credential);

        InstantAccessServlet servlet = new InstantAccessServletImpl(store);