All Downloads are FREE. Search and download functionalities are using the official Maven repository.

atg.servlet.MockDynamoHttpServletRequest Maven / Gradle / Ivy

Go to download

ATG DUST is a framework for building JUnit tests for applications built on the ATG Dynamo platform. This framework allows one to quickly write test code that depends up Nucleus or ATG Repositories. By using this framework one can drastically cut down on development time. It takes only a few seconds to start up a test with a repository, but it may take multiple minutes to start up an application server. To get started with DUST, take a look at http://atgdust.sourceforge.net/first-test.html. This page will walk you through the process of running a basic test which starts Nucleus. After that, read the other getting started guides to describe how to create standalone Junit tests which can startup repositories and use the DynamoHttpServletResponse classes. For only ATG10 and tested.

The newest version!
/**
 * Copyright 2007 ATG DUST Project
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License 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 atg.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import atg.nucleus.naming.ParameterName;

/**
 * Mock DynamoHttpServletRequest object
 * @author robert
 * @deprecated Instead use atg.servlet.ServletTestUtils.createDynamoRequest()
 * 
 */
public class MockDynamoHttpServletRequest extends DynamoHttpServletRequest {

  private final Map cookieParameters = new HashMap(),
      headers = new HashMap();

  private final Map parameters = new HashMap(),
      components = new HashMap(),
      attributes = new HashMap();

  private final List serviceParameters = new ArrayList(),
      servicedLocalParameter = new ArrayList();

  public MockDynamoHttpServletRequest() {
    super();
  }

  @Override
  public String encodeURL(String str) {
    return str + ";sessionId=" + System.currentTimeMillis();
  }

  @Override
  public Object getAttribute(String attribute) {
    return attributes.get(attribute);
  }

  @Override
  @SuppressWarnings("unchecked")
  public Enumeration getAttributeNames() {

    // Cheesy way converting an iterator to an enumeration
    final Properties properties = new Properties();
    for (final Iterator it = attributes.keySet().iterator(); it
        .hasNext();) {
      final String s = it.next();
      properties.put(s, s);
    }
    return properties.elements();
  }

  @Override
  public String getCookieParameter(String parameter) {
    return cookieParameters.get(parameter);
  }

  @Override
  public String getHeader(String param) {
    return (String) headers.get(param);
  }

  @Override
  public Object getLocalParameter(String name) {
    return parameters.get(name);
  }

  @Override
  public Object getObjectParameter(ParameterName name) {
    return getObjectParameter(name.getName());
  }

  @Override
  public Object getObjectParameter(String name) {
    return parameters.get(name);
  }

  @Override
  public String getParameter(String name) {
    return (String) parameters.get(name);
  }

  public List getServiceParameters() {
    return serviceParameters;
  }

  @Override
  public void removeAttribute(String name) {
    attributes.remove(name);
  }

  @Override
  public boolean serviceLocalParameter(String name, ServletRequest request,
      ServletResponse response) throws ServletException, IOException {
    servicedLocalParameter.add(name);
    return true;
  }

  @Override
  public boolean serviceParameter(String name, ServletRequest request,
      ServletResponse response) throws ServletException, IOException {
    serviceParameters.add(name);
    return serviceParameter(name, request, response, null, null);
  }

  @Override
  public void setAttribute(String name, Object value) {
    attributes.put(name, value);
  }

  public void setCookieParameter(String name, String value) {
    cookieParameters.put(name, value);
  }

  public void setHeaders(String name, String value) {
    headers.put(name, value);
  }

  public void setInputParameter(ParameterName name, Object value) {
    setInputParameter(name.getName(), value);
  }

  public void setInputParameter(String name, Object value) {
    parameters.put(name, value);
  }

  public void setNamedParameter(String name, Object value) {
    components.put(name, value);
  }

  public void setParameter(String key, Object value) {
    parameters.put(key, value);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy